Skip to content

Commit

Permalink
Get steps for animation worked out
Browse files Browse the repository at this point in the history
  • Loading branch information
bobtfish committed Feb 7, 2021
1 parent 6f41bdb commit 04fd07d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
1 change: 1 addition & 0 deletions movable/movable.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Attackerable interface {
GetAttackRange() int
GetAttackFx() *fx.Fx
CanAttackUndead() bool
GetBoardPosition() logical.Vec
}

type Corpseable interface {
Expand Down
46 changes: 29 additions & 17 deletions screen/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ func (screen *RangedCombat) Step(ctx screeniface.GameCtx) screeniface.GameScreen
textBottomColor("No line of sight", render.GetColor(0, 233, 233), ss, batch)
screen.OutOfRange = true
} else {
// Do ranged attack
fx := attacker.GetAttackFx()
grid.PlaceGameObject(attackPosition, fx)

return &AnimateRangedAttack{
AttackPosition: attackPosition,
PlayerIdx: screen.PlayerIdx,
Expand All @@ -99,26 +95,42 @@ type AnimateRangedAttack struct {
PlayerIdx int
MovedCharacters map[movable.Movable]bool
Attacker movable.Attackerable
StepIdx int
AnimationSteps []logical.Vec
}

func (screen *AnimateRangedAttack) Enter(ctx screeniface.GameCtx) {
from := screen.Attacker.GetBoardPosition()
to := screen.AttackPosition
fmt.Printf("Attack from %d, %d TO %d, %d\n", from.X, from.Y, to.X, to.Y)
screen.AnimationSteps = to.Subtract(from).Path()
for i, s := range screen.AnimationSteps {
screen.AnimationSteps[i] = from.Add(s)
}
screen.AnimationSteps = append(screen.AnimationSteps, to)
}

func (screen *AnimateRangedAttack) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
// Do ranged attack
fx := screen.Attacker.GetAttackFx()
grid := ctx.GetGrid()
grid.PlaceGameObject(screen.AttackPosition, fx)

return &WaitForFx{
Fx: fx,
NextScreen: &DoRangedAttack{
AttackPosition: screen.AttackPosition,
PlayerIdx: screen.PlayerIdx,
MovedCharacters: screen.MovedCharacters,
Attacker: screen.Attacker,
},
if screen.StepIdx == len(screen.AnimationSteps) {
// Do ranged attack
fx := screen.Attacker.GetAttackFx()
grid := ctx.GetGrid()
grid.PlaceGameObject(screen.AttackPosition, fx)

return &WaitForFx{
Fx: fx,
NextScreen: &DoRangedAttack{
AttackPosition: screen.AttackPosition,
PlayerIdx: screen.PlayerIdx,
MovedCharacters: screen.MovedCharacters,
Attacker: screen.Attacker,
},
}
}
step := screen.AnimationSteps[screen.StepIdx]
fmt.Printf("Animation step %d, %d\n", step.X, step.Y)
screen.StepIdx++
return screen
}

type DoRangedAttack struct {
Expand Down

0 comments on commit 04fd07d

Please sign in to comment.