Skip to content

Commit

Permalink
feat: 添加英雄机射击策略
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim-shop committed May 10, 2023
1 parent db3fe6b commit 0d78149
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
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))
}
}
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()
}
}
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>
}
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()
}
}
}

0 comments on commit 0d78149

Please sign in to comment.