Skip to content

Commit

Permalink
refactor: 清理
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim-shop committed May 26, 2023
1 parent 5f2e557 commit 0f79ef9
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions app/src/main/java/net/imshit/aircraftwar/logic/game/Games.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,18 @@ sealed class Games(context: Context, attrs: AttributeSet?, soundMode: Boolean) :
const val SCORE_SIZE = 128f
const val SCORE_X = 10f
const val SCORE_Y = SCORE_SIZE + 10f
}

class AccelerateSensorListener(val callback: (Float, Float, Float) -> Unit) :
SensorEventListener {
override fun onSensorChanged(event: SensorEvent?) {
val ax = event?.values?.get(0) ?: 0.0f
val ay = event?.values?.get(1) ?: 0.0f
val az = event?.values?.get(2) ?: 0.0f
callback(ax, ay, az)
}

override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {}
class AccelerateSensorListener(val callback: (Float, Float, Float) -> Unit) :
SensorEventListener {
override fun onSensorChanged(event: SensorEvent?) {
val ax = event?.values?.get(0) ?: 0.0f
val ay = event?.values?.get(1) ?: 0.0f
val az = event?.values?.get(2) ?: 0.0f
callback(ax, ay, az)
}

override fun onAccuracyChanged(sensor: Sensor?, accuracy: Int) {}
}

/** used by design tool */
Expand All @@ -91,15 +91,15 @@ sealed class Games(context: Context, attrs: AttributeSet?, soundMode: Boolean) :
private lateinit var gravitySensorListener: AccelerateSensorListener
var mainHandle: Handler? = null
lateinit var images: ImageManager
private val musicStrategy: MusicStrategies =
if (soundMode) BasicMusicStrategy(context) else MuteMusicStrategy
private var logicJob: Job? = null

// configs
lateinit var background: Bitmap

// strategies
abstract val generateStrategy: EnemyGenerateStrategies
private val musicStrategy: MusicStrategies =
if (soundMode) BasicMusicStrategy(context) else MuteMusicStrategy

// status
private var score = 0
Expand Down Expand Up @@ -161,12 +161,14 @@ sealed class Games(context: Context, attrs: AttributeSet?, soundMode: Boolean) :
}

private fun initHeroController() {
// 触摸屏
setOnTouchListener { view, motionEvent ->
view.performClick()
this.heroAircraft.x = motionEvent.x
this.heroAircraft.y = motionEvent.y
true
}
// 重力感应
sensorManager = context.getSystemService(Context.SENSOR_SERVICE) as SensorManager
with(sensorManager) {
gravitySensor =
Expand Down

0 comments on commit 0f79ef9

Please sign in to comment.