67 lines
1.2 KiB
Go
67 lines
1.2 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 *component.Player
|
|
for i := 0; i < 2; i++ {
|
|
if i == 0 {
|
|
p = &world.Player1
|
|
} else {
|
|
p = &world.Player2
|
|
}
|
|
|
|
r := image.Rect(int(p.X), int(p.Y), int(p.X)+size, int(p.Y)+size)
|
|
screen.SubImage(r).(*ebiten.Image).Fill(p.Color)
|
|
|
|
// TODO animate
|
|
/*if p.ActionTicksLeft != 0 {
|
|
frameNum := p.ActionTicksLeft - 1
|
|
frame := component.AllPlayerFrames[p.Action][frameNum]
|
|
log.Printf("frame %+v", frame)
|
|
}*/
|
|
|
|
switch p.Action {
|
|
case component.ActionPunch:
|
|
ebitenutil.DebugPrintAt(screen, "PUNCH", int(p.X), int(p.Y))
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|