Added weapon sprite into the mix.
This commit is contained in:
22
game.go
22
game.go
@@ -24,6 +24,7 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
weaponImage *ebiten.Image
|
||||
tilesetImage *ebiten.Image
|
||||
altarImage *ebiten.Image
|
||||
|
||||
@@ -31,6 +32,8 @@ var (
|
||||
tileset_img []byte
|
||||
//go:embed altar.png
|
||||
altar_img []byte
|
||||
//go:embed weapon.png
|
||||
weapon_img []byte
|
||||
)
|
||||
|
||||
type Game struct {
|
||||
@@ -73,6 +76,12 @@ func init() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
altarImage = ebiten.NewImageFromImage(img)
|
||||
|
||||
img, _, err = image.Decode(bytes.NewReader(weapon_img))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
weaponImage = ebiten.NewImageFromImage(img)
|
||||
}
|
||||
|
||||
func (g *Game) Initialize() {
|
||||
@@ -167,10 +176,16 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||
}
|
||||
|
||||
op.GeoM.Translate(-MOVER_WIDTH/2, -MOVER_HEIGHT/2)
|
||||
op.GeoM.Rotate(g.hero.Angle)
|
||||
//op.GeoM.Rotate(g.hero.Angle)
|
||||
op.GeoM.Translate(g.hero.Pos.X, g.hero.Pos.Y)
|
||||
screen.DrawImage(g.hero.Sprite, op)
|
||||
|
||||
op.GeoM.Reset()
|
||||
op.GeoM.Translate(0, -16)
|
||||
op.GeoM.Rotate(g.hero.Angle)
|
||||
op.GeoM.Translate(g.hero.Pos.X, g.hero.Pos.Y)
|
||||
screen.DrawImage(weaponImage, op)
|
||||
|
||||
for _, target := range g.targets {
|
||||
target.Draw()
|
||||
|
||||
@@ -447,11 +462,12 @@ func (g *Game) UpdateHeroPosition() {
|
||||
inpx := ebiten.GamepadAxisValue(0, 0)
|
||||
inpy := ebiten.GamepadAxisValue(0, 1)
|
||||
if inpx >= 0.15 || inpx <= -0.15 {
|
||||
g.hero.Pos.X += ebiten.GamepadAxisValue(0, 0) * 5
|
||||
g.hero.Left = inpx < 0
|
||||
g.hero.Pos.X += inpx * 5
|
||||
}
|
||||
|
||||
if inpy >= 0.15 || inpy <= -0.15 {
|
||||
g.hero.Pos.Y += ebiten.GamepadAxisValue(0, 1) * 5
|
||||
g.hero.Pos.Y += inpy * 5
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
14
hero.go
14
hero.go
@@ -55,12 +55,14 @@ type Hero struct {
|
||||
Angle float64
|
||||
Pos Coordinates
|
||||
Origin Coordinates
|
||||
Lastpos Coordinates
|
||||
Action HeroAction
|
||||
cycles int
|
||||
rotating bool
|
||||
Toggled bool
|
||||
Hit bool
|
||||
Touched bool
|
||||
Left bool
|
||||
dyingcount int
|
||||
}
|
||||
|
||||
@@ -105,18 +107,24 @@ func (m *Hero) Draw() {
|
||||
x0 := 48 * idx
|
||||
x1 := x0 + 48
|
||||
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
if m.Left {
|
||||
op.GeoM.Scale(-1, 1)
|
||||
op.GeoM.Translate(MOVER_WIDTH, 0)
|
||||
}
|
||||
|
||||
switch m.Action {
|
||||
case HeroActionDefault:
|
||||
m.Sprite.DrawImage(heroImage.SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), nil)
|
||||
m.Sprite.DrawImage(heroImage.SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), op)
|
||||
case HeroActionDying:
|
||||
m.Sprite.DrawImage(heroDeath.SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), nil)
|
||||
m.Sprite.DrawImage(heroDeath.SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), op)
|
||||
|
||||
if m.dyingcount >= 31 {
|
||||
m.cycles = 0
|
||||
m.Action++
|
||||
}
|
||||
case HeroActionExploding:
|
||||
m.Sprite.DrawImage(heroDeath.SubImage(image.Rect(48*3, 0, 48*4, 48)).(*ebiten.Image), nil)
|
||||
m.Sprite.DrawImage(heroDeath.SubImage(image.Rect(48*3, 0, 48*4, 48)).(*ebiten.Image), op)
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
BIN
weapon.png
Normal file
BIN
weapon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 741 B |
Reference in New Issue
Block a user