add moving animation support, fix debug printing
This commit is contained in:
parent
f2f134fddb
commit
b7383f065f
3
TODO.md
3
TODO.md
@ -15,11 +15,10 @@
|
|||||||
- Add player collision animation
|
- Add player collision animation
|
||||||
|
|
||||||
- Create pixel art ui elements (button, list things) and ui borders/backgrounds
|
- 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
|
- 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)
|
- On game start respond to any key (ebitengine-input has an anykey func)
|
||||||
|
|
||||||
- Switch to use https://github.com/quasilyte/ebitengine-input
|
- Switch to use https://github.com/quasilyte/ebitengine-input
|
||||||
|
|||||||
@ -18,6 +18,7 @@ type TileAnimation struct {
|
|||||||
OnCollision bool // wether to animate a collision
|
OnCollision bool // wether to animate a collision
|
||||||
OnDestruction bool // wether to animate destruction
|
OnDestruction bool // wether to animate destruction
|
||||||
OnIdle bool // wether to animate during idling
|
OnIdle bool // wether to animate during idling
|
||||||
|
OnMoving bool // wether to animate during moving
|
||||||
|
|
||||||
CollisionSheet AnimationSet // an entry in assets.Animations[name]
|
CollisionSheet AnimationSet // an entry in assets.Animations[name]
|
||||||
DestructionSheet AnimationSet
|
DestructionSheet AnimationSet
|
||||||
|
|||||||
@ -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) {
|
func (position *Position) Move(velocity *Velocity) {
|
||||||
// if velocity.Direction != 0 {
|
// if velocity.Direction != 0 {
|
||||||
// slog.Debug("moving", "velocity", velocity, "speed", speed)
|
// slog.Debug("moving", "velocity", velocity, "speed", speed)
|
||||||
|
|||||||
@ -35,6 +35,7 @@ type Renderable struct {
|
|||||||
DestructionAnimate Animation
|
DestructionAnimate Animation
|
||||||
IdleAnimate Animation
|
IdleAnimate Animation
|
||||||
CollisionAnimate Animation
|
CollisionAnimate Animation
|
||||||
|
MovingAnimate Animation
|
||||||
Hidden bool
|
Hidden bool
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,6 +52,8 @@ func (render *Renderable) StartAnimation(which int) {
|
|||||||
render.IdleAnimate.Active = true
|
render.IdleAnimate.Active = true
|
||||||
render.IdleAnimate.Loop = true
|
render.IdleAnimate.Loop = true
|
||||||
render.IdleAnimate.Timer.Start(0)
|
render.IdleAnimate.Timer.Start(0)
|
||||||
|
case Moving:
|
||||||
|
render.MovingAnimate.Loop = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
14
grid/grid.go
14
grid/grid.go
@ -159,24 +159,28 @@ func NewGrid(world *ecs.World,
|
|||||||
render.Image = tile.Sprite
|
render.Image = tile.Sprite
|
||||||
render.Pos = pos
|
render.Pos = pos
|
||||||
|
|
||||||
if tile.Animation.OnCollision {
|
switch {
|
||||||
|
case tile.Animation.OnCollision:
|
||||||
render.CollisionAnimate.Sprites = tile.Animation.CollisionSheet.Sprites
|
render.CollisionAnimate.Sprites = tile.Animation.CollisionSheet.Sprites
|
||||||
render.CollisionAnimate.Width = tile.Animation.CollisionSheet.Width
|
render.CollisionAnimate.Width = tile.Animation.CollisionSheet.Width
|
||||||
render.CollisionAnimate.Height = tile.Animation.CollisionSheet.Height
|
render.CollisionAnimate.Height = tile.Animation.CollisionSheet.Height
|
||||||
}
|
|
||||||
|
|
||||||
if tile.Animation.OnDestruction {
|
case tile.Animation.OnDestruction:
|
||||||
render.DestructionAnimate.Sprites = tile.Animation.DestructionSheet.Sprites
|
render.DestructionAnimate.Sprites = tile.Animation.DestructionSheet.Sprites
|
||||||
render.DestructionAnimate.Width = tile.Animation.DestructionSheet.Width
|
render.DestructionAnimate.Width = tile.Animation.DestructionSheet.Width
|
||||||
render.DestructionAnimate.Height = tile.Animation.DestructionSheet.Height
|
render.DestructionAnimate.Height = tile.Animation.DestructionSheet.Height
|
||||||
}
|
|
||||||
|
|
||||||
if tile.Animation.OnIdle {
|
case tile.Animation.OnIdle:
|
||||||
render.IdleAnimate.Sprites = tile.Animation.IdleSheet.Sprites
|
render.IdleAnimate.Sprites = tile.Animation.IdleSheet.Sprites
|
||||||
render.IdleAnimate.Width = tile.Animation.IdleSheet.Width
|
render.IdleAnimate.Width = tile.Animation.IdleSheet.Width
|
||||||
render.IdleAnimate.Height = tile.Animation.IdleSheet.Height
|
render.IdleAnimate.Height = tile.Animation.IdleSheet.Height
|
||||||
render.StartAnimation(components.Idle)
|
render.StartAnimation(components.Idle)
|
||||||
render.Hidden = true // we do NOT render the sprite, but the idle animation instead
|
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:
|
default:
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import (
|
|||||||
. "openquell/config"
|
. "openquell/config"
|
||||||
"openquell/grid"
|
"openquell/grid"
|
||||||
"openquell/observers"
|
"openquell/observers"
|
||||||
|
"openquell/util"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2"
|
"github.com/hajimehoshi/ebiten/v2"
|
||||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||||
@ -136,7 +137,9 @@ func (system *PlayerSystem) Draw(screen *ebiten.Image) {
|
|||||||
|
|
||||||
screen.DrawImage(sprite.Image, op)
|
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()
|
observer.AddMove()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("------------------------")
|
if util.DebugEnabled() {
|
||||||
|
fmt.Println("------------------------")
|
||||||
|
}
|
||||||
slog.Debug("(1) player is at", "current", position.String())
|
slog.Debug("(1) player is at", "current", position.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
. "openquell/config"
|
. "openquell/config"
|
||||||
|
|
||||||
|
"log/slog"
|
||||||
)
|
)
|
||||||
|
|
||||||
// find an item in a list, generic variant
|
// find an item in a list, generic variant
|
||||||
@ -41,3 +44,7 @@ func DirectionStr(dir int) string {
|
|||||||
|
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DebugEnabled() bool {
|
||||||
|
return slog.Default().Enabled(context.TODO(), slog.LevelDebug)
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user