Commit 122aee1b authored by deregges's avatar deregges

Added doc

parent 4955b6c9
......@@ -5,6 +5,10 @@ import android.content.Context
import android.graphics.Canvas
import android.view.SurfaceView
/**
* A SurfaceView which delegates its draw method to a constructor parameter
*/
@SuppressLint("ViewConstructor")
class DelegatingSurfaceView(ctx: Context, private val pDraw: (Canvas) -> Unit) : SurfaceView(ctx) {
override fun draw(canvas: Canvas) {
......
......@@ -13,6 +13,11 @@ import kotlinx.android.synthetic.main.end_game_dialog.*
import splitties.views.design.string
import splitties.views.design.text
/**
* The dialog to be shown after the player dies.
* registeres highscore on any button click leading away
* constructor private, Call EndGameDialog.show(Activity, Int)
*/
class EndGameDialog private constructor(a: Activity, private val score: Int) : Dialog(a) {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -63,6 +68,11 @@ class EndGameDialog private constructor(a: Activity, private val score: Int) : D
}
companion object {
/**
* Shows the dialog
* @param a the parent activity
* @param score the reached score
*/
fun show(a: Activity, score: Int) {
val diag = EndGameDialog(a, score)
......
......@@ -46,7 +46,7 @@ class GameActivity : AppCompatActivity(), SensorEventListener {
var speed: Float = Preferences.difficulty.initialSpeed
private var background = Color.BLACK
val highscore
get() = collectedCoins * Constants.pointsCoinSimple + (ticks * Constants.pointsPerTick).toInt() + defeatedBosses * 1000
get() = collectedCoins * Constants.pointsCoinSimple + (ticks * Constants.pointsPerTick).toInt() + defeatedBosses * Constants.pointsPerBoss
private var gameThread: GameThread? = null
private val surface: SurfaceView by lazy {
......
......@@ -9,18 +9,40 @@ import splitties.resources.appStr
import splitties.systemservices.sensorManager
object Constants {
// The radius of the drawn player circle
const val playerRadius = 50f
// The radius of the drawn starting circle
const val startCircleRadius = 200f
// The points (highscore) gained per tick
const val pointsPerTick = 0.1
// The points (highscore) gained per Coin
const val pointsCoinSimple = 100
// The points (highscore) gained per defeated boss
const val pointsPerBoss = 1000
// The period at wich the background color changes to red/black when player got hit
const val blinkMs = 300L
// The time the player is invincible after hit in seconds
const val invincibleSec = 4
// The targetted frames per second (all second definitions should base on this)
const val targetFPS = 30
// The second color of the background while cooldown (after player got hit)
const val blinkColor = Color.RED
// The amount of entries tracked per difficulty in highscores
const val maxTrackedHighscoreCount = 30
// The offset of the player when using touch mode (so the user can see the point)
val playerOffset: PointF = PointF(0f, -40f)
// The available range of the sensitivity multiplier.
// Example: 2 => 0.25 (2^-2) -- 0.5 (2^-1) -- 1 (2^0) -- 2 (2^1) -- 4 (2^2)
const val rotationSensitivityRadius: Int = 2
/**
* @param diffRes the app-string name for this difficulty
* @param lives available lived in this difficulty
* @param initialSpeed the starting background movement of the game (px per tick)
* @param speedPerSecond the absolute speed increase per second (see @initialSpeed)
* @param speedUpCoinStrength the absolute speed increase per collected speed-up coin (see @initialSpeed)
* @param speedDownCoinStrength the absolute speed decrease per collected speed-down coint (see @initalSpeed)
*/
enum class Difficulty(
val diffRes: Int,
val lives: Int,
......@@ -37,6 +59,10 @@ object Constants {
val diffName: String get() = appStr(diffRes)
}
/**
* @param display the app-string name for this input method
* @param isValid a predicate returning wether this input method is available
*/
enum class InputMethod(@StringRes val display: Int, private val isValid: () -> Boolean) {
TOUCH(R.string.inputMethodTouch, { true }),
ROTATION(R.string.inputMethodRotation, { sensorManager.getDefaultSensor(Sensor.TYPE_ROTATION_VECTOR) != null }),
......
......@@ -2,6 +2,9 @@ package io.ender.pathchaser.util
import android.graphics.Path
/**
* does an intersection check wether 'other' path is IN 'this' path
*/
fun Path.contains(other: Path): Boolean {
val opResult = Path()
val otherInverted = Path(other)
......@@ -10,6 +13,9 @@ fun Path.contains(other: Path): Boolean {
return opResult.isEmpty
}
/**
* does an intersection check wether 'other' path intersected with 'this' path
*/
fun Path.intersects(other:Path):Boolean{
return !Path().apply { op(this@intersects, other, Path.Op.INTERSECT) }.isEmpty
}
\ No newline at end of file
......@@ -5,60 +5,63 @@ package io.ender.pathchaser.util
import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import splitties.systemservices.layoutInflater
/**
* A small adapter that provides comfort functionality for the ViewHolder
*/
abstract class ViewHolder<T>(itemView: View) : androidx.recyclerview.widget.RecyclerView.ViewHolder(itemView) {
abstract class ViewHolder<T>(itemView: View) : RecyclerView.ViewHolder(itemView) {
val ctx: Context = itemView.context
abstract fun View.bind(el: T)
fun bind(el: T) = itemView.bind(el)
}
fun androidx.recyclerview.widget.RecyclerView.init0(adapter: androidx.recyclerview.widget.RecyclerView.Adapter<*>) {
if (layoutManager == null) layoutManager = androidx.recyclerview.widget.LinearLayoutManager(context)
fun RecyclerView.init0(adapter: RecyclerView.Adapter<*>) {
if (layoutManager == null) layoutManager = LinearLayoutManager(context)
addItemDecoration(
androidx.recyclerview.widget.DividerItemDecoration(
DividerItemDecoration(
context,
androidx.recyclerview.widget.DividerItemDecoration.VERTICAL
DividerItemDecoration.VERTICAL
)
)
this.adapter = adapter
}
fun <T, VH : ViewHolder<T>> androidx.recyclerview.widget.RecyclerView.init0(
fun <T, VH : ViewHolder<T>> RecyclerView.init0(
bindVH: (VH, Int) -> Unit,
getCount: () -> Int,
createVH: (ViewGroup, Int) -> VH
) {
init0(object : androidx.recyclerview.widget.RecyclerView.Adapter<VH>() {
init0(object : RecyclerView.Adapter<VH>() {
override fun onBindViewHolder(vh: VH, pos: Int) = bindVH(vh, pos)
override fun onCreateViewHolder(group: ViewGroup, type: Int): VH = createVH(group, type)
override fun getItemCount(): Int = getCount()
})
}
fun <T, VH : ViewHolder<T>> androidx.recyclerview.widget.RecyclerView.init0(
fun <T, VH : ViewHolder<T>> RecyclerView.init0(
data: List<T>,
vhConstr: (ViewGroup) -> VH
) = init0({ vh, pos -> vh.bind(data[pos]) }, { data.size }, { g, _ -> vhConstr(g) })
fun <T, VH : ViewHolder<T>> androidx.recyclerview.widget.RecyclerView.init(data: List<T>, vhConstr: (Context) -> VH) =
fun <T, VH : ViewHolder<T>> RecyclerView.init(data: List<T>, vhConstr: (Context) -> VH) =
init0(data) { vhConstr(it.context) }
fun <T, VH : ViewHolder<T>> androidx.recyclerview.widget.RecyclerView.init(
fun <T, VH : ViewHolder<T>> RecyclerView.init(
data: List<T>,
layout: Int,
vhConstr: (View) -> VH
) = init0(data) { vhConstr(layoutInflater.inflate(layout, it, false)) }
fun <T, VH : ViewHolder<T>> androidx.recyclerview.widget.RecyclerView.init(
fun <T, VH : ViewHolder<T>> RecyclerView.init(
data: List<T>,
getLayout: (T) -> Int,
vhConstr: (View) -> VH
) = init0(object : androidx.recyclerview.widget.RecyclerView.Adapter<VH>() {
) = init0(object : RecyclerView.Adapter<VH>() {
override fun onCreateViewHolder(group: ViewGroup, type: Int): VH =
vhConstr(layoutInflater.inflate(type, group, 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