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 878a833 commit 7c971f6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/src/main/java/net/imshit/aircraftwar/element/prop/BloodProp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.imshit.aircraftwar.element.prop

import net.imshit.aircraftwar.logic.Games

class BloodProp(
game: Games, initialX: Float, initialY: Float, speedX: Float, speedY: Float
) : Props(
game = game, initialX = initialX, initialY = initialY, speedX = speedX, speedY = speedY
) {
override val image = game.images.propBlood
override fun activate() {
game.heroAircraft.increaseHp(100)
}
}
15 changes: 15 additions & 0 deletions app/src/main/java/net/imshit/aircraftwar/element/prop/BombProp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package net.imshit.aircraftwar.element.prop

import net.imshit.aircraftwar.logic.GameEvents
import net.imshit.aircraftwar.logic.Games

class BombProp(
game: Games, initialX: Float, initialY: Float, speedX: Float, speedY: Float
) : Props(
game = game, initialX = initialX, initialY = initialY, speedX = speedX, speedY = speedY
) {
override val image = game.images.propBomb
override fun activate() {
game.notify(GameEvents.BOMB_ACTIVATE)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.imshit.aircraftwar.element.prop

import net.imshit.aircraftwar.logic.Games
import java.util.Timer
import java.util.TimerTask
import java.util.concurrent.atomic.AtomicInteger

class BulletProp(
game: Games, initialX: Float, initialY: Float, speedX: Float, speedY: Float
) : Props(
game = game, initialX = initialX, initialY = initialY, speedX = speedX, speedY = speedY
) {
companion object {
private val usedCount = AtomicInteger(0)
}

override val image = game.images.propBullet

override fun activate() {
usedCount.getAndIncrement()
val heroAircraft = game.heroAircraft
heroAircraft.setShootNum(3)
Timer().schedule(object : TimerTask() {
override fun run() {
if (usedCount.decrementAndGet() <= 0) {
heroAircraft.setShootNum(1)
}
}
}, 10000)
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/net/imshit/aircraftwar/element/prop/Props.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.imshit.aircraftwar.element.prop

import net.imshit.aircraftwar.element.AbstractFlyingObject
import net.imshit.aircraftwar.logic.Games

sealed class Props(
game: Games, initialX: Float, initialY: Float, speedX: Float, speedY: Float
) : AbstractFlyingObject(
game = game, initialX = initialX, initialY = initialY, speedX = speedX, speedY = speedY
) {
abstract fun activate()
}

0 comments on commit 7c971f6

Please sign in to comment.