From db3fe6b2c7f597f27e3b5b08b0dc03357d7f9c04 Mon Sep 17 00:00:00 2001 From: js Date: Thu, 11 May 2023 05:24:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AD=90=E5=BC=B9?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../element/bullet/AbstractBullet.kt | 18 +++++++++++++++ .../aircraftwar/element/bullet/EnemyBullet.kt | 23 +++++++++++++++++++ .../aircraftwar/element/bullet/HeroBullet.kt | 16 +++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 app/src/main/java/net/imshit/aircraftwar/element/bullet/AbstractBullet.kt create mode 100644 app/src/main/java/net/imshit/aircraftwar/element/bullet/EnemyBullet.kt create mode 100644 app/src/main/java/net/imshit/aircraftwar/element/bullet/HeroBullet.kt diff --git a/app/src/main/java/net/imshit/aircraftwar/element/bullet/AbstractBullet.kt b/app/src/main/java/net/imshit/aircraftwar/element/bullet/AbstractBullet.kt new file mode 100644 index 0000000..70bade3 --- /dev/null +++ b/app/src/main/java/net/imshit/aircraftwar/element/bullet/AbstractBullet.kt @@ -0,0 +1,18 @@ +package net.imshit.aircraftwar.element.bullet + +import net.imshit.aircraftwar.element.AbstractFlyingObject +import net.imshit.aircraftwar.logic.Games + +abstract class AbstractBullet( + game: Games, initialX: Float, initialY: Float, speedX: Float, speedY: Float, val power: Int +) : AbstractFlyingObject( + game = game, initialX = initialX, initialY = initialY, speedX = speedX, speedY = speedY +) { + override fun forward(timeMs: Int) { + super.forward(timeMs) + // 额外判定 y 轴出界 + if (this.y <= 0) { + vanish() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/net/imshit/aircraftwar/element/bullet/EnemyBullet.kt b/app/src/main/java/net/imshit/aircraftwar/element/bullet/EnemyBullet.kt new file mode 100644 index 0000000..631d06e --- /dev/null +++ b/app/src/main/java/net/imshit/aircraftwar/element/bullet/EnemyBullet.kt @@ -0,0 +1,23 @@ +package net.imshit.aircraftwar.element.bullet + +import net.imshit.aircraftwar.logic.Games +import net.imshit.aircraftwar.util.listener.EnemyListener +import net.imshit.aircraftwar.util.listener.GameEvents + +class EnemyBullet( + game: Games, initialX: Float, initialY: Float, speedX: Float, speedY: Float, power: Int +) : AbstractBullet( + game = game, + initialX = initialX, + initialY = initialY, + speedX = speedX, + speedY = speedY, + power = power +), EnemyListener { + override val image = game.images.bulletEnemy + override fun notify(e: GameEvents) { + when (e) { + GameEvents.BOMB_ACTIVATE -> this.vanish() + } + } +} \ No newline at end of file diff --git a/app/src/main/java/net/imshit/aircraftwar/element/bullet/HeroBullet.kt b/app/src/main/java/net/imshit/aircraftwar/element/bullet/HeroBullet.kt new file mode 100644 index 0000000..a35b3e5 --- /dev/null +++ b/app/src/main/java/net/imshit/aircraftwar/element/bullet/HeroBullet.kt @@ -0,0 +1,16 @@ +package net.imshit.aircraftwar.element.bullet + +import net.imshit.aircraftwar.logic.Games + +class HeroBullet( + game: Games, initialX: Float, initialY: Float, speedX: Float, speedY: Float, power: Int +) : AbstractBullet( + game = game, + initialX = initialX, + initialY = initialY, + speedX = speedX, + speedY = speedY, + power = power +) { + override val image = game.images.bulletHero +} \ No newline at end of file