fixes:
- using 1 func for grid collision checking with func arguments in player and obstacle systems. - moving obstacles now kill player if business ends points toward him on contact - added retry in popup menu
This commit is contained in:
@@ -30,6 +30,23 @@ func NewObstacleSystem(world *ecs.World, gridcontainer *grid.GridContainer) Syst
|
||||
return system
|
||||
}
|
||||
|
||||
func ObstacleBumpEdgeResponder(
|
||||
pos *components.Position,
|
||||
vel *components.Velocity,
|
||||
newpos *components.Position) {
|
||||
|
||||
pos.Set(newpos)
|
||||
}
|
||||
|
||||
func ObstacleBumpWallResponder(
|
||||
pos *components.Position,
|
||||
vel *components.Velocity,
|
||||
newpos *components.Position) {
|
||||
|
||||
pos.Set(newpos)
|
||||
vel.ResetDirectionAndStop()
|
||||
}
|
||||
|
||||
func (system *ObstacleSystem) Update() error {
|
||||
observer := observers.GetGameObserver(system.World)
|
||||
|
||||
@@ -58,16 +75,15 @@ func (system *ObstacleSystem) Update() error {
|
||||
|
||||
ok, newpos := obsposition.Intersects(playerposition, playervelocity)
|
||||
if ok {
|
||||
// slog.Debug("bumped into obstacle", "obstacle", obstacle)
|
||||
|
||||
if CheckObstacleSide(playervelocity, obsvelocity.Direction) {
|
||||
if CheckObstacleSide(playervelocity, obsvelocity) {
|
||||
// player died
|
||||
EntitiesToRemove = append(EntitiesToRemove, player)
|
||||
} else {
|
||||
// bumped into nonlethal obstacle side, stop the
|
||||
// player, set the obstacle in motion, if possible
|
||||
//slog.Debug("bump not die", "originalpos", playerposition, "newpos", newpos, "obspos", obsposition)
|
||||
//slog.Debug("bump not die", "playervelo", playervelocity)
|
||||
obsvelocity.Set(playervelocity)
|
||||
//slog.Debug("bump not die", "obsvelo", obsvelocity)
|
||||
playervelocity.Change(Stop)
|
||||
playerposition.Set(newpos)
|
||||
}
|
||||
@@ -91,29 +107,12 @@ func (system *ObstacleSystem) Update() error {
|
||||
}
|
||||
}
|
||||
|
||||
//system.GridContainer.Grid.CheckGridCollision(obsposition, obsvelocity)
|
||||
// FIXME: this is the same loop as in player_system, unite the
|
||||
// two, just iterate over all entities with pos,vel,render, dammit
|
||||
// check if [moving] obstacle collides with walls or edges
|
||||
system.GridContainer.Grid.CheckGridCollision(
|
||||
obsposition, obsvelocity, ObstacleBumpEdgeResponder, ObstacleBumpWallResponder)
|
||||
|
||||
if obsvelocity.Moving() {
|
||||
ok, newpos := system.GridContainer.Grid.BumpEdge(obsposition, obsvelocity)
|
||||
if ok {
|
||||
//slog.Debug("falling off the edge", "newpos", newpos)
|
||||
obsposition.Set(newpos)
|
||||
} else {
|
||||
ok, tilepos := system.GridContainer.Grid.GetSolidNeighborPosition(obsposition, obsvelocity, true)
|
||||
if ok {
|
||||
intersects, newpos := tilepos.Intersects(obsposition, obsvelocity)
|
||||
if intersects {
|
||||
// slog.Debug("collision with foreign obstacle detected", "tile",
|
||||
// tilepos, "obs", obsposition, "new", newpos)
|
||||
|
||||
obsposition.Set(newpos)
|
||||
obsvelocity.ResetDirectionAndStop()
|
||||
}
|
||||
}
|
||||
|
||||
obsposition.Move(obsvelocity)
|
||||
}
|
||||
obsposition.Move(obsvelocity)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,13 +151,14 @@ func (system *ObstacleSystem) Draw(screen *ebiten.Image) {
|
||||
}
|
||||
|
||||
// return true if obstacle weapon points into the direction the player is moving
|
||||
func CheckObstacleSide(playervelocity *Velocity, obsdirection int) bool {
|
||||
// OR if the weapon points towards a non-moving player
|
||||
func CheckObstacleSide(playervelocity *Velocity, obsvelocity *Velocity) bool {
|
||||
movingdirection := playervelocity.InvertDirection()
|
||||
|
||||
if movingdirection == Stop || movingdirection == obsdirection {
|
||||
if movingdirection == Stop || movingdirection == obsvelocity.PointingAt {
|
||||
slog.Debug("Damaging obstacle collision",
|
||||
"playerdirection", util.DirectionStr(playervelocity.Direction),
|
||||
"obsdirection", util.DirectionStr(obsdirection),
|
||||
"obsdirection", util.DirectionStr(obsvelocity.PointingAt),
|
||||
"movingdirection", util.DirectionStr(movingdirection),
|
||||
)
|
||||
return true
|
||||
|
||||
@@ -33,6 +33,23 @@ func NewPlayerSystem(world *ecs.World, gridcontainer *grid.GridContainer, width,
|
||||
return system
|
||||
}
|
||||
|
||||
func PlayerBumpEdgeResponder(
|
||||
pos *components.Position,
|
||||
vel *components.Velocity,
|
||||
newpos *components.Position) {
|
||||
|
||||
pos.Set(newpos)
|
||||
}
|
||||
|
||||
func PlayerBumpWallResponder(
|
||||
pos *components.Position,
|
||||
vel *components.Velocity,
|
||||
newpos *components.Position) {
|
||||
|
||||
pos.Set(newpos)
|
||||
vel.Change(Stop)
|
||||
}
|
||||
|
||||
func (system PlayerSystem) Update() error {
|
||||
var EntitiesToRemove []ecs.Entity
|
||||
|
||||
@@ -54,7 +71,8 @@ func (system PlayerSystem) Update() error {
|
||||
system.CheckMovement(playerposition, velocity, player)
|
||||
|
||||
// check if player collides with walls or edges
|
||||
system.CheckGridCollision(playerposition, velocity)
|
||||
system.GridContainer.Grid.CheckGridCollision(
|
||||
playerposition, velocity, PlayerBumpEdgeResponder, PlayerBumpWallResponder)
|
||||
|
||||
if count > 1 {
|
||||
// check if player collides with another player, fuse them if any
|
||||
@@ -175,30 +193,6 @@ func (system *PlayerSystem) CheckMovement(
|
||||
}
|
||||
}
|
||||
|
||||
func (system *PlayerSystem) CheckGridCollision(
|
||||
playerposition *components.Position,
|
||||
velocity *components.Velocity) {
|
||||
|
||||
if velocity.Moving() {
|
||||
ok, newpos := system.GridContainer.Grid.BumpEdge(playerposition, velocity)
|
||||
if ok {
|
||||
//slog.Debug("falling off the edge", "newpos", newpos)
|
||||
playerposition.Set(newpos)
|
||||
} else {
|
||||
ok, tilepos := system.GridContainer.Grid.GetSolidNeighborPosition(playerposition, velocity, true)
|
||||
if ok {
|
||||
// slog.Debug("HaveSolidNeighbor", "ok", ok, "tilepos",
|
||||
// tilepos.Point(), "playerpos", playerposition)
|
||||
intersects, newpos := tilepos.Intersects(playerposition, velocity)
|
||||
if intersects {
|
||||
playerposition.Set(newpos)
|
||||
velocity.Change(Stop)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (system *PlayerSystem) CheckPlayerCollision(
|
||||
position *components.Position,
|
||||
velocity *components.Velocity,
|
||||
|
||||
Reference in New Issue
Block a user