diff options
author | Aki <nthirtyone@gmail.com> | 2016-05-21 01:21:42 +0200 |
---|---|---|
committer | Aki <nthirtyone@gmail.com> | 2016-05-21 01:21:42 +0200 |
commit | a828872e5160bbc657c106b4b349c14b671498ba (patch) | |
tree | 923fa51d637901f8ae3d735c3c1a8742873493a7 | |
parent | 01eb227519733ce149035955b1f2ede80102496a (diff) | |
download | roflnauts-a828872e5160bbc657c106b4b349c14b671498ba.zip roflnauts-a828872e5160bbc657c106b4b349c14b671498ba.tar.gz roflnauts-a828872e5160bbc657c106b4b349c14b671498ba.tar.bz2 |
First move into portraits and HUD
-rw-r--r-- | assets/portraits.png | bin | 0 -> 29772 bytes | |||
-rw-r--r-- | main.lua | 5 | ||||
-rw-r--r-- | player.lua | 49 | ||||
-rw-r--r-- | portraits.lua | 42 | ||||
-rw-r--r-- | world.lua | 10 |
5 files changed, 87 insertions, 19 deletions
diff --git a/assets/portraits.png b/assets/portraits.png Binary files differnew file mode 100644 index 0000000..94aa73f --- /dev/null +++ b/assets/portraits.png @@ -23,11 +23,10 @@ function love.load () w:createPlatform(290/2+140, 180/2+50, {-26,1, 26,1, 26,30, -26,30}, "assets/platform_small.png") w:createPlatform(290/2-140, 180/2+50, {-26,1, 26,1, 26,30, -26,30}, "assets/platform_small.png") w:createPlatform(290/2, 180/2-50, {-17,1, 17,1, 17,16, -17,16}, "assets/platform_top.png") - w:createNaut(290/2-10, 180/2 - 80, "assets/leon.png") - w:createNaut(290/2+10, 180/2 - 80, "assets/lonestar.png") + w:createNaut(290/2-10, 180/2 - 80, "leon") + w:createNaut(290/2+10, 180/2 - 80, "lonestar") -- Temporary settings for second player - w.Nauts[2].name = "Player2" w.Nauts[2].key_left = "a" w.Nauts[2].key_right = "d" w.Nauts[2].key_up = "w" @@ -8,7 +8,7 @@ -- nils initialized in constructor Player = { -- General and physics - name = "Player", + name = "empty", body = nil, shape = nil, fixture = nil, @@ -24,7 +24,7 @@ Player = { alive = true, punchcd = 0, punchinitial = 0.25, - punchdir = 0, + punchdir = 0, -- a really bad thing -- Animation animations = require "animations", current = nil, @@ -33,6 +33,7 @@ Player = { initial = nil, -- Movement inAir = true, + salto = false, jumpactive = false, jumpdouble = true, jumptimer = 0.14, @@ -42,11 +43,14 @@ Player = { key_right = "right", key_up = "up", key_down = "down", - key_hit = "return" + key_hit = "return", + -- HUD + portrait_sprite = nil, + portrait_sheet = require "portraits" } -- Constructor of `Player` -function Player:new (game, world, x, y, spritesheet) +function Player:new (game, world, x, y, name) -- Meta local o = {} setmetatable(o, self) @@ -60,12 +64,17 @@ function Player:new (game, world, x, y, spritesheet) o.fixture:setMask(2) o.body:setFixedRotation(true) -- Misc - o.sprite = love.graphics.newImage(spritesheet) + o.name = name or "empty" + o.sprite = love.graphics.newImage("assets/"..o.name..".png") o.world = game -- Animation o.initial = o.delay o.current = o.animations.idle o:createEffect("respawn") + -- Portrait load for first object created + if self.portrait_sprite == nil then + self.portrait_sprite = love.graphics.newImage("assets/portraits.png") + end return o end @@ -80,7 +89,7 @@ function Player:update (dt) end -- Salto - if not self.jumpdouble and self.inAir and (self.current == self.animations.walk or self.current == self.animations.idle) then + if self.salto and (self.current == self.animations.walk or self.current == self.animations.idle) then self.rotate = (self.rotate + 17 * dt * self.facing) % 360 elseif self.rotate ~= 0 then self.rotate = 0 @@ -157,16 +166,15 @@ function Player:update (dt) -- # PUNCH -- Cooldown - if self.punchcd > 0 then - self.punchcd = self.punchcd - dt - end + self.punchcd = self.punchcd - dt -- Stop vertical - if self.punchcd > 0.1 then + local c,a = self.current, self.animations + if (c == a.attack_up or c == a.attack_down or c == a.attack) and self.frame < c.frames then if self.punchdir == 0 then self.body:setLinearVelocity(0,0) else - self.body:setLinearVelocity(28*self.facing,0) + self.body:setLinearVelocity(32*self.facing,0) end end @@ -191,6 +199,7 @@ function Player:keypressed (key) self:createEffect("doublejump") self.jumpactive = true self.jumpdouble = false + self.salto = true end end @@ -202,17 +211,24 @@ function Player:keypressed (key) -- Punching if key == self.key_hit and self.punchcd <= 0 then local f = self.facing + self.salto = false if love.keyboard.isDown(self.key_up) then -- Punch up - self:changeAnimation("attack_up") + if self.current ~= self.animations.damage then + self:changeAnimation("attack_up") + end self:hit(2*f,-10,3*f,7, 0, -1) elseif love.keyboard.isDown(self.key_down) and self.inAir then -- Punch down - self:changeAnimation("attack_down") + if self.current ~= self.animations.damage then + self:changeAnimation("attack_down") + end self:hit(-4,-2,4,7, 0, 1) else -- Punch horizontal - self:changeAnimation("attack") + if self.current ~= self.animations.damage then + self:changeAnimation("attack") + end self:hit(2*f,-4,8*f,4, f, 0) self.punchdir = 1 end @@ -254,6 +270,11 @@ function Player:draw (offset_x, offset_y, scale, debug) end end +-- Draw HUD of `Player` +function Player:drawHUD (x,y,scale) + love.graphics.draw(self.portrait_sprite, self.portrait_sheet[self.name].normal, x*scale, y*scale, 0, scale, scale) +end + -- Change animation of `Player` -- idle, walk, attack, attack_up, attack_down, damage function Player:changeAnimation(animation) diff --git a/portraits.lua b/portraits.lua new file mode 100644 index 0000000..80ffe8a --- /dev/null +++ b/portraits.lua @@ -0,0 +1,42 @@ +-- Spritesheet for character portraits +-- Original size: 331x199 (say what?) +-- Single size: 32x32 1px border merged between +local w, h = 331, 199 +return { + empty = { + normal = love.graphics.newQuad(298,133,32,32,w,h), + active = love.graphics.newQuad(298,166,32,32,w,h) + }, + frog = { + normal = love.graphics.newQuad( 1, 1,32,32,w,h), + active = love.graphics.newQuad( 1, 34,32,32,w,h) + }, + lonestar = { + normal = love.graphics.newQuad( 34, 1,32,32,w,h), + active = love.graphics.newQuad( 34, 34,32,32,w,h) + }, + leon = { + normal = love.graphics.newQuad( 67, 1,32,32,w,h), + active = love.graphics.newQuad( 67, 34,32,32,w,h) + }, + coco = { + normal = love.graphics.newQuad( 1, 67,32,32,w,h), + active = love.graphics.newQuad( 1,100,32,32,w,h) + }, + derpl = { + normal = love.graphics.newQuad(100, 67,32,32,w,h), + active = love.graphics.newQuad(100,100,32,32,w,h) + }, + voltar = { + normal = love.graphics.newQuad(265, 1,32,32,w,h), + active = love.graphics.newQuad(265, 34,32,32,w,h) + }, + yuri = { + normal = love.graphics.newQuad( 67, 67,32,32,w,h), + active = love.graphics.newQuad( 67,100,32,32,w,h) + }, + clunk = { + normal = love.graphics.newQuad(232, 1,32,32,w,h), + active = love.graphics.newQuad(232, 34,32,32,w,h) + } +}
\ No newline at end of file @@ -56,8 +56,8 @@ function World:createPlatform(x, y, polygon, sprite) end -- Add new naut to the world -function World:createNaut(x, y, sprite) - table.insert(self.Nauts, Player:new(self, self.world, x, y, sprite)) +function World:createNaut(x, y, name) + table.insert(self.Nauts, Player:new(self, self.world, x, y, name)) end -- Add new cloud to the world @@ -168,6 +168,11 @@ function World:draw() for _,platform in pairs(self.Platforms) do platform:draw(offset_x, offset_y, scale, debug) end + + -- Draw HUDs + for _,naut in pairs(self.Nauts) do + naut:drawHUD(1, 1+(_-1)*33, scale) + end end -- beginContact @@ -178,6 +183,7 @@ function World.beginContact(a, b, coll) print(b:getUserData().name .. " is not in air") b:getUserData().inAir = false b:getUserData().jumpdouble = true + b:getUserData().salto = false b:getUserData():createEffect("land") end end |