|
|
|
@ -209,6 +209,14 @@ func (g *Game) ReadInputs() InputBits {
|
|
|
|
|
in.setButtonOn(ButtonPunch)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ebiten.IsKeyPressed(ebiten.KeyJ) {
|
|
|
|
|
in.setButtonOn(ButtonKick)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ebiten.IsKeyPressed(ebiten.KeyK) {
|
|
|
|
|
in.setButtonOn(ButtonBlock)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ebiten.IsKeyPressed(ebiten.KeyL) {
|
|
|
|
|
in.setButtonOn(ButtonTaunt)
|
|
|
|
|
}
|
|
|
|
@ -345,6 +353,12 @@ func (g *Game) UpdateByInputs(inputs []InputBits) {
|
|
|
|
|
g.Players[i].VY = g.Players[i].VY * 0.8
|
|
|
|
|
|
|
|
|
|
if g.Players[i].Action == component.ActionIdle {
|
|
|
|
|
if input.isButtonOn(ButtonBlock) {
|
|
|
|
|
g.Players[i].Action = component.ActionBlock
|
|
|
|
|
g.Players[i].ActionTicksLeft = len(component.AllPlayerFrames[component.ActionBlock])
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if input.isButtonOn(ButtonTaunt) {
|
|
|
|
|
var tauntAction component.PlayerAction
|
|
|
|
|
switch {
|
|
|
|
@ -421,16 +435,23 @@ func (g *Game) UpdateByInputs(inputs []InputBits) {
|
|
|
|
|
if frame.T == component.HitboxHurt {
|
|
|
|
|
// Hit opponent.
|
|
|
|
|
if oppRect.Overlaps(component.TranslateRect(frameRect, int(player.X), int(player.Y))) {
|
|
|
|
|
hitStrength := 4.0
|
|
|
|
|
if g.Players[opp].Action == component.ActionBlock {
|
|
|
|
|
hitStrength = 1.0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Send the opponent flying in some direction.
|
|
|
|
|
if opponent.X <= player.X { // Opponent is to the left of the player.
|
|
|
|
|
opponent.VX = -4
|
|
|
|
|
opponent.VX = -hitStrength
|
|
|
|
|
} else { // Opponent is to the right of the player.
|
|
|
|
|
opponent.VX = 4
|
|
|
|
|
opponent.VX = hitStrength
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Stun the opponent.
|
|
|
|
|
opponent.Action = component.ActionStunned
|
|
|
|
|
opponent.ActionTicksLeft = 14
|
|
|
|
|
if g.Players[opp].Action != component.ActionBlock {
|
|
|
|
|
opponent.Action = component.ActionStunned
|
|
|
|
|
opponent.ActionTicksLeft = 14
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -446,6 +467,12 @@ func (g *Game) UpdateByInputs(inputs []InputBits) {
|
|
|
|
|
g.Players[i].ActionTicksLeft--
|
|
|
|
|
}
|
|
|
|
|
if g.Players[i].ActionTicksLeft == 0 {
|
|
|
|
|
// Hold block.
|
|
|
|
|
if input.isButtonOn(ButtonBlock) {
|
|
|
|
|
g.Players[i].ActionTicksLeft = len(component.AllPlayerFrames[component.ActionBlock])
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Return to the idle action.
|
|
|
|
|
g.Players[i].Action = component.ActionIdle
|
|
|
|
|
g.Players[i].ActionTicksLeft = len(component.AllPlayerFrames[component.ActionIdle]) // TODO
|
|
|
|
@ -480,11 +507,15 @@ func (g *Game) playerStateUpdated() {
|
|
|
|
|
func (g *Game) RunLocalFrame() {
|
|
|
|
|
inputs := make([]InputBits, 2)
|
|
|
|
|
inputs[0] = g.ReadInputs()
|
|
|
|
|
if world.Mirror || true {
|
|
|
|
|
|
|
|
|
|
if world.AI == world.AIMirror {
|
|
|
|
|
inputs[1] = mirrorInput(inputs[0])
|
|
|
|
|
} else if world.AI == world.AIBlock {
|
|
|
|
|
inputs[1] = inputs[0]
|
|
|
|
|
inputs[1].setButtonOn(ButtonBlock)
|
|
|
|
|
}
|
|
|
|
|
g.UpdateByInputs(inputs)
|
|
|
|
|
|
|
|
|
|
g.UpdateByInputs(inputs)
|
|
|
|
|
g.playerStateUpdated()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -544,6 +575,17 @@ func (g *Game) Update() error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if inpututil.IsKeyJustPressed(ebiten.KeyI) && ebiten.IsKeyPressed(ebiten.KeyControl) {
|
|
|
|
|
switch world.AI {
|
|
|
|
|
case world.AIMirror:
|
|
|
|
|
world.AI = world.AIBlock
|
|
|
|
|
case world.AIBlock:
|
|
|
|
|
world.AI = world.AINone
|
|
|
|
|
default:
|
|
|
|
|
world.AI = world.AIMirror
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if inpututil.IsKeyJustPressed(ebiten.KeyV) && ebiten.IsKeyPressed(ebiten.KeyControl) {
|
|
|
|
|
world.Debug++
|
|
|
|
|
if world.Debug > world.MaxDebug {
|
|
|
|
|