Add crouching
parent
d41d7ad0a3
commit
8685a3e37c
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 19 KiB After Width: | Height: | Size: 22 KiB |
|
@ -107,6 +107,9 @@ type Player struct {
|
|||
WalkFrame int
|
||||
WalkFrameReverse bool
|
||||
|
||||
Crouching bool
|
||||
CrouchFrame int
|
||||
|
||||
NoPunch bool
|
||||
NoKick bool
|
||||
|
||||
|
@ -145,3 +148,29 @@ var WalkFrames = []*ebiten.Image{
|
|||
asset.FrameAt(asset.ImgPlayer, 6, 13),
|
||||
asset.FrameAt(asset.ImgPlayer, 7, 13),
|
||||
}
|
||||
|
||||
// CrouchFrames are defined in chronological order.
|
||||
var CrouchFrames = []*ebiten.Image{
|
||||
asset.FrameAt(asset.ImgPlayer, 0, 14),
|
||||
asset.FrameAt(asset.ImgPlayer, 1, 14),
|
||||
asset.FrameAt(asset.ImgPlayer, 2, 14),
|
||||
asset.FrameAt(asset.ImgPlayer, 3, 14),
|
||||
asset.FrameAt(asset.ImgPlayer, 4, 14),
|
||||
asset.FrameAt(asset.ImgPlayer, 5, 14),
|
||||
asset.FrameAt(asset.ImgPlayer, 6, 14),
|
||||
asset.FrameAt(asset.ImgPlayer, 7, 14),
|
||||
asset.FrameAt(asset.ImgPlayer, 8, 14),
|
||||
asset.FrameAt(asset.ImgPlayer, 9, 14),
|
||||
}
|
||||
|
||||
// CrouchWalkFrames are defined in chronological order.
|
||||
var CrouchWalkFrames = []*ebiten.Image{
|
||||
asset.FrameAt(asset.ImgPlayer, 0, 15),
|
||||
asset.FrameAt(asset.ImgPlayer, 1, 15),
|
||||
asset.FrameAt(asset.ImgPlayer, 2, 15),
|
||||
asset.FrameAt(asset.ImgPlayer, 3, 15),
|
||||
asset.FrameAt(asset.ImgPlayer, 4, 15),
|
||||
asset.FrameAt(asset.ImgPlayer, 5, 15),
|
||||
asset.FrameAt(asset.ImgPlayer, 6, 15),
|
||||
asset.FrameAt(asset.ImgPlayer, 7, 15),
|
||||
}
|
||||
|
|
21
game/game.go
21
game/game.go
|
@ -375,12 +375,20 @@ func (g *Game) UpdateByInputs(inputs []InputBits) {
|
|||
}
|
||||
_ = oppFlipped // TODO
|
||||
|
||||
playerRect := world.FloatRect(g.Players[i].X, g.Players[i].Y, g.Players[i].X+float64(component.PlayerSize), g.Players[i].Y+float64(component.PlayerSize))
|
||||
oppRect := world.FloatRect(g.Players[opp].X, g.Players[opp].Y, g.Players[opp].X+float64(component.PlayerSize), g.Players[opp].Y+float64(component.PlayerSize))
|
||||
|
||||
g.Players[i].VX = g.Players[i].VX * 0.8
|
||||
g.Players[i].VY = g.Players[i].VY * 0.8
|
||||
|
||||
// Advance crouching animation frame.
|
||||
const crouchFrames = 10
|
||||
if player.Crouching && player.CrouchFrame < crouchFrames-1 {
|
||||
player.CrouchFrame++
|
||||
} else if !player.Crouching && player.CrouchFrame != 0 {
|
||||
player.CrouchFrame--
|
||||
}
|
||||
|
||||
g.Players[i].Crouching = false
|
||||
if g.Players[i].Action == component.ActionIdle {
|
||||
if input.isButtonOn(ButtonBlock) {
|
||||
g.Players[i].Action = component.ActionBlock
|
||||
|
@ -432,16 +440,17 @@ func (g *Game) UpdateByInputs(inputs []InputBits) {
|
|||
if input.isButtonOn(ButtonUp) && g.Players[i].Grounded {
|
||||
g.Players[i].VY = world.JumpVelocity
|
||||
}
|
||||
if input.isButtonOn(ButtonDown) && !component.TranslateRect(playerRect, 0, 1).Overlaps(oppRect) {
|
||||
//g.Players[i].VY = -1
|
||||
// TODO crouch
|
||||
if input.isButtonOn(ButtonDown) {
|
||||
g.Players[i].Crouching = true
|
||||
}
|
||||
if input.isButtonOn(ButtonLeft) && !component.TranslateRect(playerRect, -1, 0).Overlaps(oppRect) {
|
||||
if input.isButtonOn(ButtonLeft) {
|
||||
g.Players[i].VX = -1
|
||||
}
|
||||
if input.isButtonOn(ButtonRight) && !component.TranslateRect(playerRect, 1, 0).Overlaps(oppRect) {
|
||||
if input.isButtonOn(ButtonRight) {
|
||||
g.Players[i].VX = 1
|
||||
}
|
||||
} else {
|
||||
g.Players[i].CrouchFrame = 0
|
||||
}
|
||||
|
||||
// TODO player starts in idle action?
|
||||
|
|
4
go.mod
4
go.mod
|
@ -15,8 +15,8 @@ require (
|
|||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b // indirect
|
||||
github.com/hajimehoshi/file2byteslice v1.0.0 // indirect
|
||||
github.com/jezek/xgb v1.1.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20230129154200-a960b3787bd2 // indirect
|
||||
golang.org/x/exp/shiny v0.0.0-20230129154200-a960b3787bd2 // indirect
|
||||
golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 // indirect
|
||||
golang.org/x/exp/shiny v0.0.0-20230131160201-f062dba9d201 // indirect
|
||||
golang.org/x/image v0.3.0 // indirect
|
||||
golang.org/x/mobile v0.0.0-20221110043201-43a038452099 // indirect
|
||||
golang.org/x/sys v0.4.0 // indirect
|
||||
|
|
8
go.sum
8
go.sum
|
@ -38,10 +38,10 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
|
|||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4=
|
||||
golang.org/x/exp v0.0.0-20230129154200-a960b3787bd2 h1:5sPMf9HJXrvBWIamTw+rTST0bZ3Mho2n1p58M0+W99c=
|
||||
golang.org/x/exp v0.0.0-20230129154200-a960b3787bd2/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
||||
golang.org/x/exp/shiny v0.0.0-20230129154200-a960b3787bd2 h1:xiw7QDza+jS0x7vU7fwNbRSDE/QreNk9f9CZmXHs+Uw=
|
||||
golang.org/x/exp/shiny v0.0.0-20230129154200-a960b3787bd2/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0=
|
||||
golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 h1:BEABXpNXLEz0WxtA+6CQIz2xkg80e+1zrhWyMcq8VzE=
|
||||
golang.org/x/exp v0.0.0-20230131160201-f062dba9d201/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
||||
golang.org/x/exp/shiny v0.0.0-20230131160201-f062dba9d201 h1:Y5QA5ZjU4BIgfpTmSB+07A4sIMFk6nLx0Q0/mJlIduE=
|
||||
golang.org/x/exp/shiny v0.0.0-20230131160201-f062dba9d201/go.mod h1:UH99kUObWAZkDnWqppdQe5ZhPYESUw8I0zVV1uWBR+0=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.1.0/go.mod h1:iyPr49SD/G/TBxYVB/9RRtGUT5eNbo2u4NamWeQcD5c=
|
||||
|
|
|
@ -58,8 +58,19 @@ func (s *PlayerSystem) Draw(e gohan.Entity, screen *ebiten.Image) error {
|
|||
break
|
||||
}
|
||||
|
||||
drawCrouch := p.Crouching || (p.Action == component.ActionIdle && p.CrouchFrame != 0)
|
||||
if p.Walking() {
|
||||
sprite = component.WalkFrames[p.WalkFrame]
|
||||
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 {
|
||||
|
|
|
@ -6,12 +6,11 @@ import (
|
|||
"image/color"
|
||||
"math"
|
||||
|
||||
"github.com/assemblaj/ggpo"
|
||||
|
||||
"code.rocketnine.space/tslocum/boxbrawl/component"
|
||||
"code.rocketnine.space/tslocum/boxbrawl/world"
|
||||
"code.rocketnine.space/tslocum/etk"
|
||||
"code.rocketnine.space/tslocum/gohan"
|
||||
"github.com/assemblaj/ggpo"
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
|
||||
"github.com/hajimehoshi/ebiten/v2/inpututil"
|
||||
|
|
Loading…
Reference in New Issue