add moving animation support, fix debug printing

This commit is contained in:
Thomas von Dein 2024-04-16 17:46:53 +02:00
parent f2f134fddb
commit b7383f065f
7 changed files with 37 additions and 9 deletions

View File

@ -15,11 +15,10 @@
- Add player collision animation
- Create pixel art ui elements (button, list things) and ui borders/backgrounds
Replace HUD with pixel art variant
- Modify font and font color matching the palette
- Replace HUD with pixel art variant
- On game start respond to any key (ebitengine-input has an anykey func)
- Switch to use https://github.com/quasilyte/ebitengine-input

View File

@ -18,6 +18,7 @@ type TileAnimation struct {
OnCollision bool // wether to animate a collision
OnDestruction bool // wether to animate destruction
OnIdle bool // wether to animate during idling
OnMoving bool // wether to animate during moving
CollisionSheet AnimationSet // an entry in assets.Animations[name]
DestructionSheet AnimationSet

View File

@ -71,6 +71,15 @@ func (position *Position) String() string {
)
}
func (position *Position) SmallString() string {
return fmt.Sprintf("%d,%d\n%d,%d",
position.X/32,
position.Y/32,
position.X,
position.Y,
)
}
func (position *Position) Move(velocity *Velocity) {
// if velocity.Direction != 0 {
// slog.Debug("moving", "velocity", velocity, "speed", speed)

View File

@ -35,6 +35,7 @@ type Renderable struct {
DestructionAnimate Animation
IdleAnimate Animation
CollisionAnimate Animation
MovingAnimate Animation
Hidden bool
}
@ -51,6 +52,8 @@ func (render *Renderable) StartAnimation(which int) {
render.IdleAnimate.Active = true
render.IdleAnimate.Loop = true
render.IdleAnimate.Timer.Start(0)
case Moving:
render.MovingAnimate.Loop = true
}
}

View File

@ -159,24 +159,28 @@ func NewGrid(world *ecs.World,
render.Image = tile.Sprite
render.Pos = pos
if tile.Animation.OnCollision {
switch {
case tile.Animation.OnCollision:
render.CollisionAnimate.Sprites = tile.Animation.CollisionSheet.Sprites
render.CollisionAnimate.Width = tile.Animation.CollisionSheet.Width
render.CollisionAnimate.Height = tile.Animation.CollisionSheet.Height
}
if tile.Animation.OnDestruction {
case tile.Animation.OnDestruction:
render.DestructionAnimate.Sprites = tile.Animation.DestructionSheet.Sprites
render.DestructionAnimate.Width = tile.Animation.DestructionSheet.Width
render.DestructionAnimate.Height = tile.Animation.DestructionSheet.Height
}
if tile.Animation.OnIdle {
case tile.Animation.OnIdle:
render.IdleAnimate.Sprites = tile.Animation.IdleSheet.Sprites
render.IdleAnimate.Width = tile.Animation.IdleSheet.Width
render.IdleAnimate.Height = tile.Animation.IdleSheet.Height
render.StartAnimation(components.Idle)
render.Hidden = true // we do NOT render the sprite, but the idle animation instead
case tile.Animation.OnMoving:
render.MovingAnimate.Sprites = tile.Animation.IdleSheet.Sprites
render.MovingAnimate.Width = tile.Animation.IdleSheet.Width
render.MovingAnimate.Height = tile.Animation.IdleSheet.Height
}
default:

View File

@ -8,6 +8,7 @@ import (
. "openquell/config"
"openquell/grid"
"openquell/observers"
"openquell/util"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
@ -136,7 +137,9 @@ func (system *PlayerSystem) Draw(screen *ebiten.Image) {
screen.DrawImage(sprite.Image, op)
ebitenutil.DebugPrintAt(screen, pos.String(), pos.X, pos.Y) // print player pos
if util.DebugEnabled() {
ebitenutil.DebugPrintAt(screen, pos.SmallString(), pos.X, pos.Y+16) // print player pos
}
}
}
@ -210,7 +213,9 @@ func (system *PlayerSystem) CheckMovement(
observer.AddMove()
}
} else {
fmt.Println("------------------------")
if util.DebugEnabled() {
fmt.Println("------------------------")
}
slog.Debug("(1) player is at", "current", position.String())
}
}

View File

@ -1,7 +1,10 @@
package util
import (
"context"
. "openquell/config"
"log/slog"
)
// find an item in a list, generic variant
@ -41,3 +44,7 @@ func DirectionStr(dir int) string {
return str
}
func DebugEnabled() bool {
return slog.Default().Enabled(context.TODO(), slog.LevelDebug)
}