You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.1 KiB
Go
106 lines
2.1 KiB
Go
package system
|
|
|
|
import (
|
|
"image"
|
|
|
|
"code.rocketnine.space/tslocum/boxbrawl/component"
|
|
"code.rocketnine.space/tslocum/boxbrawl/world"
|
|
"code.rocketnine.space/tslocum/gohan"
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
|
)
|
|
|
|
type PlayerSystem struct {
|
|
*component.Once
|
|
|
|
initialized bool
|
|
debugImg *ebiten.Image
|
|
}
|
|
|
|
func (s *PlayerSystem) initialize() {
|
|
}
|
|
|
|
func (s *PlayerSystem) Update(e gohan.Entity) error {
|
|
if !s.initialized {
|
|
s.initialize()
|
|
}
|
|
|
|
if world.ConnectPromptVisible {
|
|
return nil
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *PlayerSystem) Draw(e gohan.Entity, screen *ebiten.Image) error {
|
|
if world.ConnectPromptVisible {
|
|
return nil
|
|
}
|
|
|
|
size := 20
|
|
var p, o *component.Player
|
|
for i := 0; i < 2; i++ {
|
|
if i == 0 {
|
|
p = &world.Player1
|
|
o = &world.Player2
|
|
} else {
|
|
p = &world.Player2
|
|
o = &world.Player1
|
|
}
|
|
|
|
var sprite *ebiten.Image
|
|
frameData := component.FrameDataForActionTick(p.Action, p.ActionTicksLeft)
|
|
for _, frame := range frameData {
|
|
if frame.S == nil {
|
|
continue
|
|
}
|
|
sprite = frame.S
|
|
break
|
|
}
|
|
|
|
drawCrouch := p.Crouching || (p.Action == component.ActionIdle && p.CrouchFrame != 0)
|
|
if p.Walking() {
|
|
if drawCrouch {
|
|
if p.CrouchFrame == 9 {
|
|
sprite = component.CrouchWalkFrames[p.WalkFrame]
|
|
} else {
|
|
sprite = component.CrouchFrames[p.CrouchFrame]
|
|
}
|
|
} else {
|
|
sprite = component.WalkFrames[p.WalkFrame]
|
|
}
|
|
} else if drawCrouch {
|
|
sprite = component.CrouchFrames[p.CrouchFrame]
|
|
}
|
|
|
|
if sprite != nil {
|
|
x, y := world.GameCoordsToScreen(p.X-24, p.Y+64)
|
|
op := &ebiten.DrawImageOptions{}
|
|
|
|
if component.PlayerOnRightSide(*p, *o) {
|
|
op.GeoM.Scale(-1, 1)
|
|
op.GeoM.Translate(64, 0)
|
|
}
|
|
|
|
op.GeoM.Translate(float64(x), float64(y))
|
|
op.ColorM.ScaleWithColor(p.Color)
|
|
|
|
screen.DrawImage(sprite, op)
|
|
continue // TODO
|
|
}
|
|
|
|
r := image.Rect(int(p.X), int(p.Y), int(p.X)+size, int(p.Y)+size)
|
|
|
|
screen.SubImage(world.GameRectToScreen(r)).(*ebiten.Image).Fill(p.Color)
|
|
|
|
// TODO animate
|
|
|
|
switch p.Action {
|
|
case component.ActionPunch:
|
|
ebitenutil.DebugPrintAt(screen, "PUNCH", int(p.X), int(p.Y))
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|