summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--i18n/locales.lua8
-rw-r--r--main.lua57
-rw-r--r--resources/sound/gameover.wavbin0 -> 421640 bytes
-rw-r--r--utils/audio.lua9
4 files changed, 53 insertions, 21 deletions
diff --git a/i18n/locales.lua b/i18n/locales.lua
index 2265cb0..a951e1b 100644
--- a/i18n/locales.lua
+++ b/i18n/locales.lua
@@ -12,7 +12,9 @@ local locales = {
},
roomCleared = "Room cleared: ",
waveStart = "New enemies are coming.",
- giftHeartSpeech = "You've received a gift!"
+ giftHeartSpeech = "You've received a gift!",
+ gameOver = "Game Over",
+ pressSpaceToRestart = "Press [Space] to Restart"
},
zh = {
newRealm = "你进入了新的领域,没有回头路了",
@@ -27,7 +29,9 @@ local locales = {
},
roomCleared = "已清理房间:",
waveStart = "有人来了",
- giftHeartSpeech = "你收到了礼物!"
+ giftHeartSpeech = "你收到了礼物!",
+ gameOver = "游戏结束",
+ pressSpaceToRestart = "按[空格键]重新开始"
}
}
diff --git a/main.lua b/main.lua
index 5ac09d0..7a7ecef 100644
--- a/main.lua
+++ b/main.lua
@@ -7,6 +7,8 @@ local map = require "logic.map"
local controller = require "logic.controller"
local translator = require "i18n.translator"
+local gameState = "playing" -- 初始状态为playing
+
function love.load()
G = {}
-- load font
@@ -28,33 +30,52 @@ function love.load()
end
function love.draw()
- RenderManager:draw()
+ if gameState == "playing" then
+ RenderManager:draw()
+ elseif gameState == "gameOver" then
+ -- show game over screen
+ love.graphics.setColor(1, 0, 0, 1)
+ love.graphics.printf(translator.T("gameOver"), 0, love.graphics.getHeight() / 2 - 20, love.graphics.getWidth(), "center")
+ love.graphics.setColor(1, 1, 1, 1)
+ love.graphics.printf(translator.T("pressSpaceToRestart"), 0, love.graphics.getHeight() / 2 + 20, love.graphics.getWidth(), "center")
+ -- play game over sound
+ audio.play("gameover")
+ end
end
function love.update(dt)
- -- game state updates
- local gameStates = { G.BodyLifeCycleManager, G.world, G.currentRoom, G.player }
- for _, state in ipairs(gameStates) do
- state:update(dt)
- end
+ if gameState == "playing" then
+ -- game state updates
+ local gameStates = { G.BodyLifeCycleManager, G.world, G.currentRoom, G.player }
+ for _, state in ipairs(gameStates) do
+ state:update(dt)
+ end
- -- game logic updates
- local updates = { map, controller, speaker }
- for _, entity in ipairs(updates) do
- entity.update(dt)
- end
+ -- game logic updates
+ local updates = { map, controller, speaker }
+ for _, entity in ipairs(updates) do
+ entity.update(dt)
+ end
- -- check if game has ended
- if not G.player:isAlive() then
- initGame()
- end
+ -- check if game has ended
+ if not G.player:isAlive() then
+ gameState = "gameOver"
+ audio.stopAll()
+ end
- -- time update
- G.time = G.time + dt
+ -- time update
+ G.time = G.time + dt
+ end
end
function love.keypressed(key)
- controller.keypressed(key)
+ -- press space to restart gane
+ if gameState == "gameOver" and key == "space" then
+ initGame()
+ gameState = "playing"
+ else
+ controller.keypressed(key)
+ end
end
function love.mousereleased(x, y, button)
diff --git a/resources/sound/gameover.wav b/resources/sound/gameover.wav
new file mode 100644
index 0000000..31d6f31
--- /dev/null
+++ b/resources/sound/gameover.wav
Binary files differ
diff --git a/utils/audio.lua b/utils/audio.lua
index 5a4ab64..25fb6dc 100644
--- a/utils/audio.lua
+++ b/utils/audio.lua
@@ -12,7 +12,8 @@ local soundResources = {
punch = "punch.wav",
door = "door.wav",
fart = "fart.wav",
- spring = "spring.wav"
+ spring = "spring.wav",
+ gameover = "gameover.wav"
}
local musicResources = {
@@ -81,4 +82,10 @@ function audio.stopMusic()
end
end
+function audio.stopAll()
+ for _, audio in pairs(AudioData) do
+ audio:stop()
+ end
+end
+
return audio