summaryrefslogtreecommitdiffhomepage
path: root/ground.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2017-02-26 01:28:08 +0100
committerAki <nthirtyone@gmail.com>2017-02-26 01:28:08 +0100
commitf6931cb1bda8c7ec1301f359f28ecc3b1fdb1566 (patch)
treee6b51ec7a27dba06c79ec7e7f500a100fd82594a /ground.lua
parent0b287c4750553ab72c04680378487b9d11cd0b43 (diff)
downloadroflnauts-f6931cb1bda8c7ec1301f359f28ecc3b1fdb1566.zip
roflnauts-f6931cb1bda8c7ec1301f359f28ecc3b1fdb1566.tar.gz
roflnauts-f6931cb1bda8c7ec1301f359f28ecc3b1fdb1566.tar.bz2
Ground => Platform
Diffstat (limited to 'ground.lua')
-rw-r--r--ground.lua73
1 files changed, 0 insertions, 73 deletions
diff --git a/ground.lua b/ground.lua
deleted file mode 100644
index 1318c11..0000000
--- a/ground.lua
+++ /dev/null
@@ -1,73 +0,0 @@
--- `Ground`
--- Static platform physical object with a sprite. `Players` can walk on it.
--- Collision category: [1]
-
--- WHOLE CODE HAS FLAG OF "need a cleanup"
-require "animated"
-
--- Metatable of `Ground`
--- nils initialized in constructor
-Ground = {
- body = nil,
- shape = nil,
- fixture = nil,
- world = nil,
-}
-Ground.__index = Ground
-setmetatable(Ground, Animated)
-
--- Constructor of `Ground`
-function Ground:new (game, world, x, y, shape, sprite, animations)
- local o = {}
- setmetatable(o, self)
- o.body = love.physics.newBody(world, x, y)
- -- MULTIPLE SHAPES NEED TO BE REWRITED!
- o.shape = {}
- if type(shape[1]) == "number" then
- local poly = love.physics.newPolygonShape(shape)
- table.insert(o.shape, poly)
- o.fixture = love.physics.newFixture(o.body, poly)
- o.fixture:setCategory(1)
- o.fixture:setFriction(0.2)
- else
- for i,v in pairs(shape) do
- local poly = love.physics.newPolygonShape(v)
- table.insert(o.shape, poly)
- local fixture = love.physics.newFixture(o.body, poly)
- fixture:setCategory(1)
- fixture:setFriction(0.2)
- end
- end
- -- END HERE
- o:setSprite(love.graphics.newImage(sprite))
- o:setAnimationsList(animations)
- o.world = game
- return o
-end
-
--- Position
-function Ground:getPosition()
- return self.body:getPosition()
-end
-
--- Draw of `Ground`
-function Ground:draw (offset_x, offset_y, scale, debug)
- -- locals
- local offset_x = offset_x or 0
- local offset_y = offset_y or 0
- local scale = scale or 1
- local debug = debug or false
- local x, y = self:getPosition()
- -- pixel grid
- local draw_x = (math.floor(x) + offset_x) * scale
- local draw_y = (math.floor(y) + offset_y) * scale
- -- sprite draw
- Animated.draw(self, draw_x, draw_y, 0, scale, scale)
- -- debug draw
- if debug then
- love.graphics.setColor(255, 69, 0, 140)
- for i,v in pairs(self.shape) do
- love.graphics.polygon("fill", self.world.camera:translatePoints(self.body:getWorldPoints(v:getPoints())))
- end
- end
-end \ No newline at end of file