Skip to content

Commit

Permalink
add 'about' section
Browse files Browse the repository at this point in the history
  • Loading branch information
awcz committed Jun 9, 2024
1 parent bbdc0ae commit 8689573
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/commonMain/kotlin/com/github/awcz/torch/scene/GameScene.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import korlibs.event.Key
import korlibs.image.atlas.MutableAtlasUnit
import korlibs.image.bitmap.NativeImage
import korlibs.image.color.Colors
import korlibs.image.color.Colors.DARKSLATEGREY
import korlibs.image.format.ASE
import korlibs.image.format.readBitmap
import korlibs.image.format.readImageDataContainer
Expand Down Expand Up @@ -89,6 +90,8 @@ class GameScene : Scene() {
private var godModeEnabled = false
private var moveInput = 0.0
private var lastGroundXPositions: ArrayDeque<Long> = ArrayDeque(listOf(5, 5, 5, 5, 5))
private lateinit var aboutLabel: UIText;

override suspend fun SContainer.sceneMain() {
bg1view = container {
image(resourcesVfs["background1.jpg"].readBitmap()) {
Expand All @@ -97,6 +100,7 @@ class GameScene : Scene() {
}
bg1view.y = -sceneContainer.height
bg1view.x = -600.0
aboutLabel = uiText("")
val world = resourcesVfs["ldtk/torch_map.ldtk"].readLDTKWorld()
val mapView = LDTKWorldView(world)
val starsView = Container()
Expand Down Expand Up @@ -142,8 +146,11 @@ class GameScene : Scene() {

uiButton("Restart", Size(60, 30)) {
onClick { sceneContainer.changeTo { LevelInfoScene(LEVEL_1_NAME) } }
bgColorOut = DARKSLATEGREY
}.positionY(this.height - 30).positionX(5).alpha(0.4)

configureAboutButton(mapView)

val specialEvents: MutableMap<SpecialEvent, Long> = mutableMapOf()

val distanceImg =
Expand Down Expand Up @@ -345,9 +352,9 @@ class GameScene : Scene() {
}

private fun isDead() = playerState.health <= 0

private fun levelFinished() = player.pos.x >= 7400
private fun isOutOfTheMap() = player.pos.y > 500

private fun updateStars(stars: MutableList<FastRoundRect>) {
// starsFalling(stars, starsView) // TODO implement bonus
starsBlinking(stars)
Expand Down Expand Up @@ -386,6 +393,27 @@ class GameScene : Scene() {
}
}

private fun SContainer.configureAboutButton(mapView: LDTKWorldView) {
uiButton("about", Size(40, 15)) {
onClick {
if (aboutLabel.text.isEmpty()) {
val aboutText = "Torch 2D (2024) github.com/awcz/torch\n\n" +
"CONTROLS\njump: SPACE up arrow, move left: left arrow, move right: right arrow\n" +
"on mobile: tap to move in the desired direction. Horizontal mode recommended.\n\n" +
"KorGE: modern Multiplatform Game Engine for Kotlin (https://korge.org)\n\n" +
"Icons by Icons8: \nDistance (https://icons8.com/icon/fodDbvH8xepW/distance)\nTorch (https://icons8.com/icon/vaGMa7gNKVuJ/torch)\nFlame (https://icons8.com/icon/QV5JEtrTP6nH/fire)\nBlur (https://icons8.com/icon/wBkQ-LolCVEo/blur)\nHeart (https://icons8.com/icon/CDX3UwscuB9X/heart) "
aboutLabel = mapView.parent?.parent?.uiText((aboutText))!!
aboutLabel.y = 65.0
aboutLabel.x = 5.0
aboutLabel.alpha(0.6)
} else {
aboutLabel.visible = !aboutLabel.visible
}
}
bgColorOut = DARKSLATEGREY
}.positionY(this.height - 15).positionX(this.width - 40).alpha(0.4)
}

private fun updateDebugData(
healthLabel: String,
debugLabel: UIText,
Expand Down Expand Up @@ -464,5 +492,4 @@ class GameScene : Scene() {
}
return isValidMove
}

}
}

0 comments on commit 8689573

Please sign in to comment.