Skip to content

Commit

Permalink
Adding Battery and adding types to shapes.
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkie committed Nov 6, 2011
1 parent 9a71690 commit ccc096b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
31 changes: 31 additions & 0 deletions battery.lua
@@ -0,0 +1,31 @@
-- Battery

-- Represents a battery object

Battery = {}

function Battery:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end

function Battery:with(position, world)
self.body = love.physics.newBody(world.physics, position.x*32, position.y*32, 0, 0)
self.shape = love.physics.newRectangleShape(self.body, -16, -16, 32, 32, 0)
self.shape:setFriction(1.0)
self.shape:setSensor(true)
self.type = "battery"
self.shape:setData(self)

return self
end

function Battery:draw(x, y)
local x1,y1,x2,y2 = self.shape:getPoints()

love.graphics.setColor(0,255,255)
love.graphics.rectangle("fill", x1-x, y1-y, 32, 32)
love.graphics.setColor(255,255,255)
end
8 changes: 8 additions & 0 deletions main.lua
Expand Up @@ -2,6 +2,7 @@
require "loader"
require "world"
require "player"
require "battery"
require "viewport"

-- Load Initial World
Expand All @@ -14,6 +15,10 @@ load_data = Loader:load("world_1")

world = World:new():with(load_data.map)
player = Player:new():with(load_data.start, world)
batteries = {}
for i=1,#load_data.batteries do
batteries[#batteries+1] = Battery:new():with(load_data.batteries[i], world)
end

viewport = Viewport:new()

Expand Down Expand Up @@ -76,4 +81,7 @@ function love.draw()

viewport:draw(world)
viewport:draw(player)
for i=1,#batteries do
viewport:draw(batteries[i])
end
end
5 changes: 4 additions & 1 deletion player.lua
Expand Up @@ -14,9 +14,12 @@ end
function Player:with(position, world)
self.start = position

self.body = love.physics.newBody(world.physics, (position.x*32-32)+16, (position.y*32-32)+16, 10, 0)
self.body = love.physics.newBody(world.physics, position.x*32, position.y*32, 10, 0)
self.shape = love.physics.newRectangleShape(self.body, -16, -16, 32, 32, 0)
self.shape:setFriction(1.0)
self.type = "player"
self.shape:setData(self)

return self
end

Expand Down
2 changes: 2 additions & 0 deletions world.lua
Expand Up @@ -40,6 +40,8 @@ function World:with(map)
tile.body = love.physics.newBody(self.physics, lx*32, ly*32, 0, 0)
tile.shape = love.physics.newRectangleShape(tile.body, -16, -16, 32, 32, 0)
tile.shape:setFriction(1.0)
tile.type = "wall"
tile.shape:setData(tile)
end
end
end
Expand Down

0 comments on commit ccc096b

Please sign in to comment.