|
|
|
@ -79,6 +79,9 @@ func (g *Game) reset() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g.Winner = 0
|
|
|
|
|
|
|
|
|
|
botTauntTicks = 0
|
|
|
|
|
botTauntTotalTicks = 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *Game) Layout(_, _ int) (screenWidth, screenHeight int) {
|
|
|
|
@ -214,7 +217,7 @@ func (g *Game) ReadInputs() InputBits {
|
|
|
|
|
in.setButtonOn(ButtonTaunt)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ebiten.IsKeyPressed(ebiten.KeyEnter) {
|
|
|
|
|
if ebiten.IsKeyPressed(ebiten.KeyEnter) || ebiten.IsKeyPressed(ebiten.KeyKPEnter) {
|
|
|
|
|
in.setButtonOn(ButtonStart)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -261,7 +264,11 @@ func (g *Game) applyPhysics() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if collideG == -1 && p.VY > -world.Gravity {
|
|
|
|
|
outOfBounds := p.Y < -world.GroundHeight-component.PlayerHeight
|
|
|
|
|
|
|
|
|
|
if outOfBounds {
|
|
|
|
|
p.VX, p.VY = 0, 0
|
|
|
|
|
} else if collideG == -1 && p.VY > -world.Gravity {
|
|
|
|
|
p.VY -= math.Max(math.Abs(p.VY/2.5), 0.1)
|
|
|
|
|
if p.VY < -world.Gravity {
|
|
|
|
|
p.VY = -world.Gravity
|
|
|
|
@ -313,13 +320,15 @@ func (g *Game) applyPhysics() {
|
|
|
|
|
p.VX, o.VX = o.VX, p.VX // TODO
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if g.Winner == 0 && p.Y < -world.GroundHeight {
|
|
|
|
|
if g.Winner == 0 && outOfBounds {
|
|
|
|
|
g.Winner = o.PlayerNum
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (g *Game) UpdateByInputs(inputs []InputBits) {
|
|
|
|
|
const punchStunTicks = 15
|
|
|
|
|
|
|
|
|
|
var player, opponent *component.Player
|
|
|
|
|
var playerFlipped, oppFlipped bool
|
|
|
|
|
for i, input := range inputs {
|
|
|
|
@ -443,7 +452,7 @@ func (g *Game) UpdateByInputs(inputs []InputBits) {
|
|
|
|
|
// Stun the opponent.
|
|
|
|
|
if g.Players[opp].Action != component.ActionBlock {
|
|
|
|
|
opponent.Action = component.ActionStunned
|
|
|
|
|
opponent.ActionTicksLeft = 14
|
|
|
|
|
opponent.ActionTicksLeft = punchStunTicks
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -473,7 +482,11 @@ func (g *Game) UpdateByInputs(inputs []InputBits) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if world.Winner != 0 && input.isButtonOn(ButtonStart) {
|
|
|
|
|
g.Players[i].PlayAgain = true
|
|
|
|
|
if world.Local {
|
|
|
|
|
g.reset()
|
|
|
|
|
} else {
|
|
|
|
|
g.Players[i].PlayAgain = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -501,7 +514,9 @@ func (g *Game) RunLocalFrame() {
|
|
|
|
|
inputs := make([]InputBits, 2)
|
|
|
|
|
inputs[0] = g.ReadInputs()
|
|
|
|
|
|
|
|
|
|
if world.AI == world.AIMirror {
|
|
|
|
|
if world.AI == world.AIStandard {
|
|
|
|
|
inputs[1] = botInput()
|
|
|
|
|
} else if world.AI == world.AIMirror {
|
|
|
|
|
inputs[1] = mirrorInput(inputs[0])
|
|
|
|
|
} else if world.AI == world.AIBlock {
|
|
|
|
|
inputs[1] = inputs[0]
|
|
|
|
@ -568,17 +583,28 @@ func (g *Game) Update() error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if inpututil.IsKeyJustPressed(ebiten.KeyI) && ebiten.IsKeyPressed(ebiten.KeyControl) {
|
|
|
|
|
// Toggle fullscreen.
|
|
|
|
|
if (inpututil.IsKeyJustPressed(ebiten.KeyEnter) || inpututil.IsKeyJustPressed(ebiten.KeyKPEnter)) && ebiten.IsKeyPressed(ebiten.KeyAlt) {
|
|
|
|
|
world.Fullscreen = !world.Fullscreen
|
|
|
|
|
ebiten.SetFullscreen(world.Fullscreen)
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Change local opponent type.
|
|
|
|
|
if inpututil.IsKeyJustPressed(ebiten.KeyO) && ebiten.IsKeyPressed(ebiten.KeyControl) {
|
|
|
|
|
switch world.AI {
|
|
|
|
|
case world.AIStandard:
|
|
|
|
|
world.AI = world.AIMirror
|
|
|
|
|
case world.AIMirror:
|
|
|
|
|
world.AI = world.AIBlock
|
|
|
|
|
case world.AIBlock:
|
|
|
|
|
world.AI = world.AINone
|
|
|
|
|
default:
|
|
|
|
|
world.AI = world.AIMirror
|
|
|
|
|
world.AI = world.AIStandard
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Change debug level.
|
|
|
|
|
if inpututil.IsKeyJustPressed(ebiten.KeyV) && ebiten.IsKeyPressed(ebiten.KeyControl) {
|
|
|
|
|
world.Debug++
|
|
|
|
|
if world.Debug > world.MaxDebug {
|
|
|
|
@ -586,6 +612,7 @@ func (g *Game) Update() error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Decreate TPS.
|
|
|
|
|
if inpututil.IsKeyJustPressed(ebiten.KeyMinus) && ebiten.IsKeyPressed(ebiten.KeyControl) {
|
|
|
|
|
for i, preset := range world.TPSPresets {
|
|
|
|
|
if preset == world.TPS {
|
|
|
|
@ -599,6 +626,7 @@ func (g *Game) Update() error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Increase TPS.
|
|
|
|
|
if inpututil.IsKeyJustPressed(ebiten.KeyEqual) && ebiten.IsKeyPressed(ebiten.KeyControl) {
|
|
|
|
|
for i, preset := range world.TPSPresets {
|
|
|
|
|
if preset == world.TPS {
|
|
|
|
|