Added game timer that slows when lights are off
This commit is contained in:
@@ -120,6 +120,9 @@ function Game:enter()
|
||||
for _, enemy in ipairs(self.enemies) do
|
||||
enemy:enter()
|
||||
end
|
||||
|
||||
self.startTime = love.timer.getTime()
|
||||
self.gameTime = '0:00'
|
||||
end
|
||||
|
||||
function Game:update(dt)
|
||||
@@ -137,6 +140,15 @@ function Game:update(dt)
|
||||
end
|
||||
|
||||
self.effect:update(dt)
|
||||
|
||||
if not self.player.isLightOn then
|
||||
self.startTime = self.startTime + (dt / 2)
|
||||
end
|
||||
|
||||
local timeDiff = love.timer.getTime() - self.startTime
|
||||
local minute = math.floor(timeDiff / 60)
|
||||
local second = timeDiff % 60
|
||||
self.gameTime = string.format('%d:%02d', minute, second)
|
||||
end
|
||||
|
||||
function Game:draw()
|
||||
@@ -166,9 +178,11 @@ function Game:draw()
|
||||
-- love.graphics.rectangle('line', ix, iy, iw, ih)
|
||||
-- end
|
||||
end)
|
||||
|
||||
-- Draw HUD view
|
||||
end)
|
||||
|
||||
-- Draw HUD view
|
||||
|
||||
love.graphics.print(self.gameTime, 8, 8)
|
||||
end
|
||||
|
||||
function Game:exit()
|
||||
|
||||
@@ -32,7 +32,6 @@ function Effects.new(game)
|
||||
-- they can't be retrieved from Moonshine
|
||||
self.localEffect = {}
|
||||
self.localEffect.light = {}
|
||||
self.localEffect.light.isOn = false
|
||||
self.localEffect.light.radius = 10
|
||||
self.localEffect.light.targetRadius = 10
|
||||
self.localEffect.light.minRadius = 10
|
||||
@@ -55,20 +54,6 @@ function Effects:update(dt)
|
||||
|
||||
self.effect.light.playerPos = { self.game.camera:toScreen(self.game.player:getCenter()) }
|
||||
|
||||
self:_updateLightShader()
|
||||
end
|
||||
|
||||
function Effects:_updateLightShader()
|
||||
-- Toggle light on/off
|
||||
if (self.game.input:pressed 'action') then
|
||||
self.localEffect.light.isOn = not self.localEffect.light.isOn
|
||||
if (self.localEffect.light.isOn) then
|
||||
self.localEffect.light.targetRadius = self.localEffect.light.maxRadius
|
||||
else
|
||||
self.localEffect.light.targetRadius = self.localEffect.light.minRadius
|
||||
end
|
||||
end
|
||||
|
||||
-- Tween current light radius to target radius (based on on/off status)
|
||||
Flux.to(self.localEffect.light, 0.5, { radius = self.localEffect.light.targetRadius })
|
||||
self.effect.light.lightRadius = self.localEffect.light.radius
|
||||
@@ -76,6 +61,14 @@ function Effects:_updateLightShader()
|
||||
self.effect.light.time = self.localEffect.time
|
||||
end
|
||||
|
||||
function Effects:setLightShader(isOn)
|
||||
if (isOn) then
|
||||
self.localEffect.light.targetRadius = self.localEffect.light.maxRadius
|
||||
else
|
||||
self.localEffect.light.targetRadius = self.localEffect.light.minRadius
|
||||
end
|
||||
end
|
||||
|
||||
function Effects:render(fn)
|
||||
self.effect(fn)
|
||||
end
|
||||
|
||||
@@ -24,6 +24,8 @@ function Player.new(startX, startY, game)
|
||||
self.input.x = 0
|
||||
self.input.y = 0
|
||||
|
||||
self.isLightOn = false
|
||||
|
||||
self.texture = love.graphics.newImage 'assets/images/player.png'
|
||||
|
||||
self.game = game
|
||||
@@ -63,6 +65,11 @@ function Player:update(dt)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if self.game.input:pressed 'action' then
|
||||
self.isLightOn = not self.isLightOn
|
||||
self.game.effect:setLightShader(self.isLightOn)
|
||||
end
|
||||
end
|
||||
|
||||
function Player:draw()
|
||||
|
||||
9
todo.md
9
todo.md
@@ -4,18 +4,18 @@
|
||||
|
||||
# backlog
|
||||
|
||||
- [ ] Create player sprite
|
||||
- Make a mouse sprite for the player
|
||||
- [ ] Fix CRT bubble effect (doesn't like RS displays)
|
||||
- [ ] Try replacing the Moonshine scan-line effect with the custom shader (or delete it)
|
||||
- [ ] Create player sprite
|
||||
- Make a mouse sprite for the player
|
||||
- [ ] Create a siren sprite
|
||||
- [ ] Make the maze end after 5 solves, with progressive difficulty (9x9 no enemies, increase size + enemy count each stage)
|
||||
- [ ] Create a that displays in the top corner as the game goes on
|
||||
- [ ] When the lights are off, slow down the timer tick rate
|
||||
- [ ] Create a local leaderboard to see who clears maze in the lowest amount of time
|
||||
|
||||
# in progress
|
||||
|
||||
- [ ] When the lights are off, slow down the timer tick rate
|
||||
|
||||
# complete
|
||||
|
||||
- [x] Set up Lua formatter
|
||||
@@ -40,3 +40,4 @@
|
||||
- [x] Create end gate sprite
|
||||
- [x] The tiles start to flicker when the map is large. Caused by camera not being pixel-aligned
|
||||
- [x] Create a worm sprite
|
||||
- [x] Create a timer that displays in the top corner as the game goes on
|
||||
|
||||
Reference in New Issue
Block a user