Skip to content

Commit

Permalink
iconography, flashdown, weak randomness
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinorg committed May 16, 2022
1 parent 6cdafcc commit f2fd15e
Show file tree
Hide file tree
Showing 17 changed files with 87 additions and 44 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ sdk.dir=/opt/homebrew/share/android-commandlinetools/
* Achieving greatness:

```shell
desktop/build/libs/desktop-1.1.jar
desktop/build/libs/desktop-x.y.jar
```

* Which you can run:

```shell
java -jar desktop/build/libs/desktop-1.1.jar
java -jar desktop/build/libs/desktop-x.y.jar
# or, on a Mac
java -XstartOnFirstThread -jar desktop/build/libs/desktop-1.1.jar
java -XstartOnFirstThread -jar desktop/build/libs/desktop-x.y.jar
```

### Packaging for a Mac
Expand All @@ -80,15 +80,15 @@ export JAVA_HOME=/path/to/java/17
jpackage \
--input desktop/build/libs/ \
--name Tertis \
--app-version 1.1 \
--main-jar desktop-1.1.jar \
--app-version x.y \
--main-jar desktop-x.y.jar \
--main-class org.merlin.tertis.DesktopLauncher \
--type dmg \
--java-options '-XstartOnFirstThread' \
--icon mac/Tertis.icns
```

Yielding: `Tertis-1.1.dmg`.
Yielding: `Tertis-x.y.dmg`.

## Building for Android

Expand Down
Binary file modified assets/arrow-key.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/check-off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/check-on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/help.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/meta-key.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ buildscript {
allprojects {
apply plugin: "eclipse"

version = '1.1'
version = '1.2'
ext {
appName = "run"
gdxVersion = '1.11.0'
Expand Down
1 change: 1 addition & 0 deletions core/src/org/merlin/tertis/Prefs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ object Prefs {
final val HighContrast = new Pref("highContrast")
final val TiltSpeed = new Pref("tiltSpeed")
final val StuffHappens = new Pref("stuffHappens")
final val WeakRandomness = new Pref("weakRandomness")
}
6 changes: 6 additions & 0 deletions core/src/org/merlin/tertis/game/Block.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ package game
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.math.MathUtils

import scala.collection.mutable
import scala.util.Random

trait Test extends ((Int, Int) => Boolean)

/** The symmetric flag causes ---- and _|- to alternate between two positions
Expand Down Expand Up @@ -89,6 +92,9 @@ object Block {

def random: Block = blocks(randomNumber(blocks.length))

def bag: Iterator[Block] =
Random.shuffle(blocks).iterator

// I question the randomness of MathUtils.random for 7
private def randomNumber(n: Int): Int = {
if (n == 7) {
Expand Down
16 changes: 8 additions & 8 deletions core/src/org/merlin/tertis/game/Board.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package game
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
import org.merlin.tertis.Geometry._
import org.merlin.tertis.home.Icon.White
import org.merlin.tertis.{Prefs, Tertis}

import scala.collection.mutable
Expand Down Expand Up @@ -102,14 +101,15 @@ class Board(game: Game) {
val region = board(j * Columns + i)
if (region ne null) {
Red.a = 1f - redAlpha // fade through red to invisible
val color =
if (ending || region.dead)
region.color.cpy.lerp(Red, redAlpha * redAlpha)
else if (flash.contains(region.identifier) && flashdown > 0)
val baseColor =
(flash.contains(region.identifier) && flashdown > 0).fold(
region.color.cpy
.lerp(Color.WHITE, flashdown)
else
.lerp(Color.WHITE, flashdown),
region.color
)
val color =
(ending || region.dead)
.fold(baseColor.cpy.lerp(Red, redAlpha * redAlpha), baseColor)
BlockRenderer.render(
batch,
color,
Expand Down Expand Up @@ -211,5 +211,5 @@ object Board {
private val Red = new Color(1, 0, 0, 1f) // nb: mutates
val RedFadeSeconds = .5f
val RedShiftAccelerationSeconds = .5f
val FlashdownSeconds = 0.3f
val FlashdownSeconds = 0.5f
}
5 changes: 3 additions & 2 deletions core/src/org/merlin/tertis/game/Game.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ class Game extends Scene {
var state: State = PlayingState

val zenMode: Boolean = Prefs.ZenMode.isTrue
var stuffHappens: Boolean = Prefs.StuffHappens.isTrue
val stuffHappens: Boolean = Prefs.StuffHappens.isTrue
val weakRandomness: Boolean = Prefs.WeakRandomness.isTrue

val board: Board = new Board(this)
val nextUp: NextUp = new NextUp
val nextUp: NextUp = new NextUp(this)
var player: Player = new Player(this)
val score: Score = new Score
var fast: Boolean = false
Expand Down
26 changes: 19 additions & 7 deletions core/src/org/merlin/tertis/game/NextUp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,40 @@ package game
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
import org.merlin.tertis.Geometry._

class NextUp {
var previous: Block = Block.random
class NextUp(game: Game) {
private var previous = Option.empty[Block]
private var previousAlpha = 0f

private var next: Block = Block.random
private var bag = Iterator.empty[Block]
private var next: Block = nextBlock
private var nextAlpha = 0f

def shift(): Block = {
previous = next
val current = next
previous = Some(next)
previousAlpha = nextAlpha
next = Block.random
next = nextBlock
nextAlpha = 0f
previous
current
}

private def nextBlock: Block =
if (!game.weakRandomness) {
Block.random
} else {
if (!bag.hasNext) bag = Block.bag
bag.next()
}

def update(delta: Float): Unit = {
previousAlpha = (previousAlpha - delta / FadeOutSeconds) max 0f
nextAlpha = (nextAlpha + delta / FadeInSeconds) min 1f
}

def render(batch: PolygonSpriteBatch): Unit = {
draw(batch, previous, previousAlpha, -.5f)
previous foreach { prev =>
draw(batch, prev, previousAlpha, -.5f)
}
draw(batch, next, nextAlpha, 1f)
}

Expand Down
22 changes: 13 additions & 9 deletions core/src/org/merlin/tertis/home/Help.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ class Help(home: Home, game: Option[Game] = None) extends Scene {
Frame.render(batch)
}

private val DesktopIconLeft = Dimension * 3
private val DesktopIconInterval = IconSize * 2
private val DesktopIconsTop =
((Geometry.ScreenHeight + (DesktopIconInterval * 4 + IconSize)) / 2).floor
private val DesktopIconLeft = IconSize * 2
private val DesktopIconInterval = IconSize * 3
private val DesktopIconsTop = Geometry.ScreenHeight - IconSize * 5

val desktopIcons: List[Icon] = List(
new KeyIcon(
Expand All @@ -81,39 +80,44 @@ class Help(home: Home, game: Option[Game] = None) extends Scene {
IconSize,
Tertis.arrowKey,
0f,
"Right"
"Right",
"Right arrow key"
),
new KeyIcon(
DesktopIconLeft,
DesktopIconsTop - DesktopIconInterval,
IconSize,
Tertis.arrowKey,
180f,
"Left"
"Left",
"Left arrow key"
),
new KeyIcon(
DesktopIconLeft,
DesktopIconsTop - DesktopIconInterval * 2,
IconSize,
Tertis.arrowKey,
90f,
"Rotate"
"Rotate",
"Up arrow key"
),
new KeyIcon(
DesktopIconLeft,
DesktopIconsTop - DesktopIconInterval * 3,
IconSize,
Tertis.arrowKey,
270f,
"Drop"
"Drop",
"Down arrow key"
),
new KeyIcon(
DesktopIconLeft,
DesktopIconsTop - DesktopIconInterval * 4,
IconSize,
Tertis.metaKey,
0f,
"Velocitator"
"Velocitator",
"Shift/control/alt/option key"
)
)

Expand Down
21 changes: 16 additions & 5 deletions core/src/org/merlin/tertis/home/Icon.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
import org.merlin.tertis.Geometry.Dimension
import org.merlin.tertis.home.Icon.White
import org.merlin.tertis.home.Icon._
import org.merlin.tertis.util.TextureWrapper

trait Icon {
Expand Down Expand Up @@ -132,11 +132,13 @@ class KeyIcon(
val size: Float,
icon: TextureWrapper,
rotation: Float,
label: String
label: String,
description: String
) extends BaseIcon {

override def draw(batch: PolygonSpriteBatch, alpha: Float): Unit = {
batch.setColor(White alpha)
val color = White alpha
batch.setColor(color)
batch.draw(
icon,
x - size / 2,
Expand All @@ -155,9 +157,18 @@ class KeyIcon(
false,
false
)
Text.smallFont.setColor(White alpha)
val textY = y + Text.smallFont.getAscent
Text.smallFont.setColor(color)
val textY =
y + (Text.smallFont.getLineHeight + Text.tinyFont.getAscent - Text.tinyFont.getDescent) / 2
Text.smallFont.draw(batch, label, x + size * 1.25f, textY)
val grey = Grey alpha
Text.tinyFont.setColor(grey)
Text.tinyFont.draw(
batch,
description,
x + size * 1.25f,
textY - Text.smallFont.getLineHeight
)
}

override def clicked(): Unit = ()
Expand Down
8 changes: 8 additions & 0 deletions core/src/org/merlin/tertis/home/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class Settings(home: Home) extends Scene {
"High contrast",
"More vivid colours."
),
new CheckIcon(
IconSize * 2,
IconTop - IconSpacing * 3,
IconSize,
Prefs.WeakRandomness,
"Weak randomness",
"Bind the hands of fate."
),
)

override def init(): SettingsControl =
Expand Down
12 changes: 6 additions & 6 deletions logo/Tertis2Round.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f2fd15e

Please sign in to comment.