Skip to content

Commit

Permalink
Tempest: Add empty game with controller.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pserwylo committed Jul 30, 2021
1 parent b8ce092 commit 4d7d89d
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 4 deletions.
17 changes: 13 additions & 4 deletions core/src/com/serwylo/retrowars/core/OptionsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import com.serwylo.beatgame.ui.makeHeading
import com.serwylo.retrowars.RetrowarsGame
import com.serwylo.retrowars.games.GameDetails
import com.serwylo.retrowars.games.Games
import com.serwylo.retrowars.input.AsteroidsSoftController
import com.serwylo.retrowars.input.SnakeSoftController
import com.serwylo.retrowars.input.SoftController
import com.serwylo.retrowars.input.TetrisSoftController
import com.serwylo.retrowars.input.*
import com.serwylo.retrowars.ui.IconButton
import com.serwylo.retrowars.utils.Options

Expand Down Expand Up @@ -88,6 +85,18 @@ class OptionsScreen(game: RetrowarsGame): Scene2dScreen(game, { game.showMainMen
}
)

addActor(
IconButton(skin, Games.tempest.icon(sprites)) {
Gdx.app.postRunnable {
game.screen = ControllerSelectScreen(
game,
Games.tempest,
TempestSoftController.layouts,
) { index -> TempestSoftController(index, game.uiAssets) }
}
}
)

addActor(
IconButton(skin, Games.tetris.icon(sprites)) {
Gdx.app.postRunnable {
Expand Down
9 changes: 9 additions & 0 deletions core/src/com/serwylo/retrowars/games/Games.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.serwylo.retrowars.core.UnimplementedGameScreen
import com.serwylo.retrowars.games.asteroids.AsteroidsGameScreen
import com.serwylo.retrowars.games.missilecommand.MissileCommandGameScreen
import com.serwylo.retrowars.games.snake.SnakeGameScreen
import com.serwylo.retrowars.games.tempest.TempestGameScreen
import com.serwylo.retrowars.games.tetris.TetrisGameScreen

object Games {
Expand All @@ -33,6 +34,13 @@ object Games {
{ app -> SnakeGameScreen(app) }
)

val tempest = GameDetails(
"tempest",
true,
{ s -> s.icons.tempest },
{ app -> TempestGameScreen(app) }
)

val tetris = GameDetails(
"tetris",
true,
Expand All @@ -46,6 +54,7 @@ object Games {
asteroids,
missileCommand,
snake,
tempest,
tetris,
other,
)
Expand Down
40 changes: 40 additions & 0 deletions core/src/com/serwylo/retrowars/games/tempest/TempestGameScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.serwylo.retrowars.games.tempest

import com.badlogic.gdx.Gdx
import com.badlogic.gdx.graphics.OrthographicCamera
import com.serwylo.retrowars.RetrowarsGame
import com.serwylo.retrowars.games.GameScreen
import com.serwylo.retrowars.games.Games
import com.serwylo.retrowars.input.TempestSoftController
import com.serwylo.retrowars.utils.Options

class TempestGameScreen(game: RetrowarsGame) : GameScreen(game, Games.tempest, 400f, 400f) {

companion object {
@Suppress("unused")
const val TAG = "TempestGameScreen"
}

private val state = TempestGameState()

private val controller = TempestSoftController(Options.getSoftController(Games.tempest), game.uiAssets)

init {
addGameOverlayToHUD(controller.getActor())
showMessage("Shoot the enemies", "Don't let them touch you")
}

override fun show() {
Gdx.input.inputProcessor = getInputProcessor()
}

override fun updateGame(delta: Float) {
}

override fun onReceiveDamage(strength: Int) {
}

override fun renderGame(camera: OrthographicCamera) {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.serwylo.retrowars.games.tempest

class TempestGameState
26 changes: 26 additions & 0 deletions core/src/com/serwylo/retrowars/input/SoftController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,29 @@ class TetrisSoftController(layout: Int, uiAssets: UiAssets): SoftController(
}

}

class TempestSoftController(layout: Int, uiAssets: UiAssets): SoftController(
uiAssets,
getLayout(layouts, layout),
mapOf(
Buttons.MOVE_CLOCKWISE to uiAssets.getSprites().buttonIcons.rotate_clockwise,
Buttons.MOVE_COUNTER_CLOCKWISE to uiAssets.getSprites().buttonIcons.rotate_counter_clockwise,
)
) {

companion object {

val layouts = listOf(
"[ move_counter_clockwise ][<---->][ move_clockwise ]",
"[ move_counter_clockwise ][ move_clockwise ][<---->]",
"[<---->][ move_counter_clockwise ][ move_clockwise ]",
)

}

object Buttons {
const val MOVE_CLOCKWISE = "move_clockwise"
const val MOVE_COUNTER_CLOCKWISE = "move_counter_clockwise"
}

}

0 comments on commit 4d7d89d

Please sign in to comment.