Fireballs and shadows.
This commit is contained in:
@@ -26,12 +26,14 @@ type Canvas struct {
|
||||
|
||||
initialized bool
|
||||
goblinspawned bool
|
||||
goblindead bool
|
||||
lastInputs gamedata.GameInputs
|
||||
runtime float64
|
||||
counter int
|
||||
score int
|
||||
hero *elements.Hero
|
||||
charge *elements.Explosion
|
||||
goblin *elements.FlyGoblin
|
||||
enemies []elements.Enemies
|
||||
projectiles []*elements.Projectile
|
||||
gameover bool
|
||||
@@ -49,6 +51,7 @@ func NewCanvas(a gamedata.Area) *Canvas {
|
||||
initialized: false,
|
||||
gameover: false,
|
||||
goblinspawned: false,
|
||||
goblindead: false,
|
||||
score: 0,
|
||||
runtime: 0.,
|
||||
counter: 0,
|
||||
@@ -97,10 +100,35 @@ func (c *Canvas) Draw(drawimg *ebiten.Image) {
|
||||
c.Sprite.DrawImage(assets.ImageBank[assets.Weapon], op)
|
||||
}
|
||||
|
||||
for _, es := range c.enemies {
|
||||
if es.GetEnemyState() < gamedata.EnemyStateExploding {
|
||||
|
||||
dx := float64(assets.ImageBank[assets.FlyEyeShadow].Bounds().Dx()) / 2
|
||||
dy := float64(assets.ImageBank[assets.FlyEyeShadow].Bounds().Dy()) / 2
|
||||
sx := float64(es.GetSprite().Bounds().Dx()) / 48
|
||||
sy := float64(es.GetSprite().Bounds().Dy()) / 48
|
||||
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Translate(-dx, -dy)
|
||||
op.GeoM.Scale(sx, sy)
|
||||
op.GeoM.Translate(es.GetPosition().X, es.GetPosition().Y+float64(es.GetSprite().Bounds().Dx())/2)
|
||||
c.Sprite.DrawImage(assets.ImageBank[assets.FlyEyeShadow], op)
|
||||
}
|
||||
}
|
||||
|
||||
for _, e := range c.enemies {
|
||||
e.Draw()
|
||||
|
||||
xshift := float64(e.GetSprite().Bounds().Dx() / 2)
|
||||
yshift := float64(e.GetSprite().Bounds().Dy() / 2)
|
||||
|
||||
op := &ebiten.DrawImageOptions{}
|
||||
op.GeoM.Translate(e.GetPosition().X-float64(e.GetSprite().Bounds().Dx())/2, e.GetPosition().Y-float64(e.GetSprite().Bounds().Dy())/2)
|
||||
op.GeoM.Translate(-xshift, -yshift)
|
||||
op.GeoM.Rotate(e.GetAngle())
|
||||
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)
|
||||
|
||||
//do we need a health bar for this enemy?
|
||||
@@ -152,6 +180,7 @@ func (c *Canvas) Initialize() {
|
||||
c.counter = 0
|
||||
c.runtime = 0.
|
||||
c.goblinspawned = false
|
||||
c.goblindead = false
|
||||
|
||||
//temporary
|
||||
c.hero.Action = elements.HeroActionDefault
|
||||
@@ -354,43 +383,70 @@ func (c *Canvas) UpdateEnemies() {
|
||||
}
|
||||
if !c.gameover {
|
||||
|
||||
if !c.goblinspawned {
|
||||
//spawn new enemies
|
||||
f := 40000 / (c.counter + 1)
|
||||
|
||||
if c.counter%f == 0 {
|
||||
newenemy := elements.NewFlyEye()
|
||||
|
||||
x0 := rand.Float64() * 640
|
||||
y0 := rand.Float64() * 480
|
||||
quadrant := rand.IntN(3)
|
||||
|
||||
switch quadrant {
|
||||
case 0:
|
||||
newenemy.SetPosition(gamedata.Coordinates{X: x0, Y: -48})
|
||||
case 1:
|
||||
newenemy.SetPosition(gamedata.Coordinates{X: x0, Y: 480 + 48})
|
||||
case 2:
|
||||
newenemy.SetPosition(gamedata.Coordinates{X: -48, Y: y0})
|
||||
case 3:
|
||||
newenemy.SetPosition(gamedata.Coordinates{X: 640 + x0, Y: y0})
|
||||
}
|
||||
|
||||
newenemy.SetTarget(c.hero.Pos)
|
||||
|
||||
c.enemies = append(c.enemies, newenemy)
|
||||
}
|
||||
if !c.goblinspawned || c.goblindead {
|
||||
c.SpawnFlyEyes()
|
||||
}
|
||||
|
||||
if !c.goblinspawned && c.counter > 1200 {
|
||||
newfg := elements.NewFlyGoblin()
|
||||
c.enemies = append(c.enemies, newfg)
|
||||
c.goblinspawned = true
|
||||
if !c.goblinspawned { //&& c.counter > 1200 && !c.goblindead {
|
||||
c.SpawnGoblin()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Canvas) SpawnFlyEyes() {
|
||||
//spawn new enemies
|
||||
f := 40000 / (c.counter + 1)
|
||||
|
||||
if c.counter%f == 0 {
|
||||
newenemy := elements.NewFlyEye()
|
||||
|
||||
x0 := rand.Float64() * 640
|
||||
y0 := rand.Float64() * 480
|
||||
quadrant := rand.IntN(3)
|
||||
|
||||
switch quadrant {
|
||||
case 0:
|
||||
newenemy.SetPosition(gamedata.Coordinates{X: x0, Y: -48})
|
||||
case 1:
|
||||
newenemy.SetPosition(gamedata.Coordinates{X: x0, Y: 480 + 48})
|
||||
case 2:
|
||||
newenemy.SetPosition(gamedata.Coordinates{X: -48, Y: y0})
|
||||
case 3:
|
||||
newenemy.SetPosition(gamedata.Coordinates{X: 640 + x0, Y: y0})
|
||||
}
|
||||
|
||||
newenemy.SetTarget(c.hero.Pos)
|
||||
|
||||
c.enemies = append(c.enemies, newenemy)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Canvas) SpawnGoblin() {
|
||||
newfg := elements.NewFlyGoblin()
|
||||
newfg.SetDeathEvent(c.GoblinDeathEvent)
|
||||
newfg.SetFireballCallback(c.GoblinFireballEvent)
|
||||
|
||||
x0 := rand.Float64() * 640
|
||||
y0 := rand.Float64() * 480
|
||||
quadrant := rand.IntN(3)
|
||||
|
||||
switch quadrant {
|
||||
case 0:
|
||||
newfg.SetPosition(gamedata.Coordinates{X: x0, Y: -96})
|
||||
case 1:
|
||||
newfg.SetPosition(gamedata.Coordinates{X: x0, Y: 480 + 48})
|
||||
case 2:
|
||||
newfg.SetPosition(gamedata.Coordinates{X: -96, Y: y0})
|
||||
case 3:
|
||||
newfg.SetPosition(gamedata.Coordinates{X: 640 + x0, Y: y0})
|
||||
}
|
||||
|
||||
c.goblin = newfg
|
||||
c.enemies = append(c.enemies, newfg)
|
||||
c.goblinspawned = true
|
||||
}
|
||||
|
||||
func (c *Canvas) HasCollided(mask *ebiten.Image, size int) bool {
|
||||
var result bool = false
|
||||
var pixels []byte = make([]byte, size)
|
||||
@@ -430,3 +486,27 @@ func (c *Canvas) CleanupTargets() {
|
||||
}
|
||||
c.enemies = c.enemies[:i]
|
||||
}
|
||||
|
||||
func (c *Canvas) GoblinDeathEvent() {
|
||||
c.goblindead = true
|
||||
c.goblinspawned = false
|
||||
c.score += 10
|
||||
}
|
||||
|
||||
func (c *Canvas) GoblinFireballEvent() {
|
||||
|
||||
if !c.gameover {
|
||||
velocity := 8.
|
||||
dx := c.hero.Pos.X - c.goblin.GetPosition().X
|
||||
dy := c.hero.Pos.Y - c.goblin.GetPosition().Y
|
||||
angle := math.Atan2(dy, dx)
|
||||
|
||||
//add some randomness to the angle
|
||||
arand := rand.Float64() * math.Pi / 3
|
||||
|
||||
newfb := elements.NewFireBall(angle+arand, velocity)
|
||||
newfb.SetPosition(c.goblin.GetPosition())
|
||||
c.enemies = append(c.enemies, newfb)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user