Fixed health bar positioning. Added fireball sfx.
This commit is contained in:
@@ -41,6 +41,8 @@ var (
|
|||||||
PauseIn []byte
|
PauseIn []byte
|
||||||
//go:embed pauseout.wav
|
//go:embed pauseout.wav
|
||||||
PauseOut []byte
|
PauseOut []byte
|
||||||
|
//go:embed flare.wav
|
||||||
|
Flare []byte
|
||||||
)
|
)
|
||||||
|
|
||||||
func LoadSounds() {
|
func LoadSounds() {
|
||||||
|
|||||||
BIN
assets/flare.wav
Normal file
BIN
assets/flare.wav
Normal file
Binary file not shown.
@@ -19,6 +19,7 @@ type FlyEye struct {
|
|||||||
state gamedata.EnemyState
|
state gamedata.EnemyState
|
||||||
cycle int
|
cycle int
|
||||||
dyingcount int
|
dyingcount int
|
||||||
|
health int
|
||||||
hit bool
|
hit bool
|
||||||
touched bool
|
touched bool
|
||||||
toggle bool
|
toggle bool
|
||||||
@@ -30,6 +31,7 @@ func NewFlyEye() *FlyEye {
|
|||||||
Sprite: ebiten.NewImage(46, 46),
|
Sprite: ebiten.NewImage(46, 46),
|
||||||
Maks: ebiten.NewImage(48, 48),
|
Maks: ebiten.NewImage(48, 48),
|
||||||
MaksDest: ebiten.NewImage(48, 48),
|
MaksDest: ebiten.NewImage(48, 48),
|
||||||
|
health: 0,
|
||||||
cycle: 0,
|
cycle: 0,
|
||||||
dyingcount: 0,
|
dyingcount: 0,
|
||||||
hit: false,
|
hit: false,
|
||||||
@@ -124,6 +126,7 @@ func (f *FlyEye) SetHit() {
|
|||||||
f.hit = true
|
f.hit = true
|
||||||
f.state = gamedata.EnemyStateDying
|
f.state = gamedata.EnemyStateDying
|
||||||
f.cycle = 0
|
f.cycle = 0
|
||||||
|
f.health--
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FlyEye) IsTouched() bool {
|
func (f *FlyEye) IsTouched() bool {
|
||||||
@@ -165,7 +168,7 @@ func (f *FlyEye) SetExplosionInitiated() {
|
|||||||
func (f *FlyEye) Health() int {
|
func (f *FlyEye) Health() int {
|
||||||
//health bars reserved for special enemies, flyeye is a one
|
//health bars reserved for special enemies, flyeye is a one
|
||||||
//hitter so returning zero ensure no health bar is rendered
|
//hitter so returning zero ensure no health bar is rendered
|
||||||
return 0
|
return f.health
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FlyEye) MaxHealth() int {
|
func (f *FlyEye) MaxHealth() int {
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ const (
|
|||||||
GameEventNewShot
|
GameEventNewShot
|
||||||
GameEventTargetHit
|
GameEventTargetHit
|
||||||
GameEventExplosion
|
GameEventExplosion
|
||||||
|
GameEventFireball
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -68,12 +68,11 @@ func (c *Canvas) Update() error {
|
|||||||
if !c.initialized {
|
if !c.initialized {
|
||||||
c.Initialize()
|
c.Initialize()
|
||||||
} else {
|
} else {
|
||||||
//update positions()
|
|
||||||
//hero first
|
|
||||||
c.UpdateHero()
|
c.UpdateHero()
|
||||||
c.UpdateProjectiles()
|
c.UpdateProjectiles()
|
||||||
c.UpdateCharge()
|
c.UpdateCharge()
|
||||||
c.UpdateEnemies()
|
c.UpdateEnemies()
|
||||||
|
c.SpawnEnemies()
|
||||||
c.CleanupTargets()
|
c.CleanupTargets()
|
||||||
c.counter++
|
c.counter++
|
||||||
}
|
}
|
||||||
@@ -100,6 +99,7 @@ func (c *Canvas) Draw(drawimg *ebiten.Image) {
|
|||||||
c.Sprite.DrawImage(assets.ImageBank[assets.Weapon], op)
|
c.Sprite.DrawImage(assets.ImageBank[assets.Weapon], op)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//draw enemy shadows
|
||||||
for _, es := range c.enemies {
|
for _, es := range c.enemies {
|
||||||
if es.GetEnemyState() < gamedata.EnemyStateExploding {
|
if es.GetEnemyState() < gamedata.EnemyStateExploding {
|
||||||
|
|
||||||
@@ -116,6 +116,7 @@ func (c *Canvas) Draw(drawimg *ebiten.Image) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//draw enemies
|
||||||
for _, e := range c.enemies {
|
for _, e := range c.enemies {
|
||||||
e.Draw()
|
e.Draw()
|
||||||
|
|
||||||
@@ -127,13 +128,15 @@ func (c *Canvas) Draw(drawimg *ebiten.Image) {
|
|||||||
op.GeoM.Rotate(e.GetAngle())
|
op.GeoM.Rotate(e.GetAngle())
|
||||||
op.GeoM.Translate(e.GetPosition().X, e.GetPosition().Y)
|
op.GeoM.Translate(e.GetPosition().X, e.GetPosition().Y)
|
||||||
|
|
||||||
//op := &ebiten.DrawImageOptions{}
|
|
||||||
//op.GeoM.Translate(e.GetPosition().X-float64(e.GetSprite().Bounds().Dx())/2, e.GetPosition().Y-float64(e.GetSprite().Bounds().Dy())/2)
|
|
||||||
c.Sprite.DrawImage(e.GetSprite(), op)
|
c.Sprite.DrawImage(e.GetSprite(), op)
|
||||||
|
|
||||||
//do we need a health bar for this enemy?
|
//do we need a health bar for this enemy?
|
||||||
if e.Health() > 0 {
|
if e.Health() > 0 {
|
||||||
x0 := e.GetPosition().X - float64(e.GetSprite().Bounds().Dx())
|
|
||||||
|
hbWidth := float64(e.MaxHealth())*2 + 4
|
||||||
|
p1 := float64(e.GetSprite().Bounds().Dx())
|
||||||
|
p0 := e.GetPosition().X - p1/2
|
||||||
|
x0 := p0 - (hbWidth-p1)/2
|
||||||
y0 := e.GetPosition().Y - 2/3.*float64(e.GetSprite().Bounds().Dy())
|
y0 := e.GetPosition().Y - 2/3.*float64(e.GetSprite().Bounds().Dy())
|
||||||
vector.DrawFilledRect(c.Sprite, float32(x0), float32(y0), float32(e.MaxHealth())*2+4, 12, color.Black, true)
|
vector.DrawFilledRect(c.Sprite, float32(x0), float32(y0), float32(e.MaxHealth())*2+4, 12, color.Black, true)
|
||||||
vector.DrawFilledRect(c.Sprite, float32(x0+2), float32(y0+2), float32(e.Health())*2, 8, color.RGBA{R: 0xff, G: 0x00, B: 0x00, A: 0xff}, true)
|
vector.DrawFilledRect(c.Sprite, float32(x0+2), float32(y0+2), float32(e.Health())*2, 8, color.RGBA{R: 0xff, G: 0x00, B: 0x00, A: 0xff}, true)
|
||||||
@@ -165,7 +168,6 @@ func (c *Canvas) Draw(drawimg *ebiten.Image) {
|
|||||||
text.Draw(c.Sprite, "PRESS START TO TRY AGAIN", fonts.SurviveFont.Arcade, 640/2-150, 480/2, color.White)
|
text.Draw(c.Sprite, "PRESS START TO TRY AGAIN", fonts.SurviveFont.Arcade, 640/2-150, 480/2, color.White)
|
||||||
}
|
}
|
||||||
|
|
||||||
//op := &ebiten.DrawImageOptions{}
|
|
||||||
op.GeoM.Reset()
|
op.GeoM.Reset()
|
||||||
drawimg.DrawImage(c.Sprite, op)
|
drawimg.DrawImage(c.Sprite, op)
|
||||||
}
|
}
|
||||||
@@ -293,16 +295,9 @@ func (c *Canvas) UpdateProjectiles() {
|
|||||||
c.collisionMask.DrawImage(e.GetSprite(), op)
|
c.collisionMask.DrawImage(e.GetSprite(), op)
|
||||||
|
|
||||||
if c.HasCollided(c.collisionMask, 640*480*4) {
|
if c.HasCollided(c.collisionMask, 640*480*4) {
|
||||||
//fmt.Println("pixel collision")
|
|
||||||
//delete(g.projectiles, k)
|
|
||||||
projectilevalid = false
|
projectilevalid = false
|
||||||
//target.ToggleColor()
|
|
||||||
e.SetHit()
|
e.SetHit()
|
||||||
//target.SetOrigin(gamedata.Coordinates{X: rand.Float64() * 640, Y: rand.Float64() * 480})
|
|
||||||
//target.Hit = true
|
|
||||||
|
|
||||||
/*player := audioContext.NewPlayerFromBytes(assets.TargetHit)
|
|
||||||
player.Play()*/
|
|
||||||
if c.eventmap[gamedata.GameEventTargetHit] != nil {
|
if c.eventmap[gamedata.GameEventTargetHit] != nil {
|
||||||
c.eventmap[gamedata.GameEventTargetHit]()
|
c.eventmap[gamedata.GameEventTargetHit]()
|
||||||
}
|
}
|
||||||
@@ -381,13 +376,17 @@ func (c *Canvas) UpdateEnemies() {
|
|||||||
|
|
||||||
e.Update()
|
e.Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Canvas) SpawnEnemies() {
|
||||||
if !c.gameover {
|
if !c.gameover {
|
||||||
|
|
||||||
if !c.goblinspawned || c.goblindead {
|
if !c.goblinspawned || c.goblindead {
|
||||||
c.SpawnFlyEyes()
|
c.SpawnFlyEyes()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.goblinspawned { //&& c.counter > 1200 && !c.goblindead {
|
if !c.goblinspawned && c.counter > 2400 && !c.goblindead {
|
||||||
c.SpawnGoblin()
|
c.SpawnGoblin()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -508,5 +507,9 @@ func (c *Canvas) GoblinFireballEvent() {
|
|||||||
newfb.SetPosition(c.goblin.GetPosition())
|
newfb.SetPosition(c.goblin.GetPosition())
|
||||||
c.enemies = append(c.enemies, newfb)
|
c.enemies = append(c.enemies, newfb)
|
||||||
|
|
||||||
|
if c.eventmap[gamedata.GameEventFireball] != nil {
|
||||||
|
c.eventmap[gamedata.GameEventFireball]()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ func NewPrimary() *Primary {
|
|||||||
canvas.RegisterEvents(gamedata.GameEventNewShot, p.EventHandlerNewShot)
|
canvas.RegisterEvents(gamedata.GameEventNewShot, p.EventHandlerNewShot)
|
||||||
canvas.RegisterEvents(gamedata.GameEventTargetHit, p.EventHandlerTargetHit)
|
canvas.RegisterEvents(gamedata.GameEventTargetHit, p.EventHandlerTargetHit)
|
||||||
canvas.RegisterEvents(gamedata.GameEventExplosion, p.EventHandlerExplosion)
|
canvas.RegisterEvents(gamedata.GameEventExplosion, p.EventHandlerExplosion)
|
||||||
|
canvas.RegisterEvents(gamedata.GameEventFireball, p.EventHandlerFireball)
|
||||||
p.elements = append(p.elements, canvas)
|
p.elements = append(p.elements, canvas)
|
||||||
|
|
||||||
//create foreground cloud layer
|
//create foreground cloud layer
|
||||||
@@ -211,6 +212,9 @@ func (p *Primary) PlayAudio(e gamedata.GameEvent) {
|
|||||||
case gamedata.GameEventExplosion:
|
case gamedata.GameEventExplosion:
|
||||||
player := audioContext.NewPlayerFromBytes(assets.Splode)
|
player := audioContext.NewPlayerFromBytes(assets.Splode)
|
||||||
player.Play()
|
player.Play()
|
||||||
|
case gamedata.GameEventFireball:
|
||||||
|
player := audioContext.NewPlayerFromBytes(assets.Flare)
|
||||||
|
player.Play()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,3 +238,7 @@ func (p *Primary) EventHandlerTargetHit() {
|
|||||||
func (p *Primary) EventHandlerExplosion() {
|
func (p *Primary) EventHandlerExplosion() {
|
||||||
p.gameevents[gamedata.GameEventExplosion] = true
|
p.gameevents[gamedata.GameEventExplosion] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Primary) EventHandlerFireball() {
|
||||||
|
p.gameevents[gamedata.GameEventFireball] = true
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user