Skip to content

Commit 4d7d89d

Browse files
committed
Tempest: Add empty game with controller.
This is the bare minimum required in order to add a new game to retrowars (assumping it uses a soft controller and not a touch screen - if just touch screen such as Missile Command then we could ommit the controller). Not particularly happy with the number of places things need to be added, but that can be addressed in the future as we add more games and realise where refactorings would be most appropriate.
1 parent b8ce092 commit 4d7d89d

File tree

5 files changed

+91
-4
lines changed

5 files changed

+91
-4
lines changed

core/src/com/serwylo/retrowars/core/OptionsScreen.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ import com.serwylo.beatgame.ui.makeHeading
1111
import com.serwylo.retrowars.RetrowarsGame
1212
import com.serwylo.retrowars.games.GameDetails
1313
import com.serwylo.retrowars.games.Games
14-
import com.serwylo.retrowars.input.AsteroidsSoftController
15-
import com.serwylo.retrowars.input.SnakeSoftController
16-
import com.serwylo.retrowars.input.SoftController
17-
import com.serwylo.retrowars.input.TetrisSoftController
14+
import com.serwylo.retrowars.input.*
1815
import com.serwylo.retrowars.ui.IconButton
1916
import com.serwylo.retrowars.utils.Options
2017

@@ -88,6 +85,18 @@ class OptionsScreen(game: RetrowarsGame): Scene2dScreen(game, { game.showMainMen
8885
}
8986
)
9087

88+
addActor(
89+
IconButton(skin, Games.tempest.icon(sprites)) {
90+
Gdx.app.postRunnable {
91+
game.screen = ControllerSelectScreen(
92+
game,
93+
Games.tempest,
94+
TempestSoftController.layouts,
95+
) { index -> TempestSoftController(index, game.uiAssets) }
96+
}
97+
}
98+
)
99+
91100
addActor(
92101
IconButton(skin, Games.tetris.icon(sprites)) {
93102
Gdx.app.postRunnable {

core/src/com/serwylo/retrowars/games/Games.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.serwylo.retrowars.core.UnimplementedGameScreen
88
import com.serwylo.retrowars.games.asteroids.AsteroidsGameScreen
99
import com.serwylo.retrowars.games.missilecommand.MissileCommandGameScreen
1010
import com.serwylo.retrowars.games.snake.SnakeGameScreen
11+
import com.serwylo.retrowars.games.tempest.TempestGameScreen
1112
import com.serwylo.retrowars.games.tetris.TetrisGameScreen
1213

1314
object Games {
@@ -33,6 +34,13 @@ object Games {
3334
{ app -> SnakeGameScreen(app) }
3435
)
3536

37+
val tempest = GameDetails(
38+
"tempest",
39+
true,
40+
{ s -> s.icons.tempest },
41+
{ app -> TempestGameScreen(app) }
42+
)
43+
3644
val tetris = GameDetails(
3745
"tetris",
3846
true,
@@ -46,6 +54,7 @@ object Games {
4654
asteroids,
4755
missileCommand,
4856
snake,
57+
tempest,
4958
tetris,
5059
other,
5160
)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.serwylo.retrowars.games.tempest
2+
3+
import com.badlogic.gdx.Gdx
4+
import com.badlogic.gdx.graphics.OrthographicCamera
5+
import com.serwylo.retrowars.RetrowarsGame
6+
import com.serwylo.retrowars.games.GameScreen
7+
import com.serwylo.retrowars.games.Games
8+
import com.serwylo.retrowars.input.TempestSoftController
9+
import com.serwylo.retrowars.utils.Options
10+
11+
class TempestGameScreen(game: RetrowarsGame) : GameScreen(game, Games.tempest, 400f, 400f) {
12+
13+
companion object {
14+
@Suppress("unused")
15+
const val TAG = "TempestGameScreen"
16+
}
17+
18+
private val state = TempestGameState()
19+
20+
private val controller = TempestSoftController(Options.getSoftController(Games.tempest), game.uiAssets)
21+
22+
init {
23+
addGameOverlayToHUD(controller.getActor())
24+
showMessage("Shoot the enemies", "Don't let them touch you")
25+
}
26+
27+
override fun show() {
28+
Gdx.input.inputProcessor = getInputProcessor()
29+
}
30+
31+
override fun updateGame(delta: Float) {
32+
}
33+
34+
override fun onReceiveDamage(strength: Int) {
35+
}
36+
37+
override fun renderGame(camera: OrthographicCamera) {
38+
}
39+
40+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.serwylo.retrowars.games.tempest
2+
3+
class TempestGameState

core/src/com/serwylo/retrowars/input/SoftController.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,29 @@ class TetrisSoftController(layout: Int, uiAssets: UiAssets): SoftController(
254254
}
255255

256256
}
257+
258+
class TempestSoftController(layout: Int, uiAssets: UiAssets): SoftController(
259+
uiAssets,
260+
getLayout(layouts, layout),
261+
mapOf(
262+
Buttons.MOVE_CLOCKWISE to uiAssets.getSprites().buttonIcons.rotate_clockwise,
263+
Buttons.MOVE_COUNTER_CLOCKWISE to uiAssets.getSprites().buttonIcons.rotate_counter_clockwise,
264+
)
265+
) {
266+
267+
companion object {
268+
269+
val layouts = listOf(
270+
"[ move_counter_clockwise ][<---->][ move_clockwise ]",
271+
"[ move_counter_clockwise ][ move_clockwise ][<---->]",
272+
"[<---->][ move_counter_clockwise ][ move_clockwise ]",
273+
)
274+
275+
}
276+
277+
object Buttons {
278+
const val MOVE_CLOCKWISE = "move_clockwise"
279+
const val MOVE_COUNTER_CLOCKWISE = "move_counter_clockwise"
280+
}
281+
282+
}

0 commit comments

Comments
 (0)