Added weapon sprite into the mix.
This commit is contained in:
22
game.go
22
game.go
@@ -24,6 +24,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
weaponImage *ebiten.Image
|
||||||
tilesetImage *ebiten.Image
|
tilesetImage *ebiten.Image
|
||||||
altarImage *ebiten.Image
|
altarImage *ebiten.Image
|
||||||
|
|
||||||
@@ -31,6 +32,8 @@ var (
|
|||||||
tileset_img []byte
|
tileset_img []byte
|
||||||
//go:embed altar.png
|
//go:embed altar.png
|
||||||
altar_img []byte
|
altar_img []byte
|
||||||
|
//go:embed weapon.png
|
||||||
|
weapon_img []byte
|
||||||
)
|
)
|
||||||
|
|
||||||
type Game struct {
|
type Game struct {
|
||||||
@@ -73,6 +76,12 @@ func init() {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
altarImage = ebiten.NewImageFromImage(img)
|
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() {
|
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.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)
|
op.GeoM.Translate(g.hero.Pos.X, g.hero.Pos.Y)
|
||||||
screen.DrawImage(g.hero.Sprite, op)
|
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 {
|
for _, target := range g.targets {
|
||||||
target.Draw()
|
target.Draw()
|
||||||
|
|
||||||
@@ -447,11 +462,12 @@ func (g *Game) UpdateHeroPosition() {
|
|||||||
inpx := ebiten.GamepadAxisValue(0, 0)
|
inpx := ebiten.GamepadAxisValue(0, 0)
|
||||||
inpy := ebiten.GamepadAxisValue(0, 1)
|
inpy := ebiten.GamepadAxisValue(0, 1)
|
||||||
if inpx >= 0.15 || inpx <= -0.15 {
|
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 {
|
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
|
Angle float64
|
||||||
Pos Coordinates
|
Pos Coordinates
|
||||||
Origin Coordinates
|
Origin Coordinates
|
||||||
|
Lastpos Coordinates
|
||||||
Action HeroAction
|
Action HeroAction
|
||||||
cycles int
|
cycles int
|
||||||
rotating bool
|
rotating bool
|
||||||
Toggled bool
|
Toggled bool
|
||||||
Hit bool
|
Hit bool
|
||||||
Touched bool
|
Touched bool
|
||||||
|
Left bool
|
||||||
dyingcount int
|
dyingcount int
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,18 +107,24 @@ func (m *Hero) Draw() {
|
|||||||
x0 := 48 * idx
|
x0 := 48 * idx
|
||||||
x1 := x0 + 48
|
x1 := x0 + 48
|
||||||
|
|
||||||
|
op := &ebiten.DrawImageOptions{}
|
||||||
|
if m.Left {
|
||||||
|
op.GeoM.Scale(-1, 1)
|
||||||
|
op.GeoM.Translate(MOVER_WIDTH, 0)
|
||||||
|
}
|
||||||
|
|
||||||
switch m.Action {
|
switch m.Action {
|
||||||
case HeroActionDefault:
|
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:
|
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 {
|
if m.dyingcount >= 31 {
|
||||||
m.cycles = 0
|
m.cycles = 0
|
||||||
m.Action++
|
m.Action++
|
||||||
}
|
}
|
||||||
case HeroActionExploding:
|
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:
|
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