diff --git a/app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroDirectShootStrategy.kt b/app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroDirectShootStrategy.kt new file mode 100644 index 0000000..8269ca6 --- /dev/null +++ b/app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroDirectShootStrategy.kt @@ -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 { + val direction = -1 + val bulletY = y + direction * 2 + val bulletSpeedY = speedY + direction * 0.2f + return listOf(HeroBullet(game, x, bulletY, 0f, bulletSpeedY, power)) + } +} \ No newline at end of file diff --git a/app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroScatterShootStrategy.kt b/app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroScatterShootStrategy.kt new file mode 100644 index 0000000..09d2096 --- /dev/null +++ b/app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroScatterShootStrategy.kt @@ -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 { + val direction = -1 + val shootNum = 3 + val bulletY = y + direction * 2 + val bulletCenterSpeedX = 0f + val bulletCenterSpeedY = speedY + direction * 0.2f + return mutableListOf().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() + } +} \ No newline at end of file diff --git a/app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroShootStrategy.kt b/app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroShootStrategy.kt new file mode 100644 index 0000000..bb03a9f --- /dev/null +++ b/app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroShootStrategy.kt @@ -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 +} \ No newline at end of file diff --git a/app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroShootStrategyFactory.kt b/app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroShootStrategyFactory.kt new file mode 100644 index 0000000..66ad9f4 --- /dev/null +++ b/app/src/main/java/net/imshit/aircraftwar/element/shoot/hero/HeroShootStrategyFactory.kt @@ -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() + } + } +} \ No newline at end of file