Commit 7134e73a authored by Daniel Drießen's avatar Daniel Drießen

ArcPath now pulsates in update()

Player now loses Shields after they hit a wall only in Difficulties Hard and Extreme
Bug fix in Game (Restoring the app caused an error)
parent 4a7c464f
......@@ -34,26 +34,24 @@ class EndGameDialog private constructor(a: GameActivity, private val score: Int)
btnRestart.setOnClickListener {
writeHighscore()
ownerActivity?.finish()
context.startActivity<GameActivity> {}
ownerActivity?.finish()
}
btnHighscores.setOnClickListener {
writeHighscore()
ownerActivity?.finish()
context.startActivity<Highscores> { }
ownerActivity?.finish()
}
btnMainMenu.setOnClickListener {
writeHighscore()
ownerActivity?.finish()
context.startActivity<MainMenu> { }
}
setOnDismissListener {
writeHighscore()
ownerActivity?.finish()
context.startActivity<MainMenu> { }
}
}
......
......@@ -19,7 +19,9 @@ class Game(@Transient private val gameActivity: GameActivity, val options: GameO
var collectedCoins = 0
private var paused = true
@Transient
private lateinit var pathManager: PathManager
@Transient
private lateinit var player: Player
@Transient
val size = PointF().apply {
......@@ -29,7 +31,7 @@ class Game(@Transient private val gameActivity: GameActivity, val options: GameO
var speed: Float = options.difficulty.initialSpeed
private var background = Color.BLACK
private val highscore
get() = collectedCoins * Constants.pointsCoinSimple + ticks * Constants.pointsPerTick
get() = collectedCoins * Constants.pointsCoinSimple + (ticks * Constants.pointsPerTick).toInt()
init {
holder.addCallback(this)
......@@ -57,9 +59,9 @@ class Game(@Transient private val gameActivity: GameActivity, val options: GameO
if (player.intersects(Path().apply {
addRect(
event.x,
event.y,
event.y - Constants.playerOffset.y,
event.x + 1,
event.y + 1,
event.y + 1 - Constants.playerOffset.y,
Path.Direction.CW
)
})) {
......
......@@ -44,7 +44,7 @@ class GameThread(private val game: Game) : Thread() {
val waitTime = targetTime - (System.currentTimeMillis() - start)
if (waitTime > 0) {
Thread.sleep(waitTime)
sleep(waitTime)
}
}
}
......@@ -27,7 +27,6 @@ class Player(pm: PathManager) : Sprite(pm) {
set(value) {
invincibleStart = if (value) pm.game.ticks else -1
}
lateinit var pos: PointF
val shields: MutableCollection<Shields> = mutableSetOf()
......@@ -70,13 +69,15 @@ class Player(pm: PathManager) : Sprite(pm) {
for (sh in shields) {
sh.transform(Matrix().apply { setRotate(pm.game.speed, pos.x, pos.y) })
}
var rs: Shields? = null
for (sh in shields)
for (e in pm.getEnemies())
if (sh.intersects(e)) {
pm.removeEnemy(e)
rs = sh
}
shields.remove(rs)
if (pm.game.options.difficulty.diffRes < Constants.Difficulty.HARD.diffRes) {
var rs: Shields? = null
for (sh in shields)
for (e in pm.getEnemies())
if (sh.intersects(e)) {
pm.removeEnemy(e)
rs = sh
}
shields.remove(rs)
}
}
}
......@@ -24,8 +24,8 @@ class ArcPath(pm: PathManager, width: Float, private val length: Float, p: Point
this.p = p
end.set(p.x, p.y - length / 2)
pm.addRandomCollectible( PointF(p.x - (pulsatingWidth + Constants.playerRadius), p.y),this)
pm.addRandomCollectible( PointF(p.x + (pulsatingWidth + Constants.playerRadius), p.y),this)
pm.addRandomCollectible(PointF(p.x - (pulsatingWidth + Constants.playerRadius), p.y), this)
pm.addRandomCollectible(PointF(p.x + (pulsatingWidth + Constants.playerRadius), p.y), this)
}
override fun draw(canvas: Canvas, paint: Paint) {
......@@ -33,6 +33,14 @@ class ArcPath(pm: PathManager, width: Float, private val length: Float, p: Point
if (pulsating) {
reset()
addCircle(p.x, p.y, (length / 2), Path.Direction.CW)
addCircle(p.x, p.y, (pulsatingWidth), Path.Direction.CCW)
}
}
override fun update() {
super.update()
if (pulsating) {
if (pulsatingWidth >= pulsatingMax || pulsatingWidth <= pulsatingMin)
pulsDirectionOut = !pulsDirectionOut
......@@ -41,9 +49,6 @@ class ArcPath(pm: PathManager, width: Float, private val length: Float, p: Point
} else {
pulsatingWidth -= 1 * pm.game.speed
}
addCircle(p.x, p.y, (length / 2), Path.Direction.CW)
addCircle(p.x, p.y, (pulsatingWidth), Path.Direction.CCW)
}
}
}
......@@ -49,9 +49,10 @@ class PathManager(val game: Game) : Serializable {
}
if (!paths.first().isOnSurface(Region(0, 0, game.size.x.toInt(), game.size.y.toInt()))) {
extendPath()
paths.removeAt(0)
}
if(paths.last().isOnSurface(Region(0, 0, game.size.x.toInt(), game.size.y.toInt())))
extendPath()
}
private fun extendPath() {
......
......@@ -8,7 +8,7 @@ import splitties.resources.appStr
object Constants {
const val playerRadius = 50f
const val startCircleRadius = 200f
const val pointsPerTick = 1
const val pointsPerTick = 0.1
const val pointsCoinSimple = 100
const val blinkMs = 300L
const val invincibleSec = 4
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment