Squashing to remove big audio files

viewport-stuff
trivernis 2 years ago
parent 0a0e5334b5
commit 9b44cc6194
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,5 +1,6 @@
package com.last.commit
import GameState
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input.Keys
import com.badlogic.gdx.InputProcessor
@ -15,12 +16,14 @@ import com.badlogic.gdx.math.MathUtils
import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.math.Vector3
import com.badlogic.gdx.utils.Json
import com.last.commit.config.ActionCommand
import com.last.commit.config.GameConfig
import com.last.commit.map.Interactable
import com.last.commit.map.TimeMap
import com.last.commit.stages.InventoryStage
import com.last.commit.audio.GameSoundEffect
import com.last.commit.audio.GameMusic
import kotlin.math.floor
import GameState
/** First screen of the application. Displayed after the application is created. */
class FirstScreen(val gameState: GameState) : Screen, InputProcessor {
@ -58,6 +61,7 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor {
shapeRenderer.setAutoShapeType(true)
Gdx.input.setInputProcessor(this)
gameState.soundEngine.play(GameMusic.WORLD_MUSIC, 0.5f)
}
fun loadGameConfig(): GameConfig {
@ -245,26 +249,25 @@ class FirstScreen(val gameState: GameState) : Screen, InputProcessor {
}
override fun keyUp(keycode: Int): Boolean {
if (keycode == Keys.ESCAPE) {
if (gameState.settings.getAction(keycode) == ActionCommand.OPEN_MENU) {
Gdx.app.exit()
}
return false
}
override fun keyTyped(character: Char): Boolean {
val keyCode = character.code
val characterUpperCase = character.uppercase()
val characterKey = Keys.valueOf(characterUpperCase)
if (gameState.settings.isInteractPressed(keyCode)) {
if (gameState.settings.getAction(characterKey) == ActionCommand.INTERACT) {
openDoor()
} else if (gameState.settings.isTimeTravelPressed(keyCode)) {
} else if (gameState.settings.getAction(characterKey) == ActionCommand.TIME_TRAVEL) {
map.teleport(player)
} else if (gameState.settings.isOpenInventoryPressed(keyCode)) {
} else if (gameState.settings.getAction(characterKey) == ActionCommand.OPEN_INVENTORY) {
inventoryStage.visible = !inventoryStage.visible
} else if (character == 'p') {
gameState.inventory.add("compass")
inventoryStage.refresh()
} else if (gameState.settings.isInteractPressed(keyCode)) {
this.openDoor()
}
return false
}

@ -1,9 +1,10 @@
package com.last.commit
import GameState
import com.badlogic.gdx.Game
import com.last.commit.config.GameSettings
import com.last.commit.inventory.Inventory
import com.last.commit.config.PlayerSettings
import GameState
import com.last.commit.audio.SoundEngine
/** [com.badlogic.gdx.ApplicationListener] implementation shared by all platforms. */
class Game : Game() {
@ -18,7 +19,8 @@ class Game : Game() {
fun createState() {
state = GameState(
Inventory(),
PlayerSettings()
GameSettings(),
SoundEngine()
)
}
}

@ -1,7 +1,9 @@
import com.last.commit.inventory.Inventory
import com.last.commit.config.PlayerSettings
import com.last.commit.config.GameSettings
import com.last.commit.audio.SoundEngine
public data class GameState(
public val inventory: Inventory,
public val settings: PlayerSettings,
data class GameState(
val inventory: Inventory,
val settings: GameSettings,
public val soundEngine: SoundEngine,
)

@ -5,6 +5,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.math.Rectangle
import com.badlogic.gdx.math.Vector2
import com.last.commit.inventory.Inventory
import com.last.commit.audio.GameSoundEffect
import GameState

@ -0,0 +1,9 @@
package com.last.commit.audio
import com.last.commit.audio.GameSound
class GameMusic(name: String): GameSound(name) {
companion object {
val WORLD_MUSIC = GameMusic("world_music.mp3")
}
}

@ -0,0 +1,5 @@
package com.last.commit.audio;
public abstract class GameSound(public val name: String) {
}

@ -0,0 +1,9 @@
package com.last.commit.audio;
import com.last.commit.audio.GameSound
public class GameSoundEffect(name: String): GameSound(name) {
companion object {
val STEPS_INDOOR = GameSoundEffect("steps_indoor.mp3");
}
}

@ -0,0 +1,51 @@
package com.last.commit.audio;
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.audio.Sound
import com.badlogic.gdx.audio.Music
import com.last.commit.audio.GameSound
import com.last.commit.audio.GameMusic
public class SoundEngine {
private val sounds: HashMap<String, Sound> = HashMap()
private var playingMusic: Music? = null
public fun play(gameSound: GameSound, volume: Float = 1f) {
if (gameSound is GameSoundEffect) {
val sound = loadEffect(gameSound.name)
sound.play(volume)
println("Playing sound ${gameSound.name}")
} else if (gameSound is GameMusic) {
if (playingMusic != null && playingMusic!!.isPlaying()) {
playingMusic!!.stop()
}
val music = loadMusic(gameSound.name)
music.volume = volume
music.setLooping(true)
music.play()
playingMusic = music
}
}
private fun loadEffect(name: String): Sound {
return loadSound("effects/$name")
}
private fun loadMusic(name: String): Music {
return Gdx.audio.newMusic(Gdx.files.internal("sounds/music/$name"))
}
private fun loadSound(name: String): Sound {
var sound = sounds.get(name)
if (sound == null) {
println("Loading sound $name")
sound = Gdx.audio.newSound(Gdx.files.internal("sounds/$name"))
sounds[name] = sound
}
return sound!!
}
}

@ -3,21 +3,20 @@ package com.last.commit.config
import com.badlogic.gdx.Input.Keys
import java.util.*
class PlayerSettings {
class GameSettings {
val fullscreen: Boolean = false
private val actionKeys: EnumMap<ActionCommand, List<Int>> = EnumMap(ActionCommand::class.java)
private val actionKeysReversed: HashMap<Int, ActionCommand> = hashMapOf()
init {
actionKeys[ActionCommand.UP] = listOf(Keys.UP, Keys.W)
actionKeys[ActionCommand.DOWN] = listOf(Keys.DOWN, Keys.S)
actionKeys[ActionCommand.LEFT] = listOf(Keys.LEFT, Keys.A)
actionKeys[ActionCommand.RIGHT] = listOf(Keys.RIGHT, Keys.D)
actionKeys[ActionCommand.OPEN_MENU] = listOf(Keys.ESCAPE)
actionKeys[ActionCommand.OPEN_INVENTORY] = listOf(Keys.I, Keys.A)
actionKeys[ActionCommand.OPEN_INVENTORY] = listOf(Keys.I)
actionKeys[ActionCommand.TIME_TRAVEL] = listOf(Keys.T)
actionKeys[ActionCommand.INTERACT] = listOf(Keys.E)
@ -38,41 +37,10 @@ class PlayerSettings {
return actionKeysReversed[keyCode]
}
fun getKeyCode(actionCommand: ActionCommand): List<Int>? {
return actionKeys[actionCommand]
}
private fun isActionPressed(actionCommand: ActionCommand, keyCode: Int): Boolean {
return actionCommand == getAction(keyCode)
}
fun isOpenMenuPressed(keyCode: Int): Boolean {
return isActionPressed(ActionCommand.OPEN_MENU, keyCode)
}
fun isOpenInventoryPressed(keyCode: Int): Boolean {
return isActionPressed(ActionCommand.OPEN_INVENTORY, keyCode)
}
fun isUpPressed(keyCode: Int): Boolean {
return isActionPressed(ActionCommand.UP, keyCode)
}
fun isDownPressed(keyCode: Int): Boolean {
return isActionPressed(ActionCommand.DOWN, keyCode)
}
fun isLeftPressed(keyCode: Int): Boolean {
return isActionPressed(ActionCommand.LEFT, keyCode)
}
fun isRightPressed(keyCode: Int): Boolean {
return isActionPressed(ActionCommand.RIGHT, keyCode)
}
fun isTimeTravelPressed(keyCode: Int): Boolean {
return isActionPressed(ActionCommand.TIME_TRAVEL, keyCode)
}
fun isInteractPressed(keyCode: Int): Boolean {
return isActionPressed(ActionCommand.INTERACT, keyCode)
}
}
Loading…
Cancel
Save