diff options
-rw-r--r-- | ground.lua | 19 | ||||
-rw-r--r-- | main.lua | 34 | ||||
-rw-r--r-- | player.lua | 33 |
3 files changed, 57 insertions, 29 deletions
@@ -1,6 +1,9 @@ -- `Ground` +-- Static platform physical object with a sprite. `Players` can walk on it. -- Collision category: [1] +-- WHOLE CODE HAS FLAG OF "need a cleanup" + -- Metatable of `Ground` -- nils initialized in constructor Ground = { @@ -21,4 +24,20 @@ function Ground:new (world, x, y, shape, sprite) o.fixture:setCategory(1) o.fixture:setFriction(0.2) return o +end + +-- Draw of `Ground` +function Ground:draw (offset_x, offset_y, debug) + -- defaults + local offset_x = offset_x or 0 + local offset_y = offset_y or 0 + local debug = debug or false + -- sprite draw + love.graphics.setColor(255,255,255,255) + love.graphics.draw(self.sprite, self.body:getX()-math.ceil(self.sprite:getWidth()/2), self.body:getY()) + -- debug draw + if debug then + love.graphics.setColor(220, 220, 220, 100) + love.graphics.polygon("fill", self.body:getWorldPoints(self.shape:getPoints())) + end end
\ No newline at end of file @@ -1,9 +1,12 @@ +-- "NOTNAUTS" +-- WHOLE CODE HAS FLAG OF "need a cleanup" + require "ground" require "player" debug = false -function love.load() +function love.load () -- Graphics love.graphics.setBackgroundColor(189, 95, 93) love.graphics.setDefaultFilter("nearest", "nearest") @@ -35,7 +38,7 @@ function love.load() Nauts[2].key_hit = "g" end -function love.update(dt) +function love.update (dt) -- Put world in motion! world:update(dt) -- Players @@ -44,7 +47,7 @@ function love.update(dt) end end -function love.keypressed(key) +function love.keypressed (key) -- Switch hitbox display on/off if key == "x" then debug = not debug @@ -62,7 +65,7 @@ function love.keyreleased(key) end end -function love.draw() +function love.draw () -- Draw SOME background -- I'm already bored with solid color! love.graphics.setColor(193, 100, 99, 255) @@ -72,31 +75,16 @@ function love.draw() -- Draw ground for k,platform in pairs(Platforms) do - love.graphics.setColor(255,255,255,255) - love.graphics.draw(platform.sprite, platform.body:getX()-math.ceil(platform.sprite:getWidth()/2), platform.body:getY()) - if debug then - love.graphics.setColor(220, 220, 220, 100) - love.graphics.polygon("fill", platform.body:getWorldPoints(platform.shape:getPoints())) - end + platform:draw(0, 0, debug) end -- Draw player for k,naut in pairs(Nauts) do - love.graphics.setColor(255,255,255,255) - love.graphics.draw(naut.sprite, naut.current[naut.frame], naut.body:getX(), naut.body:getY(), naut.rotate, naut.facing, 1, 12, 15) - if debug then - love.graphics.setColor(50, 255, 50, 100) - love.graphics.polygon("fill", naut.body:getWorldPoints(naut.shape:getPoints())) - love.graphics.setColor(255,255,255,255) - love.graphics.points(naut.body:getX()+12*naut.facing,naut.body:getY()-2) - love.graphics.points(naut.body:getX()+6*naut.facing,naut.body:getY()+2) - love.graphics.points(naut.body:getX()+18*naut.facing,naut.body:getY()+2) - love.graphics.points(naut.body:getX()+12*naut.facing,naut.body:getY()+6) - end + naut:draw(0, 0, debug) end end -function beginContact(a, b, coll) +function beginContact (a, b, coll) local x,y = coll:getNormal() if y == -1 then print(b:getUserData().name .. " is not in air") @@ -105,7 +93,7 @@ function beginContact(a, b, coll) end end -function endContact(a, b, coll) +function endContact (a, b, coll) print(b:getUserData().name .. " is in air") b:getUserData().inAir = true end
\ No newline at end of file @@ -38,7 +38,7 @@ Player = { } -- Constructor of `Player` -function Player:new(world, x, y, spritesheet) +function Player:new (world, x, y, spritesheet) -- Meta local o = {} setmetatable(o, self) @@ -59,7 +59,7 @@ function Player:new(world, x, y, spritesheet) end -- Update callback of `Player` -function Player:update(dt) +function Player:update (dt) -- # VERTICAL MOVEMENT -- Jumping if self.jumpactive and self.jumptimer > 0 then @@ -131,7 +131,7 @@ function Player:update(dt) end -- Keypressed callback of `Player` -function Player:keypressed(key) +function Player:keypressed (key) -- Jumping if key == self.key_jump then if not self.inAir then @@ -168,7 +168,7 @@ function Player:keypressed(key) end -- Keyreleased callback of `Player` -function Player:keyreleased(key) +function Player:keyreleased (key) -- Jumping if key == self.key_jump then self.jumpactive = false @@ -184,6 +184,27 @@ function Player:keyreleased(key) end end +-- Draw of `Player` +function Player:draw (offset_x, offset_y, debug) + -- defaults + local offset_x = offset_x or 0 + local offset_y = offset_y or 0 + local debug = debug or false + -- sprite draw + love.graphics.setColor(255,255,255,255) + love.graphics.draw(self.sprite, self.current[self.frame], self.body:getX(), self.body:getY(), self.rotate, self.facing, 1, 12, 15) + -- debug draw + if debug then + love.graphics.setColor(50, 255, 50, 100) + love.graphics.polygon("fill", self.body:getWorldPoints(self.shape:getPoints())) + love.graphics.setColor(255,255,255,255) + love.graphics.points(self.body:getX()+12*self.facing,self.body:getY()-2) + love.graphics.points(self.body:getX()+ 6*self.facing,self.body:getY()+2) + love.graphics.points(self.body:getX()+18*self.facing,self.body:getY()+2) + love.graphics.points(self.body:getX()+12*self.facing,self.body:getY()+6) + end +end + -- Change animation of `Player` -- idle, walk, attack, attack_up, attack_down, damage function Player:changeAnimation(animation) @@ -194,7 +215,7 @@ end -- Punch of `Player` -- REWORK NEEDED -function Player:hit(horizontal, vertical) +function Player:hit (horizontal, vertical) if vertical == -1 then self:changeAnimation("attack_up") elseif vertical == 1 then @@ -228,7 +249,7 @@ function Player:hit(horizontal, vertical) end -- Taking damage of `Player` by successful hit test -function Player:damage(horizontal, vertical) +function Player:damage (horizontal, vertical) self.body:applyLinearImpulse((34+12*self.combo)*horizontal, (50+10*self.combo)*vertical + 15) self:changeAnimation("damage") end
\ No newline at end of file |