From fd0c29f0895670ef8953f941b30c8bdc9e26119d Mon Sep 17 00:00:00 2001 From: merlin Date: Sat, 14 May 2022 17:14:47 -0400 Subject: [PATCH] grant speed score bonus to all manner of fast play --- README.md | 10 +++++----- build.gradle | 2 +- core/src/org/merlin/tertis/game/Player.scala | 14 ++++++++------ core/src/org/merlin/tertis/game/Score.scala | 10 +++++----- core/src/org/merlin/tertis/util/Average.scala | 18 ++++++++++++++++++ 5 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 core/src/org/merlin/tertis/util/Average.scala diff --git a/README.md b/README.md index 4615758..e6d8181 100644 --- a/README.md +++ b/README.md @@ -58,15 +58,15 @@ sdk.dir=/opt/homebrew/share/android-commandlinetools/ * Achieving greatness: ```shell -desktop/build/libs/desktop-0.1.jar +desktop/build/libs/desktop-1.0.jar ``` * Which you can run: ```shell -java -jar desktop/build/libs/desktop-0.1.jar +java -jar desktop/build/libs/desktop-1.0.jar # or, on a Mac -java -XstartOnFirstThread -jar desktop/build/libs/desktop-0.1.jar +java -XstartOnFirstThread -jar desktop/build/libs/desktop-1.0.jar ``` ### Packaging for a Mac @@ -81,14 +81,14 @@ jpackage \ --input desktop/build/libs/ \ --name Tertis \ --app-version 1.0 \ - --main-jar desktop-0.1.jar \ + --main-jar desktop-1.0.jar \ --main-class org.merlin.tertis.DesktopLauncher \ --type dmg \ --java-options '-XstartOnFirstThread' \ --icon mac/Tertis.icns ``` -Yielding: `Tertis-1.0.dmg`. Version 0 is not allowed. +Yielding: `Tertis-1.0.dmg`. ## Building for Android diff --git a/build.gradle b/build.gradle index a03e941..f6728bd 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,7 @@ buildscript { allprojects { apply plugin: "eclipse" - version = '0.1' + version = '1.0' ext { appName = "run" gdxVersion = '1.11.0' diff --git a/core/src/org/merlin/tertis/game/Player.scala b/core/src/org/merlin/tertis/game/Player.scala index b27d321..89626e3 100644 --- a/core/src/org/merlin/tertis/game/Player.scala +++ b/core/src/org/merlin/tertis/game/Player.scala @@ -6,6 +6,7 @@ import com.badlogic.gdx.Input.Peripheral import com.badlogic.gdx.graphics.g2d.{BitmapFont, PolygonSpriteBatch} import org.merlin.tertis.Geometry._ import org.merlin.tertis.Tertis +import org.merlin.tertis.util.Average case class BlockLoc(block: Block, rotation: Int, column: Int, y: Float) @@ -15,15 +16,15 @@ object BlockLoc { } class Player(game: Game) { - // how many seconds has this been touched down + // how many seconds has the piece been touched down var touchdown: Option[Float] = None - // was this piece played all speeidly - var speedy: Boolean = true + // average speed + val speed = new Average var blockOpt: Option[BlockLoc] = None def next(block: Block): Unit = { - speedy = true + speed.reset() blockOpt = Some(BlockLoc(block)) } @@ -53,7 +54,6 @@ class Player(game: Game) { val now = System.currentTimeMillis val fastness = game.fast.fold(1f, Prefs.TiltSpeed.fold(tiltSpeed, 0f)) - if (fastness < .8f) speedy = false val speedup = 1f + game.zenMode.fold( @@ -64,6 +64,8 @@ class Player(game: Game) { GravitySpeed, SlowSpeed + (FastSpeed - SlowSpeed) * fastness * speedup ) + speed += velocityY + // if you move two dimension units you could jump through blocks val deltaY = (velocityY * Dimension * delta) min (Dimension * 15 / 8) val newY = oldLoc.y - deltaY @@ -105,7 +107,7 @@ class Player(game: Game) { touchdown = None blockOpt = None game.gravity = false - game.score.drop(speedy) + game.score.drop(speed.value / SlowSpeed) } else { touchdown = touchdown.map(_ + delta).orElse(Some(0f)) } diff --git a/core/src/org/merlin/tertis/game/Score.scala b/core/src/org/merlin/tertis/game/Score.scala index a4d6119..608d208 100644 --- a/core/src/org/merlin/tertis/game/Score.scala +++ b/core/src/org/merlin/tertis/game/Score.scala @@ -12,14 +12,13 @@ class Score { var score: Int = 0 var count: Int = 0 var rows: Int = 0 - var speedRun: Int = 0 + var speedRun: Int = 0 // sequential piece dropped at >= SpeedRunSpeed var highScore: Boolean = false - // TODO: gravity assist should be equivalent to speedy if you are quick about it. zen lower score? - - def drop(speedy: Boolean): Unit = { + // speed is multiple of slow speed that was used + def drop(speed: Float): Unit = { count = count + 1 - speedRun = speedy.fold(1 + speedRun, 0) + speedRun = (speed >= SpeedRunSpeed).fold(1 + speedRun, 0) score = score + speedRun } @@ -71,4 +70,5 @@ class Score { } val FadeInSeconds = 1f + val SpeedRunSpeed = 4f // a piece is speedy if dropped at >= 4x slow speed } diff --git a/core/src/org/merlin/tertis/util/Average.scala b/core/src/org/merlin/tertis/util/Average.scala new file mode 100644 index 0000000..127d7f4 --- /dev/null +++ b/core/src/org/merlin/tertis/util/Average.scala @@ -0,0 +1,18 @@ +package org.merlin.tertis.util + +class Average { + private var average = 0f + private var count = 0 + + def +=(f: Float): Unit = { + average += f + count += 1 + } + + def value: Float = average / (count max 1) // heh + + def reset(): Unit = { + average = 0f + count = 0 + } +}