Skip to content

Commit

Permalink
Prepare Player to draw in different states: standing and paddling
Browse files Browse the repository at this point in the history
  • Loading branch information
TomK32 committed Jan 11, 2013
1 parent 1f6c27d commit 4bc7f62
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions actors/player.lua
Expand Up @@ -31,20 +31,48 @@ function Player:initialize(position)
self.dt_since_input = 0
self.entity_type = 'Actor'
self.inputs = {}
self.state = 'standing'
self:setBoard()
self:setInputs(Player.input_alternatives['wasd'])
self:setInputs(Player.input_alternatives['arrows'])
end

function Player:draw()
local board = {}
game.renderer:print('@', {255,0,0,255}, self.position.x, self.position.y)
game.renderer:print('|', {255,100,0,255}, self.position.x + 1, self.position.y - 1)
game.renderer:print('|', {255,100,0,255}, self.position.x + 1, self.position.y)
game.renderer:print('|', {255,100,0,255}, self.position.x + 1, self.position.y + 1)
for i, tile in pairs(self.board) do
game.renderer:print(tile.c, {255,100,0,255}, self.position.x + tile.x, self.position.y - tile.y)
end
end

function Player:setInputs(inputs)
for direction, key in pairs(inputs.keyboard) do
self.inputs[key] = Player.movements[direction]
end
end

function Player:switchState()
if self.state == 'standing' then
self.state = 'paddling'
elseif self.state == 'padding' then
self.state = 'surfing'
else
self.self = 'standing'
end
self:setBoard()
end

function Player:setBoard()
if self.state == 'standing' then
self.board = {
{x = 1, y = -1, c = '|'},
{x = 1, y = 0, c = '|'},
{x = 1, y = 1, c = '|'}
}
elseif self.state == 'paddling' then
self.board = {
{x = 0, y = -1, c = ''},
{x = 0, y = 1, c = ''}
}
end
end

0 comments on commit 4bc7f62

Please sign in to comment.