Commit ed24d2f7 authored by Daniel Drießen's avatar Daniel Drießen

Implemented Boss

Game now pauses if you touch the display, while playing without touch.
parent 731feade
......@@ -23,6 +23,7 @@ class GameActivity : AppCompatActivity(), SensorEventListener {
var ticks = 0
private set
var collectedCoins = 0
var defeatedBosses = 0
private var paused = Preferences.inputMethod == Constants.InputMethod.TOUCH
private val pathManager: PathManager by lazy {
......@@ -41,8 +42,8 @@ class GameActivity : AppCompatActivity(), SensorEventListener {
}
var speed: Float = Preferences.difficulty.initialSpeed
private var background = Color.BLACK
private val highscore
get() = collectedCoins * Constants.pointsCoinSimple + (ticks * Constants.pointsPerTick).toInt()
val highscore
get() = collectedCoins * Constants.pointsCoinSimple + (ticks * Constants.pointsPerTick).toInt() + defeatedBosses * 1000
private var gameThread: GameThread? = null
private val surface: SurfaceView by lazy {
......@@ -163,6 +164,12 @@ class GameActivity : AppCompatActivity(), SensorEventListener {
paused = true
}
}
} else {
when (event.action) {
MotionEvent.ACTION_UP -> {
paused = !paused
}
}
}
return true
}
......
......@@ -2,6 +2,7 @@ package io.ender.pathchaser
import android.graphics.*
import io.ender.pathchaser.collectibles.Shields
import io.ender.pathchaser.enemys.Boss
import io.ender.pathchaser.paths.PathManager
import io.ender.pathchaser.util.Constants
import io.ender.pathchaser.util.Preferences
......@@ -87,7 +88,10 @@ class Player(pm: PathManager) : Sprite(pm) {
for (e in pm.getEnemies()) {
e.detransform()
if (sh.intersects(e)) {
pm.removeEnemy(e)
if (e is Boss) {
e.life--
} else
pm.removeEnemy(e)
rs = sh
}
e.transform()
......
......@@ -5,6 +5,7 @@ import io.ender.pathchaser.paths.PathManager
import java.io.Serializable
abstract class Sprite(val pm: PathManager) : Path(), Serializable {
var rotated = 0f
abstract fun getPaint(): Paint
open fun update() {}
......@@ -37,4 +38,24 @@ abstract class Sprite(val pm: PathManager) : Path(), Serializable {
)
})
}
fun rotate(x: Float, y: Float) {
transform(Matrix().apply {
setRotate(
rotated,
x,
y
)
})
}
fun derotate(x: Float, y: Float) {
transform(Matrix().apply {
setRotate(
-rotated,
x,
y
)
})
}
}
package io.ender.pathchaser.enemys
import android.graphics.Color
import android.graphics.Paint
import android.graphics.PointF
import io.ender.pathchaser.Sprite
import io.ender.pathchaser.collectibles.*
import io.ender.pathchaser.paths.BossPath
import io.ender.pathchaser.paths.PathManager
import io.ender.pathchaser.util.Constants
class Boss(p: PointF, pm: PathManager, val bp: BossPath) : Enemy(p, pm) {
var life = 10
set(value) {
if (value == 0) {
pm.bossDefeated()
pm.removeEnemy(this)
}
field = value
}
override fun getPaint(): Paint {
return Paint().apply { color = Color.MAGENTA }
}
init {
reset()
addCircle(p.x, p.y, Constants.playerRadius, Direction.CW)
}
fun spawn() {
for (i in 0..1) {
val sp = sprite()
if (sp is Sprite) {
sp.rotated = rotated + i * 360 / 3
sp.rotate(p.x, p.y)
if (sp is Collectible)
bp.collectibles.add(sp)
if (sp is Enemy)
bp.enemies.add(sp)
}
}
}
private fun sprite(): Sprite? {
val p = PointF(p.x, p.y + Constants.playerRadius * 1.5f)
return when ((0..100).random()) {
in 1..3 -> SpeedUp(pm, p)
in 5..6 -> SpeedDown(pm, p)
in 10..18 -> Shields(pm, p)
in 20..40 -> null
in 50..55 -> Coin(pm, p)
else -> Enemy(p, pm)
}
}
}
\ No newline at end of file
......@@ -8,7 +8,7 @@ import io.ender.pathchaser.util.Constants
import io.ender.pathchaser.Sprite
import io.ender.pathchaser.paths.PathManager
class Enemy(private var p: PointF, pm:PathManager) : Sprite(pm) {
open class Enemy(var p: PointF, pm:PathManager) : Sprite(pm) {
override fun getPaint() = Paint().apply { color = Color.MAGENTA }
init{
......
package io.ender.pathchaser.paths
import android.graphics.*
import io.ender.pathchaser.Sprite
import io.ender.pathchaser.collectibles.Collectible
import io.ender.pathchaser.enemys.Boss
import io.ender.pathchaser.util.contains
import io.ender.pathchaser.util.intersects
class BossPath(pm: PathManager, start: PointF, r: Float) : Pathway(pm, start) {
private val speed = pm.game.speed
private var boss = Boss(PointF(start.x, start.y), pm, this)
init {
addCircle(start.x, start.y, r, Path.Direction.CW)
end.set(start.x, start.y - r)
enemies.add(boss)
showCollectibles = true
}
override fun move(x: Float, y: Float) {
super.move(x, y)
for (e in enemies) e.move(x, y)
pm.pause = start.y > pm.game.size.y / 2 && boss.life > 0
}
override fun update() {
super.update()
boss.rotated += pm.game.speed / 4
boss.rotated %= 360
if (pm.game.ticks % 20 == 0 && boss.life > 0)
boss.spawn()
val spDel = mutableListOf<Sprite>()
for (e in enemies) {
e.transform(Matrix().apply {
setRotate(pm.game.speed / 4, start.x, start.y)
})
e.rotated += pm.game.speed / 4
e.rotated %= 360
if (e !is Boss) {
e.derotate(start.x, start.y)
e.move(0f, speed)
e.rotate(start.x, start.y)
}
e.detransform()
if (e.intersects(pm.game.player)) {
pm.game.player.lives--
}
e.transform()
if (!e.contains(this))
spDel.add(e)
}
for (c in collectibles) {
c.transform(Matrix().apply {
setRotate(pm.game.speed / 4, start.x, start.y)
})
c.rotated += pm.game.speed / 4
c.rotated %= 360
c.derotate(start.x, start.y)
c.move(0f, speed)
c.rotate(start.x, start.y)
if (!c.contains(this))
spDel.add(c)
}
for (sp in spDel) {
if (sp is Collectible)
collectibles.remove(sp)
else enemies.remove(sp)
}
}
override fun draw(canvas: Canvas, paint: Paint) {
super.draw(canvas, paint)
for (e in enemies) e.draw(canvas, e.getPaint())
}
}
\ No newline at end of file
......@@ -18,6 +18,8 @@ class PathManager(val game: GameActivity) : Serializable {
fun getPaths(): List<Pathway> = paths
var degreesRotated = 0f
var degreesToRotate = 0f
var pause = false
var boss = false
init {
// start path wrapping the player
......@@ -30,7 +32,11 @@ class PathManager(val game: GameActivity) : Serializable {
canvas.rotate(-degreesRotated, game.size.x / 2, game.size.y / 2)
for (path in paths)
if(path is RectPath)
path.draw(canvas, path.getPaint())
for (path in paths)
if(path !is RectPath)
path.draw(canvas, path.getPaint())
canvas.rotate(degreesRotated, game.size.x / 2, game.size.y / 2)
}
......@@ -43,7 +49,7 @@ class PathManager(val game: GameActivity) : Serializable {
for (path in paths) {
path.update()
path.move(0f, game.speed)
path.move(0f, if (!pause) game.speed else 0f)
path.collect(game.player)?.trigger()
}
......@@ -65,7 +71,9 @@ class PathManager(val game: GameActivity) : Serializable {
private fun extendPath() {
val upper = paths.last().end
paths.add(
when (if (paths.last() is RectPath) (0..3).random() else 0) {
when (if (paths.last() is RectPath)
if (game.defeatedBosses < game.highscore / 5000 && !boss) 4.apply { boss = true } else (0..3).random()
else 0) {
0 -> RectPath(this, Constants.playerRadius * 4.2f, 400f, PointF(upper.x, upper.y - 75))
1 -> ArcPath(
this,
......@@ -74,8 +82,9 @@ class PathManager(val game: GameActivity) : Serializable {
PointF(upper.x, upper.y - 200),
(0..1).random() == 0
)
2 -> CirclePath(this, PointF(upper.x, upper.y - 200), 300f, (0..4).random())
2 -> CirclePath(this, PointF(upper.x, upper.y - 200), 300f, (0..3).random())
3 -> ForkPath(this, PointF(upper.x, upper.y - 250), 800, 200, 200)
4 -> BossPath(this, PointF(upper.x, upper.y - 350), 450f)
else -> throw IllegalStateException()
}.apply { showCollectibles = true }
)
......@@ -104,4 +113,10 @@ class PathManager(val game: GameActivity) : Serializable {
}
)
}
fun bossDefeated() {
game.defeatedBosses++
pause = false
boss = false
}
}
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