Skip to content

Commit

Permalink
Add level selection + 2 new levels
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierperez committed May 13, 2021
1 parent 8f319c6 commit dd7a2c8
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.gradle/
.idea/
build/
/GameLib.save
/SoulGame.save
12 changes: 12 additions & 0 deletions SoulGameImpl/resources/levels/level_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#######A########
# #+# #
# # # # :## #
# # # # #
# ### # #### #
# # # #
# #:### # :## #
# ###:# ###### #
# #
### #### ### ###
#: :#
################
12 changes: 12 additions & 0 deletions SoulGameImpl/resources/levels/level_3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#######A########
#:# #+# #:#
# # ## #
# # # ###### # #
# # # #: # #
# # # # # # # #
# # # # # # # #
# # :# # # #
# # ###### # # #
# # #
#:# ###### #:#
################
21 changes: 17 additions & 4 deletions SoulGameImpl/src/main/kotlin/fr/o80/soulgame/SoulSceneManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import fr.o80.gamelib.loop.GameLoop
import fr.o80.soulgame.scenes.gameover.GameOverInfo
import fr.o80.soulgame.scenes.gameover.GameOverScene
import fr.o80.soulgame.scenes.level.LevelScene
import fr.o80.soulgame.scenes.levelselector.LevelSelectorScene
import fr.o80.soulgame.scenes.main.MainScene

class SoulSceneManager(
Expand All @@ -15,12 +16,14 @@ class SoulSceneManager(
override val initialScene: Scene
get() = MainScene(this)

fun openLevel(leveName: String) {
gameLoop.open(LevelScene(this, leveName))
fun openMain() {
gameLoop.open(MainScene(this))
}

fun quit() {
gameLoop.stop()
fun openLevel(leveName: String) {
gameLoop.open(
LevelScene(this, leveName)
)
}

fun openGameOver(levelName: String, score: Long) {
Expand All @@ -32,4 +35,14 @@ class SoulSceneManager(
)
}

fun openLevelSelector() {
gameLoop.open(
LevelSelectorScene(this)
)
}

fun quit() {
gameLoop.stop()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class GameOverScene(
text { "SCORE: ${state.score}" }
text { "Best: ${state.bestScore}" }
button("Restart") {
sceneManager.openLevel("level_1")
sceneManager.openLevel(info.levelName)
}
button("Quit") {
sceneManager.quit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class LevelScene(
system.open(keyPipeline)
levelState = LevelState(level, mob, knight, score, timing)

keyPipeline.onKey(GLFW.GLFW_KEY_ESCAPE, GLFW.GLFW_PRESS) { sceneManager.quit() }
keyPipeline.onKey(GLFW.GLFW_KEY_ESCAPE, GLFW.GLFW_PRESS) { sceneManager.openMain() }
}

override fun close() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package fr.o80.soulgame.scenes.levelselector

import fr.o80.gamelib.Scene
import fr.o80.gamelib.loop.KeyPipeline
import fr.o80.gamelib.loop.MouseButtonPipeline
import fr.o80.gamelib.loop.MouseMovePipeline
import fr.o80.gamelib.loop.Window
import fr.o80.gamelib.menu.Menu
import fr.o80.gamelib.menu.TextResources
import fr.o80.gamelib.service.Services
import fr.o80.soulgame.SoulSceneManager
import fr.o80.soulgame.resource
import fr.o80.soulgame.scenes.greenBackground

class LevelSelectorScene(
private val sceneManager: SoulSceneManager
) : Scene {

private lateinit var menu: Menu

private val system = LevelSelectorSystem()

override fun open(
window: Window,
services: Services,
keyPipeline: KeyPipeline,
mouseButtonPipeline: MouseButtonPipeline,
mouseMovePipeline: MouseMovePipeline
) {
menu = Menu.MenuBuilder()
.of(
top = .0,
left = .0,
right = window.width.toDouble(),
bottom = window.height.toDouble()
)
.andResources(
background = greenBackground,
textResources = TextResources(
font = resource("fonts/LaserCutRegular.ttf"),
fontHeight = 50f
),
titleResources = TextResources(
font = resource("fonts/LaserCutRegular.ttf"),
fontHeight = 99f
)
)
.withPipelines(
mouseButtonPipeline,
mouseMovePipeline
)
.andLayout {
system.forEachLevel { levelName ->
button(levelName) {
sceneManager.openLevel(levelName)
}
}
button("Back") {
sceneManager.openMain()
}
}
.build()
}

override fun close() {
menu.close()
}

override suspend fun update() {
menu.update()
}

override suspend fun render() {
menu.render()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package fr.o80.soulgame.scenes.levelselector

import fr.o80.soulgame.resourceFile

class LevelSelectorSystem {

private val levelNames: List<String> by lazy {
resourceFile("levels/").list()?.toList()?.map { it.removeSuffix(".txt") }
?: emptyList()
}

fun forEachLevel(block: (String) -> Unit) {
levelNames.forEach { levelName ->
block(levelName)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import fr.o80.soulgame.scenes.greenBackground
class MainScene(
private val sceneManager: SoulSceneManager
) : Scene {

private lateinit var menu: Menu

override fun open(
Expand Down Expand Up @@ -54,6 +55,9 @@ class MainScene(
button("Start") {
sceneManager.openLevel("level_1")
}
button("Select level") {
sceneManager.openLevelSelector()
}
button("Quit") {
sceneManager.quit()
}
Expand Down
10 changes: 7 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
- [x] Corriger la hauteur du text renvoyée par TextRender
- [x] Afficher un menu de game-over pour relancer

- [ ] Kotlin 1.5
- [x] Kotlin 1.5

- [ ] Se souvenir du best score
- [x] Se souvenir du best score

- [ ] Laisser le choix du niveau au joueur
- [x] Laisser le choix du niveau au joueur

- [ ] i18n-er le jeu

- [ ] Au moment où la scène de jeu s'affiche
- Décompte "3... 2... 1..." (le jeu est en freeze)
- "Capturez-les tous !" (le jeu démarre)

- [ ] Mettre le jeu en pause quand on appuie sur espace

- [ ] Quand on convertit une âme
- Jouer un petit son
- Afficher des particules ?
Expand Down

0 comments on commit dd7a2c8

Please sign in to comment.