Skip to content

Commit

Permalink
Movement left and right. No collisions.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkie committed Nov 6, 2011
1 parent 819fab4 commit 039e2ad
Showing 1 changed file with 50 additions and 8 deletions.
58 changes: 50 additions & 8 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,62 @@
-- Require List
require "loader"
require "world"
require "player"
require "viewport"

function love.draw()
love.graphics.setBackgroundColor(255,0,0)
-- Load Initial World

State = {REST = 0, MOVE_LEFT = 1, MOVE_RIGHT = 2}
state = State.REST
keys_down = 0

load_data = Loader:load("world_1")

world = World:new():with(load_data.map)
player = Player:new():with(load_data.start)

viewport = Viewport:new()

local load_data = Loader:load("world_1")
viewport.x = 18
viewport.y = 15

local world = World:new():with(load_data.map)
local player = Player:new():with(load_data.start)
load_data = nil

local viewport = Viewport:new()
-- Events

viewport.x = 18
viewport.y = 15
function love.keypressed(key, unicode)
if key == "q" then
love.event.push("q")
elseif key == "left" then
state = State.MOVE_LEFT
keys_down = keys_down + 1
elseif key == "right" then
state = State.MOVE_RIGHT
keys_down = keys_down + 1
end
end

function love.keyreleased(key)
if key == "left" then
keys_down = keys_down - 1
elseif key == "right" then
keys_down = keys_down - 1
end
if keys_down == 0 then
state = State.REST
end
end

function love.update(dt)
if state == State.MOVE_LEFT then
player.x = player.x - (250*dt)
elseif state == State.MOVE_RIGHT then
player.x = player.x + (250*dt)
end
end

function love.draw()
love.graphics.setBackgroundColor(255,0,0)

viewport:draw(world)
viewport:draw(player)
Expand Down

0 comments on commit 039e2ad

Please sign in to comment.