fixed snap in bug, started with space themed sprites
This commit is contained in:
@@ -3,6 +3,8 @@ package grid
|
||||
import (
|
||||
"openquell/components"
|
||||
. "openquell/config"
|
||||
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
// Check a collision on the grid. We check if the entity in question
|
||||
@@ -24,8 +26,8 @@ func (grid *Grid) CheckGridCollision(
|
||||
} else {
|
||||
ok, tilepos := grid.GetSolidNeighborPosition(position, velocity, true)
|
||||
if ok {
|
||||
// slog.Debug("HaveSolidNeighbor", "ok", ok, "tilepos",
|
||||
// tilepos.Point(), "playerpos", playerposition)
|
||||
slog.Debug("(3) HaveSolidNeighbor", "tilepos",
|
||||
tilepos.String(), "playpos", position.String())
|
||||
intersects, newpos := tilepos.Intersects(position, velocity)
|
||||
if intersects {
|
||||
respond_solid(position, velocity, newpos)
|
||||
@@ -44,6 +46,66 @@ func (grid *Grid) GetSolidNeighborPosition(
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// set to true if we are already on the last tile in the current
|
||||
// direction, i.e. on the edge of the grid
|
||||
edge := true
|
||||
moving := position.GetMoved(velocity)
|
||||
|
||||
neighborpos := position.Point()
|
||||
if velocity.Direction == East || velocity.Direction == South {
|
||||
// FIXES snapin to down+right, but now top+left fail. Only in
|
||||
// these cases we need to look at the neighbor in the future
|
||||
// position where we will be when we move forward. I don't
|
||||
// know why it is like this, in fact it doesn't really make
|
||||
// any sense. But it works, so I'll keep it that way for the
|
||||
// moment.
|
||||
neighborpos = moving.Point()
|
||||
}
|
||||
|
||||
switch velocity.Direction {
|
||||
case East:
|
||||
if neighborpos.X < grid.TilesX {
|
||||
neighborpos.X++
|
||||
edge = false
|
||||
}
|
||||
case West:
|
||||
if neighborpos.X > 0 {
|
||||
neighborpos.X--
|
||||
edge = false
|
||||
}
|
||||
case South:
|
||||
if neighborpos.Y < grid.TilesY {
|
||||
neighborpos.Y++
|
||||
edge = false
|
||||
}
|
||||
case North:
|
||||
if neighborpos.Y > 0 {
|
||||
neighborpos.Y--
|
||||
edge = false
|
||||
}
|
||||
}
|
||||
|
||||
newpos := components.NewPosition(neighborpos, grid.Tilesize)
|
||||
|
||||
slog.Debug("SolidNeighbor?", "player", position.Point(),
|
||||
"neighbor", neighborpos, "edge", edge, "neighbor-solid",
|
||||
grid.Map[neighborpos].Solid, "newpos", newpos.Point())
|
||||
if !edge && grid.Map[neighborpos].Solid {
|
||||
return true, newpos
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (grid *Grid) OrigGetSolidNeighborPosition(
|
||||
position *components.Position,
|
||||
velocity *components.Velocity,
|
||||
solid bool) (bool, *components.Position) {
|
||||
|
||||
if !solid {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// set to true if we are already on the last tile in the current
|
||||
// direction, i.e. on the edge of the grid
|
||||
edge := true
|
||||
@@ -74,9 +136,9 @@ func (grid *Grid) GetSolidNeighborPosition(
|
||||
|
||||
newpos := components.NewPosition(neighborpos, grid.Tilesize)
|
||||
|
||||
// slog.Debug("SolidNeighbor?", "player", position.Point(),
|
||||
// "neighbor", neighborpos, "edge", edge, "neighbor-solid",
|
||||
// grid.Map[neighborpos].Solid, "newpos", newpos.Point())
|
||||
slog.Debug("SolidNeighbor?", "player", position.Point(),
|
||||
"neighbor", neighborpos, "edge", edge, "neighbor-solid",
|
||||
grid.Map[neighborpos].Solid, "newpos", newpos.Point())
|
||||
if !edge && grid.Map[neighborpos].Solid {
|
||||
return true, newpos
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user