fixed snap in bug, started with space themed sprites

This commit is contained in:
2024-04-12 15:08:40 +02:00
parent f23bdaf121
commit a84b8b58e1
7 changed files with 148 additions and 29 deletions

View File

@@ -1,6 +1,7 @@
package systems
import (
"fmt"
"log/slog"
"openquell/components"
. "openquell/components"
@@ -9,6 +10,7 @@ import (
"openquell/observers"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/mlange-42/arche/ecs"
"github.com/mlange-42/arche/generic"
@@ -46,6 +48,7 @@ func PlayerBumpWallResponder(
vel *components.Velocity,
newpos *components.Position) {
slog.Debug("(2) PlayerBumpWallResponder", "old", pos.String(), "new", newpos.String())
pos.Set(newpos)
vel.Change(Stop)
}
@@ -67,12 +70,16 @@ func (system PlayerSystem) Update() error {
continue
}
// check if the user alters or initiates movement
// check if the user alters or initiates movement, only
// changes player direction
system.CheckMovement(playerposition, velocity, player)
// check if player collides with walls or edges
system.GridContainer.Grid.CheckGridCollision(
playerposition, velocity, PlayerBumpEdgeResponder, PlayerBumpWallResponder)
if velocity.Moving() {
slog.Debug("(2) checking grid collision")
system.GridContainer.Grid.CheckGridCollision(
playerposition, velocity, PlayerBumpEdgeResponder, PlayerBumpWallResponder)
}
if count > 1 {
// check if player collides with another player, fuse them if any
@@ -99,7 +106,11 @@ func (system PlayerSystem) Update() error {
query = system.Selector.Query(system.World)
for query.Next() {
playerposition, velocity, _, _ := query.Get()
playerposition.Move(velocity)
oldpos := playerposition.String()
if velocity.Moving() {
playerposition.Move(velocity)
slog.Debug("(4) moving player", "old", oldpos, "new", playerposition.String())
}
}
// we may have lost players, remove them here
@@ -124,6 +135,8 @@ func (system *PlayerSystem) Draw(screen *ebiten.Image) {
op.GeoM.Translate(float64(pos.X), float64(pos.Y))
screen.DrawImage(sprite.Image, op)
ebitenutil.DebugPrintAt(screen, pos.String(), pos.X, pos.Y) // print player pos
}
}
@@ -196,6 +209,9 @@ func (system *PlayerSystem) CheckMovement(
player.LoopCount = 0
observer.AddMove()
}
} else {
fmt.Println("------------------------")
slog.Debug("(1) player is at", "current", position.String())
}
}