Exemple #1
0
func (p *Player) Fire() {
	// Search for a dead projectile to reuse
	for e := p.projectileList.Front(); e != nil; e = e.Next() {
		tempProjectile := e.Value.(*projectile.Projectile)
		if tempProjectile.Alive == false {
			tempProjectile.Init(p.x, p.y-1, p.lastUpdate, PLAYER_PROJECTILE_SPEED, tm.ColorCyan)
			tempProjectile.Draw()

			return
		}

	}
	projectile := new(projectile.Projectile)
	projectile.Init(p.x, p.y-1, p.lastUpdate, PLAYER_PROJECTILE_SPEED, tm.ColorCyan)
	projectile.Draw()
	p.projectileList.PushBack(projectile)
}
func (a *AlienManager) Fire(x int, y int, lastUpdate int64) {
	// Search for a dead projectile to reuse
	for e := a.alienProjectileList.Front(); e != nil; e = e.Next() {
		tempProjectile := e.Value.(*projectile.Projectile)
		if tempProjectile.Alive == false {
			tempProjectile.Init(x, y, a.lastUpdate, ALIEN_PROJECTILE_SPEED, tm.ColorRed)
			tempProjectile.Draw()

			return
		}

	}

	projectile := new(projectile.Projectile)
	projectile.Init(x, y, a.lastUpdate, ALIEN_PROJECTILE_SPEED, tm.ColorRed)
	projectile.Draw()
	a.alienProjectileList.PushBack(projectile)
}