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

Documented Classes

parent 317e26d2
......@@ -9,6 +9,10 @@ import io.ender.pathchaser.util.Preferences
import io.ender.pathchaser.util.contains
import io.ender.pathchaser.util.intersects
/**
* Player-Sprite
* @param pm the PathManager
*/
class Player(pm: PathManager) : Sprite(pm) {
var lives = Preferences.difficulty.lives
set(value) {
......@@ -52,6 +56,9 @@ class Player(pm: PathManager) : Sprite(pm) {
return paint
}
/**
* @return whether the Player is on the viewed Path
*/
private fun isOnPath(): Boolean {
val unified = Path()
for (path in pm.getPaths()) unified.addPath(path)
......@@ -76,6 +83,10 @@ class Player(pm: PathManager) : Sprite(pm) {
sh.draw(canvas, sh.getPaint())
}
/**
* Rotates Shields, checks if one hits an enemy and removes it, if it does.
* Moves Player if the game isn't played with touch
*/
override fun update() {
super.update()
......
......@@ -4,6 +4,10 @@ import android.graphics.*
import io.ender.pathchaser.paths.PathManager
import java.io.Serializable
/**
* Fundamental viewing element
* @param pm the PathManager
*/
abstract class Sprite(val pm: PathManager) : Path(), Serializable {
var rotated = 0f
abstract fun getPaint(): Paint
......@@ -19,6 +23,9 @@ abstract class Sprite(val pm: PathManager) : Path(), Serializable {
offset(x, y)
}
/**
* used to turn a Sprite into its unrotated form while drawing
*/
fun transform() {
transform(Matrix().apply {
setRotate(
......@@ -29,6 +36,9 @@ abstract class Sprite(val pm: PathManager) : Path(), Serializable {
})
}
/**
* used to turn a Sprite into its rotated form while drawing
*/
fun detransform() {
transform(Matrix().apply {
setRotate(
......@@ -39,6 +49,11 @@ abstract class Sprite(val pm: PathManager) : Path(), Serializable {
})
}
/**
* used to turn a Sprite so that it has 0 degree
* @param x x-Coordinate of the Point it will rotate
* @param y y-Coordinate of the Point it will rotate
*/
fun rotate(x: Float, y: Float) {
transform(Matrix().apply {
setRotate(
......@@ -49,6 +64,11 @@ abstract class Sprite(val pm: PathManager) : Path(), Serializable {
})
}
/**
* used to turn a Sprite so that it has it natural angle
* @param x x-Coordinate of the Point it will rotate
* @param y y-Coordinate of the Point it will rotate
*/
fun derotate(x: Float, y: Float) {
transform(Matrix().apply {
setRotate(
......
......@@ -6,6 +6,14 @@ import android.graphics.Path
import android.graphics.PointF
import io.ender.pathchaser.util.Constants
/**
* Circular Path with a circular hole
* @param pm the PathManager
* @param width width of the path on which the player can move if puls false
* @param length Radius of the Circle
* @param p central Point of the Path
* @param puls if true the hole pulsates
*/
class ArcPath(pm: PathManager, width: Float, private val length: Float, p: PointF, puls: Boolean) : Pathway(pm, p) {
private var pulsatingWidth: Float = length / 2 - width //Float describing the width of the hole at the moment
private var pulsatingMax = length / 2 - Constants.playerRadius * 2.5 //Int describing the max radius of the Hole
......@@ -13,11 +21,6 @@ class ArcPath(pm: PathManager, width: Float, private val length: Float, p: Point
private var pulsating = puls
private var pulsDirectionOut = true
/*private var collect = arrayOf(
PointF(p.x - (pulsatingWidth + getPlayerRadius()), p.y),
PointF(p.x + (pulsatingWidth + getPlayerRadius()), p.y)
)*/
init {
addCircle(p.x, p.y, (length / 2), Path.Direction.CW)
addCircle(p.x, p.y, (length / 2 - width), Path.Direction.CCW)
......@@ -38,6 +41,9 @@ class ArcPath(pm: PathManager, width: Float, private val length: Float, p: Point
}
}
/**
* Makes hole bigger and smaller if it reached max width
*/
override fun update() {
super.update()
if (pulsating) {
......
......@@ -7,6 +7,12 @@ import io.ender.pathchaser.enemies.Boss
import io.ender.pathchaser.util.contains
import io.ender.pathchaser.util.intersects
/**
* Circular Path which contains a Boss (Enemy) and stops movement if it reaches the display center
* @param pm the PathManager
* @param r Circle radius in px
* @param start central Point of the Path
*/
class BossPath(pm: PathManager, start: PointF, r: Float) : Pathway(pm, start) {
......@@ -26,6 +32,9 @@ class BossPath(pm: PathManager, start: PointF, r: Float) : Pathway(pm, start) {
pm.pause = start.y > pm.game.size.y / 2 && boss.life > 0
}
/**
* Rotates every Enemy and Collectible in a spiral
*/
override fun update() {
super.update()
boss.rotated += pm.game.speed / 4
......
......@@ -4,6 +4,13 @@ import android.graphics.*
import io.ender.pathchaser.enemies.Enemy
import io.ender.pathchaser.util.intersects
/**
* Circular Path which can contain enemies
* @param pm the PathManager
* @param r Circle radius in px
* @param start central Point of the Path
* @param enemyNumber number of enemies spawned
*/
class CirclePath(pm: PathManager, start: PointF, r: Float, enemyNumber: Int = 0) : Pathway(pm, start) {
......
......@@ -3,6 +3,14 @@ package io.ender.pathchaser.paths
import android.graphics.Path
import android.graphics.PointF
/**
* Rectangular Path with a rectangular hole
* @param pm the PathManager
* @param width absolute width (x-Axis) in px
* @param length absolute length (y-Axis) in px
* @param p central Point of the Path
* @param gap absolute width of the gap (x-Axis) in px
*/
class ForkPath(pm: PathManager, start: PointF, length: Int, width: Int, gap: Int) : Pathway(pm, start) {
init {
p = start
......
......@@ -16,7 +16,10 @@ class PathManager(val game: GameActivity) : Serializable {
fun getPaths(): List<Pathway> = paths
var degreesRotated = 0f
var degreesToRotate = 0f
//if true game stops moving
var pause = false
//if true a boss has spawned and is alive
private var boss = false
init {
......@@ -29,16 +32,21 @@ class PathManager(val game: GameActivity) : Serializable {
fun draw(canvas: Canvas) {
canvas.rotate(-degreesRotated, game.size.x / 2, game.size.y / 2)
//Rectpaths only connect to other paths and have to be drawn first, so that they won't overdraw special paths
for (path in paths)
if(path is RectPath)
path.draw(canvas, path.getPaint())
if (path is RectPath)
path.draw(canvas, path.getPaint())
for (path in paths)
if(path !is RectPath)
if (path !is RectPath)
path.draw(canvas, path.getPaint())
canvas.rotate(degreesRotated, game.size.x / 2, game.size.y / 2)
}
/**
* Updates all paths, moves them and triggers any collected Collectibles.
* Adds paths and deletes paths, which aren't viewed anymore.
*/
fun update() {
if (paths.isEmpty()) {
Log.e("PM", "empty path list!")
......@@ -51,12 +59,15 @@ class PathManager(val game: GameActivity) : Serializable {
path.collect(game.player)?.trigger()
}
//looks if the oldest path isn't on the screen anymore
if (!paths.first().isOnSurface(Region(0, 0, game.size.x.toInt(), game.size.y.toInt()))) {
paths.removeAt(0)
}
//looks if the new path is on the screen and adds a new one if it is
if (paths.last().isOnSurface(Region(0, 0, game.size.x.toInt(), game.size.y.toInt())))
extendPath()
//changes the rotation degree (experimental)
if (degreesRotated - degreesToRotate < 0) {
degreesRotated += 0.5f
} else {
......@@ -66,8 +77,13 @@ class PathManager(val game: GameActivity) : Serializable {
}
/**
* Randomly generate a new Path.
*/
private fun extendPath() {
val upper = paths.last().end
//adds a new path on top of the newest path, if the newest path wasn't a RectPath, a RectPath will be drawn
paths.add(
when (if (paths.last() is RectPath)
if (game.defeatedBosses < game.highscore / 5000 && !boss) 4.apply { boss = true } else (0..3).random()
......@@ -100,6 +116,11 @@ class PathManager(val game: GameActivity) : Serializable {
path.enemies.remove(e)
}
/**
* Adds a random Collectible to the path
* @param p Point where the Collectible is added
* @param path Pathway to which a new Collectible is added
*/
fun addRandomCollectible(p: PointF, path: Pathway) {
path.collectibles.add(
when ((1..100).random()) {
......@@ -112,6 +133,9 @@ class PathManager(val game: GameActivity) : Serializable {
)
}
/**
* Game starts moving again and Boss is defeated
*/
fun bossDefeated() {
game.defeatedBosses++
pause = false
......
......@@ -42,6 +42,10 @@ abstract class Pathway(pm: PathManager, val start: PointF = PointF(), val end: P
coll.draw(canvas, coll.getPaint())
}
/**
* @param p the Player
* @return the Collectible if the player hits one else null
*/
open fun collect(p: Player): Collectible? {
var collected: Collectible? = null
if (showCollectibles)
......
......@@ -3,6 +3,13 @@ package io.ender.pathchaser.paths
import android.graphics.Path
import android.graphics.PointF
/**
* Rectangular Path which is spawned at the end of every other path typ
* @param pm the PathManager
* @param width absolute width (x-Axis) in px
* @param height absolute length (y-Axis) in px
* @param p central Point of the Path
*/
class RectPath(pm: PathManager, width: Float, height: Float, p: PointF) : Pathway(pm, p) {
init {
addRect(
......@@ -14,7 +21,6 @@ class RectPath(pm: PathManager, width: Float, height: Float, p: PointF) : Pathwa
)
end.set(p.x, p.y - height / 2)
//rotate(45f)
pm.addRandomCollectible(PointF(p.x, p.y), this)
}
}
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