- 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:
2024-03-21 13:25:06 +01:00
parent 1d16fcb73f
commit e93c08f81f
9 changed files with 201 additions and 90 deletions

View File

@@ -5,25 +5,30 @@ import (
. "openquell/config"
)
// FIXME: make available everywhere
// Check a collision on the grid. We check if the entity in question
// bumps into the egde of the grid or if it bumps onto a solid wall
// tile. For both cases the user must provide responder funcs in which
// it must be implemented how to react on those events.
func (grid *Grid) CheckGridCollision(
playerposition *components.Position,
velocity *components.Velocity) {
position *components.Position,
velocity *components.Velocity,
respond_edge func(*components.Position, *components.Velocity, *components.Position),
respond_solid func(*components.Position, *components.Velocity, *components.Position),
) {
if velocity.Moving() {
ok, newpos := grid.BumpEdge(playerposition, velocity)
ok, newpos := grid.BumpEdge(position, velocity)
if ok {
//slog.Debug("falling off the edge", "newpos", newpos)
playerposition.Set(newpos)
respond_edge(position, velocity, newpos)
} else {
ok, tilepos := grid.GetSolidNeighborPosition(playerposition, velocity, true)
ok, tilepos := grid.GetSolidNeighborPosition(position, velocity, true)
if ok {
// slog.Debug("HaveSolidNeighbor", "ok", ok, "tilepos",
// tilepos.Point(), "playerpos", playerposition)
intersects, newpos := tilepos.Intersects(playerposition, velocity)
intersects, newpos := tilepos.Intersects(position, velocity)
if intersects {
playerposition.Set(newpos)
velocity.Change(Stop)
respond_solid(position, velocity, newpos)
}
}
}