Skip to content

Commit

Permalink
Add a finish screen and get player killed by rocks
Browse files Browse the repository at this point in the history
  • Loading branch information
TomK32 committed Jan 30, 2013
1 parent 042e4c3 commit 0e6be3e
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 9 deletions.
11 changes: 11 additions & 0 deletions actors/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ function Player:initialize(position)
self.dt_since_input = 0
self.entity_type = 'Actor'
self.inputs = {}
self.health = 10
self.death_message = nil
self.state = 'standing'
self.had_wave = false
self.wait_for_wave = false
Expand Down Expand Up @@ -120,6 +122,15 @@ function Player:update(dt)
game.ticked = self.moved or self.wait_for_wave
self:speedChange(self.speed * - self.drag[self.state], 0, self:maxSpeed(self.state))
self.had_wave = false
if true or #self.map:entitiesOfType(self.position, 'Rock') > 0 then
-- hit a rock, ouch
self.health = self.health - 1
if self.health <= 0 then
self.death_message = 'You got minced by the rocks'
return game:killed(self)
end
end

for i, wave in ipairs(self.map:waves(self.position)) do
self.had_wave = true
self.wait_for_wave = false
Expand Down
8 changes: 8 additions & 0 deletions game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ function game:setMode(mode)
end


function game:startMenu()
game.current_state = StartMenu()
end

function game:start()
game.current_state = MapState()
end

function game:killed(player)
game.current_state = FinishScreen(player)
end
14 changes: 14 additions & 0 deletions game_states/finish_screen.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

require 'views/finish_view'

FinishScreen = class("FinishScreen", GameState)

function FinishScreen:initialize(player)
self.view = FinishView(player)
end

function FinishScreen:keypressed(key)
if key == ' ' then
game:startMenu()
end
end
2 changes: 1 addition & 1 deletion game_states/game_state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ end

function GameState:draw()
if self.view then
self.view.draw()
self.view:draw()
end
end

Expand Down
2 changes: 0 additions & 2 deletions generators/map_generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ end

function MapGenerator:newRocks(z, y1, y2)
self:incrementSeed(1)
print(y1, y2)
local tiles = self:fillTiles(1, 1, (y2-y1), 3,
function(x,y)
local color_offset = (SimplexNoise.Noise2D(x/16, y/8) * 20) % 20
Expand All @@ -141,7 +140,6 @@ function MapGenerator:newRocks(z, y1, y2)
1, (y2-y1)/self.map.height,
0, y1)
position.z = z
print(position.x, position.y, position.z, y1, y2)
return self.map:addEntity(Rock(position, tiles))
end

Expand Down
4 changes: 3 additions & 1 deletion main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ require 'views/view'
require 'game_states/game_state'
require 'game_states/start_menu'
require 'game_states/map_state'
require 'game_states/finish_screen'

function love.load()
game:createFonts(0)
game.current_state = StartMenu()
game:startMenu()
love.audio.play(game.sounds.music[1])
love.graphics.setMode(love.graphics.getWidth(), love.graphics.getHeight(), game.graphics.fullscreen)
game:start()
end

function love.draw()
Expand Down
22 changes: 22 additions & 0 deletions views/finish_view.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

FinishView = class("FinishView", View)

function FinishView:initialize(player)
self.display.x = 40
self.display.align = { y = 'center' }
self:setDisplay(self.display)
self.player = player
end

function FinishView:drawContent()
love.graphics.setFont(game.fonts.regular)

love.graphics.push()
love.graphics.scale(2,2)
love.graphics.setColor(200, 50, 50, 255)
love.graphics.print(self.player.death_message, 0, 0)
love.graphics.pop()

love.graphics.setColor(255,255,255,255)
love.graphics.print('Press [space] to return to the start menu', 0, 50)
end
3 changes: 0 additions & 3 deletions views/start_menu_view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ function StartMenuView:draw()
y = 20
end

love.graphics.push()
love.graphics.setFont(game.fonts.regular)
love.graphics.scale(1.8,1.8)
love.graphics.setColor(255,255,255,200)
love.graphics.print('Rogue Beach, CA', x, y)
love.graphics.setColor(255,200, 10, 255)
love.graphics.print('Rogue Beach, CA', x-1, y-1)

love.graphics.pop()
end

function StartMenuView:update(dt)
Expand Down
4 changes: 2 additions & 2 deletions views/view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ View:include({
display = {x = 0, y = 0, width = 200, height = 100},
focus = nil,

draw = function(self, ...)
draw = function(self)
love.graphics.push()
love.graphics.translate(self.display.x, self.display.y)
self:drawContent(...)
self:drawContent()
love.graphics.pop()
end
})
Expand Down

0 comments on commit 0e6be3e

Please sign in to comment.