-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroDirectShootStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package net.imshit.aircraftwar.element.shoot.hero | ||
|
||
import net.imshit.aircraftwar.element.bullet.HeroBullet | ||
import net.imshit.aircraftwar.logic.Games | ||
|
||
class HeroDirectShootStrategy : HeroShootStrategy { | ||
override fun shoot( | ||
game: Games, x: Float, y: Float, speedY: Float, power: Int | ||
): List<HeroBullet> { | ||
val direction = -1 | ||
val bulletY = y + direction * 2 | ||
val bulletSpeedY = speedY + direction * 0.2f | ||
return listOf(HeroBullet(game, x, bulletY, 0f, bulletSpeedY, power)) | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroScatterShootStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package net.imshit.aircraftwar.element.shoot.hero | ||
|
||
import net.imshit.aircraftwar.element.bullet.HeroBullet | ||
import net.imshit.aircraftwar.logic.Games | ||
|
||
class HeroScatterShootStrategy : HeroShootStrategy { | ||
override fun shoot( | ||
game: Games, x: Float, y: Float, speedY: Float, power: Int | ||
): List<HeroBullet> { | ||
val direction = -1 | ||
val shootNum = 3 | ||
val bulletY = y + direction * 2 | ||
val bulletCenterSpeedX = 0f | ||
val bulletCenterSpeedY = speedY + direction * 0.2f | ||
return mutableListOf<HeroBullet>().apply { | ||
for (i in 0 until shootNum) { | ||
add( | ||
HeroBullet( | ||
game, | ||
x + (i * 2 - shootNum + 1) * 10, | ||
bulletY, | ||
bulletCenterSpeedX + (i * 2 - shootNum + 1) * 0.01f, | ||
bulletCenterSpeedY, | ||
power | ||
) | ||
) | ||
} | ||
}.toList() | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroShootStrategy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.imshit.aircraftwar.element.shoot.hero | ||
|
||
import net.imshit.aircraftwar.element.bullet.HeroBullet | ||
import net.imshit.aircraftwar.element.shoot.ShootStrategy | ||
import net.imshit.aircraftwar.logic.Games | ||
|
||
interface HeroShootStrategy : ShootStrategy { | ||
override fun shoot(game: Games, x: Float, y: Float, speedY: Float, power: Int): List<HeroBullet> | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroShootStrategyFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package net.imshit.aircraftwar.element.shoot.hero | ||
|
||
import net.imshit.aircraftwar.element.shoot.AbstractShootStrategyFactory | ||
|
||
class HeroShootStrategyFactory : AbstractShootStrategyFactory() { | ||
override fun getStrategy(shootNum: Int): HeroShootStrategy { | ||
return when (shootNum) { | ||
1 -> HeroDirectShootStrategy() | ||
3 -> HeroScatterShootStrategy() | ||
else -> HeroDirectShootStrategy() | ||
} | ||
} | ||
} |