From bd22a09dc862ac5480426bfd5e0311a97b6cfa77 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 1 Mar 2017 21:31:11 +0100 Subject: Rename: Animated -> Sprite Rename: getSprite, setSprite -> getImage, setImage --- animated.lua | 81 ---------------------------------------------------------- decoration.lua | 6 ++--- platform.lua | 8 +++--- player.lua | 10 ++++---- sprite.lua | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 93 deletions(-) delete mode 100644 animated.lua create mode 100644 sprite.lua diff --git a/animated.lua b/animated.lua deleted file mode 100644 index 160ee44..0000000 --- a/animated.lua +++ /dev/null @@ -1,81 +0,0 @@ --- `Animated` --- Abstract class for drawable animated entities. - --- Metatable -Animated = { - animations--[[table with animations]], - current--[[animations.default]], - sprite--[[love.graphics.newImage()]], - frame = 1, - delay = .1, -} -Animated.__index = Animated - --- Cleans up reference to sprite on deletion. -function Animated:delete() - self.sprite = nil -end - --- Sets an Image as a sprite. -function Animated:setSprite(image) - self.sprite = image -end --- Returns current sprite Image. -function Animated:getSprite() - return self.sprite -end - --- Sets new animations list. -function Animated:setAnimationsList(t) - if t then - self.animations = t - self:setAnimation("default") - end -end - --- Sets current animation by table key. -function Animated:setAnimation(animation) - self.frame = 1 - self.delay = Animated.delay -- INITIAL from metatable - self.current = self.animations[animation] -end --- Returns current animation table. -function Animated:getAnimation() - return self.current -end - --- Get frame quad for drawing. -function Animated:getQuad() - if self.animations and self.current then - return self.current[self.frame] - end -end - --- Drawing self to LOVE2D buffer. --- If there is no Quad, it will draw entire sprite. -function Animated:draw(...) - local s, q = self:getSprite(), self:getQuad() - if s then - love.graphics.setColor(255,255,255,255) - if q then love.graphics.draw(s, q, ...) - else love.graphics.draw(s, ...) end - end -end --- Animation updating. -function Animated:update(dt) - if self.animations and self.current then - self.delay = self.delay - dt - if self.delay < 0 then - self.delay = self.delay + Animated.delay -- INITIAL from metatable - self:nextFrame() - end - end -end --- Moving to the next frame. -function Animated:nextFrame() - if self.current.repeated or not (self.frame == self.current.frames) then - self.frame = (self.frame % self.current.frames) + 1 - else - self:setAnimation("default") - end -end \ No newline at end of file diff --git a/decoration.lua b/decoration.lua index 3ca6f76..ffb007d 100644 --- a/decoration.lua +++ b/decoration.lua @@ -5,11 +5,11 @@ Decoration = { y = 0 } Decoration.__index = Decoration -setmetatable(Decoration, Animated) +setmetatable(Decoration, Sprite) function Decoration:new(x, y, sprite) local o = {} setmetatable(o, self) - o.sprite = love.graphics.newImage(sprite) + o:setImage(love.graphics.newImage(sprite)) o:setPosition(x,y) return o end @@ -29,5 +29,5 @@ function Decoration:draw(offset_x, offset_y, scale) local draw_x = (math.floor(x) + offset_x) * scale local draw_y = (math.floor(y) + offset_y) * scale -- draw - Animated.draw(self, draw_x, draw_y, 0, scale, scale) + Sprite.draw(self, draw_x, draw_y, 0, scale, scale) end \ No newline at end of file diff --git a/platform.lua b/platform.lua index 908cf73..9d75e66 100644 --- a/platform.lua +++ b/platform.lua @@ -3,7 +3,7 @@ -- Collision category: [1] -- WHOLE CODE HAS FLAG OF "need a cleanup" -require "animated" +require "sprite" -- Metatable of `Platform` -- nils initialized in constructor @@ -14,7 +14,7 @@ Platform = { world = nil, } Platform.__index = Platform -setmetatable(Platform, Animated) +setmetatable(Platform, Sprite) -- Constructor of `Platform` function Platform:new (game, world, x, y, shape, sprite, animations) @@ -39,7 +39,7 @@ function Platform:new (game, world, x, y, shape, sprite, animations) end end -- END HERE - o:setSprite(love.graphics.newImage(sprite)) + o:setImage(love.graphics.newImage(sprite)) o:setAnimationsList(animations) o.world = game return o @@ -62,7 +62,7 @@ function Platform:draw (offset_x, offset_y, scale, debug) 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) + Sprite.draw(self, draw_x, draw_y, 0, scale, scale) -- debug draw if debug then love.graphics.setColor(255, 69, 0, 140) diff --git a/player.lua b/player.lua index 775dd60..a5b4bd2 100644 --- a/player.lua +++ b/player.lua @@ -3,7 +3,7 @@ -- Collision category: [2] -- WHOLE CODE HAS FLAG OF "need a cleanup" -require "animated" +require "sprite" -- Metatable of `Player` -- nils initialized in constructor @@ -45,7 +45,7 @@ Player = { animations = require "animations" } Player.__index = Player -setmetatable(Player, Animated) +setmetatable(Player, Sprite) -- Constructor of `Player` function Player:new (game, world, x, y, name) @@ -64,7 +64,7 @@ function Player:new (game, world, x, y, name) o.body:setFixedRotation(true) -- Misc o.name = name or "empty" - o:setSprite(newImage("assets/nauts/"..o.name..".png")) + o:setImage(newImage("assets/nauts/"..o.name..".png")) o.world = game o.punchcd = 0 -- Animation @@ -146,7 +146,7 @@ function Player:update(dt) end end - Animated.update(self, dt) + Sprite.update(self, dt) -- # DEATH -- We all die in the end. @@ -299,7 +299,7 @@ function Player:draw(offset_x, offset_y, scale, debug) local draw_y = (approx(y) + offset_y) * scale local draw_x = (math.floor(x) + offset_x) * scale -- sprite draw - Animated.draw(self, draw_x, draw_y, self.rotate, self.facing*scale, scale, 12, 15) + Sprite.draw(self, draw_x, draw_y, self.rotate, self.facing*scale, scale, 12, 15) -- debug draw if debug then for _,fixture in pairs(self.body:getFixtureList()) do diff --git a/sprite.lua b/sprite.lua new file mode 100644 index 0000000..1cc46f7 --- /dev/null +++ b/sprite.lua @@ -0,0 +1,81 @@ +-- `Sprite` +-- Abstract class for drawable animated entities. + +-- Metatable +Sprite = { + animations--[[table with animations]], + current--[[animations.default]], + image--[[love.graphics.newImage()]], + frame = 1, + delay = .1, +} +Sprite.__index = Sprite + +-- Cleans up reference to image on deletion. +function Sprite:delete() + self.image = nil +end + +-- Sets an Image as a image. +function Sprite:setImage(image) + self.image = image +end +-- Returns current image Image. +function Sprite:getImage() + return self.image +end + +-- Sets new animations list. +function Sprite:setAnimationsList(t) + if t then + self.animations = t + self:setAnimation("default") + end +end + +-- Sets current animation by table key. +function Sprite:setAnimation(animation) + self.frame = 1 + self.delay = Sprite.delay -- INITIAL from metatable + self.current = self.animations[animation] +end +-- Returns current animation table. +function Sprite:getAnimation() + return self.current +end + +-- Get frame quad for drawing. +function Sprite:getQuad() + if self.animations and self.current then + return self.current[self.frame] + end +end + +-- Drawing self to LOVE2D buffer. +-- If there is no Quad, it will draw entire image. +function Sprite:draw(...) + local s, q = self:getImage(), self:getQuad() + if s then + love.graphics.setColor(255,255,255,255) + if q then love.graphics.draw(s, q, ...) + else love.graphics.draw(s, ...) end + end +end +-- Animation updating. +function Sprite:update(dt) + if self.animations and self.current then + self.delay = self.delay - dt + if self.delay < 0 then + self.delay = self.delay + Sprite.delay -- INITIAL from metatable + self:nextFrame() + end + end +end +-- Moving to the next frame. +function Sprite:nextFrame() + if self.current.repeated or not (self.frame == self.current.frames) then + self.frame = (self.frame % self.current.frames) + 1 + else + self:setAnimation("default") + end +end \ No newline at end of file -- cgit v1.1 From 84278ed41f61c586dbb38dd99c45ee33e2f58c77 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 16 Mar 2017 19:05:50 +0100 Subject: Moved ? -> not.?; Renamed Player -> Hero --- cloud.lua | 63 -------- decoration.lua | 33 ---- effect.lua | 68 -------- main.lua | 2 +- not/Cloud.lua | 63 ++++++++ not/Decoration.lua | 34 ++++ not/Effect.lua | 68 ++++++++ not/Hero.lua | 449 +++++++++++++++++++++++++++++++++++++++++++++++++++++ not/Platform.lua | 73 +++++++++ not/Sprite.lua | 81 ++++++++++ not/World.lua | 424 ++++++++++++++++++++++++++++++++++++++++++++++++++ platform.lua | 73 --------- player.lua | 449 ----------------------------------------------------- sprite.lua | 81 ---------- world.lua | 424 -------------------------------------------------- 15 files changed, 1193 insertions(+), 1192 deletions(-) delete mode 100644 cloud.lua delete mode 100644 decoration.lua delete mode 100644 effect.lua create mode 100644 not/Cloud.lua create mode 100644 not/Decoration.lua create mode 100644 not/Effect.lua create mode 100644 not/Hero.lua create mode 100644 not/Platform.lua create mode 100644 not/Sprite.lua create mode 100644 not/World.lua delete mode 100644 platform.lua delete mode 100644 player.lua delete mode 100644 sprite.lua delete mode 100644 world.lua diff --git a/cloud.lua b/cloud.lua deleted file mode 100644 index c12e236..0000000 --- a/cloud.lua +++ /dev/null @@ -1,63 +0,0 @@ --- `Cloud` --- That white thing moving in the background. - --- WHOLE CODE HAS FLAG OF "need a cleanup" - --- Metatable of `Cloud` --- nils initialized in constructor -Cloud = { - x = 0, -- position horizontal - y = 0, -- position vertical - t = 1, -- type (sprite number) - v = 13, -- velocity - sprite = nil, - quads = { - [1] = love.graphics.newQuad( 1, 1, 158,47, 478,49), - [2] = love.graphics.newQuad(160, 1, 158,47, 478,49), - [3] = love.graphics.newQuad(319, 1, 158,47, 478,49) - } -} - --- Constructor of `Cloud` -function Cloud:new(x, y, t, v) - -- Meta - local o = {} - setmetatable(o, self) - self.__index = self - -- Load spritesheet to metatable if not yet loaded - if self.sprite == nil then - self.sprite = love.graphics.newImage("assets/clouds.png") - end - -- Init - o.x = x or self.x - o.y = y or self.y - o.t = t or self.t - o.v = v or self.v - return o -end - --- Position -function Cloud:getPosition() - return self.x, self.y -end - --- Update of `Cloud`, returns x for world to delete cloud after reaching right corner -function Cloud:update(dt) - self.x = self.x + self.v*dt - return self.x -end - --- Draw `Cloud` -function Cloud:draw(offset_x, offset_y, scale) - -- locals - local offset_x = offset_x or 0 - local offset_y = offset_y or 0 - local scale = scale or 1 - 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 - -- draw - love.graphics.setColor(255,255,255,255) - love.graphics.draw(self.sprite, self.quads[self.t], draw_x, draw_y, 0, scale, scale) -end \ No newline at end of file diff --git a/decoration.lua b/decoration.lua deleted file mode 100644 index ffb007d..0000000 --- a/decoration.lua +++ /dev/null @@ -1,33 +0,0 @@ -Decoration = { - world = nil, - sprite = nil, - x = 0, - y = 0 -} -Decoration.__index = Decoration -setmetatable(Decoration, Sprite) -function Decoration:new(x, y, sprite) - local o = {} - setmetatable(o, self) - o:setImage(love.graphics.newImage(sprite)) - o:setPosition(x,y) - return o -end -function Decoration:setPosition(x, y) - self.x, self.y = x, y -end -function Decoration:getPosition() - return self.x, self.y -end -function Decoration:draw(offset_x, offset_y, scale) - -- locals - local offset_x = offset_x or 0 - local offset_y = offset_y or 0 - local scale = scale or 1 - 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 - -- draw - Sprite.draw(self, draw_x, draw_y, 0, scale, scale) -end \ No newline at end of file diff --git a/effect.lua b/effect.lua deleted file mode 100644 index 4e327a1..0000000 --- a/effect.lua +++ /dev/null @@ -1,68 +0,0 @@ --- `Effect` --- Short animation with graphics that plays in various situation. - --- Metatable of `Effect` --- nils initialized in constructor -Effect = { - x = 0, - y = 0, - delay = 0.06, - initial = nil, - frame = 1, - animation = nil, - sprite = nil, - quads = require "effects" -} - --- Construct of `Effect` -function Effect:new(name, x, y) - -- Meta - local o = {} - setmetatable(o, self) - self.__index = self - -- Load spritesheet to metatable if not yet loaded - if self.sprite == nil then - self.sprite = love.graphics.newImage("assets/effects.png") - end - -- Init - o.initial = o.delay - o.animation = name - o.x = x or self.x - o.y = y or self.y - return o -end - --- Position -function Effect:getPosition() - return self.x, self.y -end - --- Animation and return flag for deletion after completion --- returns true if completed and ready to delete -function Effect:update(dt) - self.delay = self.delay - dt - if self.delay < 0 then - if self.frame < self.quads[self.animation].frames then - self.frame = self.frame + 1 - self.delay = self.delay + self.initial - else - return true -- delete - end - end - return false -end - --- Draw me with scale and offsets, senpai -function Effect:draw(offset_x, offset_y, scale) - -- locals - local offset_x = offset_x or 0 - local offset_y = offset_y or 0 - local scale = scale or 1 - 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 - -- draw - love.graphics.setColor(255,255,255,255) - love.graphics.draw(self.sprite, self.quads[self.animation][self.frame], draw_x, draw_y, 0, scale, scale) -end \ No newline at end of file diff --git a/main.lua b/main.lua index deff1a1..bbcf0e0 100644 --- a/main.lua +++ b/main.lua @@ -34,7 +34,7 @@ function newImage(path) end -- Require -require "world" +require "not.World" require "camera" require "menu" require "controller" diff --git a/not/Cloud.lua b/not/Cloud.lua new file mode 100644 index 0000000..c12e236 --- /dev/null +++ b/not/Cloud.lua @@ -0,0 +1,63 @@ +-- `Cloud` +-- That white thing moving in the background. + +-- WHOLE CODE HAS FLAG OF "need a cleanup" + +-- Metatable of `Cloud` +-- nils initialized in constructor +Cloud = { + x = 0, -- position horizontal + y = 0, -- position vertical + t = 1, -- type (sprite number) + v = 13, -- velocity + sprite = nil, + quads = { + [1] = love.graphics.newQuad( 1, 1, 158,47, 478,49), + [2] = love.graphics.newQuad(160, 1, 158,47, 478,49), + [3] = love.graphics.newQuad(319, 1, 158,47, 478,49) + } +} + +-- Constructor of `Cloud` +function Cloud:new(x, y, t, v) + -- Meta + local o = {} + setmetatable(o, self) + self.__index = self + -- Load spritesheet to metatable if not yet loaded + if self.sprite == nil then + self.sprite = love.graphics.newImage("assets/clouds.png") + end + -- Init + o.x = x or self.x + o.y = y or self.y + o.t = t or self.t + o.v = v or self.v + return o +end + +-- Position +function Cloud:getPosition() + return self.x, self.y +end + +-- Update of `Cloud`, returns x for world to delete cloud after reaching right corner +function Cloud:update(dt) + self.x = self.x + self.v*dt + return self.x +end + +-- Draw `Cloud` +function Cloud:draw(offset_x, offset_y, scale) + -- locals + local offset_x = offset_x or 0 + local offset_y = offset_y or 0 + local scale = scale or 1 + 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 + -- draw + love.graphics.setColor(255,255,255,255) + love.graphics.draw(self.sprite, self.quads[self.t], draw_x, draw_y, 0, scale, scale) +end \ No newline at end of file diff --git a/not/Decoration.lua b/not/Decoration.lua new file mode 100644 index 0000000..7f020e1 --- /dev/null +++ b/not/Decoration.lua @@ -0,0 +1,34 @@ +require "not.Sprite" +Decoration = { + world = nil, + sprite = nil, + x = 0, + y = 0 +} +Decoration.__index = Decoration +setmetatable(Decoration, Sprite) +function Decoration:new(x, y, sprite) + local o = {} + setmetatable(o, self) + o:setImage(love.graphics.newImage(sprite)) + o:setPosition(x,y) + return o +end +function Decoration:setPosition(x, y) + self.x, self.y = x, y +end +function Decoration:getPosition() + return self.x, self.y +end +function Decoration:draw(offset_x, offset_y, scale) + -- locals + local offset_x = offset_x or 0 + local offset_y = offset_y or 0 + local scale = scale or 1 + 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 + -- draw + Sprite.draw(self, draw_x, draw_y, 0, scale, scale) +end \ No newline at end of file diff --git a/not/Effect.lua b/not/Effect.lua new file mode 100644 index 0000000..4e327a1 --- /dev/null +++ b/not/Effect.lua @@ -0,0 +1,68 @@ +-- `Effect` +-- Short animation with graphics that plays in various situation. + +-- Metatable of `Effect` +-- nils initialized in constructor +Effect = { + x = 0, + y = 0, + delay = 0.06, + initial = nil, + frame = 1, + animation = nil, + sprite = nil, + quads = require "effects" +} + +-- Construct of `Effect` +function Effect:new(name, x, y) + -- Meta + local o = {} + setmetatable(o, self) + self.__index = self + -- Load spritesheet to metatable if not yet loaded + if self.sprite == nil then + self.sprite = love.graphics.newImage("assets/effects.png") + end + -- Init + o.initial = o.delay + o.animation = name + o.x = x or self.x + o.y = y or self.y + return o +end + +-- Position +function Effect:getPosition() + return self.x, self.y +end + +-- Animation and return flag for deletion after completion +-- returns true if completed and ready to delete +function Effect:update(dt) + self.delay = self.delay - dt + if self.delay < 0 then + if self.frame < self.quads[self.animation].frames then + self.frame = self.frame + 1 + self.delay = self.delay + self.initial + else + return true -- delete + end + end + return false +end + +-- Draw me with scale and offsets, senpai +function Effect:draw(offset_x, offset_y, scale) + -- locals + local offset_x = offset_x or 0 + local offset_y = offset_y or 0 + local scale = scale or 1 + 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 + -- draw + love.graphics.setColor(255,255,255,255) + love.graphics.draw(self.sprite, self.quads[self.animation][self.frame], draw_x, draw_y, 0, scale, scale) +end \ No newline at end of file diff --git a/not/Hero.lua b/not/Hero.lua new file mode 100644 index 0000000..7ddc724 --- /dev/null +++ b/not/Hero.lua @@ -0,0 +1,449 @@ +-- `Hero` +-- Entity controlled by a player. It has a physical body and a sprite. Can play animations and interact with other instances of the same class. +-- Collision category: [2] + +-- WHOLE CODE HAS FLAG OF "need a cleanup" +require "not.Sprite" + +-- Metatable of `Hero` +-- nils initialized in constructor +Hero = { + -- General and physics + name = "empty", + body = nil, + shape = nil, + fixture = nil, + sprite = nil, + rotate = 0, -- "angle" would sound better + facing = 1, + max_velocity = 105, + world = nil, -- game world + -- Combat + combo = 0, + lives = 3, + spawntimer = 2, + alive = true, + punchcd = 0.25, + punchdir = 0, -- a really bad thing + -- Movement + inAir = true, + salto = false, + jumpactive = false, + jumpdouble = true, + jumptimer = 0.16, + jumpnumber = 2, + -- Keys + controlset = nil, + -- HUD + portrait_sprite = nil, + portrait_frame = nil, + portrait_sheet = require "nautsicons", + portrait_box = love.graphics.newQuad( 0, 15, 32,32, 80,130), + -- Sounds + sfx = require "sounds", + -- Animations table + animations = require "animations" +} +Hero.__index = Hero +setmetatable(Hero, Sprite) + +-- Constructor of `Hero` +function Hero:new (game, world, x, y, name) + -- Meta + local o = {} + setmetatable(o, self) + -- Physics + local group = -1-#game.Nauts + o.body = love.physics.newBody(world, x, y, "dynamic") + o.shape = love.physics.newRectangleShape(10, 16) + o.fixture = love.physics.newFixture(o.body, o.shape, 8) + o.fixture:setUserData(o) + o.fixture:setCategory(2) + o.fixture:setMask(2) + o.fixture:setGroupIndex(group) + o.body:setFixedRotation(true) + -- Misc + o.name = name or "empty" + o:setImage(newImage("assets/nauts/"..o.name..".png")) + o.world = game + o.punchcd = 0 + -- Animation + o.current = o.animations.default + o:createEffect("respawn") + -- Portrait load for first object created + if self.portrait_sprite == nil then + self.portrait_sprite = love.graphics.newImage("assets/portraits.png") + self.portrait_frame = love.graphics.newImage("assets/menu.png") + end + return o +end + +-- Control set managment +function Hero:assignControlSet(set) + self.controlset = set +end +function Hero:getControlSet() + return self.controlset +end + +-- Update callback of `Hero` +function Hero:update(dt) + -- hotfix? for destroyed bodies + if self.body:isDestroyed() then return end + -- locals + local x, y = self.body:getLinearVelocity() + local isDown = Controller.isDown + local controlset = self:getControlSet() + + -- # VERTICAL MOVEMENT + -- Jumping + if self.jumpactive and self.jumptimer > 0 then + self.body:setLinearVelocity(x,-160) + self.jumptimer = self.jumptimer - dt + end + + -- Salto + if self.salto and (self.current == self.animations.walk or self.current == self.animations.default) then + self.rotate = (self.rotate + 17 * dt * self.facing) % 360 + elseif self.rotate ~= 0 then + self.rotate = 0 + end + + -- # HORIZONTAL MOVEMENT + -- Walking + if isDown(controlset, "left") then + self.facing = -1 + self.body:applyForce(-250, 0) + -- Controlled speed limit + if x < -self.max_velocity then + self.body:applyForce(250, 0) + end + end + if isDown(controlset, "right") then + self.facing = 1 + self.body:applyForce(250, 0) + -- Controlled speed limit + if x > self.max_velocity then + self.body:applyForce(-250, 0) + end + end + + -- Custom linear damping + if not isDown(controlset, "left") and + not isDown(controlset, "right") + then + local face = nil + if x < -12 then + face = 1 + elseif x > 12 then + face = -1 + else + face = 0 + end + self.body:applyForce(40*face,0) + if not self.inAir then + self.body:applyForce(80*face,0) + end + end + + Sprite.update(self, dt) + + -- # DEATH + -- We all die in the end. + local m = self.world.map + if (self.body:getX() < m.center_x - m.width*1.5 or self.body:getX() > m.center_x + m.width*1.5 or + self.body:getY() < m.center_y - m.height*1.5 or self.body:getY() > m.center_y + m.height*1.5) and + self.alive + then + self:die() + end + + -- respawn + if self.spawntimer > 0 then + self.spawntimer = self.spawntimer - dt + end + if self.spawntimer <= 0 and not self.alive and self.lives >= 0 then + self:respawn() + end + + -- # PUNCH + -- Cooldown + self.punchcd = self.punchcd - dt + if not self.body:isDestroyed() then -- This is weird + for _,fixture in pairs(self.body:getFixtureList()) do + if fixture:getUserData() ~= self then + fixture:setUserData({fixture:getUserData()[1] - dt, fixture:getUserData()[2]}) + if fixture:getUserData()[1] < 0 then + fixture:destroy() + end + end + end + end + + -- Stop vertical + 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(38*self.facing,0) + end + end + + if self.punchcd <= 0 and self.punchdir == 1 then + self.punchdir = 0 + end +end + +-- Controller callbacks +function Hero:controlpressed(set, action, key) + if set ~= self:getControlSet() then return end + local isDown = Controller.isDown + local controlset = self:getControlSet() + -- Jumping + if action == "jump" then + if self.jumpnumber > 0 then + -- General jump logics + self.jumpactive = true + --self:playSound(6) + -- Spawn proper effect + if not self.inAir then + self:createEffect("jump") + else + self:createEffect("doublejump") + end + -- Start salto if last jump + if self.jumpnumber == 1 then + self.salto = true + end + -- Animation clear + if (self.current == self.animations.attack) or + (self.current == self.animations.attack_up) or + (self.current == self.animations.attack_down) then + self:setAnimation("default") + end + -- Remove jump + self.jumpnumber = self.jumpnumber - 1 + end + end + + -- Walking + if (action == "left" or action == "right") and + (self.current ~= self.animations.attack) and + (self.current ~= self.animations.attack_up) and + (self.current ~= self.animations.attack_down) then + self:setAnimation("walk") + end + + -- Punching + if action == "attack" and self.punchcd <= 0 then + local f = self.facing + self.salto = false + if isDown(controlset, "up") then + -- Punch up + if self.current ~= self.animations.damage then + self:setAnimation("attack_up") + end + self:hit("up") + elseif isDown(controlset, "down") then + -- Punch down + if self.current ~= self.animations.damage then + self:setAnimation("attack_down") + end + self:hit("down") + else + -- Punch horizontal + if self.current ~= self.animations.damage then + self:setAnimation("attack") + end + if f == 1 then + self:hit("right") + else + self:hit("left") + end + self.punchdir = 1 + end + end +end +function Hero:controlreleased(set, action, key) + if set ~= self:getControlSet() then return end + local isDown = Controller.isDown + local controlset = self:getControlSet() + -- Jumping + if action == "jump" then + self.jumpactive = false + self.jumptimer = Hero.jumptimer -- take initial from metatable + end + -- Walking + if (action == "left" or action == "right") and not + (isDown(controlset, "left") or isDown(controlset, "right")) and + self.current == self.animations.walk + then + self:setAnimation("default") + end +end + +-- Draw of `Hero` +function Hero:draw(offset_x, offset_y, scale, debug) + -- draw only alive + if not self.alive then return end + -- 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 ; `approx` selected to prevent floating characters on certain conditions + local approx = math.floor + if (y - math.floor(y)) > 0.5 then approx = math.ceil end + local draw_y = (approx(y) + offset_y) * scale + local draw_x = (math.floor(x) + offset_x) * scale + -- sprite draw + Sprite.draw(self, draw_x, draw_y, self.rotate, self.facing*scale, scale, 12, 15) + -- debug draw + if debug then + for _,fixture in pairs(self.body:getFixtureList()) do + if fixture:getCategory() == 2 then + love.graphics.setColor(137, 255, 0, 120) + else + love.graphics.setColor(137, 0, 255, 40) + end + love.graphics.polygon("fill", self.world.camera:translatePoints(self.body:getWorldPoints(fixture:getShape():getPoints()))) + end + for _,contact in pairs(self.body:getContactList()) do + love.graphics.setColor(255, 0, 0, 255) + love.graphics.setPointSize(scale) + love.graphics.points(self.world.camera:translatePoints(contact:getPositions())) + end + end +end + +-- getPosition +function Hero:getPosition() + return self.body:getPosition() +end + +-- Draw HUD of `Hero` +-- elevation: 1 bottom, 0 top +function Hero:drawHUD(x,y,scale,elevation) + -- hud displays only if player is alive + if self.alive then + love.graphics.setColor(255,255,255,255) + love.graphics.draw(self.portrait_frame, self.portrait_box, (x)*scale, (y)*scale, 0, scale, scale) + love.graphics.draw(self.portrait_sprite, self.portrait_sheet[self.name], (x+2)*scale, (y+3)*scale, 0, scale, scale) + local dy = 30 * elevation + love.graphics.setFont(Font) + love.graphics.print((self.combo*10).."%",(x+2)*scale,(y-3+dy)*scale,0,scale,scale) + love.graphics.print(math.max(0, self.lives),(x+24)*scale,(y-3+dy)*scale,0,scale,scale) + end +end + +-- Change animation of `Hero` +-- default, walk, attack, attack_up, attack_down, damage +function Hero:nextFrame() + local isDown = Controller.isDown + local controlset = self:getControlSet() + if self.current.repeated or not (self.frame == self.current.frames) then + self.frame = (self.frame % self.current.frames) + 1 + elseif isDown(controlset, "right") or isDown(controlset, "left") then + -- If nonrepeatable animation is finished and player is walking + self:setAnimation("walk") + elseif self.current == self.animations.damage then + self:setAnimation("default") + end +end + +-- Spawn `Effect` relative to `Hero` +function Hero:createEffect(name) + if name == "trail" or name == "hit" then + -- 16px effect: -7 -7 + self.world:createEffect(name, self.body:getX()-8, self.body:getY()-8) + elseif name ~= nil then + -- 24px effect: -12 -15 + self.world:createEffect(name, self.body:getX()-12, self.body:getY()-15) + end +end + +-- Punch of `Hero` +-- direction: left, right, up, down +-- creates temporary fixture for player's body that acts as sensor; fixture is deleted after time set in UserData[1]; deleted by Hero:update(dt) +function Hero:hit(direction) + -- start cooldown + self.punchcd = Hero.punchcd -- INITIAL from metatable + -- actual punch + local fixture + if direction == "left" then + fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(-2,-6, -20,-6, -20,6, -2,6), 0) + end + if direction == "right" then + fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(2,-6, 20,-6, 20,6, 2,6), 0) + end + if direction == "up" then + fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(-8,-4, -8,-20, 8,-20, 8,-4), 0) + end + if direction == "down" then + fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(-8,4, -8,20, 8,20, 8,4), 0) + end + fixture:setSensor(true) + fixture:setCategory(3) + fixture:setMask(1,3) + fixture:setGroupIndex(self.fixture:getGroupIndex()) + fixture:setUserData({0.08, direction}) + -- sound + self:playSound(4) +end + +-- Taking damage of `Hero` by successful hit test +-- currently called from World's startContact +function Hero:damage(direction) + local horizontal, vertical = 0, 0 + if direction == "left" then + horizontal = -1 + end + if direction == "right" then + horizontal = 1 + end + if direction == "up" then + vertical = -1 + end + if direction == "down" then + vertical = 1 + end + self:createEffect("hit") + local x,y = self.body:getLinearVelocity() + self.body:setLinearVelocity(x,0) + self.body:applyLinearImpulse((42+10*self.combo)*horizontal, (68+10*self.combo)*vertical + 15) + self:setAnimation("damage") + self.combo = math.min(27, self.combo + 1) + self.punchcd = 0.08 + self.combo*0.006 + self:playSound(2) +end + +-- DIE +function Hero:die() + self:playSound(1) + self.combo = Hero.combo -- INITIAL from metatable + self.lives = self.lives - 1 + self.alive = false + self.spawntimer = Hero.spawntimer -- INITIAL from metatable + self.body:setActive(false) + self.world:onNautKilled(self) +end + +-- And then respawn. Like Jon Snow. +function Hero:respawn() + self.alive = true + self.body:setLinearVelocity(0,0) + self.body:setPosition(self.world:getSpawnPosition()) + self.body:setActive(true) + self:createEffect("respawn") + self:playSound(7) +end + +-- Sounds +function Hero:playSound(sfx, force) + if self.alive or force then + local source = love.audio.newSource(self.sfx[sfx]) + source:play() + end +end diff --git a/not/Platform.lua b/not/Platform.lua new file mode 100644 index 0000000..9b7b03c --- /dev/null +++ b/not/Platform.lua @@ -0,0 +1,73 @@ +-- `Platform` +-- Static platform physical object with a sprite. `Players` can walk on it. +-- Collision category: [1] + +-- WHOLE CODE HAS FLAG OF "need a cleanup" +require "not.Sprite" + +-- Metatable of `Platform` +-- nils initialized in constructor +Platform = { + body = nil, + shape = nil, + fixture = nil, + world = nil, +} +Platform.__index = Platform +setmetatable(Platform, Sprite) + +-- Constructor of `Platform` +function Platform: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:setImage(love.graphics.newImage(sprite)) + o:setAnimationsList(animations) + o.world = game + return o +end + +-- Position +function Platform:getPosition() + return self.body:getPosition() +end + +-- Draw of `Platform` +function Platform: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 + Sprite.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 diff --git a/not/Sprite.lua b/not/Sprite.lua new file mode 100644 index 0000000..1cc46f7 --- /dev/null +++ b/not/Sprite.lua @@ -0,0 +1,81 @@ +-- `Sprite` +-- Abstract class for drawable animated entities. + +-- Metatable +Sprite = { + animations--[[table with animations]], + current--[[animations.default]], + image--[[love.graphics.newImage()]], + frame = 1, + delay = .1, +} +Sprite.__index = Sprite + +-- Cleans up reference to image on deletion. +function Sprite:delete() + self.image = nil +end + +-- Sets an Image as a image. +function Sprite:setImage(image) + self.image = image +end +-- Returns current image Image. +function Sprite:getImage() + return self.image +end + +-- Sets new animations list. +function Sprite:setAnimationsList(t) + if t then + self.animations = t + self:setAnimation("default") + end +end + +-- Sets current animation by table key. +function Sprite:setAnimation(animation) + self.frame = 1 + self.delay = Sprite.delay -- INITIAL from metatable + self.current = self.animations[animation] +end +-- Returns current animation table. +function Sprite:getAnimation() + return self.current +end + +-- Get frame quad for drawing. +function Sprite:getQuad() + if self.animations and self.current then + return self.current[self.frame] + end +end + +-- Drawing self to LOVE2D buffer. +-- If there is no Quad, it will draw entire image. +function Sprite:draw(...) + local s, q = self:getImage(), self:getQuad() + if s then + love.graphics.setColor(255,255,255,255) + if q then love.graphics.draw(s, q, ...) + else love.graphics.draw(s, ...) end + end +end +-- Animation updating. +function Sprite:update(dt) + if self.animations and self.current then + self.delay = self.delay - dt + if self.delay < 0 then + self.delay = self.delay + Sprite.delay -- INITIAL from metatable + self:nextFrame() + end + end +end +-- Moving to the next frame. +function Sprite:nextFrame() + if self.current.repeated or not (self.frame == self.current.frames) then + self.frame = (self.frame % self.current.frames) + 1 + else + self:setAnimation("default") + end +end \ No newline at end of file diff --git a/not/World.lua b/not/World.lua new file mode 100644 index 0000000..5afc5bf --- /dev/null +++ b/not/World.lua @@ -0,0 +1,424 @@ +-- `World` +-- Used to manage physical world and everything inside it: clouds, platforms, nauts, background etc. + +-- WHOLE CODE HAS FLAG OF "need a cleanup" + +require "not.Platform" +require "not.Hero" +require "not.Cloud" +require "not.Effect" +require "not.Decoration" +require "ray" + +-- Metatable of `World` +-- nils initialized in constructor +World = { + -- inside + world = nil, + Nauts = nil, + Platforms = nil, + Clouds = nil, + Decorations = nil, + Effects = nil, + Rays = nil, + camera = nil, + -- cloud generator + clouds_delay = 5, + -- Map + map = nil, + background = nil, + -- Gameplay status + lastNaut = false, + -- "WINNER" + win_move = 0, + -- Music + music = nil +} + +-- Constructor of `World` ZA WARUDO! +function World:new(map, nauts) + -- Meta + local o = {} + setmetatable(o, self) + self.__index = self + -- Physical world initialization + love.physics.setMeter(64) + o.world = love.physics.newWorld(0, 9.81*64, true) + o.world:setCallbacks(o.beginContact, o.endContact) + -- Empty tables for objects + local n = {} + o.Nauts = n + local p = {} + o.Platforms = {} + local c = {} + o.Clouds = c + local e = {} + o.Effects = e + local d = {} + o.Decorations = d + local r = {} + o.Rays = r + -- Random init + math.randomseed(os.time()) + -- Map + local map = map or "default" + o:loadMap(map) + -- Nauts + o:spawnNauts(nauts) + -- Create camera + o.camera = Camera:new(o) + -- Play music + o.music = Music:new(o.map.theme) + return o +end + +-- The end of the world +function World:delete() + self.world:destroy() + for _,platform in pairs(self.Platforms) do + platform:delete() + end + for _,naut in pairs(self.Nauts) do + naut:delete() + end + self.music:delete() + self = nil +end + +-- Load map from file +function World:loadMap(name) + local name = name or "default" + name = "maps/" .. name .. ".lua" + local map = love.filesystem.load(name) + self.map = map() + -- Platforms + for _,platform in pairs(self.map.platforms) do + self:createPlatform(platform.x, platform.y, platform.shape, platform.sprite, platform.animations) + end + -- Decorations + for _,decoration in pairs(self.map.decorations) do + self:createDecoration(decoration.x, decoration.y, decoration.sprite) + end + -- Background + self.background = love.graphics.newImage(self.map.background) + -- Clouds + if self.map.clouds then + for i=1,6 do + self:randomizeCloud(false) + end + end +end + +-- Spawn all the nauts for the round +function World:spawnNauts(nauts) + for _,naut in pairs(nauts) do + local x,y = self:getSpawnPosition() + local spawn = self:createNaut(x, y, naut[1]) + spawn:assignControlSet(naut[2]) + end +end + +-- Get respawn location +function World:getSpawnPosition() + local n = math.random(1, #self.map.respawns) + return self.map.respawns[n].x, self.map.respawns[n].y +end + +-- Add new platform to the world +function World:createPlatform(x, y, polygon, sprite, animations) + table.insert(self.Platforms, Platform:new(self, self.world, x, y, polygon, sprite, animations)) +end + +-- Add new naut to the world +function World:createNaut(x, y, name) + local naut = Hero:new(self, self.world, x, y, name) + table.insert(self.Nauts, naut) + return naut +end + +-- Add new decoration to the world +function World:createDecoration(x, y, sprite) + table.insert(self.Decorations, Decoration:new(x, y, sprite)) +end + +-- Add new cloud to the world +function World:createCloud(x, y, t, v) + table.insert(self.Clouds, Cloud:new(x, y, t, v)) +end + +-- Randomize Cloud creation +function World:randomizeCloud(outside) + if outside == nil then + outside = true + else + outside = outside + end + local x,y,t,v + local m = self.map + if outside then + x = m.center_x-m.width*1.2+math.random(-50,20) + else + x = math.random(m.center_x-m.width/2,m.center_x+m.width/2) + end + y = math.random(m.center_y-m.height/2, m.center_y+m.height/2) + t = math.random(1,3) + v = math.random(8,18) + self:createCloud(x, y, t, v) +end + +-- Add an effect behind nauts +function World:createEffect(name, x, y) + table.insert(self.Effects, Effect:new(name, x, y)) +end + +-- Add a ray +function World:createRay(naut) + table.insert(self.Rays, Ray:new(naut, self)) +end + +-- get Nauts functions +-- more than -1 lives +function World:getNautsPlayable() + local nauts = {} + for _,naut in pairs(self.Nauts) do + if naut.lives > -1 then + table.insert(nauts, naut) + end + end + return nauts +end +-- are alive +function World:getNautsAlive() + local nauts = {} + for _,naut in self.Nauts do + if naut.alive then + table.insert(nauts, naut) + end + end + return nauts +end +-- all of them +function World:getNautsAll() + return self.Nauts +end + +-- get Map name +function World:getMapName() + return self.map.name +end + +-- Event: when player is killed +function World:onNautKilled(naut) + self.camera:startShake() + self:createRay(naut) + local nauts = self:getNautsPlayable() + if self.lastNaut then + changeScene(Menu:new()) + elseif #nauts < 2 then + self.lastNaut = true + naut:playSound(5, true) + end +end + +function World:getBounce(f) + local f = f or 1 + return math.sin(self.win_move*f*math.pi) +end + +-- LÖVE2D callbacks +-- Update ZU WARUDO +function World:update(dt) + -- Physical world + self.world:update(dt) + -- Camera + self.camera:update(dt) + -- Engine world: Nauts, Grounds (kek) and Decorations - all Animateds (top kek) + for _,naut in pairs(self.Nauts) do + naut:update(dt) + end + for _,platform in pairs(self.Platforms) do + platform:update(dt) + end + for _,decoration in pairs(self.Decorations) do + decoration:update(dt) + end + -- Clouds + if self.map.clouds then + -- generator + local n = table.getn(self.Clouds) + self.clouds_delay = self.clouds_delay - dt + if self.clouds_delay < 0 and + n < 18 + then + self:randomizeCloud() + self.clouds_delay = self.clouds_delay + World.clouds_delay -- World.clouds_delay is initial + end + -- movement + for _,cloud in pairs(self.Clouds) do + if cloud:update(dt) > 340 then + table.remove(self.Clouds, _) + end + end + end + -- Effects + for _,effect in pairs(self.Effects) do + if effect:update(dt) then + table.remove(self.Effects, _) + end + end + -- Rays + for _,ray in pairs(self.Rays) do + if ray:update(dt) then + table.remove(self.Rays, _) + end + end + -- Bounce `winner` + self.win_move = self.win_move + dt + if self.win_move > 2 then + self.win_move = self.win_move - 2 + end +end +-- Draw +function World:draw() + -- Camera stuff + local offset_x, offset_y = self.camera:getOffsets() + local scale = self.camera.scale + local scaler = self.camera.scaler + + -- Background + love.graphics.draw(self.background, 0, 0, 0, scaler, scaler) + + -- This needs to be reworked! + -- Draw clouds + for _,cloud in pairs(self.Clouds) do + cloud:draw(offset_x, offset_y, scale) + end + + -- Draw decorations + for _,decoration in pairs(self.Decorations) do + decoration:draw(offset_x, offset_y, scale) + end + + -- Draw effects + for _,effect in pairs(self.Effects) do + effect:draw(offset_x,offset_y, scale) + end + + -- Draw player + for _,naut in pairs(self.Nauts) do + naut:draw(offset_x, offset_y, scale, debug) + end + + -- Draw ground + for _,platform in pairs(self.Platforms) do + platform:draw(offset_x, offset_y, scale, debug) + end + + -- Draw rays + for _,ray in pairs(self.Rays) do + ray:draw(offset_x, offset_y, scale) + end + + -- draw center + if debug then + local c = self.camera + local w, h = love.graphics.getWidth(), love.graphics.getHeight() + -- draw map center + love.graphics.setColor(130,130,130) + love.graphics.setLineWidth(1) + love.graphics.setLineStyle("rough") + local cx, cy = c:getPositionScaled() + local x1, y1 = c:translatePosition(self.map.center_x, cy) + local x2, y2 = c:translatePosition(self.map.center_x, cy+h) + love.graphics.line(x1,y1,x2,y2) + local x1, y1 = c:translatePosition(cx, self.map.center_y) + local x2, y2 = c:translatePosition(cx+w, self.map.center_y) + love.graphics.line(x1,y1,x2,y2) + -- draw ox, oy + love.graphics.setColor(200,200,200) + love.graphics.setLineStyle("rough") + local cx, cy = c:getPositionScaled() + local x1, y1 = c:translatePosition(0, cy) + local x2, y2 = c:translatePosition(0, cy+h) + love.graphics.line(x1,y1,x2,y2) + local x1, y1 = c:translatePosition(cx, 0) + local x2, y2 = c:translatePosition(cx+w, 0) + love.graphics.line(x1,y1,x2,y2) + end + + -- Draw HUDs + for _,naut in pairs(self.Nauts) do + -- I have no idea where to place them T_T + -- let's do: bottom-left, bottom-right, top-left, top-right + local w, h = love.graphics.getWidth()/scale, love.graphics.getHeight()/scale + local y, e = 1, 1 + if _ < 3 then y, e = h-33, 0 end + naut:drawHUD(1+(_%2)*(w-34), y, scale, e) + end + + -- Draw winner + if self.lastNaut then + local w, h = love.graphics.getWidth()/scale, love.graphics.getHeight()/scale + local angle = self:getBounce(2) + local dy = self:getBounce()*3 + love.graphics.setFont(Bold) + love.graphics.printf("WINNER",(w/2)*scale,(42+dy)*scale,336,"center",(angle*5)*math.pi/180,scale,scale,168,12) + love.graphics.setFont(Font) + love.graphics.printf("rofl, now kill yourself", w/2*scale, 18*scale, 160, "center", 0, scale, scale, 80, 3) + end +end + +-- Box2D callbacks +-- beginContact +function World.beginContact(a, b, coll) + if a:getCategory() == 1 then + local x,y = coll:getNormal() + if y < -0.6 then + print(b:getUserData().name .. " is not in air") + -- Move them to Hero + b:getUserData().inAir = false + b:getUserData().jumpnumber = 2 + b:getUserData().salto = false + b:getUserData():createEffect("land") + end + local vx, vy = b:getUserData().body:getLinearVelocity() + if math.abs(x) == 1 or (y < -0.6 and x == 0) then + b:getUserData():playSound(3) + end + end + if a:getCategory() == 3 then + b:getUserData():damage(a:getUserData()[2]) + end + if b:getCategory() == 3 then + a:getUserData():damage(b:getUserData()[2]) + end +end +-- endContact +function World.endContact(a, b, coll) + if a:getCategory() == 1 then + print(b:getUserData().name .. " is in air") + -- Move them to Hero + b:getUserData().inAir = true + end +end + +-- Controller callbacks +function World:controlpressed(set, action, key) + if key == "f6" and debug then + local map = self:getMapName() + local nauts = {} + for _,naut in pairs(self:getNautsAll()) do + table.insert(nauts, {naut.name, naut:getControlSet()}) + end + local new = World:new(map, nauts) + changeScene(new) + end + for k,naut in pairs(self:getNautsAll()) do + naut:controlpressed(set, action, key) + end +end +function World:controlreleased(set, action, key) + for k,naut in pairs(self:getNautsAll()) do + naut:controlreleased(set, action, key) + end +end \ No newline at end of file diff --git a/platform.lua b/platform.lua deleted file mode 100644 index 9d75e66..0000000 --- a/platform.lua +++ /dev/null @@ -1,73 +0,0 @@ --- `Platform` --- Static platform physical object with a sprite. `Players` can walk on it. --- Collision category: [1] - --- WHOLE CODE HAS FLAG OF "need a cleanup" -require "sprite" - --- Metatable of `Platform` --- nils initialized in constructor -Platform = { - body = nil, - shape = nil, - fixture = nil, - world = nil, -} -Platform.__index = Platform -setmetatable(Platform, Sprite) - --- Constructor of `Platform` -function Platform: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:setImage(love.graphics.newImage(sprite)) - o:setAnimationsList(animations) - o.world = game - return o -end - --- Position -function Platform:getPosition() - return self.body:getPosition() -end - --- Draw of `Platform` -function Platform: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 - Sprite.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 diff --git a/player.lua b/player.lua deleted file mode 100644 index a5b4bd2..0000000 --- a/player.lua +++ /dev/null @@ -1,449 +0,0 @@ --- `Player` --- Entity controlled by a player. It has a physical body and a sprite. Can play animations and interact with other instances of the same class. --- Collision category: [2] - --- WHOLE CODE HAS FLAG OF "need a cleanup" -require "sprite" - --- Metatable of `Player` --- nils initialized in constructor -Player = { - -- General and physics - name = "empty", - body = nil, - shape = nil, - fixture = nil, - sprite = nil, - rotate = 0, -- "angle" would sound better - facing = 1, - max_velocity = 105, - world = nil, -- game world - -- Combat - combo = 0, - lives = 3, - spawntimer = 2, - alive = true, - punchcd = 0.25, - punchdir = 0, -- a really bad thing - -- Movement - inAir = true, - salto = false, - jumpactive = false, - jumpdouble = true, - jumptimer = 0.16, - jumpnumber = 2, - -- Keys - controlset = nil, - -- HUD - portrait_sprite = nil, - portrait_frame = nil, - portrait_sheet = require "nautsicons", - portrait_box = love.graphics.newQuad( 0, 15, 32,32, 80,130), - -- Sounds - sfx = require "sounds", - -- Animations table - animations = require "animations" -} -Player.__index = Player -setmetatable(Player, Sprite) - --- Constructor of `Player` -function Player:new (game, world, x, y, name) - -- Meta - local o = {} - setmetatable(o, self) - -- Physics - local group = -1-#game.Nauts - o.body = love.physics.newBody(world, x, y, "dynamic") - o.shape = love.physics.newRectangleShape(10, 16) - o.fixture = love.physics.newFixture(o.body, o.shape, 8) - o.fixture:setUserData(o) - o.fixture:setCategory(2) - o.fixture:setMask(2) - o.fixture:setGroupIndex(group) - o.body:setFixedRotation(true) - -- Misc - o.name = name or "empty" - o:setImage(newImage("assets/nauts/"..o.name..".png")) - o.world = game - o.punchcd = 0 - -- Animation - o.current = o.animations.default - o:createEffect("respawn") - -- Portrait load for first object created - if self.portrait_sprite == nil then - self.portrait_sprite = love.graphics.newImage("assets/portraits.png") - self.portrait_frame = love.graphics.newImage("assets/menu.png") - end - return o -end - --- Control set managment -function Player:assignControlSet(set) - self.controlset = set -end -function Player:getControlSet() - return self.controlset -end - --- Update callback of `Player` -function Player:update(dt) - -- hotfix? for destroyed bodies - if self.body:isDestroyed() then return end - -- locals - local x, y = self.body:getLinearVelocity() - local isDown = Controller.isDown - local controlset = self:getControlSet() - - -- # VERTICAL MOVEMENT - -- Jumping - if self.jumpactive and self.jumptimer > 0 then - self.body:setLinearVelocity(x,-160) - self.jumptimer = self.jumptimer - dt - end - - -- Salto - if self.salto and (self.current == self.animations.walk or self.current == self.animations.default) then - self.rotate = (self.rotate + 17 * dt * self.facing) % 360 - elseif self.rotate ~= 0 then - self.rotate = 0 - end - - -- # HORIZONTAL MOVEMENT - -- Walking - if isDown(controlset, "left") then - self.facing = -1 - self.body:applyForce(-250, 0) - -- Controlled speed limit - if x < -self.max_velocity then - self.body:applyForce(250, 0) - end - end - if isDown(controlset, "right") then - self.facing = 1 - self.body:applyForce(250, 0) - -- Controlled speed limit - if x > self.max_velocity then - self.body:applyForce(-250, 0) - end - end - - -- Custom linear damping - if not isDown(controlset, "left") and - not isDown(controlset, "right") - then - local face = nil - if x < -12 then - face = 1 - elseif x > 12 then - face = -1 - else - face = 0 - end - self.body:applyForce(40*face,0) - if not self.inAir then - self.body:applyForce(80*face,0) - end - end - - Sprite.update(self, dt) - - -- # DEATH - -- We all die in the end. - local m = self.world.map - if (self.body:getX() < m.center_x - m.width*1.5 or self.body:getX() > m.center_x + m.width*1.5 or - self.body:getY() < m.center_y - m.height*1.5 or self.body:getY() > m.center_y + m.height*1.5) and - self.alive - then - self:die() - end - - -- respawn - if self.spawntimer > 0 then - self.spawntimer = self.spawntimer - dt - end - if self.spawntimer <= 0 and not self.alive and self.lives >= 0 then - self:respawn() - end - - -- # PUNCH - -- Cooldown - self.punchcd = self.punchcd - dt - if not self.body:isDestroyed() then -- This is weird - for _,fixture in pairs(self.body:getFixtureList()) do - if fixture:getUserData() ~= self then - fixture:setUserData({fixture:getUserData()[1] - dt, fixture:getUserData()[2]}) - if fixture:getUserData()[1] < 0 then - fixture:destroy() - end - end - end - end - - -- Stop vertical - 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(38*self.facing,0) - end - end - - if self.punchcd <= 0 and self.punchdir == 1 then - self.punchdir = 0 - end -end - --- Controller callbacks -function Player:controlpressed(set, action, key) - if set ~= self:getControlSet() then return end - local isDown = Controller.isDown - local controlset = self:getControlSet() - -- Jumping - if action == "jump" then - if self.jumpnumber > 0 then - -- General jump logics - self.jumpactive = true - --self:playSound(6) - -- Spawn proper effect - if not self.inAir then - self:createEffect("jump") - else - self:createEffect("doublejump") - end - -- Start salto if last jump - if self.jumpnumber == 1 then - self.salto = true - end - -- Animation clear - if (self.current == self.animations.attack) or - (self.current == self.animations.attack_up) or - (self.current == self.animations.attack_down) then - self:setAnimation("default") - end - -- Remove jump - self.jumpnumber = self.jumpnumber - 1 - end - end - - -- Walking - if (action == "left" or action == "right") and - (self.current ~= self.animations.attack) and - (self.current ~= self.animations.attack_up) and - (self.current ~= self.animations.attack_down) then - self:setAnimation("walk") - end - - -- Punching - if action == "attack" and self.punchcd <= 0 then - local f = self.facing - self.salto = false - if isDown(controlset, "up") then - -- Punch up - if self.current ~= self.animations.damage then - self:setAnimation("attack_up") - end - self:hit("up") - elseif isDown(controlset, "down") then - -- Punch down - if self.current ~= self.animations.damage then - self:setAnimation("attack_down") - end - self:hit("down") - else - -- Punch horizontal - if self.current ~= self.animations.damage then - self:setAnimation("attack") - end - if f == 1 then - self:hit("right") - else - self:hit("left") - end - self.punchdir = 1 - end - end -end -function Player:controlreleased(set, action, key) - if set ~= self:getControlSet() then return end - local isDown = Controller.isDown - local controlset = self:getControlSet() - -- Jumping - if action == "jump" then - self.jumpactive = false - self.jumptimer = Player.jumptimer -- take initial from metatable - end - -- Walking - if (action == "left" or action == "right") and not - (isDown(controlset, "left") or isDown(controlset, "right")) and - self.current == self.animations.walk - then - self:setAnimation("default") - end -end - --- Draw of `Player` -function Player:draw(offset_x, offset_y, scale, debug) - -- draw only alive - if not self.alive then return end - -- 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 ; `approx` selected to prevent floating characters on certain conditions - local approx = math.floor - if (y - math.floor(y)) > 0.5 then approx = math.ceil end - local draw_y = (approx(y) + offset_y) * scale - local draw_x = (math.floor(x) + offset_x) * scale - -- sprite draw - Sprite.draw(self, draw_x, draw_y, self.rotate, self.facing*scale, scale, 12, 15) - -- debug draw - if debug then - for _,fixture in pairs(self.body:getFixtureList()) do - if fixture:getCategory() == 2 then - love.graphics.setColor(137, 255, 0, 120) - else - love.graphics.setColor(137, 0, 255, 40) - end - love.graphics.polygon("fill", self.world.camera:translatePoints(self.body:getWorldPoints(fixture:getShape():getPoints()))) - end - for _,contact in pairs(self.body:getContactList()) do - love.graphics.setColor(255, 0, 0, 255) - love.graphics.setPointSize(scale) - love.graphics.points(self.world.camera:translatePoints(contact:getPositions())) - end - end -end - --- getPosition -function Player:getPosition() - return self.body:getPosition() -end - --- Draw HUD of `Player` --- elevation: 1 bottom, 0 top -function Player:drawHUD(x,y,scale,elevation) - -- hud displays only if player is alive - if self.alive then - love.graphics.setColor(255,255,255,255) - love.graphics.draw(self.portrait_frame, self.portrait_box, (x)*scale, (y)*scale, 0, scale, scale) - love.graphics.draw(self.portrait_sprite, self.portrait_sheet[self.name], (x+2)*scale, (y+3)*scale, 0, scale, scale) - local dy = 30 * elevation - love.graphics.setFont(Font) - love.graphics.print((self.combo*10).."%",(x+2)*scale,(y-3+dy)*scale,0,scale,scale) - love.graphics.print(math.max(0, self.lives),(x+24)*scale,(y-3+dy)*scale,0,scale,scale) - end -end - --- Change animation of `Player` --- default, walk, attack, attack_up, attack_down, damage -function Player:nextFrame() - local isDown = Controller.isDown - local controlset = self:getControlSet() - if self.current.repeated or not (self.frame == self.current.frames) then - self.frame = (self.frame % self.current.frames) + 1 - elseif isDown(controlset, "right") or isDown(controlset, "left") then - -- If nonrepeatable animation is finished and player is walking - self:setAnimation("walk") - elseif self.current == self.animations.damage then - self:setAnimation("default") - end -end - --- Spawn `Effect` relative to `Player` -function Player:createEffect(name) - if name == "trail" or name == "hit" then - -- 16px effect: -7 -7 - self.world:createEffect(name, self.body:getX()-8, self.body:getY()-8) - elseif name ~= nil then - -- 24px effect: -12 -15 - self.world:createEffect(name, self.body:getX()-12, self.body:getY()-15) - end -end - --- Punch of `Player` --- direction: left, right, up, down --- creates temporary fixture for player's body that acts as sensor; fixture is deleted after time set in UserData[1]; deleted by Player:update(dt) -function Player:hit(direction) - -- start cooldown - self.punchcd = Player.punchcd -- INITIAL from metatable - -- actual punch - local fixture - if direction == "left" then - fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(-2,-6, -20,-6, -20,6, -2,6), 0) - end - if direction == "right" then - fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(2,-6, 20,-6, 20,6, 2,6), 0) - end - if direction == "up" then - fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(-8,-4, -8,-20, 8,-20, 8,-4), 0) - end - if direction == "down" then - fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(-8,4, -8,20, 8,20, 8,4), 0) - end - fixture:setSensor(true) - fixture:setCategory(3) - fixture:setMask(1,3) - fixture:setGroupIndex(self.fixture:getGroupIndex()) - fixture:setUserData({0.08, direction}) - -- sound - self:playSound(4) -end - --- Taking damage of `Player` by successful hit test --- currently called from World's startContact -function Player:damage(direction) - local horizontal, vertical = 0, 0 - if direction == "left" then - horizontal = -1 - end - if direction == "right" then - horizontal = 1 - end - if direction == "up" then - vertical = -1 - end - if direction == "down" then - vertical = 1 - end - self:createEffect("hit") - local x,y = self.body:getLinearVelocity() - self.body:setLinearVelocity(x,0) - self.body:applyLinearImpulse((42+10*self.combo)*horizontal, (68+10*self.combo)*vertical + 15) - self:setAnimation("damage") - self.combo = math.min(27, self.combo + 1) - self.punchcd = 0.08 + self.combo*0.006 - self:playSound(2) -end - --- DIE -function Player:die() - self:playSound(1) - self.combo = Player.combo -- INITIAL from metatable - self.lives = self.lives - 1 - self.alive = false - self.spawntimer = Player.spawntimer -- INITIAL from metatable - self.body:setActive(false) - self.world:onNautKilled(self) -end - --- And then respawn. Like Jon Snow. -function Player:respawn() - self.alive = true - self.body:setLinearVelocity(0,0) - self.body:setPosition(self.world:getSpawnPosition()) - self.body:setActive(true) - self:createEffect("respawn") - self:playSound(7) -end - --- Sounds -function Player:playSound(sfx, force) - if self.alive or force then - local source = love.audio.newSource(self.sfx[sfx]) - source:play() - end -end diff --git a/sprite.lua b/sprite.lua deleted file mode 100644 index 1cc46f7..0000000 --- a/sprite.lua +++ /dev/null @@ -1,81 +0,0 @@ --- `Sprite` --- Abstract class for drawable animated entities. - --- Metatable -Sprite = { - animations--[[table with animations]], - current--[[animations.default]], - image--[[love.graphics.newImage()]], - frame = 1, - delay = .1, -} -Sprite.__index = Sprite - --- Cleans up reference to image on deletion. -function Sprite:delete() - self.image = nil -end - --- Sets an Image as a image. -function Sprite:setImage(image) - self.image = image -end --- Returns current image Image. -function Sprite:getImage() - return self.image -end - --- Sets new animations list. -function Sprite:setAnimationsList(t) - if t then - self.animations = t - self:setAnimation("default") - end -end - --- Sets current animation by table key. -function Sprite:setAnimation(animation) - self.frame = 1 - self.delay = Sprite.delay -- INITIAL from metatable - self.current = self.animations[animation] -end --- Returns current animation table. -function Sprite:getAnimation() - return self.current -end - --- Get frame quad for drawing. -function Sprite:getQuad() - if self.animations and self.current then - return self.current[self.frame] - end -end - --- Drawing self to LOVE2D buffer. --- If there is no Quad, it will draw entire image. -function Sprite:draw(...) - local s, q = self:getImage(), self:getQuad() - if s then - love.graphics.setColor(255,255,255,255) - if q then love.graphics.draw(s, q, ...) - else love.graphics.draw(s, ...) end - end -end --- Animation updating. -function Sprite:update(dt) - if self.animations and self.current then - self.delay = self.delay - dt - if self.delay < 0 then - self.delay = self.delay + Sprite.delay -- INITIAL from metatable - self:nextFrame() - end - end -end --- Moving to the next frame. -function Sprite:nextFrame() - if self.current.repeated or not (self.frame == self.current.frames) then - self.frame = (self.frame % self.current.frames) + 1 - else - self:setAnimation("default") - end -end \ No newline at end of file diff --git a/world.lua b/world.lua deleted file mode 100644 index 9c308b8..0000000 --- a/world.lua +++ /dev/null @@ -1,424 +0,0 @@ --- `World` --- Used to manage physical world and everything inside it: clouds, platforms, nauts, background etc. - --- WHOLE CODE HAS FLAG OF "need a cleanup" - -require "platform" -require "player" -require "cloud" -require "effect" -require "decoration" -require "ray" - --- Metatable of `World` --- nils initialized in constructor -World = { - -- inside - world = nil, - Nauts = nil, - Platforms = nil, - Clouds = nil, - Decorations = nil, - Effects = nil, - Rays = nil, - camera = nil, - -- cloud generator - clouds_delay = 5, - -- Map - map = nil, - background = nil, - -- Gameplay status - lastNaut = false, - -- "WINNER" - win_move = 0, - -- Music - music = nil -} - --- Constructor of `World` ZA WARUDO! -function World:new(map, nauts) - -- Meta - local o = {} - setmetatable(o, self) - self.__index = self - -- Physical world initialization - love.physics.setMeter(64) - o.world = love.physics.newWorld(0, 9.81*64, true) - o.world:setCallbacks(o.beginContact, o.endContact) - -- Empty tables for objects - local n = {} - o.Nauts = n - local p = {} - o.Platforms = {} - local c = {} - o.Clouds = c - local e = {} - o.Effects = e - local d = {} - o.Decorations = d - local r = {} - o.Rays = r - -- Random init - math.randomseed(os.time()) - -- Map - local map = map or "default" - o:loadMap(map) - -- Nauts - o:spawnNauts(nauts) - -- Create camera - o.camera = Camera:new(o) - -- Play music - o.music = Music:new(o.map.theme) - return o -end - --- The end of the world -function World:delete() - self.world:destroy() - for _,platform in pairs(self.Platforms) do - platform:delete() - end - for _,naut in pairs(self.Nauts) do - naut:delete() - end - self.music:delete() - self = nil -end - --- Load map from file -function World:loadMap(name) - local name = name or "default" - name = "maps/" .. name .. ".lua" - local map = love.filesystem.load(name) - self.map = map() - -- Platforms - for _,platform in pairs(self.map.platforms) do - self:createPlatform(platform.x, platform.y, platform.shape, platform.sprite, platform.animations) - end - -- Decorations - for _,decoration in pairs(self.map.decorations) do - self:createDecoration(decoration.x, decoration.y, decoration.sprite) - end - -- Background - self.background = love.graphics.newImage(self.map.background) - -- Clouds - if self.map.clouds then - for i=1,6 do - self:randomizeCloud(false) - end - end -end - --- Spawn all the nauts for the round -function World:spawnNauts(nauts) - for _,naut in pairs(nauts) do - local x,y = self:getSpawnPosition() - local spawn = self:createNaut(x, y, naut[1]) - spawn:assignControlSet(naut[2]) - end -end - --- Get respawn location -function World:getSpawnPosition() - local n = math.random(1, #self.map.respawns) - return self.map.respawns[n].x, self.map.respawns[n].y -end - --- Add new platform to the world -function World:createPlatform(x, y, polygon, sprite, animations) - table.insert(self.Platforms, Platform:new(self, self.world, x, y, polygon, sprite, animations)) -end - --- Add new naut to the world -function World:createNaut(x, y, name) - local naut = Player:new(self, self.world, x, y, name) - table.insert(self.Nauts, naut) - return naut -end - --- Add new decoration to the world -function World:createDecoration(x, y, sprite) - table.insert(self.Decorations, Decoration:new(x, y, sprite)) -end - --- Add new cloud to the world -function World:createCloud(x, y, t, v) - table.insert(self.Clouds, Cloud:new(x, y, t, v)) -end - --- Randomize Cloud creation -function World:randomizeCloud(outside) - if outside == nil then - outside = true - else - outside = outside - end - local x,y,t,v - local m = self.map - if outside then - x = m.center_x-m.width*1.2+math.random(-50,20) - else - x = math.random(m.center_x-m.width/2,m.center_x+m.width/2) - end - y = math.random(m.center_y-m.height/2, m.center_y+m.height/2) - t = math.random(1,3) - v = math.random(8,18) - self:createCloud(x, y, t, v) -end - --- Add an effect behind nauts -function World:createEffect(name, x, y) - table.insert(self.Effects, Effect:new(name, x, y)) -end - --- Add a ray -function World:createRay(naut) - table.insert(self.Rays, Ray:new(naut, self)) -end - --- get Nauts functions --- more than -1 lives -function World:getNautsPlayable() - local nauts = {} - for _,naut in pairs(self.Nauts) do - if naut.lives > -1 then - table.insert(nauts, naut) - end - end - return nauts -end --- are alive -function World:getNautsAlive() - local nauts = {} - for _,naut in self.Nauts do - if naut.alive then - table.insert(nauts, naut) - end - end - return nauts -end --- all of them -function World:getNautsAll() - return self.Nauts -end - --- get Map name -function World:getMapName() - return self.map.name -end - --- Event: when player is killed -function World:onNautKilled(naut) - self.camera:startShake() - self:createRay(naut) - local nauts = self:getNautsPlayable() - if self.lastNaut then - changeScene(Menu:new()) - elseif #nauts < 2 then - self.lastNaut = true - naut:playSound(5, true) - end -end - -function World:getBounce(f) - local f = f or 1 - return math.sin(self.win_move*f*math.pi) -end - --- LÖVE2D callbacks --- Update ZU WARUDO -function World:update(dt) - -- Physical world - self.world:update(dt) - -- Camera - self.camera:update(dt) - -- Engine world: Nauts, Grounds (kek) and Decorations - all Animateds (top kek) - for _,naut in pairs(self.Nauts) do - naut:update(dt) - end - for _,platform in pairs(self.Platforms) do - platform:update(dt) - end - for _,decoration in pairs(self.Decorations) do - decoration:update(dt) - end - -- Clouds - if self.map.clouds then - -- generator - local n = table.getn(self.Clouds) - self.clouds_delay = self.clouds_delay - dt - if self.clouds_delay < 0 and - n < 18 - then - self:randomizeCloud() - self.clouds_delay = self.clouds_delay + World.clouds_delay -- World.clouds_delay is initial - end - -- movement - for _,cloud in pairs(self.Clouds) do - if cloud:update(dt) > 340 then - table.remove(self.Clouds, _) - end - end - end - -- Effects - for _,effect in pairs(self.Effects) do - if effect:update(dt) then - table.remove(self.Effects, _) - end - end - -- Rays - for _,ray in pairs(self.Rays) do - if ray:update(dt) then - table.remove(self.Rays, _) - end - end - -- Bounce `winner` - self.win_move = self.win_move + dt - if self.win_move > 2 then - self.win_move = self.win_move - 2 - end -end --- Draw -function World:draw() - -- Camera stuff - local offset_x, offset_y = self.camera:getOffsets() - local scale = self.camera.scale - local scaler = self.camera.scaler - - -- Background - love.graphics.draw(self.background, 0, 0, 0, scaler, scaler) - - -- This needs to be reworked! - -- Draw clouds - for _,cloud in pairs(self.Clouds) do - cloud:draw(offset_x, offset_y, scale) - end - - -- Draw decorations - for _,decoration in pairs(self.Decorations) do - decoration:draw(offset_x, offset_y, scale) - end - - -- Draw effects - for _,effect in pairs(self.Effects) do - effect:draw(offset_x,offset_y, scale) - end - - -- Draw player - for _,naut in pairs(self.Nauts) do - naut:draw(offset_x, offset_y, scale, debug) - end - - -- Draw ground - for _,platform in pairs(self.Platforms) do - platform:draw(offset_x, offset_y, scale, debug) - end - - -- Draw rays - for _,ray in pairs(self.Rays) do - ray:draw(offset_x, offset_y, scale) - end - - -- draw center - if debug then - local c = self.camera - local w, h = love.graphics.getWidth(), love.graphics.getHeight() - -- draw map center - love.graphics.setColor(130,130,130) - love.graphics.setLineWidth(1) - love.graphics.setLineStyle("rough") - local cx, cy = c:getPositionScaled() - local x1, y1 = c:translatePosition(self.map.center_x, cy) - local x2, y2 = c:translatePosition(self.map.center_x, cy+h) - love.graphics.line(x1,y1,x2,y2) - local x1, y1 = c:translatePosition(cx, self.map.center_y) - local x2, y2 = c:translatePosition(cx+w, self.map.center_y) - love.graphics.line(x1,y1,x2,y2) - -- draw ox, oy - love.graphics.setColor(200,200,200) - love.graphics.setLineStyle("rough") - local cx, cy = c:getPositionScaled() - local x1, y1 = c:translatePosition(0, cy) - local x2, y2 = c:translatePosition(0, cy+h) - love.graphics.line(x1,y1,x2,y2) - local x1, y1 = c:translatePosition(cx, 0) - local x2, y2 = c:translatePosition(cx+w, 0) - love.graphics.line(x1,y1,x2,y2) - end - - -- Draw HUDs - for _,naut in pairs(self.Nauts) do - -- I have no idea where to place them T_T - -- let's do: bottom-left, bottom-right, top-left, top-right - local w, h = love.graphics.getWidth()/scale, love.graphics.getHeight()/scale - local y, e = 1, 1 - if _ < 3 then y, e = h-33, 0 end - naut:drawHUD(1+(_%2)*(w-34), y, scale, e) - end - - -- Draw winner - if self.lastNaut then - local w, h = love.graphics.getWidth()/scale, love.graphics.getHeight()/scale - local angle = self:getBounce(2) - local dy = self:getBounce()*3 - love.graphics.setFont(Bold) - love.graphics.printf("WINNER",(w/2)*scale,(42+dy)*scale,336,"center",(angle*5)*math.pi/180,scale,scale,168,12) - love.graphics.setFont(Font) - love.graphics.printf("rofl, now kill yourself", w/2*scale, 18*scale, 160, "center", 0, scale, scale, 80, 3) - end -end - --- Box2D callbacks --- beginContact -function World.beginContact(a, b, coll) - if a:getCategory() == 1 then - local x,y = coll:getNormal() - if y < -0.6 then - print(b:getUserData().name .. " is not in air") - -- Move them to Player - b:getUserData().inAir = false - b:getUserData().jumpnumber = 2 - b:getUserData().salto = false - b:getUserData():createEffect("land") - end - local vx, vy = b:getUserData().body:getLinearVelocity() - if math.abs(x) == 1 or (y < -0.6 and x == 0) then - b:getUserData():playSound(3) - end - end - if a:getCategory() == 3 then - b:getUserData():damage(a:getUserData()[2]) - end - if b:getCategory() == 3 then - a:getUserData():damage(b:getUserData()[2]) - end -end --- endContact -function World.endContact(a, b, coll) - if a:getCategory() == 1 then - print(b:getUserData().name .. " is in air") - -- Move them to Player - b:getUserData().inAir = true - end -end - --- Controller callbacks -function World:controlpressed(set, action, key) - if key == "f6" and debug then - local map = self:getMapName() - local nauts = {} - for _,naut in pairs(self:getNautsAll()) do - table.insert(nauts, {naut.name, naut:getControlSet()}) - end - local new = World:new(map, nauts) - changeScene(new) - end - for k,naut in pairs(self:getNautsAll()) do - naut:controlpressed(set, action, key) - end -end -function World:controlreleased(set, action, key) - for k,naut in pairs(self:getNautsAll()) do - naut:controlreleased(set, action, key) - end -end \ No newline at end of file -- cgit v1.1 From c16c1206f5884614157b8f5049e601ff77478d7f Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 17 Mar 2017 18:35:54 +0100 Subject: Ray renamed and moved --- not/Ray.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ not/World.lua | 2 +- ray.lua | 52 ---------------------------------------------------- 3 files changed, 53 insertions(+), 53 deletions(-) create mode 100644 not/Ray.lua delete mode 100644 ray.lua diff --git a/not/Ray.lua b/not/Ray.lua new file mode 100644 index 0000000..bbe11c1 --- /dev/null +++ b/not/Ray.lua @@ -0,0 +1,52 @@ +-- `Ray` +-- That awesome effect that blinks when player dies! + +-- WHOLE CODE HAS FLAG OF "need a cleanup" + +Ray = { + naut = nil, + world = nil, + canvas = nil, + delay = 0.3 +} +function Ray:new(naut, world) + -- Meta + local o = {} + setmetatable(o, self) + self.__index = self + -- Init + o.naut = naut + o.world = world + -- Cavas, this is temporary, I believe. + local scale = o.world.camera.scale + local w, h = love.graphics.getWidth(), love.graphics.getHeight() + o.canvas = love.graphics.newCanvas(w/scale, h/scale) + return o +end +function Ray:update(dt) + self.delay = self.delay - dt + if self.delay < 0 then + return true -- delete + end + return false +end +function Ray:draw(offset_x, offset_y, scale) + love.graphics.setCanvas(self.canvas) + love.graphics.clear() + love.graphics.setColor(255, 247, 228, 247) + love.graphics.setLineStyle("rough") + love.graphics.setLineWidth(self.delay*160) + local x, y = self.naut:getPosition() + local m = self.world.map + local dy = m.height + if y > m.center_y then + dy = -dy + end + love.graphics.line(-x+offset_x,-y+offset_y-dy*0.7,x+offset_x,y+dy*0.7+offset_y) + -- reset + love.graphics.setCanvas() + love.graphics.setLineWidth(1) + love.graphics.setColor(255,255,255,255) + -- draw on screen + love.graphics.draw(self.canvas, 0, 0, 0, scale, scale) +end diff --git a/not/World.lua b/not/World.lua index 5afc5bf..6d81918 100644 --- a/not/World.lua +++ b/not/World.lua @@ -8,7 +8,7 @@ require "not.Hero" require "not.Cloud" require "not.Effect" require "not.Decoration" -require "ray" +require "not.Ray" -- Metatable of `World` -- nils initialized in constructor diff --git a/ray.lua b/ray.lua deleted file mode 100644 index bbe11c1..0000000 --- a/ray.lua +++ /dev/null @@ -1,52 +0,0 @@ --- `Ray` --- That awesome effect that blinks when player dies! - --- WHOLE CODE HAS FLAG OF "need a cleanup" - -Ray = { - naut = nil, - world = nil, - canvas = nil, - delay = 0.3 -} -function Ray:new(naut, world) - -- Meta - local o = {} - setmetatable(o, self) - self.__index = self - -- Init - o.naut = naut - o.world = world - -- Cavas, this is temporary, I believe. - local scale = o.world.camera.scale - local w, h = love.graphics.getWidth(), love.graphics.getHeight() - o.canvas = love.graphics.newCanvas(w/scale, h/scale) - return o -end -function Ray:update(dt) - self.delay = self.delay - dt - if self.delay < 0 then - return true -- delete - end - return false -end -function Ray:draw(offset_x, offset_y, scale) - love.graphics.setCanvas(self.canvas) - love.graphics.clear() - love.graphics.setColor(255, 247, 228, 247) - love.graphics.setLineStyle("rough") - love.graphics.setLineWidth(self.delay*160) - local x, y = self.naut:getPosition() - local m = self.world.map - local dy = m.height - if y > m.center_y then - dy = -dy - end - love.graphics.line(-x+offset_x,-y+offset_y-dy*0.7,x+offset_x,y+dy*0.7+offset_y) - -- reset - love.graphics.setCanvas() - love.graphics.setLineWidth(1) - love.graphics.setColor(255,255,255,255) - -- draw on screen - love.graphics.draw(self.canvas, 0, 0, 0, scale, scale) -end -- cgit v1.1 From 340a3a4b92de5495b47e8e1e102178edfd97514f Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 00:21:02 +0100 Subject: Night commit, added PhysicalBody, newImage to sprite --- main.lua | 14 ----------- not/Hero.lua | 19 +++++++-------- not/PhysicalBody.lua | 16 +++++++++++++ not/Sprite.lua | 66 ++++++++++++++++++++++++++++++++++------------------ 4 files changed, 68 insertions(+), 47 deletions(-) create mode 100644 not/PhysicalBody.lua diff --git a/main.lua b/main.lua index bbcf0e0..9180ebf 100644 --- a/main.lua +++ b/main.lua @@ -18,20 +18,6 @@ end function getRealScale() return math.max(1, math.max(love.graphics.getWidth() / 320, love.graphics.getHeight() / 180)) end --- Should be moved to Sprite metaclass (non-existent yet) -function newImage(path) - local imagedata = love.image.newImageData(path) - local transparency = function(x, y, r, g, b, a) - if (r == 0 and g == 128 and b == 64) or - (r == 0 and g == 240 and b == 6) then - a = 0 - end - return r, g, b, a - end - imagedata:mapPixel(transparency) - local image = love.graphics.newImage(imagedata) - return image -end -- Require require "not.World" diff --git a/not/Hero.lua b/not/Hero.lua index 7ddc724..8d226ac 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -1,12 +1,6 @@ --- `Hero` --- Entity controlled by a player. It has a physical body and a sprite. Can play animations and interact with other instances of the same class. +--- `Hero` +-- Hero (naut) entity that exists in a game world. -- Collision category: [2] - --- WHOLE CODE HAS FLAG OF "need a cleanup" -require "not.Sprite" - --- Metatable of `Hero` --- nils initialized in constructor Hero = { -- General and physics name = "empty", @@ -44,10 +38,13 @@ Hero = { -- Animations table animations = require "animations" } + +-- `Hero` is a child of `PhysicalBody`. +require "not.PhysicalBody" Hero.__index = Hero -setmetatable(Hero, Sprite) +setmetatable(Hero, PhysicalBody) --- Constructor of `Hero` +-- Constructor of `Hero`. function Hero:new (game, world, x, y, name) -- Meta local o = {} @@ -64,7 +61,7 @@ function Hero:new (game, world, x, y, name) o.body:setFixedRotation(true) -- Misc o.name = name or "empty" - o:setImage(newImage("assets/nauts/"..o.name..".png")) + o:setImage(Sprite.newImage("assets/nauts/"..o.name..".png")) o.world = game o.punchcd = 0 -- Animation diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua new file mode 100644 index 0000000..6e6a8a6 --- /dev/null +++ b/not/PhysicalBody.lua @@ -0,0 +1,16 @@ +--- `PhysicalBody` +-- Abstract class for drawable body existing in Box2D's physical world. +PhysicalBody = { + body =--[[love.physics.newBody]]nil, +} + +-- `PhysicalBody` is a child of `Sprite`. +require "not.Sprite" +PhysicalBody.__index = PhysicalBody +setmetatable(PhysicalBody, Sprite) + +-- Constructor of `PhysicalBody`. +function PhysicalBody:new (world, x, y, imagePath) + local o = Sprite:new(imagePath) + return o +end \ No newline at end of file diff --git a/not/Sprite.lua b/not/Sprite.lua index 1cc46f7..905816b 100644 --- a/not/Sprite.lua +++ b/not/Sprite.lua @@ -1,32 +1,54 @@ -- `Sprite` -- Abstract class for drawable animated entities. - --- Metatable Sprite = { - animations--[[table with animations]], - current--[[animations.default]], - image--[[love.graphics.newImage()]], + animations =--[[table with animations]]nil, + current =--[[animations.default]]nil, + image =--[[love.graphics.newImage]]nil, frame = 1, delay = .1, } Sprite.__index = Sprite +-- Constructor of `Sprite`. +function Sprite:new (imagePath) + local o = setmetatable({}, self) + if type(imagePath) == "string" then + o:setImage(self.newImage(imagePath)) + end + return o +end + -- Cleans up reference to image on deletion. -function Sprite:delete() +function Sprite:delete () self.image = nil end --- Sets an Image as a image. -function Sprite:setImage(image) +-- Creates new Image object from path. Key-colours two shades of green. Static. +function Sprite.newImage (path) + local imagedata = love.image.newImageData(path) + local transparency = function(x, y, r, g, b, a) + if (r == 0 and g == 128 and b == 64) or + (r == 0 and g == 240 and b == 6) then + a = 0 + end + return r, g, b, a + end + imagedata:mapPixel(transparency) + local image = love.graphics.newImage(imagedata) + return image +end + +-- Sets an Image as an image. +function Sprite:setImage (image) self.image = image end -- Returns current image Image. -function Sprite:getImage() +function Sprite:getImage () return self.image end -- Sets new animations list. -function Sprite:setAnimationsList(t) +function Sprite:setAnimationsList (t) if t then self.animations = t self:setAnimation("default") @@ -34,45 +56,45 @@ function Sprite:setAnimationsList(t) end -- Sets current animation by table key. -function Sprite:setAnimation(animation) +function Sprite:setAnimation (animation) self.frame = 1 self.delay = Sprite.delay -- INITIAL from metatable self.current = self.animations[animation] end -- Returns current animation table. -function Sprite:getAnimation() +function Sprite:getAnimation () return self.current end -- Get frame quad for drawing. -function Sprite:getQuad() +function Sprite:getQuad () if self.animations and self.current then return self.current[self.frame] end end -- Drawing self to LOVE2D buffer. --- If there is no Quad, it will draw entire image. -function Sprite:draw(...) - local s, q = self:getImage(), self:getQuad() - if s then +-- If there is no Quad, it will draw entire image. It won't draw anything if there is no image. +function Sprite:draw (...) + local i, q = self:getImage(), self:getQuad() + if i then love.graphics.setColor(255,255,255,255) - if q then love.graphics.draw(s, q, ...) - else love.graphics.draw(s, ...) end + if q then love.graphics.draw(i, q, ...) + else love.graphics.draw(i, ...) end end end -- Animation updating. -function Sprite:update(dt) +function Sprite:update (dt) if self.animations and self.current then self.delay = self.delay - dt if self.delay < 0 then self.delay = self.delay + Sprite.delay -- INITIAL from metatable - self:nextFrame() + self:goToNextFrame() end end end -- Moving to the next frame. -function Sprite:nextFrame() +function Sprite:goToNextFrame () if self.current.repeated or not (self.frame == self.current.frames) then self.frame = (self.frame % self.current.frames) + 1 else -- cgit v1.1 From b262cb3eec1a797832d168f9e6d144468fb48c1d Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 01:35:43 +0100 Subject: Initializers in PhysicalBody, Hero and Sprite --- not/Hero.lua | 52 +++++++++++++++++++++++++++++----------------------- not/PhysicalBody.lua | 8 +++++++- not/Sprite.lua | 11 ++++++++--- 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index 8d226ac..eee7a83 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -36,7 +36,7 @@ Hero = { -- Sounds sfx = require "sounds", -- Animations table - animations = require "animations" + animations = nil } -- `Hero` is a child of `PhysicalBody`. @@ -46,28 +46,9 @@ setmetatable(Hero, PhysicalBody) -- Constructor of `Hero`. function Hero:new (game, world, x, y, name) - -- Meta - local o = {} - setmetatable(o, self) - -- Physics - local group = -1-#game.Nauts - o.body = love.physics.newBody(world, x, y, "dynamic") - o.shape = love.physics.newRectangleShape(10, 16) - o.fixture = love.physics.newFixture(o.body, o.shape, 8) - o.fixture:setUserData(o) - o.fixture:setCategory(2) - o.fixture:setMask(2) - o.fixture:setGroupIndex(group) - o.body:setFixedRotation(true) - -- Misc - o.name = name or "empty" - o:setImage(Sprite.newImage("assets/nauts/"..o.name..".png")) - o.world = game - o.punchcd = 0 - -- Animation - o.current = o.animations.default - o:createEffect("respawn") - -- Portrait load for first object created + local o = setmetatable({}, self) + o:init(name, game, x, y) + -- Load portraits statically. if self.portrait_sprite == nil then self.portrait_sprite = love.graphics.newImage("assets/portraits.png") self.portrait_frame = love.graphics.newImage("assets/menu.png") @@ -75,6 +56,31 @@ function Hero:new (game, world, x, y, name) return o end +-- Initializator of `Hero`. +function Hero:init (name, world, x, y) + -- Find imagePath basing on hero name and call super initializator. + local fileName = name or Hero.name -- INITIAL from metatable + local imagePath = string.format("assets/nauts/%s.png", fileName) + PhysicalBody.init(self, world, x, y, imagePath) + -- To be removed or heavily changed. + self.world = world + self.punchcd = 0 + -- To be moved to PhysicalBody abstract. + local group = -1-#world.Nauts + self.body = love.physics.newBody(world.world, x, y, "dynamic") + self.shape = love.physics.newRectangleShape(10, 16) + self.fixture = love.physics.newFixture(self.body, self.shape, 8) + self.fixture:setUserData(self) + self.fixture:setCategory(2) + self.fixture:setMask(2) + self.fixture:setGroupIndex(group) + self.body:setFixedRotation(true) + -- Actual `Hero` initialization. + self.name = name + self:setAnimationsList(require("animations")) + self:createEffect("respawn") +end + -- Control set managment function Hero:assignControlSet(set) self.controlset = set diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 6e6a8a6..1f91faf 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -11,6 +11,12 @@ setmetatable(PhysicalBody, Sprite) -- Constructor of `PhysicalBody`. function PhysicalBody:new (world, x, y, imagePath) - local o = Sprite:new(imagePath) + local o = setmetatable({}, self) + o:init(world, x, y, imagePath) return o +end + +-- Initializator of `PhysicalBody`. +function PhysicalBody:init (world, x, y, imagePath) + Sprite.init(self, imagePath) end \ No newline at end of file diff --git a/not/Sprite.lua b/not/Sprite.lua index 905816b..6342f60 100644 --- a/not/Sprite.lua +++ b/not/Sprite.lua @@ -12,9 +12,7 @@ Sprite.__index = Sprite -- Constructor of `Sprite`. function Sprite:new (imagePath) local o = setmetatable({}, self) - if type(imagePath) == "string" then - o:setImage(self.newImage(imagePath)) - end + o:init(imagePath) return o end @@ -23,6 +21,13 @@ function Sprite:delete () self.image = nil end +-- Initializes new Sprite instance. +function Sprite:init (imagePath) + if type(imagePath) == "string" then + self:setImage(Sprite.newImage(imagePath)) + end +end + -- Creates new Image object from path. Key-colours two shades of green. Static. function Sprite.newImage (path) local imagedata = love.image.newImageData(path) -- cgit v1.1 From 4652d69cc88e3d0137cac118344d21853c6a7605 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 02:45:17 +0100 Subject: Small changes, comments --- not/Hero.lua | 25 +++++++++---------------- not/PhysicalBody.lua | 2 +- not/Sprite.lua | 3 ++- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index eee7a83..362ebf9 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -4,14 +4,10 @@ Hero = { -- General and physics name = "empty", - body = nil, - shape = nil, - fixture = nil, - sprite = nil, - rotate = 0, -- "angle" would sound better + angle = 0, facing = 1, max_velocity = 105, - world = nil, -- game world + world = --[[not.World]]nil, -- Combat combo = 0, lives = 3, @@ -28,15 +24,12 @@ Hero = { jumpnumber = 2, -- Keys controlset = nil, - -- HUD + -- Statics portrait_sprite = nil, portrait_frame = nil, portrait_sheet = require "nautsicons", portrait_box = love.graphics.newQuad( 0, 15, 32,32, 80,130), - -- Sounds sfx = require "sounds", - -- Animations table - animations = nil } -- `Hero` is a child of `PhysicalBody`. @@ -62,10 +55,10 @@ function Hero:init (name, world, x, y) local fileName = name or Hero.name -- INITIAL from metatable local imagePath = string.format("assets/nauts/%s.png", fileName) PhysicalBody.init(self, world, x, y, imagePath) - -- To be removed or heavily changed. + -- TODO: probably should be removed or heavily changed. self.world = world self.punchcd = 0 - -- To be moved to PhysicalBody abstract. + -- TODO: move following lines to PhysicalBody, cut if not needed, refectorize to subfunctions in target class. local group = -1-#world.Nauts self.body = love.physics.newBody(world.world, x, y, "dynamic") self.shape = love.physics.newRectangleShape(10, 16) @@ -107,9 +100,9 @@ function Hero:update(dt) -- Salto if self.salto and (self.current == self.animations.walk or self.current == self.animations.default) then - self.rotate = (self.rotate + 17 * dt * self.facing) % 360 - elseif self.rotate ~= 0 then - self.rotate = 0 + self.angle = (self.angle + 17 * dt * self.facing) % 360 + elseif self.angle ~= 0 then + self.angle = 0 end -- # HORIZONTAL MOVEMENT @@ -302,7 +295,7 @@ function Hero:draw(offset_x, offset_y, scale, debug) local draw_y = (approx(y) + offset_y) * scale local draw_x = (math.floor(x) + offset_x) * scale -- sprite draw - Sprite.draw(self, draw_x, draw_y, self.rotate, self.facing*scale, scale, 12, 15) + Sprite.draw(self, draw_x, draw_y, self.angle, self.facing*scale, scale, 12, 15) -- debug draw if debug then for _,fixture in pairs(self.body:getFixtureList()) do diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 1f91faf..e726ea3 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -19,4 +19,4 @@ end -- Initializator of `PhysicalBody`. function PhysicalBody:init (world, x, y, imagePath) Sprite.init(self, imagePath) -end \ No newline at end of file +end diff --git a/not/Sprite.lua b/not/Sprite.lua index 6342f60..d4cde59 100644 --- a/not/Sprite.lua +++ b/not/Sprite.lua @@ -1,4 +1,4 @@ --- `Sprite` +--- `Sprite` -- Abstract class for drawable animated entities. Sprite = { animations =--[[table with animations]]nil, @@ -80,6 +80,7 @@ end -- Drawing self to LOVE2D buffer. -- If there is no Quad, it will draw entire image. It won't draw anything if there is no image. +-- TODO: it doesn't follow same pattern as `not.Hero.draw`. It should implement so it can be called from `not.World`. function Sprite:draw (...) local i, q = self:getImage(), self:getQuad() if i then -- cgit v1.1 From a8551f5da9549453381a0f2daa0ff4aefd06272f Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 02:50:40 +0100 Subject: Added tempalte for not.Player --- not/Player.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 not/Player.lua diff --git a/not/Player.lua b/not/Player.lua new file mode 100644 index 0000000..bcd72bc --- /dev/null +++ b/not/Player.lua @@ -0,0 +1,22 @@ +--- `Player` +-- Special `not.Hero` controllable by a player. +Player = { + -- TODO: move functions and properties related to controls from `not.Hero`. +} + +-- `Player` is a child of `Hero`. +require "not.Hero" +Player.__index = Player +setmetatable(Player, Hero) + +-- Constructor of `Player`. +function Player:new (...) + local o = setmetatable({}, self) + o:init(...) + return o +end + +-- Initializator of `Player`. +function Player:init (...) + Hero.init(self, ...) +end \ No newline at end of file -- cgit v1.1 From b10988b7e8a0c52148b1d3828c3739fb0eeff24e Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 03:09:36 +0100 Subject: No constructors for abstracts --- not/PhysicalBody.lua | 15 +++++++++++++-- not/Sprite.lua | 5 ++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index e726ea3..52e9357 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -1,5 +1,5 @@ --- `PhysicalBody` --- Abstract class for drawable body existing in Box2D's physical world. +-- Abstract class for drawable entity existing in `not.World`. PhysicalBody = { body =--[[love.physics.newBody]]nil, } @@ -9,14 +9,25 @@ require "not.Sprite" PhysicalBody.__index = PhysicalBody setmetatable(PhysicalBody, Sprite) --- Constructor of `PhysicalBody`. +--[[ Constructor of `PhysicalBody`. function PhysicalBody:new (world, x, y, imagePath) local o = setmetatable({}, self) o:init(world, x, y, imagePath) return o end +]] -- Initializator of `PhysicalBody`. function PhysicalBody:init (world, x, y, imagePath) Sprite.init(self, imagePath) end + +-- Update of `PhysicalBody`. +function PhysicalBody:update (dt) + Sprite.update(self, dt) +end + +-- Draw of `PhysicalBody`. +function PhysicalBody:draw (offset_x, offset_y, scale, debug) + -- TODO: Move debug part here from `not.Hero.draw`. +end diff --git a/not/Sprite.lua b/not/Sprite.lua index d4cde59..e9eb387 100644 --- a/not/Sprite.lua +++ b/not/Sprite.lua @@ -9,12 +9,13 @@ Sprite = { } Sprite.__index = Sprite --- Constructor of `Sprite`. +--[[ Constructor of `Sprite`. function Sprite:new (imagePath) local o = setmetatable({}, self) o:init(imagePath) return o end +]] -- Cleans up reference to image on deletion. function Sprite:delete () @@ -89,6 +90,7 @@ function Sprite:draw (...) else love.graphics.draw(i, ...) end end end + -- Animation updating. function Sprite:update (dt) if self.animations and self.current then @@ -99,6 +101,7 @@ function Sprite:update (dt) end end end + -- Moving to the next frame. function Sprite:goToNextFrame () if self.current.repeated or not (self.frame == self.current.frames) then -- cgit v1.1 From 19e6728c339cb029ab9a6b7762d60abe790b772a Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 03:13:34 +0100 Subject: Spaces! --- not/Hero.lua | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index 362ebf9..bd8c55c 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -75,15 +75,15 @@ function Hero:init (name, world, x, y) end -- Control set managment -function Hero:assignControlSet(set) +function Hero:assignControlSet (set) self.controlset = set end -function Hero:getControlSet() +function Hero:getControlSet () return self.controlset end -- Update callback of `Hero` -function Hero:update(dt) +function Hero:update (dt) -- hotfix? for destroyed bodies if self.body:isDestroyed() then return end -- locals @@ -192,7 +192,7 @@ function Hero:update(dt) end -- Controller callbacks -function Hero:controlpressed(set, action, key) +function Hero:controlpressed (set, action, key) if set ~= self:getControlSet() then return end local isDown = Controller.isDown local controlset = self:getControlSet() @@ -261,7 +261,7 @@ function Hero:controlpressed(set, action, key) end end end -function Hero:controlreleased(set, action, key) +function Hero:controlreleased (set, action, key) if set ~= self:getControlSet() then return end local isDown = Controller.isDown local controlset = self:getControlSet() @@ -280,7 +280,7 @@ function Hero:controlreleased(set, action, key) end -- Draw of `Hero` -function Hero:draw(offset_x, offset_y, scale, debug) +function Hero:draw (offset_x, offset_y, scale, debug) -- draw only alive if not self.alive then return end -- locals @@ -315,13 +315,13 @@ function Hero:draw(offset_x, offset_y, scale, debug) end -- getPosition -function Hero:getPosition() +function Hero:getPosition () return self.body:getPosition() end -- Draw HUD of `Hero` -- elevation: 1 bottom, 0 top -function Hero:drawHUD(x,y,scale,elevation) +function Hero:drawHUD (x,y,scale,elevation) -- hud displays only if player is alive if self.alive then love.graphics.setColor(255,255,255,255) @@ -336,7 +336,7 @@ end -- Change animation of `Hero` -- default, walk, attack, attack_up, attack_down, damage -function Hero:nextFrame() +function Hero:nextFrame () local isDown = Controller.isDown local controlset = self:getControlSet() if self.current.repeated or not (self.frame == self.current.frames) then @@ -350,7 +350,7 @@ function Hero:nextFrame() end -- Spawn `Effect` relative to `Hero` -function Hero:createEffect(name) +function Hero:createEffect (name) if name == "trail" or name == "hit" then -- 16px effect: -7 -7 self.world:createEffect(name, self.body:getX()-8, self.body:getY()-8) @@ -363,7 +363,7 @@ end -- Punch of `Hero` -- direction: left, right, up, down -- creates temporary fixture for player's body that acts as sensor; fixture is deleted after time set in UserData[1]; deleted by Hero:update(dt) -function Hero:hit(direction) +function Hero:hit (direction) -- start cooldown self.punchcd = Hero.punchcd -- INITIAL from metatable -- actual punch @@ -391,7 +391,7 @@ end -- Taking damage of `Hero` by successful hit test -- currently called from World's startContact -function Hero:damage(direction) +function Hero:damage (direction) local horizontal, vertical = 0, 0 if direction == "left" then horizontal = -1 @@ -416,7 +416,7 @@ function Hero:damage(direction) end -- DIE -function Hero:die() +function Hero:die () self:playSound(1) self.combo = Hero.combo -- INITIAL from metatable self.lives = self.lives - 1 @@ -427,7 +427,7 @@ function Hero:die() end -- And then respawn. Like Jon Snow. -function Hero:respawn() +function Hero:respawn () self.alive = true self.body:setLinearVelocity(0,0) self.body:setPosition(self.world:getSpawnPosition()) @@ -437,7 +437,7 @@ function Hero:respawn() end -- Sounds -function Hero:playSound(sfx, force) +function Hero:playSound (sfx, force) if self.alive or force then local source = love.audio.newSource(self.sfx[sfx]) source:play() -- cgit v1.1 From 2e352657813b37d17c2215b85189f18a50c099f9 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 03:29:32 +0100 Subject: Comments, todos, pretty useless --- main.lua | 4 ++++ not/Cloud.lua | 1 + not/Decoration.lua | 2 ++ not/Effect.lua | 2 ++ not/Hero.lua | 2 ++ not/Platform.lua | 3 +++ not/Sprite.lua | 1 + 7 files changed, 15 insertions(+) diff --git a/main.lua b/main.lua index 9180ebf..b985648 100644 --- a/main.lua +++ b/main.lua @@ -1,8 +1,11 @@ -- "NOTNAUTS" -- WHOLE CODE HAS FLAG OF "need a cleanup" +-- TODO: Any lua source file in root directory that is not `main` (this file), `conf` should be moved to a proper directory. Its name should be changed to show what it contains. + -- Pretend you didn't see this -- This is work for scene manager +-- TODO: Create SceneManager or similar class. Scene = nil function changeScene(scene) if Scene ~= nil then @@ -12,6 +15,7 @@ function changeScene(scene) end -- Should be moved to scene/camera +-- TODO: move following functions to `Camera`. function getScale() return math.max(1, math.floor(math.max(love.graphics.getWidth() / 320, love.graphics.getHeight() / 180))) end diff --git a/not/Cloud.lua b/not/Cloud.lua index c12e236..c9899d5 100644 --- a/not/Cloud.lua +++ b/not/Cloud.lua @@ -5,6 +5,7 @@ -- Metatable of `Cloud` -- nils initialized in constructor +-- TODO: inherit from `not.Decoration` or `not.Sprite`, depending on final result of `not.Sprite`. Cloud = { x = 0, -- position horizontal y = 0, -- position vertical diff --git a/not/Decoration.lua b/not/Decoration.lua index 7f020e1..5bfc328 100644 --- a/not/Decoration.lua +++ b/not/Decoration.lua @@ -1,3 +1,5 @@ +-- TODO: follow new code template +-- TODO: add comments require "not.Sprite" Decoration = { world = nil, diff --git a/not/Effect.lua b/not/Effect.lua index 4e327a1..7010946 100644 --- a/not/Effect.lua +++ b/not/Effect.lua @@ -3,6 +3,8 @@ -- Metatable of `Effect` -- nils initialized in constructor +-- TODO: inherit from `not.Sprite`. +-- TODO: clean-up and reformat code, see newer code for reference. Effect = { x = 0, y = 0, diff --git a/not/Hero.lua b/not/Hero.lua index bd8c55c..a6facd9 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -83,6 +83,7 @@ function Hero:getControlSet () end -- Update callback of `Hero` +-- TODO: Explode this function (method, kek), move controler-related parts to `not.Player`, physics parts to `not.PhysicalBody`. function Hero:update (dt) -- hotfix? for destroyed bodies if self.body:isDestroyed() then return end @@ -280,6 +281,7 @@ function Hero:controlreleased (set, action, key) end -- Draw of `Hero` +-- TODO: see `not.PhysicalBody.draw` and `not.Sprite.draw`. function Hero:draw (offset_x, offset_y, scale, debug) -- draw only alive if not self.alive then return end diff --git a/not/Platform.lua b/not/Platform.lua index 9b7b03c..ecf0377 100644 --- a/not/Platform.lua +++ b/not/Platform.lua @@ -1,6 +1,8 @@ -- `Platform` -- Static platform physical object with a sprite. `Players` can walk on it. -- Collision category: [1] +-- TODO: reformat code to follow new code patterns +-- TODO: comment uncovered code parts -- WHOLE CODE HAS FLAG OF "need a cleanup" require "not.Sprite" @@ -51,6 +53,7 @@ function Platform:getPosition() end -- Draw of `Platform` +-- TODO: see todos in `not.Sprite.draw`. function Platform:draw (offset_x, offset_y, scale, debug) -- locals local offset_x = offset_x or 0 diff --git a/not/Sprite.lua b/not/Sprite.lua index e9eb387..f9a9cb4 100644 --- a/not/Sprite.lua +++ b/not/Sprite.lua @@ -82,6 +82,7 @@ end -- Drawing self to LOVE2D buffer. -- If there is no Quad, it will draw entire image. It won't draw anything if there is no image. -- TODO: it doesn't follow same pattern as `not.Hero.draw`. It should implement so it can be called from `not.World`. +-- TODO: change children if above changes are in effect: `not.Platform`, `not.Decoration`. function Sprite:draw (...) local i, q = self:getImage(), self:getQuad() if i then -- cgit v1.1 From cca4d9c1bf4033c79e4bd61a257c6ea02557524c Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 04:19:59 +0100 Subject: Moving draw away to abstract classes --- not/Decoration.lua | 11 +---------- not/Hero.lua | 27 +++++++++++++-------------- not/PhysicalBody.lua | 1 + not/Platform.lua | 13 ++----------- not/Sprite.lua | 46 +++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 60 insertions(+), 38 deletions(-) diff --git a/not/Decoration.lua b/not/Decoration.lua index 5bfc328..a57c143 100644 --- a/not/Decoration.lua +++ b/not/Decoration.lua @@ -23,14 +23,5 @@ function Decoration:getPosition() return self.x, self.y end function Decoration:draw(offset_x, offset_y, scale) - -- locals - local offset_x = offset_x or 0 - local offset_y = offset_y or 0 - local scale = scale or 1 - 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 - -- draw - Sprite.draw(self, draw_x, draw_y, 0, scale, scale) + Sprite.draw(self, offset_x, offset_y, scale) end \ No newline at end of file diff --git a/not/Hero.lua b/not/Hero.lua index a6facd9..7be3104 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -280,24 +280,23 @@ function Hero:controlreleased (set, action, key) end end +-- TODO: comment them and place them somewhere properly +function Hero:getAngle () + return self.angle +end +function Hero:getHorizontalMirror() + return self.facing +end +function Hero:getOffset () + return 12,15 -- TODO: WHY? How about creating body as polygon and using 0,0 instead. LIKE EVERYWHERE ELSE? Make it obsolete both in here and in `not.Sprite`. +end + -- Draw of `Hero` -- TODO: see `not.PhysicalBody.draw` and `not.Sprite.draw`. function Hero:draw (offset_x, offset_y, scale, debug) - -- draw only alive if not self.alive then return end - -- 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 ; `approx` selected to prevent floating characters on certain conditions - local approx = math.floor - if (y - math.floor(y)) > 0.5 then approx = math.ceil end - local draw_y = (approx(y) + offset_y) * scale - local draw_x = (math.floor(x) + offset_x) * scale - -- sprite draw - Sprite.draw(self, draw_x, draw_y, self.angle, self.facing*scale, scale, 12, 15) + PhysicalBody.draw(self, offset_x, offset_y, scale, debug) + -- debug draw if debug then for _,fixture in pairs(self.body:getFixtureList()) do diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 52e9357..bbea3ac 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -30,4 +30,5 @@ end -- Draw of `PhysicalBody`. function PhysicalBody:draw (offset_x, offset_y, scale, debug) -- TODO: Move debug part here from `not.Hero.draw`. + Sprite.draw(self, offset_x, offset_y, scale) end diff --git a/not/Platform.lua b/not/Platform.lua index ecf0377..7dcea6c 100644 --- a/not/Platform.lua +++ b/not/Platform.lua @@ -55,17 +55,8 @@ end -- Draw of `Platform` -- TODO: see todos in `not.Sprite.draw`. function Platform: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 - Sprite.draw(self, draw_x, draw_y, 0, scale, scale) + Sprite.draw(self, offset_x, offset_y, scale) + -- debug draw if debug then love.graphics.setColor(255, 69, 0, 140) diff --git a/not/Sprite.lua b/not/Sprite.lua index f9a9cb4..a8785d3 100644 --- a/not/Sprite.lua +++ b/not/Sprite.lua @@ -79,16 +79,56 @@ function Sprite:getQuad () end end +-- TODO: Following five methods are stupid, do something about them! +-- Sprite can't be moved by itself. Positioning should be handled by children's methods. +function Sprite:getPosition () + return 0,0 +end +-- Sprite can't be rotated by itself. Rotation should be handled by children's methods. +function Sprite:getAngle () + return 0 +end +-- Sprite can't be mirrored by itself. Mirroring should be handled by children's methods. +function Sprite:getHorizontalMirror () + return 1 +end +function Sprite:getVerticalMirror () + return 1 +end +-- Sprite can't be offset by itself. Offsetting should be handled by children's methods. +function Sprite:getOffset () + return 0,0 +end + -- Drawing self to LOVE2D buffer. -- If there is no Quad, it will draw entire image. It won't draw anything if there is no image. -- TODO: it doesn't follow same pattern as `not.Hero.draw`. It should implement so it can be called from `not.World`. -- TODO: change children if above changes are in effect: `not.Platform`, `not.Decoration`. -function Sprite:draw (...) +function Sprite:draw (offset_x, offset_y, scale, debug) + local offset_x = offset_x or 0 + local offset_y = offset_y or 0 + local debug = debug or false + local i, q = self:getImage(), self:getQuad() + local x, y = self:getPosition() + local angle = self:getAngle() + + local scaleX = self:getHorizontalMirror()*(scale or 1) + local scaleY = self:getVerticalMirror()*(scale or 1) + + -- pixel grid ; `approx` selected to prevent floating characters on certain conditions + local approx = math.floor + if (y - math.floor(y)) > 0.5 then approx = math.ceil end + local draw_y = (approx(y) + offset_y) * scale + local draw_x = (math.floor(x) + offset_x) * scale + if i then love.graphics.setColor(255,255,255,255) - if q then love.graphics.draw(i, q, ...) - else love.graphics.draw(i, ...) end + if q then + love.graphics.draw(i, q, draw_x, draw_y, angle, scaleX, scaleY, self:getOffset()) + else + love.graphics.draw(i, draw_x, draw_y, angle, scaleX, scaleY, self:getOffset()) + end end end -- cgit v1.1 From 94f84647255e6d18f1e20ac0a1b8c8c9860b918e Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 04:20:46 +0100 Subject: Debug is obsolete in not.Sprite --- not/Sprite.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/not/Sprite.lua b/not/Sprite.lua index a8785d3..25d85f1 100644 --- a/not/Sprite.lua +++ b/not/Sprite.lua @@ -104,10 +104,9 @@ end -- If there is no Quad, it will draw entire image. It won't draw anything if there is no image. -- TODO: it doesn't follow same pattern as `not.Hero.draw`. It should implement so it can be called from `not.World`. -- TODO: change children if above changes are in effect: `not.Platform`, `not.Decoration`. -function Sprite:draw (offset_x, offset_y, scale, debug) +function Sprite:draw (offset_x, offset_y, scale) local offset_x = offset_x or 0 local offset_y = offset_y or 0 - local debug = debug or false local i, q = self:getImage(), self:getQuad() local x, y = self:getPosition() -- cgit v1.1 From fcc6dc19b495fbf21a803f10f7c4cec41d4f8a49 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 20 Mar 2017 18:20:49 +0100 Subject: Hero.nextFrame -> Hero.goToNextFrame --- not/Hero.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/not/Hero.lua b/not/Hero.lua index 7be3104..c9250e0 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -337,7 +337,7 @@ end -- Change animation of `Hero` -- default, walk, attack, attack_up, attack_down, damage -function Hero:nextFrame () +function Hero:goToNextFrame () local isDown = Controller.isDown local controlset = self:getControlSet() if self.current.repeated or not (self.frame == self.current.frames) then -- cgit v1.1 From bda0f791d64178904e655f74efce24a2f3fc2f96 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 17:20:55 +0200 Subject: Position, Fixture, Body init moved from Hero to PhysicalBody --- not/Hero.lua | 21 +++++++-------------- not/PhysicalBody.lua | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index c9250e0..4654b33 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -55,19 +55,18 @@ function Hero:init (name, world, x, y) local fileName = name or Hero.name -- INITIAL from metatable local imagePath = string.format("assets/nauts/%s.png", fileName) PhysicalBody.init(self, world, x, y, imagePath) + self:setBodyType("dynamic") + self:setBodyFixedRotation(true) -- TODO: probably should be removed or heavily changed. self.world = world self.punchcd = 0 -- TODO: move following lines to PhysicalBody, cut if not needed, refectorize to subfunctions in target class. local group = -1-#world.Nauts - self.body = love.physics.newBody(world.world, x, y, "dynamic") - self.shape = love.physics.newRectangleShape(10, 16) - self.fixture = love.physics.newFixture(self.body, self.shape, 8) - self.fixture:setUserData(self) - self.fixture:setCategory(2) - self.fixture:setMask(2) - self.fixture:setGroupIndex(group) - self.body:setFixedRotation(true) + local fixture = self:addFixture({-5,-8, 5,-8, 5,8, -5,8}, 8) + fixture:setUserData(self) + fixture:setCategory(2) + fixture:setMask(2) + fixture:setGroupIndex(group) -- Actual `Hero` initialization. self.name = name self:setAnimationsList(require("animations")) @@ -296,7 +295,6 @@ end function Hero:draw (offset_x, offset_y, scale, debug) if not self.alive then return end PhysicalBody.draw(self, offset_x, offset_y, scale, debug) - -- debug draw if debug then for _,fixture in pairs(self.body:getFixtureList()) do @@ -315,11 +313,6 @@ function Hero:draw (offset_x, offset_y, scale, debug) end end --- getPosition -function Hero:getPosition () - return self.body:getPosition() -end - -- Draw HUD of `Hero` -- elevation: 1 bottom, 0 top function Hero:drawHUD (x,y,scale,elevation) diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index bbea3ac..54d334f 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -20,6 +20,31 @@ end -- Initializator of `PhysicalBody`. function PhysicalBody:init (world, x, y, imagePath) Sprite.init(self, imagePath) + self.body = love.physics.newBody(world.world, x, y) +end + +-- Add new fixture to body. +function PhysicalBody:addFixture (shape, density) + local shape = love.physics.newPolygonShape(shape) + local fixture = love.physics.newFixture(self.body, shape, density) + return fixture +end + +-- Position-related methods. +function PhysicalBody:getPosition () + return self.body:getPosition() +end +function PhysicalBody:setPosition (x, y) + self.body:setPosition(x, y) +end + +-- Various setters from Body. +-- type: BodyType ("static", "dynamic", "kinematic") +function PhysicalBody:setBodyType (type) + self.body:setType(type) +end +function PhysicalBody:setBodyFixedRotation (bool) + self.body:setFixedRotation(bool) end -- Update of `PhysicalBody`. -- cgit v1.1 From 9af03e90acde019820021d0bc2fe546d10c25ed4 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 17:34:03 +0200 Subject: Setting group differently, moved debug draw to PhysicalBody from Hero --- not/Hero.lua | 31 ++++++++----------------------- not/PhysicalBody.lua | 12 +++++++++++- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index 4654b33..e81f10c 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -8,6 +8,7 @@ Hero = { facing = 1, max_velocity = 105, world = --[[not.World]]nil, + group = nil, -- Combat combo = 0, lives = 3, @@ -54,20 +55,20 @@ function Hero:init (name, world, x, y) -- Find imagePath basing on hero name and call super initializator. local fileName = name or Hero.name -- INITIAL from metatable local imagePath = string.format("assets/nauts/%s.png", fileName) + -- `PhysicalBody` initialization. PhysicalBody.init(self, world, x, y, imagePath) self:setBodyType("dynamic") self:setBodyFixedRotation(true) - -- TODO: probably should be removed or heavily changed. - self.world = world - self.punchcd = 0 - -- TODO: move following lines to PhysicalBody, cut if not needed, refectorize to subfunctions in target class. - local group = -1-#world.Nauts + self.group = -1-#world.Nauts + -- Main fixture initialization. local fixture = self:addFixture({-5,-8, 5,-8, 5,8, -5,8}, 8) fixture:setUserData(self) fixture:setCategory(2) fixture:setMask(2) - fixture:setGroupIndex(group) + fixture:setGroupIndex(self.group) -- Actual `Hero` initialization. + self.world = world + self.punchcd = 0 self.name = name self:setAnimationsList(require("animations")) self:createEffect("respawn") @@ -295,22 +296,6 @@ end function Hero:draw (offset_x, offset_y, scale, debug) if not self.alive then return end PhysicalBody.draw(self, offset_x, offset_y, scale, debug) - -- debug draw - if debug then - for _,fixture in pairs(self.body:getFixtureList()) do - if fixture:getCategory() == 2 then - love.graphics.setColor(137, 255, 0, 120) - else - love.graphics.setColor(137, 0, 255, 40) - end - love.graphics.polygon("fill", self.world.camera:translatePoints(self.body:getWorldPoints(fixture:getShape():getPoints()))) - end - for _,contact in pairs(self.body:getContactList()) do - love.graphics.setColor(255, 0, 0, 255) - love.graphics.setPointSize(scale) - love.graphics.points(self.world.camera:translatePoints(contact:getPositions())) - end - end end -- Draw HUD of `Hero` @@ -377,7 +362,7 @@ function Hero:hit (direction) fixture:setSensor(true) fixture:setCategory(3) fixture:setMask(1,3) - fixture:setGroupIndex(self.fixture:getGroupIndex()) + fixture:setGroupIndex(self.group) fixture:setUserData({0.08, direction}) -- sound self:playSound(4) diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 54d334f..24e87c8 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -54,6 +54,16 @@ end -- Draw of `PhysicalBody`. function PhysicalBody:draw (offset_x, offset_y, scale, debug) - -- TODO: Move debug part here from `not.Hero.draw`. Sprite.draw(self, offset_x, offset_y, scale) + if debug then + for _,fixture in pairs(self.body:getFixtureList()) do + if fixture:getCategory() == 2 then + love.graphics.setColor(137, 255, 0, 120) + else + love.graphics.setColor(137, 0, 255, 40) + end + -- TODO: `world` is not a member of `PhysicalBody` or its instance normally. + love.graphics.polygon("fill", self.world.camera:translatePoints(self.body:getWorldPoints(fixture:getShape():getPoints()))) + end + end end -- cgit v1.1 From 8fa7ec07a1a9b4307ed9b221770c91a242cd68d9 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 18:16:23 +0200 Subject: Platform is now child of PhysicalBody --- not/PhysicalBody.lua | 9 +++++-- not/Platform.lua | 74 ++++++++++++++++------------------------------------ 2 files changed, 29 insertions(+), 54 deletions(-) diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 24e87c8..7c05262 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -57,9 +57,14 @@ function PhysicalBody:draw (offset_x, offset_y, scale, debug) Sprite.draw(self, offset_x, offset_y, scale) if debug then for _,fixture in pairs(self.body:getFixtureList()) do - if fixture:getCategory() == 2 then + local category = fixture:getCategory() + if category == 1 then + love.graphics.setColor(255, 69, 0, 140) + end + if category == 2 then love.graphics.setColor(137, 255, 0, 120) - else + end + if category == 3 then love.graphics.setColor(137, 0, 255, 40) end -- TODO: `world` is not a member of `PhysicalBody` or its instance normally. diff --git a/not/Platform.lua b/not/Platform.lua index 7dcea6c..0c03e73 100644 --- a/not/Platform.lua +++ b/not/Platform.lua @@ -1,67 +1,37 @@ --- `Platform` +--- `Platform` -- Static platform physical object with a sprite. `Players` can walk on it. -- Collision category: [1] -- TODO: reformat code to follow new code patterns -- TODO: comment uncovered code parts - --- WHOLE CODE HAS FLAG OF "need a cleanup" -require "not.Sprite" - --- Metatable of `Platform` --- nils initialized in constructor Platform = { - body = nil, - shape = nil, - fixture = nil, - world = nil, + world = --[[not.World]]nil, } + +-- `Platform` is a child of `PhysicalBody`. +require "not.PhysicalBody" Platform.__index = Platform -setmetatable(Platform, Sprite) +setmetatable(Platform, PhysicalBody) -- Constructor of `Platform` function Platform: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:setImage(love.graphics.newImage(sprite)) - o:setAnimationsList(animations) - o.world = game + local o = setmetatable({}, self) + o:init(animations, shape, game, x, y, sprite) return o end --- Position -function Platform:getPosition() - return self.body:getPosition() -end - --- Draw of `Platform` --- TODO: see todos in `not.Sprite.draw`. -function Platform:draw (offset_x, offset_y, scale, debug) - Sprite.draw(self, offset_x, offset_y, 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 +-- Initializator of `Platform`. +function Platform:init (animations, shape, world, x, y, imagePath) + PhysicalBody.init(self, world, x, y, imagePath) + self:setAnimationsList(animations) + self.world = world + -- Create table of shapes if single shape is passed. + if type(shape[1]) == "number" then + shape = {shape} + end + -- Add all shapes from as fixtures to body. + for _,single in pairs(shape) do + local fixture = self:addFixture(single) + fixture:setCategory(1) + fixture:setFriction(0.2) end end \ No newline at end of file -- cgit v1.1 From 93e91c1821087b05f235ae356b7af4d8cfc3cae7 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 18:32:59 +0200 Subject: Decoration properly inherits from Sprite --- not/Decoration.lua | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/not/Decoration.lua b/not/Decoration.lua index a57c143..80f6653 100644 --- a/not/Decoration.lua +++ b/not/Decoration.lua @@ -1,27 +1,33 @@ --- TODO: follow new code template --- TODO: add comments -require "not.Sprite" +--- `Decoration` +-- Positioned sprite used to decorate maps with additional graphics. Decoration = { - world = nil, - sprite = nil, + world = --[[not.World]]nil, x = 0, y = 0 } + +-- `Decoration` is a child of `Sprite`. +require "not.Sprite" Decoration.__index = Decoration setmetatable(Decoration, Sprite) -function Decoration:new(x, y, sprite) - local o = {} - setmetatable(o, self) - o:setImage(love.graphics.newImage(sprite)) - o:setPosition(x,y) + +-- Constructor of `Decoration`. +function Decoration:new (x, y, imagePath) + local o = setmetatable({}, self) + o:init(x, y, imagePath) return o end -function Decoration:setPosition(x, y) - self.x, self.y = x, y + +-- Initializator of `Decoration`. +function Decoration:init (x, y, imagePath) + Sprite.init(self, imagePath) + self:setPosition(x, y) end -function Decoration:getPosition() + +-- Position-related methods. +function Decoration:getPosition () return self.x, self.y end -function Decoration:draw(offset_x, offset_y, scale) - Sprite.draw(self, offset_x, offset_y, scale) +function Decoration:setPosition (x, y) + self.x, self.y = x, y end \ No newline at end of file -- cgit v1.1 From e2e4164cda3b4536fcba96f5c5283eb125d2b6b1 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 18:51:51 +0200 Subject: Cloud is now child of Decoration; reworked majority of its content --- not/Cloud.lua | 105 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 49 deletions(-) diff --git a/not/Cloud.lua b/not/Cloud.lua index c9899d5..2af7d4b 100644 --- a/not/Cloud.lua +++ b/not/Cloud.lua @@ -1,64 +1,71 @@ --- `Cloud` --- That white thing moving in the background. - --- WHOLE CODE HAS FLAG OF "need a cleanup" - --- Metatable of `Cloud` --- nils initialized in constructor --- TODO: inherit from `not.Decoration` or `not.Sprite`, depending on final result of `not.Sprite`. +--- `Cloud` +-- That white thing moving in the background. +-- TODO: extends variables names to be readable. Cloud = { - x = 0, -- position horizontal - y = 0, -- position vertical t = 1, -- type (sprite number) - v = 13, -- velocity - sprite = nil, - quads = { + v = 13 -- velocity +} + +-- TODO: allow maps to use other quads and sprites for clouds +-- TODO: you know this isn't right, don't you? +local animations = { + default = { [1] = love.graphics.newQuad( 1, 1, 158,47, 478,49), - [2] = love.graphics.newQuad(160, 1, 158,47, 478,49), - [3] = love.graphics.newQuad(319, 1, 158,47, 478,49) + frames = 1, + repeated = true + }, + default2 = { + [1] = love.graphics.newQuad(160, 1, 158,47, 478,49), + frames = 1, + repeated = true + }, + default3 = { + [1] = love.graphics.newQuad(319, 1, 158,47, 478,49), + frames = 1, + repeated = true } } --- Constructor of `Cloud` -function Cloud:new(x, y, t, v) - -- Meta - local o = {} - setmetatable(o, self) - self.__index = self - -- Load spritesheet to metatable if not yet loaded - if self.sprite == nil then - self.sprite = love.graphics.newImage("assets/clouds.png") +-- `Cloud` is a child of `Decoration`. +require "not.Decoration" +Cloud.__index = Cloud +setmetatable(Cloud, Decoration) + +-- Constructor of `Cloud`. +function Cloud:new (x, y, t, v) + local o = setmetatable({}, self) + o:init(x, y, t, v) + -- Load spritesheet statically. + if self:getImage() == nil then + self:setImage(Sprite.newImage("assets/clouds.png")) end - -- Init - o.x = x or self.x - o.y = y or self.y - o.t = t or self.t - o.v = v or self.v return o end --- Position -function Cloud:getPosition() - return self.x, self.y +-- Initializator of `Cloud`. +function Cloud:init (x, y, t, v) + Decoration.init(self, x, y, nil) + self:setAnimationsList(animations) + self:setVelocity(v) + self:setType(t) end --- Update of `Cloud`, returns x for world to delete cloud after reaching right corner -function Cloud:update(dt) +-- Setters for cloud type and velocity. +function Cloud:setType (type) + local animation = "default" + if type > 1 then + animation = animation .. type + end + self:setAnimation(animation) + self.t = type +end +function Cloud:setVelocity (velocity) + self.v = velocity +end + +-- Update of `Cloud`, returns x for world to delete cloud after reaching right corner. +function Cloud:update (dt) + Decoration.update(self, dt) self.x = self.x + self.v*dt return self.x end - --- Draw `Cloud` -function Cloud:draw(offset_x, offset_y, scale) - -- locals - local offset_x = offset_x or 0 - local offset_y = offset_y or 0 - local scale = scale or 1 - 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 - -- draw - love.graphics.setColor(255,255,255,255) - love.graphics.draw(self.sprite, self.quads[self.t], draw_x, draw_y, 0, scale, scale) -end \ No newline at end of file -- cgit v1.1 From 33865425828c92bb1cf97dee8d0b0f51f9b01042 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 19:16:42 +0200 Subject: Effect is now child of Decoration. Uses Sprite methods and Decoration positioning --- effects.lua | 21 +++++++++----- not/Effect.lua | 92 ++++++++++++++++++++++------------------------------------ 2 files changed, 48 insertions(+), 65 deletions(-) diff --git a/effects.lua b/effects.lua index 6946d10..dd6d55e 100644 --- a/effects.lua +++ b/effects.lua @@ -16,14 +16,16 @@ local quads = { [2] = love.graphics.newQuad( 24, 0, 24,24, 168,120), [3] = love.graphics.newQuad( 48, 0, 24,24, 168,120), [4] = love.graphics.newQuad( 72, 0, 24,24, 168,120), - frames = 4 + frames = 4, + repeated = false }, doublejump = { [1] = love.graphics.newQuad( 0, 24, 24,24, 168,120), [2] = love.graphics.newQuad( 24, 24, 24,24, 168,120), [3] = love.graphics.newQuad( 48, 24, 24,24, 168,120), [4] = love.graphics.newQuad( 72, 24, 24,24, 168,120), - frames = 4 + frames = 4, + repeated = false }, land = { [1] = love.graphics.newQuad( 0, 48, 24,24, 168,120), @@ -31,7 +33,8 @@ local quads = { [3] = love.graphics.newQuad( 48, 48, 24,24, 168,120), [4] = love.graphics.newQuad( 72, 48, 24,24, 168,120), [5] = love.graphics.newQuad( 96, 48, 24,24, 168,120), - frames = 5 + frames = 5, + repeated = false }, respawn = { [1] = love.graphics.newQuad( 0, 72, 24,24, 168,120), @@ -41,7 +44,8 @@ local quads = { [5] = love.graphics.newQuad( 96, 72, 24,24, 168,120), [6] = love.graphics.newQuad(120, 72, 24,24, 168,120), [7] = love.graphics.newQuad(144, 72, 24,24, 168,120), - frames = 7 + frames = 7, + repeated = false }, clash = { [1] = love.graphics.newQuad( 0, 96, 24,24, 168,120), @@ -50,20 +54,23 @@ local quads = { [4] = love.graphics.newQuad( 72, 96, 24,24, 168,120), [5] = love.graphics.newQuad( 96, 96, 24,24, 168,120), [6] = love.graphics.newQuad(120, 96, 24,24, 168,120), - frames = 6 + frames = 6, + repeated = false }, trail = { [1] = love.graphics.newQuad(104, 0, 16,16, 168,120), [2] = love.graphics.newQuad(120, 0, 16,16, 168,120), [3] = love.graphics.newQuad(136, 0, 16,16, 168,120), [4] = love.graphics.newQuad(152, 0, 16,16, 168,120), - frames = 4 + frames = 4, + repeated = false }, hit = { [1] = love.graphics.newQuad(106, 18, 16,16, 168,120), [2] = love.graphics.newQuad(122, 18, 16,16, 168,120), [3] = love.graphics.newQuad(138, 18, 16,16, 168,120), - frames = 3 + frames = 3, + repeated = false } } return quads \ No newline at end of file diff --git a/not/Effect.lua b/not/Effect.lua index 7010946..1bf9ed7 100644 --- a/not/Effect.lua +++ b/not/Effect.lua @@ -1,70 +1,46 @@ --- `Effect` +--- `Effect` -- Short animation with graphics that plays in various situation. - --- Metatable of `Effect` --- nils initialized in constructor --- TODO: inherit from `not.Sprite`. --- TODO: clean-up and reformat code, see newer code for reference. +-- TODO: animation is currently slower than it used to be, check if it is ok; if not then make it possible to change it to 0.06 delay. Effect = { - x = 0, - y = 0, - delay = 0.06, - initial = nil, - frame = 1, - animation = nil, - sprite = nil, - quads = require "effects" + finished = false, } --- Construct of `Effect` -function Effect:new(name, x, y) - -- Meta - local o = {} - setmetatable(o, self) - self.__index = self - -- Load spritesheet to metatable if not yet loaded - if self.sprite == nil then - self.sprite = love.graphics.newImage("assets/effects.png") +-- `Effect` is a child of `Decoration`. +require "not.Decoration" +Effect.__index = Effect +setmetatable(Effect, Decoration) + +-- Constructor of `Effect`. +function Effect:new (name, x, y) + local o = setmetatable({}, self) + o:init(name, x, y) + -- Load spritesheet statically. + if self:getImage() == nil then + self:setImage(Sprite.newImage("assets/effects.png")) end - -- Init - o.initial = o.delay - o.animation = name - o.x = x or self.x - o.y = y or self.y return o end --- Position -function Effect:getPosition() - return self.x, self.y +-- Initializator of `Effect`. +function Effect:init (name, x, y) + Decoration.init(self, x, y, nil) + self:setAnimationsList(require("effects")) + self:setAnimation(name) end --- Animation and return flag for deletion after completion --- returns true if completed and ready to delete -function Effect:update(dt) - self.delay = self.delay - dt - if self.delay < 0 then - if self.frame < self.quads[self.animation].frames then - self.frame = self.frame + 1 - self.delay = self.delay + self.initial - else - return true -- delete - end - end - return false +-- Update of `Effect`. +-- Returns true if animation is finished and effect is ready to be deleted. +function Effect:update (dt) + Decoration.update(self, dt) + return self.finished end --- Draw me with scale and offsets, senpai -function Effect:draw(offset_x, offset_y, scale) - -- locals - local offset_x = offset_x or 0 - local offset_y = offset_y or 0 - local scale = scale or 1 - 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 - -- draw - love.graphics.setColor(255,255,255,255) - love.graphics.draw(self.sprite, self.quads[self.animation][self.frame], draw_x, draw_y, 0, scale, scale) -end \ No newline at end of file +-- Overridden from `not.Sprite`. +-- Sets finished flag if reached last frame of played animation. +function Effect:goToNextFrame () + if not (self.frame == self.current.frames) then + self.frame = (self.frame % self.current.frames) + 1 + else + self.finished = true + end +end -- cgit v1.1 From f6e0b0b7da519c610e049cdf8163d86230b7d383 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 19:35:12 +0200 Subject: Changed makefile to follow new directory tree --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 5eee011..62c3c9d 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ all: - zip not-nautz maps/*.lua config/*.lua assets/*.png assets/sounds/*.ogg assets/platforms/*.png assets/nauts/*.png assets/music/*.ogg assets/decorations/*.png assets/backgrounds/*.png *.lua gamecontrollerdb.txt settings.default + zip not-nautz not/*.lua maps/*.lua config/*.lua assets/*.png assets/sounds/*.ogg assets/platforms/*.png assets/nauts/*.png assets/music/*.ogg assets/decorations/*.png assets/backgrounds/*.png *.lua gamecontrollerdb.txt settings.default mv not-nautz.zip ../not-nautz.love clean: -- cgit v1.1 From eed0553c2f005c439a028d56d82756828e75c2ac Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 19:38:59 +0200 Subject: Hero use direct parent's update rather than distant relative's one --- not/Hero.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index e81f10c..f77e5cb 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -52,7 +52,7 @@ end -- Initializator of `Hero`. function Hero:init (name, world, x, y) - -- Find imagePath basing on hero name and call super initializator. + -- Find imagePath based on hero name. local fileName = name or Hero.name -- INITIAL from metatable local imagePath = string.format("assets/nauts/%s.png", fileName) -- `PhysicalBody` initialization. @@ -87,6 +87,7 @@ end function Hero:update (dt) -- hotfix? for destroyed bodies if self.body:isDestroyed() then return end + PhysicalBody.update(self, dt) -- locals local x, y = self.body:getLinearVelocity() local isDown = Controller.isDown @@ -143,8 +144,6 @@ function Hero:update (dt) end end - Sprite.update(self, dt) - -- # DEATH -- We all die in the end. local m = self.world.map -- cgit v1.1 From b4389dfb590862b50cc6c9ce59d3fcef9bd046b3 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 20:11:21 +0200 Subject: World comments, other comments, todos --- not/Cloud.lua | 2 +- not/Decoration.lua | 2 +- not/Effect.lua | 2 +- not/Hero.lua | 2 +- not/PhysicalBody.lua | 2 +- not/Platform.lua | 2 +- not/Player.lua | 2 +- not/World.lua | 17 +++++++++++++++-- 8 files changed, 22 insertions(+), 9 deletions(-) diff --git a/not/Cloud.lua b/not/Cloud.lua index 2af7d4b..3bc5377 100644 --- a/not/Cloud.lua +++ b/not/Cloud.lua @@ -42,7 +42,7 @@ function Cloud:new (x, y, t, v) return o end --- Initializator of `Cloud`. +-- Initializer of `Cloud`. function Cloud:init (x, y, t, v) Decoration.init(self, x, y, nil) self:setAnimationsList(animations) diff --git a/not/Decoration.lua b/not/Decoration.lua index 80f6653..9dc2bdd 100644 --- a/not/Decoration.lua +++ b/not/Decoration.lua @@ -18,7 +18,7 @@ function Decoration:new (x, y, imagePath) return o end --- Initializator of `Decoration`. +-- Initializer of `Decoration`. function Decoration:init (x, y, imagePath) Sprite.init(self, imagePath) self:setPosition(x, y) diff --git a/not/Effect.lua b/not/Effect.lua index 1bf9ed7..4051b92 100644 --- a/not/Effect.lua +++ b/not/Effect.lua @@ -21,7 +21,7 @@ function Effect:new (name, x, y) return o end --- Initializator of `Effect`. +-- Initializer of `Effect`. function Effect:init (name, x, y) Decoration.init(self, x, y, nil) self:setAnimationsList(require("effects")) diff --git a/not/Hero.lua b/not/Hero.lua index f77e5cb..47c6e33 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -50,7 +50,7 @@ function Hero:new (game, world, x, y, name) return o end --- Initializator of `Hero`. +-- Initializer of `Hero`. function Hero:init (name, world, x, y) -- Find imagePath based on hero name. local fileName = name or Hero.name -- INITIAL from metatable diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 7c05262..7b774f2 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -17,7 +17,7 @@ function PhysicalBody:new (world, x, y, imagePath) end ]] --- Initializator of `PhysicalBody`. +-- Initializer of `PhysicalBody`. function PhysicalBody:init (world, x, y, imagePath) Sprite.init(self, imagePath) self.body = love.physics.newBody(world.world, x, y) diff --git a/not/Platform.lua b/not/Platform.lua index 0c03e73..5ee2dd7 100644 --- a/not/Platform.lua +++ b/not/Platform.lua @@ -19,7 +19,7 @@ function Platform:new (game, world, x, y, shape, sprite, animations) return o end --- Initializator of `Platform`. +-- Initializer of `Platform`. function Platform:init (animations, shape, world, x, y, imagePath) PhysicalBody.init(self, world, x, y, imagePath) self:setAnimationsList(animations) diff --git a/not/Player.lua b/not/Player.lua index bcd72bc..fd1613c 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -16,7 +16,7 @@ function Player:new (...) return o end --- Initializator of `Player`. +-- Initializer of `Player`. function Player:init (...) Hero.init(self, ...) end \ No newline at end of file diff --git a/not/World.lua b/not/World.lua index 6d81918..216f9dd 100644 --- a/not/World.lua +++ b/not/World.lua @@ -1,5 +1,6 @@ -- `World` -- Used to manage physical world and everything inside it: clouds, platforms, nauts, background etc. +-- TODO: Possibly move common parts of `World` and `Menu` to abstract class `Scene`. -- WHOLE CODE HAS FLAG OF "need a cleanup" @@ -36,6 +37,7 @@ World = { } -- Constructor of `World` ZA WARUDO! +-- TODO: push stuff to initialization method. function World:new(map, nauts) -- Meta local o = {} @@ -46,6 +48,7 @@ function World:new(map, nauts) o.world = love.physics.newWorld(0, 9.81*64, true) o.world:setCallbacks(o.beginContact, o.endContact) -- Empty tables for objects + -- TODO: DEAR DEER, do you see it? local n = {} o.Nauts = n local p = {} @@ -58,7 +61,7 @@ function World:new(map, nauts) o.Decorations = d local r = {} o.Rays = r - -- Random init + -- Random init; TODO: use LOVE2D's random. math.randomseed(os.time()) -- Map local map = map or "default" @@ -86,6 +89,7 @@ function World:delete() end -- Load map from file +-- TODO: Change current map model to function-based one. function World:loadMap(name) local name = name or "default" name = "maps/" .. name .. ".lua" @@ -125,11 +129,14 @@ function World:getSpawnPosition() end -- Add new platform to the world +-- TODO: follow new parameters in `not.Platform.new` based on `not.Platform.init`. function World:createPlatform(x, y, polygon, sprite, animations) table.insert(self.Platforms, Platform:new(self, self.world, x, y, polygon, sprite, animations)) end -- Add new naut to the world +-- TODO: separate two methods for `not.Hero` and `not.Player`. +-- TODO: follow new parameters in `not.Player.new` based on `not.Player.init`. function World:createNaut(x, y, name) local naut = Hero:new(self, self.world, x, y, name) table.insert(self.Nauts, naut) @@ -137,11 +144,14 @@ function World:createNaut(x, y, name) end -- Add new decoration to the world +-- TODO: follow new parameters in `not.Decoration.new` based on `not.Decoration.init`. function World:createDecoration(x, y, sprite) table.insert(self.Decorations, Decoration:new(x, y, sprite)) end -- Add new cloud to the world +-- TODO: extend variables names to provide better readability. +-- TODO: follow new parameters in `not.Cloud.new` based on `not.Cloud.init`. function World:createCloud(x, y, t, v) table.insert(self.Clouds, Cloud:new(x, y, t, v)) end @@ -167,6 +177,8 @@ function World:randomizeCloud(outside) end -- Add an effect behind nauts +-- TODO: follow new parameters in `not.Effect.new` based on `not.Effect.init`. +-- TODO: along with `createRay` move this nearer reast of `create*` methods for readability. function World:createEffect(name, x, y) table.insert(self.Effects, Effect:new(name, x, y)) end @@ -288,7 +300,7 @@ function World:draw() -- Background love.graphics.draw(self.background, 0, 0, 0, scaler, scaler) - -- This needs to be reworked! + -- TODO: this needs to be reworked! -- Draw clouds for _,cloud in pairs(self.Clouds) do cloud:draw(offset_x, offset_y, scale) @@ -403,6 +415,7 @@ function World.endContact(a, b, coll) end -- Controller callbacks +-- TODO: names of this methods don't follow naming patterns in this project. See `Controller` and change it. function World:controlpressed(set, action, key) if key == "f6" and debug then local map = self:getMapName() -- cgit v1.1 From be64dffe9e3354fda6220a1b25251e1664cd71cc Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 21:50:40 +0200 Subject: Testing if body isn't destroyed in PhysicalBody's update --- not/Hero.lua | 2 -- not/PhysicalBody.lua | 1 + 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index 47c6e33..1b84b1c 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -85,8 +85,6 @@ end -- Update callback of `Hero` -- TODO: Explode this function (method, kek), move controler-related parts to `not.Player`, physics parts to `not.PhysicalBody`. function Hero:update (dt) - -- hotfix? for destroyed bodies - if self.body:isDestroyed() then return end PhysicalBody.update(self, dt) -- locals local x, y = self.body:getLinearVelocity() diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 7b774f2..a7abcc0 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -50,6 +50,7 @@ end -- Update of `PhysicalBody`. function PhysicalBody:update (dt) Sprite.update(self, dt) + if self.body:isDestroyed() then return end end -- Draw of `PhysicalBody`. -- cgit v1.1 From 603fac3ce18ff7df7b8d2f74d5e57cc728c0abc2 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 22:07:32 +0200 Subject: Created physics functions to influence PhysicalBody; changed Hero to use them. Comments. --- not/Hero.lua | 43 +++++++++++++++++++++++-------------------- not/PhysicalBody.lua | 19 +++++++++++++++++++ 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index 1b84b1c..1cb5e93 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -75,6 +75,7 @@ function Hero:init (name, world, x, y) end -- Control set managment +-- TODO: move these two to `not.Player`. function Hero:assignControlSet (set) self.controlset = set end @@ -87,14 +88,14 @@ end function Hero:update (dt) PhysicalBody.update(self, dt) -- locals - local x, y = self.body:getLinearVelocity() + local x, y = self:getLinearVelocity() local isDown = Controller.isDown local controlset = self:getControlSet() -- # VERTICAL MOVEMENT -- Jumping if self.jumpactive and self.jumptimer > 0 then - self.body:setLinearVelocity(x,-160) + self:setLinearVelocity(x,-160) self.jumptimer = self.jumptimer - dt end @@ -109,18 +110,18 @@ function Hero:update (dt) -- Walking if isDown(controlset, "left") then self.facing = -1 - self.body:applyForce(-250, 0) + self:applyForce(-250, 0) -- Controlled speed limit if x < -self.max_velocity then - self.body:applyForce(250, 0) + self:applyForce(250, 0) end end if isDown(controlset, "right") then self.facing = 1 - self.body:applyForce(250, 0) + self:applyForce(250, 0) -- Controlled speed limit if x > self.max_velocity then - self.body:applyForce(-250, 0) + self:applyForce(-250, 0) end end @@ -136,9 +137,9 @@ function Hero:update (dt) else face = 0 end - self.body:applyForce(40*face,0) + self:applyForce(40*face,0) if not self.inAir then - self.body:applyForce(80*face,0) + self:applyForce(80*face,0) end end @@ -163,8 +164,8 @@ function Hero:update (dt) -- # PUNCH -- Cooldown self.punchcd = self.punchcd - dt - if not self.body:isDestroyed() then -- This is weird - for _,fixture in pairs(self.body:getFixtureList()) do + if not self.body:isDestroyed() then -- TODO: This is weird + for _,fixture in pairs(self.body:getFixtureList()) do -- TODO: getFixtures from `PhysicalBody` or similar. if fixture:getUserData() ~= self then fixture:setUserData({fixture:getUserData()[1] - dt, fixture:getUserData()[2]}) if fixture:getUserData()[1] < 0 then @@ -178,9 +179,9 @@ function Hero:update (dt) 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) + self:setLinearVelocity(0,0) else - self.body:setLinearVelocity(38*self.facing,0) + self:setLinearVelocity(38*self.facing,0) end end @@ -281,7 +282,7 @@ end function Hero:getAngle () return self.angle end -function Hero:getHorizontalMirror() +function Hero:getHorizontalMirror () return self.facing end function Hero:getOffset () @@ -289,7 +290,6 @@ function Hero:getOffset () end -- Draw of `Hero` --- TODO: see `not.PhysicalBody.draw` and `not.Sprite.draw`. function Hero:draw (offset_x, offset_y, scale, debug) if not self.alive then return end PhysicalBody.draw(self, offset_x, offset_y, scale, debug) @@ -339,10 +339,12 @@ end -- Punch of `Hero` -- direction: left, right, up, down -- creates temporary fixture for player's body that acts as sensor; fixture is deleted after time set in UserData[1]; deleted by Hero:update(dt) +-- TODO: attack functions needs to be renamed, because even I have problems understanding them. function Hero:hit (direction) -- start cooldown self.punchcd = Hero.punchcd -- INITIAL from metatable -- actual punch + -- TODO: use `PhysicalBody.addFixture`. local fixture if direction == "left" then fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(-2,-6, -20,-6, -20,6, -2,6), 0) @@ -382,8 +384,8 @@ function Hero:damage (direction) vertical = 1 end self:createEffect("hit") - local x,y = self.body:getLinearVelocity() - self.body:setLinearVelocity(x,0) + local x,y = self:getLinearVelocity() + self:setLinearVelocity(x,0) self.body:applyLinearImpulse((42+10*self.combo)*horizontal, (68+10*self.combo)*vertical + 15) self:setAnimation("damage") self.combo = math.min(27, self.combo + 1) @@ -398,21 +400,22 @@ function Hero:die () self.lives = self.lives - 1 self.alive = false self.spawntimer = Hero.spawntimer -- INITIAL from metatable - self.body:setActive(false) + self:setBodyActive(false) self.world:onNautKilled(self) end -- And then respawn. Like Jon Snow. function Hero:respawn () self.alive = true - self.body:setLinearVelocity(0,0) - self.body:setPosition(self.world:getSpawnPosition()) - self.body:setActive(true) + self:setLinearVelocity(0,0) + self:setPosition(self.world:getSpawnPosition()) -- TODO: I'm not convinced about getting new position like this. + self:setBodyActive(true) self:createEffect("respawn") self:playSound(7) end -- Sounds +-- TODO: Possibly export to nonexistent SoundEmitter class. Can be used by World (Stage), too. function Hero:playSound (sfx, force) if self.alive or force then local source = love.audio.newSource(self.sfx[sfx]) diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index a7abcc0..a9ac63b 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -38,6 +38,14 @@ function PhysicalBody:setPosition (x, y) self.body:setPosition(x, y) end +-- Velocity-related methods. +function PhysicalBody:setLinearVelocity (x, y) + self.body:setLinearVelocity(x, y) +end +function PhysicalBody:getLinearVelocity () + return self.body:getLinearVelocity() +end + -- Various setters from Body. -- type: BodyType ("static", "dynamic", "kinematic") function PhysicalBody:setBodyType (type) @@ -46,6 +54,17 @@ end function PhysicalBody:setBodyFixedRotation (bool) self.body:setFixedRotation(bool) end +function PhysicalBody:setBodyActive (bool) + self.body:setActive(bool) +end + +-- Physical influence methods. +function PhysicalBody:applyLinearImpulse (x, y) + self.body:applyLinearImpulse(x, y) +end +function PhysicalBody:applyForce (x, y) + self.body:applyForce(x, y) +end -- Update of `PhysicalBody`. function PhysicalBody:update (dt) -- cgit v1.1 From cedc95538ded6ca0845f13e8ec2fdbf2b8c0c8ed Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 22:15:55 +0200 Subject: Missed applyLinearImpulse in Hero --- not/Hero.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/not/Hero.lua b/not/Hero.lua index 1cb5e93..ec7f39f 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -386,7 +386,7 @@ function Hero:damage (direction) self:createEffect("hit") local x,y = self:getLinearVelocity() self:setLinearVelocity(x,0) - self.body:applyLinearImpulse((42+10*self.combo)*horizontal, (68+10*self.combo)*vertical + 15) + self:applyLinearImpulse((42+10*self.combo)*horizontal, (68+10*self.combo)*vertical + 15) self:setAnimation("damage") self.combo = math.min(27, self.combo + 1) self.punchcd = 0.08 + self.combo*0.006 -- cgit v1.1 From 8552aee09a280f14dd84c64a0e13e3b0cb67d965 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 23:24:04 +0200 Subject: Maximum combo increased to 990 --- not/Hero.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index ec7f39f..68329ad 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -126,8 +126,8 @@ function Hero:update (dt) end -- Custom linear damping - if not isDown(controlset, "left") and - not isDown(controlset, "right") + if not isDown(controlset, "left") and + not isDown(controlset, "right") then local face = nil if x < -12 then @@ -388,7 +388,7 @@ function Hero:damage (direction) self:setLinearVelocity(x,0) self:applyLinearImpulse((42+10*self.combo)*horizontal, (68+10*self.combo)*vertical + 15) self:setAnimation("damage") - self.combo = math.min(27, self.combo + 1) + self.combo = math.min(99, self.combo + 1) self.punchcd = 0.08 + self.combo*0.006 self:playSound(2) end -- cgit v1.1 From cd025014eac8d1adf70bc3238de5c034dea80c78 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 23:56:03 +0200 Subject: Renamed jumping-related variables, removed obsoletes. --- not/Hero.lua | 37 ++++++++++++++++++------------------- not/World.lua | 4 +++- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index 68329ad..daed8fc 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -14,15 +14,14 @@ Hero = { lives = 3, spawntimer = 2, alive = true, - punchcd = 0.25, + punchCooldown = 0.25, punchdir = 0, -- a really bad thing -- Movement inAir = true, salto = false, - jumpactive = false, - jumpdouble = true, - jumptimer = 0.16, - jumpnumber = 2, + isJumping = false, + jumpTimer = 0.16, + jumpCounter = 2, -- Keys controlset = nil, -- Statics @@ -68,7 +67,7 @@ function Hero:init (name, world, x, y) fixture:setGroupIndex(self.group) -- Actual `Hero` initialization. self.world = world - self.punchcd = 0 + self.punchCooldown = 0 self.name = name self:setAnimationsList(require("animations")) self:createEffect("respawn") @@ -94,9 +93,9 @@ function Hero:update (dt) -- # VERTICAL MOVEMENT -- Jumping - if self.jumpactive and self.jumptimer > 0 then + if self.isJumping and self.jumpTimer > 0 then self:setLinearVelocity(x,-160) - self.jumptimer = self.jumptimer - dt + self.jumpTimer = self.jumpTimer - dt end -- Salto @@ -163,7 +162,7 @@ function Hero:update (dt) -- # PUNCH -- Cooldown - self.punchcd = self.punchcd - dt + self.punchCooldown = self.punchCooldown - dt if not self.body:isDestroyed() then -- TODO: This is weird for _,fixture in pairs(self.body:getFixtureList()) do -- TODO: getFixtures from `PhysicalBody` or similar. if fixture:getUserData() ~= self then @@ -185,7 +184,7 @@ function Hero:update (dt) end end - if self.punchcd <= 0 and self.punchdir == 1 then + if self.punchCooldown <= 0 and self.punchdir == 1 then self.punchdir = 0 end end @@ -197,9 +196,9 @@ function Hero:controlpressed (set, action, key) local controlset = self:getControlSet() -- Jumping if action == "jump" then - if self.jumpnumber > 0 then + if self.jumpCounter > 0 then -- General jump logics - self.jumpactive = true + self.isJumping = true --self:playSound(6) -- Spawn proper effect if not self.inAir then @@ -208,7 +207,7 @@ function Hero:controlpressed (set, action, key) self:createEffect("doublejump") end -- Start salto if last jump - if self.jumpnumber == 1 then + if self.jumpCounter == 1 then self.salto = true end -- Animation clear @@ -218,7 +217,7 @@ function Hero:controlpressed (set, action, key) self:setAnimation("default") end -- Remove jump - self.jumpnumber = self.jumpnumber - 1 + self.jumpCounter = self.jumpCounter - 1 end end @@ -231,7 +230,7 @@ function Hero:controlpressed (set, action, key) end -- Punching - if action == "attack" and self.punchcd <= 0 then + if action == "attack" and self.punchCooldown <= 0 then local f = self.facing self.salto = false if isDown(controlset, "up") then @@ -266,8 +265,8 @@ function Hero:controlreleased (set, action, key) local controlset = self:getControlSet() -- Jumping if action == "jump" then - self.jumpactive = false - self.jumptimer = Hero.jumptimer -- take initial from metatable + self.isJumping = false + self.jumpTimer = Hero.jumpTimer -- take initial from metatable end -- Walking if (action == "left" or action == "right") and not @@ -342,7 +341,7 @@ end -- TODO: attack functions needs to be renamed, because even I have problems understanding them. function Hero:hit (direction) -- start cooldown - self.punchcd = Hero.punchcd -- INITIAL from metatable + self.punchCooldown = Hero.punchCooldown -- INITIAL from metatable -- actual punch -- TODO: use `PhysicalBody.addFixture`. local fixture @@ -389,7 +388,7 @@ function Hero:damage (direction) self:applyLinearImpulse((42+10*self.combo)*horizontal, (68+10*self.combo)*vertical + 15) self:setAnimation("damage") self.combo = math.min(99, self.combo + 1) - self.punchcd = 0.08 + self.combo*0.006 + self.punchCooldown = 0.08 + self.combo*0.006 self:playSound(2) end diff --git a/not/World.lua b/not/World.lua index 216f9dd..b7bd48c 100644 --- a/not/World.lua +++ b/not/World.lua @@ -386,10 +386,12 @@ function World.beginContact(a, b, coll) if a:getCategory() == 1 then local x,y = coll:getNormal() if y < -0.6 then + -- TODO: remove debug messages + -- TODO: move landing to `not.Hero` print(b:getUserData().name .. " is not in air") -- Move them to Hero b:getUserData().inAir = false - b:getUserData().jumpnumber = 2 + b:getUserData().jumpCounter = 2 b:getUserData().salto = false b:getUserData():createEffect("land") end -- cgit v1.1 From 94fe36185b24315abccc55477c92961adf4d409c Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 4 Apr 2017 12:49:51 +0200 Subject: Punching method renamed, updated to use new stuff --- not/Hero.lua | 44 ++++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index daed8fc..e28c2ef 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -238,22 +238,22 @@ function Hero:controlpressed (set, action, key) if self.current ~= self.animations.damage then self:setAnimation("attack_up") end - self:hit("up") + self:punch("up") elseif isDown(controlset, "down") then -- Punch down if self.current ~= self.animations.damage then self:setAnimation("attack_down") end - self:hit("down") + self:punch("down") else -- Punch horizontal if self.current ~= self.animations.damage then self:setAnimation("attack") end if f == 1 then - self:hit("right") + self:punch("right") else - self:hit("left") + self:punch("left") end self.punchdir = 1 end @@ -335,39 +335,31 @@ function Hero:createEffect (name) end end --- Punch of `Hero` --- direction: left, right, up, down --- creates temporary fixture for player's body that acts as sensor; fixture is deleted after time set in UserData[1]; deleted by Hero:update(dt) --- TODO: attack functions needs to be renamed, because even I have problems understanding them. -function Hero:hit (direction) - -- start cooldown +-- Creates temporary fixture for hero's body that acts as sensor. +-- direction: ("left", "right", "up", "down") +-- Sensor fixture is deleted after time set in UserData[1]; deleted by `not.Hero.update`. +-- TODO: Magic numbers present in `not.Hero.punch`. +function Hero:punch (direction) self.punchCooldown = Hero.punchCooldown -- INITIAL from metatable - -- actual punch - -- TODO: use `PhysicalBody.addFixture`. - local fixture - if direction == "left" then - fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(-2,-6, -20,-6, -20,6, -2,6), 0) - end - if direction == "right" then - fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(2,-6, 20,-6, 20,6, 2,6), 0) - end - if direction == "up" then - fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(-8,-4, -8,-20, 8,-20, 8,-4), 0) - end - if direction == "down" then - fixture = love.physics.newFixture(self.body, love.physics.newPolygonShape(-8,4, -8,20, 8,20, 8,4), 0) - end + -- Choose shape based on punch direction. + local shape + if direction == "left" then shape = {-2,-6, -20,-6, -20,6, -2,6} end + if direction == "right" then shape = {2,-6, 20,-6, 20,6, 2,6} end + if direction == "up" then shape = {-8,-4, -8,-20, 8,-20, 8,-4} end + if direction == "down" then shape = {-8,4, -8,20, 8,20, 8,4} end + -- Create and set sensor fixture. + local fixture = self:addFixture(shape, 0) fixture:setSensor(true) fixture:setCategory(3) fixture:setMask(1,3) fixture:setGroupIndex(self.group) fixture:setUserData({0.08, direction}) - -- sound self:playSound(4) end -- Taking damage of `Hero` by successful hit test -- currently called from World's startContact +-- TODO: attack functions needs to be renamed, because even I have problems understanding them. function Hero:damage (direction) local horizontal, vertical = 0, 0 if direction == "left" then -- cgit v1.1 From 7a560cee7e7f0620656a63e91f05fbe898919246 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 4 Apr 2017 13:11:33 +0200 Subject: Kek, never commit late night. Fail statement back to not.Hero.update --- not/Hero.lua | 1 + not/PhysicalBody.lua | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/not/Hero.lua b/not/Hero.lua index e28c2ef..cddf864 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -86,6 +86,7 @@ end -- TODO: Explode this function (method, kek), move controler-related parts to `not.Player`, physics parts to `not.PhysicalBody`. function Hero:update (dt) PhysicalBody.update(self, dt) + if self.body:isDestroyed() then return end -- locals local x, y = self:getLinearVelocity() local isDown = Controller.isDown diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index a9ac63b..e9625fa 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -69,7 +69,6 @@ end -- Update of `PhysicalBody`. function PhysicalBody:update (dt) Sprite.update(self, dt) - if self.body:isDestroyed() then return end end -- Draw of `PhysicalBody`. -- cgit v1.1 From 10db7a170cf28db93740448bba76f7a9cd452664 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 4 Apr 2017 13:31:31 +0200 Subject: Combo is held the same way as shown now --- not/Hero.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index cddf864..7b968ab 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -305,7 +305,7 @@ function Hero:drawHUD (x,y,scale,elevation) love.graphics.draw(self.portrait_sprite, self.portrait_sheet[self.name], (x+2)*scale, (y+3)*scale, 0, scale, scale) local dy = 30 * elevation love.graphics.setFont(Font) - love.graphics.print((self.combo*10).."%",(x+2)*scale,(y-3+dy)*scale,0,scale,scale) + love.graphics.print((self.combo).."%",(x+2)*scale,(y-3+dy)*scale,0,scale,scale) love.graphics.print(math.max(0, self.lives),(x+24)*scale,(y-3+dy)*scale,0,scale,scale) end end @@ -378,10 +378,10 @@ function Hero:damage (direction) self:createEffect("hit") local x,y = self:getLinearVelocity() self:setLinearVelocity(x,0) - self:applyLinearImpulse((42+10*self.combo)*horizontal, (68+10*self.combo)*vertical + 15) + self:applyLinearImpulse((42+self.combo)*horizontal, (68+self.combo)*vertical + 15) self:setAnimation("damage") - self.combo = math.min(99, self.combo + 1) - self.punchCooldown = 0.08 + self.combo*0.006 + self.combo = math.min(999, self.combo + 10) + self.punchCooldown = 0.08 + self.combo*0.0006 self:playSound(2) end -- cgit v1.1 From 5c51b6e4d39bc55887f94dc65e58fd1765d86c1c Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 4 Apr 2017 14:30:15 +0200 Subject: First steps to move player-input logics into Player from Hero --- not/Hero.lua | 13 +------------ not/Player.lua | 22 +++++++++++++++++++--- not/World.lua | 6 +++--- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index 7b968ab..a0758ee 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -1,5 +1,5 @@ --- `Hero` --- Hero (naut) entity that exists in a game world. +-- Hero (often referred to as: "naut") entity that exists in a game world. -- Collision category: [2] Hero = { -- General and physics @@ -22,8 +22,6 @@ Hero = { isJumping = false, jumpTimer = 0.16, jumpCounter = 2, - -- Keys - controlset = nil, -- Statics portrait_sprite = nil, portrait_frame = nil, @@ -73,15 +71,6 @@ function Hero:init (name, world, x, y) self:createEffect("respawn") end --- Control set managment --- TODO: move these two to `not.Player`. -function Hero:assignControlSet (set) - self.controlset = set -end -function Hero:getControlSet () - return self.controlset -end - -- Update callback of `Hero` -- TODO: Explode this function (method, kek), move controler-related parts to `not.Player`, physics parts to `not.PhysicalBody`. function Hero:update (dt) diff --git a/not/Player.lua b/not/Player.lua index fd1613c..373505d 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -2,6 +2,7 @@ -- Special `not.Hero` controllable by a player. Player = { -- TODO: move functions and properties related to controls from `not.Hero`. + controlSet = --[[Controller.sets.*]]nil, } -- `Player` is a child of `Hero`. @@ -10,13 +11,28 @@ Player.__index = Player setmetatable(Player, Hero) -- Constructor of `Player`. -function Player:new (...) +-- TODO: I'm sure it is a duplicate, but `not.World.create*` methods need to pass proper parameters. +function Player:new (game, world, x, y, name) local o = setmetatable({}, self) - o:init(...) + o:init(name, game, x, y) + -- Load portraits statically to `not.Hero`. + -- TODO: this is heresy, put it into `load` method or something similar. + if Hero.portrait_sprite == nil then + Hero.portrait_sprite = love.graphics.newImage("assets/portraits.png") + Hero.portrait_frame = love.graphics.newImage("assets/menu.png") + end return o end -- Initializer of `Player`. function Player:init (...) Hero.init(self, ...) -end \ No newline at end of file +end + +-- Controller set manipulation. +function Player:assignControlSet (set) + self.controlset = set +end +function Player:getControlSet () + return self.controlset +end diff --git a/not/World.lua b/not/World.lua index b7bd48c..44923bb 100644 --- a/not/World.lua +++ b/not/World.lua @@ -5,7 +5,7 @@ -- WHOLE CODE HAS FLAG OF "need a cleanup" require "not.Platform" -require "not.Hero" +require "not.Player" require "not.Cloud" require "not.Effect" require "not.Decoration" @@ -136,9 +136,9 @@ end -- Add new naut to the world -- TODO: separate two methods for `not.Hero` and `not.Player`. --- TODO: follow new parameters in `not.Player.new` based on `not.Player.init`. +-- TODO: follow new parameters in `not.(Player/Hero).new` based on `not.(Player/Hero).init`. function World:createNaut(x, y, name) - local naut = Hero:new(self, self.world, x, y, name) + local naut = Player:new(self, self.world, x, y, name) table.insert(self.Nauts, naut) return naut end -- cgit v1.1 From 8e11bf89f1abe547c30f7d5ac39bf0d7ed555f7e Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 5 Apr 2017 18:43:14 +0200 Subject: Some of World's create methods are now following new parameter orders of entities constructors --- not/Platform.lua | 2 +- not/Player.lua | 2 +- not/World.lua | 57 ++++++++++++++++++++++++++++---------------------------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/not/Platform.lua b/not/Platform.lua index 5ee2dd7..3748c47 100644 --- a/not/Platform.lua +++ b/not/Platform.lua @@ -13,7 +13,7 @@ Platform.__index = Platform setmetatable(Platform, PhysicalBody) -- Constructor of `Platform` -function Platform:new (game, world, x, y, shape, sprite, animations) +function Platform:new (animations, shape, game, x, y, sprite) local o = setmetatable({}, self) o:init(animations, shape, game, x, y, sprite) return o diff --git a/not/Player.lua b/not/Player.lua index 373505d..5fc2adc 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -12,7 +12,7 @@ setmetatable(Player, Hero) -- Constructor of `Player`. -- TODO: I'm sure it is a duplicate, but `not.World.create*` methods need to pass proper parameters. -function Player:new (game, world, x, y, name) +function Player:new (name, game, x, y) local o = setmetatable({}, self) o:init(name, game, x, y) -- Load portraits statically to `not.Hero`. diff --git a/not/World.lua b/not/World.lua index 44923bb..fc5e229 100644 --- a/not/World.lua +++ b/not/World.lua @@ -38,7 +38,7 @@ World = { -- Constructor of `World` ZA WARUDO! -- TODO: push stuff to initialization method. -function World:new(map, nauts) +function World:new (map, nauts) -- Meta local o = {} setmetatable(o, self) @@ -76,7 +76,7 @@ function World:new(map, nauts) end -- The end of the world -function World:delete() +function World:delete () self.world:destroy() for _,platform in pairs(self.Platforms) do platform:delete() @@ -90,7 +90,7 @@ end -- Load map from file -- TODO: Change current map model to function-based one. -function World:loadMap(name) +function World:loadMap (name) local name = name or "default" name = "maps/" .. name .. ".lua" local map = love.filesystem.load(name) @@ -114,7 +114,7 @@ function World:loadMap(name) end -- Spawn all the nauts for the round -function World:spawnNauts(nauts) +function World:spawnNauts (nauts) for _,naut in pairs(nauts) do local x,y = self:getSpawnPosition() local spawn = self:createNaut(x, y, naut[1]) @@ -123,41 +123,40 @@ function World:spawnNauts(nauts) end -- Get respawn location -function World:getSpawnPosition() +function World:getSpawnPosition () local n = math.random(1, #self.map.respawns) return self.map.respawns[n].x, self.map.respawns[n].y end -- Add new platform to the world --- TODO: follow new parameters in `not.Platform.new` based on `not.Platform.init`. -function World:createPlatform(x, y, polygon, sprite, animations) - table.insert(self.Platforms, Platform:new(self, self.world, x, y, polygon, sprite, animations)) +-- TODO: it would be nice if function parameters would be same as `not.Platform.new`. +function World:createPlatform (x, y, polygon, sprite, animations) + table.insert(self.Platforms, Platform:new(animations, polygon, self, x, y, sprite)) end -- Add new naut to the world -- TODO: separate two methods for `not.Hero` and `not.Player`. --- TODO: follow new parameters in `not.(Player/Hero).new` based on `not.(Player/Hero).init`. -function World:createNaut(x, y, name) - local naut = Player:new(self, self.world, x, y, name) +function World:createNaut (x, y, name) + local naut = Player:new(name, self, x, y) table.insert(self.Nauts, naut) return naut end -- Add new decoration to the world --- TODO: follow new parameters in `not.Decoration.new` based on `not.Decoration.init`. -function World:createDecoration(x, y, sprite) +-- TODO: `not.World.create*` functions often have different naming for parameters. It is not ground-breaking but it makes reading code harder for no good reason. +function World:createDecoration (x, y, sprite) table.insert(self.Decorations, Decoration:new(x, y, sprite)) end -- Add new cloud to the world -- TODO: extend variables names to provide better readability. -- TODO: follow new parameters in `not.Cloud.new` based on `not.Cloud.init`. -function World:createCloud(x, y, t, v) +function World:createCloud (x, y, t, v) table.insert(self.Clouds, Cloud:new(x, y, t, v)) end -- Randomize Cloud creation -function World:randomizeCloud(outside) +function World:randomizeCloud (outside) if outside == nil then outside = true else @@ -179,18 +178,18 @@ end -- Add an effect behind nauts -- TODO: follow new parameters in `not.Effect.new` based on `not.Effect.init`. -- TODO: along with `createRay` move this nearer reast of `create*` methods for readability. -function World:createEffect(name, x, y) +function World:createEffect (name, x, y) table.insert(self.Effects, Effect:new(name, x, y)) end -- Add a ray -function World:createRay(naut) +function World:createRay (naut) table.insert(self.Rays, Ray:new(naut, self)) end -- get Nauts functions -- more than -1 lives -function World:getNautsPlayable() +function World:getNautsPlayable () local nauts = {} for _,naut in pairs(self.Nauts) do if naut.lives > -1 then @@ -200,7 +199,7 @@ function World:getNautsPlayable() return nauts end -- are alive -function World:getNautsAlive() +function World:getNautsAlive () local nauts = {} for _,naut in self.Nauts do if naut.alive then @@ -210,17 +209,17 @@ function World:getNautsAlive() return nauts end -- all of them -function World:getNautsAll() +function World:getNautsAll () return self.Nauts end -- get Map name -function World:getMapName() +function World:getMapName () return self.map.name end -- Event: when player is killed -function World:onNautKilled(naut) +function World:onNautKilled (naut) self.camera:startShake() self:createRay(naut) local nauts = self:getNautsPlayable() @@ -232,14 +231,14 @@ function World:onNautKilled(naut) end end -function World:getBounce(f) +function World:getBounce (f) local f = f or 1 return math.sin(self.win_move*f*math.pi) end -- LÖVE2D callbacks -- Update ZU WARUDO -function World:update(dt) +function World:update (dt) -- Physical world self.world:update(dt) -- Camera @@ -291,7 +290,7 @@ function World:update(dt) end end -- Draw -function World:draw() +function World:draw () -- Camera stuff local offset_x, offset_y = self.camera:getOffsets() local scale = self.camera.scale @@ -382,7 +381,7 @@ end -- Box2D callbacks -- beginContact -function World.beginContact(a, b, coll) +function World.beginContact (a, b, coll) if a:getCategory() == 1 then local x,y = coll:getNormal() if y < -0.6 then @@ -408,7 +407,7 @@ function World.beginContact(a, b, coll) end end -- endContact -function World.endContact(a, b, coll) +function World.endContact (a, b, coll) if a:getCategory() == 1 then print(b:getUserData().name .. " is in air") -- Move them to Hero @@ -418,7 +417,7 @@ end -- Controller callbacks -- TODO: names of this methods don't follow naming patterns in this project. See `Controller` and change it. -function World:controlpressed(set, action, key) +function World:controlpressed (set, action, key) if key == "f6" and debug then local map = self:getMapName() local nauts = {} @@ -432,7 +431,7 @@ function World:controlpressed(set, action, key) naut:controlpressed(set, action, key) end end -function World:controlreleased(set, action, key) +function World:controlreleased (set, action, key) for k,naut in pairs(self:getNautsAll()) do naut:controlreleased(set, action, key) end -- cgit v1.1 From 527901f599c79047ab9a12fbc065a93faa8f872e Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 5 Apr 2017 19:32:26 +0200 Subject: Moved most player-input-related methods from Hero to Player --- not/Hero.lua | 150 +++------------------------------------------------------ not/Player.lua | 142 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 148 insertions(+), 144 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index a0758ee..760a881 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -72,21 +72,9 @@ function Hero:init (name, world, x, y) end -- Update callback of `Hero` --- TODO: Explode this function (method, kek), move controler-related parts to `not.Player`, physics parts to `not.PhysicalBody`. function Hero:update (dt) PhysicalBody.update(self, dt) if self.body:isDestroyed() then return end - -- locals - local x, y = self:getLinearVelocity() - local isDown = Controller.isDown - local controlset = self:getControlSet() - - -- # VERTICAL MOVEMENT - -- Jumping - if self.isJumping and self.jumpTimer > 0 then - self:setLinearVelocity(x,-160) - self.jumpTimer = self.jumpTimer - dt - end -- Salto if self.salto and (self.current == self.animations.walk or self.current == self.animations.default) then @@ -95,54 +83,18 @@ function Hero:update (dt) self.angle = 0 end - -- # HORIZONTAL MOVEMENT - -- Walking - if isDown(controlset, "left") then - self.facing = -1 - self:applyForce(-250, 0) - -- Controlled speed limit - if x < -self.max_velocity then - self:applyForce(250, 0) - end - end - if isDown(controlset, "right") then - self.facing = 1 - self:applyForce(250, 0) - -- Controlled speed limit - if x > self.max_velocity then - self:applyForce(-250, 0) - end - end - - -- Custom linear damping - if not isDown(controlset, "left") and - not isDown(controlset, "right") - then - local face = nil - if x < -12 then - face = 1 - elseif x > 12 then - face = -1 - else - face = 0 - end - self:applyForce(40*face,0) - if not self.inAir then - self:applyForce(80*face,0) - end - end - - -- # DEATH - -- We all die in the end. + -- Could you please die? + -- TODO: World/Map function for testing if Point is inside playable area. local m = self.world.map - if (self.body:getX() < m.center_x - m.width*1.5 or self.body:getX() > m.center_x + m.width*1.5 or - self.body:getY() < m.center_y - m.height*1.5 or self.body:getY() > m.center_y + m.height*1.5) and + local x, y = self:getPosition() + if (x < m.center_x - m.width*1.5 or x > m.center_x + m.width*1.5 or + y < m.center_y - m.height*1.5 or y > m.center_y + m.height*1.5) and self.alive then self:die() end - -- respawn + -- Respawn timer. if self.spawntimer > 0 then self.spawntimer = self.spawntimer - dt end @@ -179,94 +131,6 @@ function Hero:update (dt) end end --- Controller callbacks -function Hero:controlpressed (set, action, key) - if set ~= self:getControlSet() then return end - local isDown = Controller.isDown - local controlset = self:getControlSet() - -- Jumping - if action == "jump" then - if self.jumpCounter > 0 then - -- General jump logics - self.isJumping = true - --self:playSound(6) - -- Spawn proper effect - if not self.inAir then - self:createEffect("jump") - else - self:createEffect("doublejump") - end - -- Start salto if last jump - if self.jumpCounter == 1 then - self.salto = true - end - -- Animation clear - if (self.current == self.animations.attack) or - (self.current == self.animations.attack_up) or - (self.current == self.animations.attack_down) then - self:setAnimation("default") - end - -- Remove jump - self.jumpCounter = self.jumpCounter - 1 - end - end - - -- Walking - if (action == "left" or action == "right") and - (self.current ~= self.animations.attack) and - (self.current ~= self.animations.attack_up) and - (self.current ~= self.animations.attack_down) then - self:setAnimation("walk") - end - - -- Punching - if action == "attack" and self.punchCooldown <= 0 then - local f = self.facing - self.salto = false - if isDown(controlset, "up") then - -- Punch up - if self.current ~= self.animations.damage then - self:setAnimation("attack_up") - end - self:punch("up") - elseif isDown(controlset, "down") then - -- Punch down - if self.current ~= self.animations.damage then - self:setAnimation("attack_down") - end - self:punch("down") - else - -- Punch horizontal - if self.current ~= self.animations.damage then - self:setAnimation("attack") - end - if f == 1 then - self:punch("right") - else - self:punch("left") - end - self.punchdir = 1 - end - end -end -function Hero:controlreleased (set, action, key) - if set ~= self:getControlSet() then return end - local isDown = Controller.isDown - local controlset = self:getControlSet() - -- Jumping - if action == "jump" then - self.isJumping = false - self.jumpTimer = Hero.jumpTimer -- take initial from metatable - end - -- Walking - if (action == "left" or action == "right") and not - (isDown(controlset, "left") or isDown(controlset, "right")) and - self.current == self.animations.walk - then - self:setAnimation("default") - end -end - -- TODO: comment them and place them somewhere properly function Hero:getAngle () return self.angle @@ -275,7 +139,7 @@ function Hero:getHorizontalMirror () return self.facing end function Hero:getOffset () - return 12,15 -- TODO: WHY? How about creating body as polygon and using 0,0 instead. LIKE EVERYWHERE ELSE? Make it obsolete both in here and in `not.Sprite`. + return 12,15 end -- Draw of `Hero` diff --git a/not/Player.lua b/not/Player.lua index 5fc2adc..2bee903 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -11,7 +11,6 @@ Player.__index = Player setmetatable(Player, Hero) -- Constructor of `Player`. --- TODO: I'm sure it is a duplicate, but `not.World.create*` methods need to pass proper parameters. function Player:new (name, game, x, y) local o = setmetatable({}, self) o:init(name, game, x, y) @@ -36,3 +35,144 @@ end function Player:getControlSet () return self.controlset end + +-- Check if control of assigned controller is pressed. +function Player:isControlDown (control) + return Controller.isDown(self:getControlSet(), control) +end + +-- Update of `Player`. +function Player:update (dt) + local x, y = self:getLinearVelocity() + Hero.update(self, dt) -- TODO: It would be probably a good idea to add return to update functions to terminate if something goes badly in parent's update. + + -- Jumping. + if self.isJumping and self.jumpTimer > 0 then + self:setLinearVelocity(x,-160) + self.jumpTimer = self.jumpTimer - dt + end + + -- Walking. + if self:isControlDown("left") then + self.facing = -1 + self:applyForce(-250, 0) + -- Controlled speed limit + if x < -self.max_velocity then + self:applyForce(250, 0) + end + end + if self:isControlDown("right") then + self.facing = 1 + self:applyForce(250, 0) + -- Controlled speed limit + if x > self.max_velocity then + self:applyForce(-250, 0) + end + end + + -- Limiting walking speed. + if not self:isControlDown("left") and + not self:isControlDown("right") + then + local face = nil + if x < -12 then + face = 1 + elseif x > 12 then + face = -1 + else + face = 0 + end + self:applyForce(40*face,0) + if not self.inAir then + self:applyForce(80*face,0) + end + end +end + +-- Controller callbacks. +function Player:controlpressed (set, action, key) + if set ~= self:getControlSet() then return end + local isDown = Controller.isDown + local controlset = self:getControlSet() + -- Jumping + if action == "jump" then + if self.jumpCounter > 0 then + -- General jump logics + self.isJumping = true + --self:playSound(6) + -- Spawn proper effect + if not self.inAir then + self:createEffect("jump") + else + self:createEffect("doublejump") + end + -- Start salto if last jump + if self.jumpCounter == 1 then + self.salto = true + end + -- Animation clear + if (self.current == self.animations.attack) or + (self.current == self.animations.attack_up) or + (self.current == self.animations.attack_down) then + self:setAnimation("default") + end + -- Remove jump + self.jumpCounter = self.jumpCounter - 1 + end + end + + -- Walking + if (action == "left" or action == "right") and + (self.current ~= self.animations.attack) and + (self.current ~= self.animations.attack_up) and + (self.current ~= self.animations.attack_down) then + self:setAnimation("walk") + end + + -- Punching + if action == "attack" and self.punchCooldown <= 0 then + local f = self.facing + self.salto = false + if isDown(controlset, "up") then + -- Punch up + if self.current ~= self.animations.damage then + self:setAnimation("attack_up") + end + self:punch("up") + elseif isDown(controlset, "down") then + -- Punch down + if self.current ~= self.animations.damage then + self:setAnimation("attack_down") + end + self:punch("down") + else + -- Punch horizontal + if self.current ~= self.animations.damage then + self:setAnimation("attack") + end + if f == 1 then + self:punch("right") + else + self:punch("left") + end + self.punchdir = 1 + end + end +end +function Player:controlreleased (set, action, key) + if set ~= self:getControlSet() then return end + local isDown = Controller.isDown + local controlset = self:getControlSet() + -- Jumping + if action == "jump" then + self.isJumping = false + self.jumpTimer = Hero.jumpTimer -- take initial from metatable + end + -- Walking + if (action == "left" or action == "right") and not + (isDown(controlset, "left") or isDown(controlset, "right")) and + self.current == self.animations.walk + then + self:setAnimation("default") + end +end -- cgit v1.1 From a46bdb0673461a69fe4467f794f0ddaab9449f85 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 5 Apr 2017 19:45:59 +0200 Subject: Hero no longer uses controler-related functions/methods --- not/Hero.lua | 6 ++---- not/Player.lua | 31 +++++++++++++++---------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index 760a881..6d0a202 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -20,6 +20,7 @@ Hero = { inAir = true, salto = false, isJumping = false, + isWalking = false, jumpTimer = 0.16, jumpCounter = 2, -- Statics @@ -166,12 +167,9 @@ end -- Change animation of `Hero` -- default, walk, attack, attack_up, attack_down, damage function Hero:goToNextFrame () - local isDown = Controller.isDown - local controlset = self:getControlSet() if self.current.repeated or not (self.frame == self.current.frames) then self.frame = (self.frame % self.current.frames) + 1 - elseif isDown(controlset, "right") or isDown(controlset, "left") then - -- If nonrepeatable animation is finished and player is walking + elseif self.isWalking then self:setAnimation("walk") elseif self.current == self.animations.damage then self:setAnimation("default") diff --git a/not/Player.lua b/not/Player.lua index 2bee903..515684f 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -92,8 +92,6 @@ end -- Controller callbacks. function Player:controlpressed (set, action, key) if set ~= self:getControlSet() then return end - local isDown = Controller.isDown - local controlset = self:getControlSet() -- Jumping if action == "jump" then if self.jumpCounter > 0 then @@ -122,24 +120,26 @@ function Player:controlpressed (set, action, key) end -- Walking - if (action == "left" or action == "right") and - (self.current ~= self.animations.attack) and - (self.current ~= self.animations.attack_up) and - (self.current ~= self.animations.attack_down) then - self:setAnimation("walk") + if (action == "left" or action == "right") then + self.isWalking = true + if (self.current ~= self.animations.attack) and + (self.current ~= self.animations.attack_up) and + (self.current ~= self.animations.attack_down) then + self:setAnimation("walk") + end end -- Punching if action == "attack" and self.punchCooldown <= 0 then local f = self.facing self.salto = false - if isDown(controlset, "up") then + if self:isControlDown("up") then -- Punch up if self.current ~= self.animations.damage then self:setAnimation("attack_up") end self:punch("up") - elseif isDown(controlset, "down") then + elseif self:isControlDown("down") then -- Punch down if self.current ~= self.animations.damage then self:setAnimation("attack_down") @@ -161,18 +161,17 @@ function Player:controlpressed (set, action, key) end function Player:controlreleased (set, action, key) if set ~= self:getControlSet() then return end - local isDown = Controller.isDown - local controlset = self:getControlSet() -- Jumping if action == "jump" then self.isJumping = false self.jumpTimer = Hero.jumpTimer -- take initial from metatable end -- Walking - if (action == "left" or action == "right") and not - (isDown(controlset, "left") or isDown(controlset, "right")) and - self.current == self.animations.walk - then - self:setAnimation("default") + if (action == "left" or action == "right") then + self.isWalking = false + if not (self:isControlDown("left") or self:isControlDown("right")) and + self.current == self.animations.walk then + self:setAnimation("default") + end end end -- cgit v1.1 From 5ed018c810a5433851fefc2c45792de1da7e7ca8 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 01:01:07 +0200 Subject: Controller-related methods and variables in Player renamed --- not/Player.lua | 16 ++++++++-------- not/World.lua | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/not/Player.lua b/not/Player.lua index 515684f..719b77e 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -2,7 +2,7 @@ -- Special `not.Hero` controllable by a player. Player = { -- TODO: move functions and properties related to controls from `not.Hero`. - controlSet = --[[Controller.sets.*]]nil, + controllerSet = --[[Controller.sets.*]]nil, } -- `Player` is a child of `Hero`. @@ -29,16 +29,16 @@ function Player:init (...) end -- Controller set manipulation. -function Player:assignControlSet (set) - self.controlset = set +function Player:assignControllerSet (set) + self.controllerSet = set end -function Player:getControlSet () - return self.controlset +function Player:getControllerSet () + return self.controllerSet end -- Check if control of assigned controller is pressed. function Player:isControlDown (control) - return Controller.isDown(self:getControlSet(), control) + return Controller.isDown(self:getControllerSet(), control) end -- Update of `Player`. @@ -91,7 +91,7 @@ end -- Controller callbacks. function Player:controlpressed (set, action, key) - if set ~= self:getControlSet() then return end + if set ~= self:getControllerSet() then return end -- Jumping if action == "jump" then if self.jumpCounter > 0 then @@ -160,7 +160,7 @@ function Player:controlpressed (set, action, key) end end function Player:controlreleased (set, action, key) - if set ~= self:getControlSet() then return end + if set ~= self:getControllerSet() then return end -- Jumping if action == "jump" then self.isJumping = false diff --git a/not/World.lua b/not/World.lua index fc5e229..8aa9d28 100644 --- a/not/World.lua +++ b/not/World.lua @@ -118,7 +118,7 @@ function World:spawnNauts (nauts) for _,naut in pairs(nauts) do local x,y = self:getSpawnPosition() local spawn = self:createNaut(x, y, naut[1]) - spawn:assignControlSet(naut[2]) + spawn:assignControllerSet(naut[2]) end end -- cgit v1.1 From 2508af1856d4b30678e11fa610c0449bf2135ed0 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 16:09:50 +0200 Subject: Hero.alive -> Hero.isAlive; World.init method --- not/Hero.lua | 16 ++++++------ not/World.lua | 81 ++++++++++++++++++++++++++--------------------------------- 2 files changed, 44 insertions(+), 53 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index 6d0a202..7c2555a 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -13,7 +13,7 @@ Hero = { combo = 0, lives = 3, spawntimer = 2, - alive = true, + isAlive = true, punchCooldown = 0.25, punchdir = 0, -- a really bad thing -- Movement @@ -90,7 +90,7 @@ function Hero:update (dt) local x, y = self:getPosition() if (x < m.center_x - m.width*1.5 or x > m.center_x + m.width*1.5 or y < m.center_y - m.height*1.5 or y > m.center_y + m.height*1.5) and - self.alive + self.isAlive then self:die() end @@ -99,7 +99,7 @@ function Hero:update (dt) if self.spawntimer > 0 then self.spawntimer = self.spawntimer - dt end - if self.spawntimer <= 0 and not self.alive and self.lives >= 0 then + if self.spawntimer <= 0 and not self.isAlive and self.lives >= 0 then self:respawn() end @@ -145,7 +145,7 @@ end -- Draw of `Hero` function Hero:draw (offset_x, offset_y, scale, debug) - if not self.alive then return end + if not self.isAlive then return end PhysicalBody.draw(self, offset_x, offset_y, scale, debug) end @@ -153,7 +153,7 @@ end -- elevation: 1 bottom, 0 top function Hero:drawHUD (x,y,scale,elevation) -- hud displays only if player is alive - if self.alive then + if self.isAlive then love.graphics.setColor(255,255,255,255) love.graphics.draw(self.portrait_frame, self.portrait_box, (x)*scale, (y)*scale, 0, scale, scale) love.graphics.draw(self.portrait_sprite, self.portrait_sheet[self.name], (x+2)*scale, (y+3)*scale, 0, scale, scale) @@ -241,7 +241,7 @@ function Hero:die () self:playSound(1) self.combo = Hero.combo -- INITIAL from metatable self.lives = self.lives - 1 - self.alive = false + self.isAlive = false self.spawntimer = Hero.spawntimer -- INITIAL from metatable self:setBodyActive(false) self.world:onNautKilled(self) @@ -249,7 +249,7 @@ end -- And then respawn. Like Jon Snow. function Hero:respawn () - self.alive = true + self.isAlive = true self:setLinearVelocity(0,0) self:setPosition(self.world:getSpawnPosition()) -- TODO: I'm not convinced about getting new position like this. self:setBodyActive(true) @@ -260,7 +260,7 @@ end -- Sounds -- TODO: Possibly export to nonexistent SoundEmitter class. Can be used by World (Stage), too. function Hero:playSound (sfx, force) - if self.alive or force then + if self.isAlive or force then local source = love.audio.newSource(self.sfx[sfx]) source:play() end diff --git a/not/World.lua b/not/World.lua index 8aa9d28..6e57ac1 100644 --- a/not/World.lua +++ b/not/World.lua @@ -1,18 +1,6 @@ --- `World` +--- `World` -- Used to manage physical world and everything inside it: clouds, platforms, nauts, background etc. -- TODO: Possibly move common parts of `World` and `Menu` to abstract class `Scene`. - --- WHOLE CODE HAS FLAG OF "need a cleanup" - -require "not.Platform" -require "not.Player" -require "not.Cloud" -require "not.Effect" -require "not.Decoration" -require "not.Ray" - --- Metatable of `World` --- nils initialized in constructor World = { -- inside world = nil, @@ -23,6 +11,7 @@ World = { Effects = nil, Rays = nil, camera = nil, + isActive = true, -- cloud generator clouds_delay = 5, -- Map @@ -36,48 +25,54 @@ World = { music = nil } +World.__index = World + +require "not.Platform" +require "not.Player" +require "not.Cloud" +require "not.Effect" +require "not.Decoration" +require "not.Ray" + -- Constructor of `World` ZA WARUDO! -- TODO: push stuff to initialization method. function World:new (map, nauts) - -- Meta - local o = {} - setmetatable(o, self) - self.__index = self - -- Physical world initialization + local o = setmetatable({}, self) + o:init(map, nauts) + return o +end + +-- Init za warudo +function World:init (map, nauts) + -- Box2D physical world. love.physics.setMeter(64) - o.world = love.physics.newWorld(0, 9.81*64, true) - o.world:setCallbacks(o.beginContact, o.endContact) - -- Empty tables for objects - -- TODO: DEAR DEER, do you see it? + self.world = love.physics.newWorld(0, 9.81*64, true) + self.world:setCallbacks(self.beginContact, self.endContact) + -- Tables for entities. TODO: DEAR DEER, do you see it? local n = {} - o.Nauts = n + self.Nauts = n local p = {} - o.Platforms = {} + self.Platforms = {} local c = {} - o.Clouds = c + self.Clouds = c local e = {} - o.Effects = e + self.Effects = e local d = {} - o.Decorations = d + self.Decorations = d local r = {} - o.Rays = r + self.Rays = r -- Random init; TODO: use LOVE2D's random. math.randomseed(os.time()) - -- Map + -- Map and misc. local map = map or "default" - o:loadMap(map) - -- Nauts - o:spawnNauts(nauts) - -- Create camera - o.camera = Camera:new(o) - -- Play music - o.music = Music:new(o.map.theme) - return o + self:loadMap(map) + self:spawnNauts(nauts) + self.camera = Camera:new(self) + self.music = Music:new(self.map.theme) end -- The end of the world function World:delete () - self.world:destroy() for _,platform in pairs(self.Platforms) do platform:delete() end @@ -85,7 +80,7 @@ function World:delete () naut:delete() end self.music:delete() - self = nil + self.world:destroy() end -- Load map from file @@ -202,7 +197,7 @@ end function World:getNautsAlive () local nauts = {} for _,naut in self.Nauts do - if naut.alive then + if naut.isAlive then table.insert(nauts, naut) end end @@ -239,9 +234,8 @@ end -- LÖVE2D callbacks -- Update ZU WARUDO function World:update (dt) - -- Physical world + self.world:update(dt) - -- Camera self.camera:update(dt) -- Engine world: Nauts, Grounds (kek) and Decorations - all Animateds (top kek) for _,naut in pairs(self.Nauts) do @@ -385,9 +379,7 @@ function World.beginContact (a, b, coll) if a:getCategory() == 1 then local x,y = coll:getNormal() if y < -0.6 then - -- TODO: remove debug messages -- TODO: move landing to `not.Hero` - print(b:getUserData().name .. " is not in air") -- Move them to Hero b:getUserData().inAir = false b:getUserData().jumpCounter = 2 @@ -409,7 +401,6 @@ end -- endContact function World.endContact (a, b, coll) if a:getCategory() == 1 then - print(b:getUserData().name .. " is in air") -- Move them to Hero b:getUserData().inAir = true end -- cgit v1.1 From 970655737ce7f497f0725d28605fc296c9923a64 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 16:16:05 +0200 Subject: Hotfix for destroyed body crash --- not/Player.lua | 4 ++-- not/World.lua | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/not/Player.lua b/not/Player.lua index 719b77e..30057bb 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -43,9 +43,9 @@ end -- Update of `Player`. function Player:update (dt) - local x, y = self:getLinearVelocity() Hero.update(self, dt) -- TODO: It would be probably a good idea to add return to update functions to terminate if something goes badly in parent's update. - + if self.body:isDestroyed() then return end + local x, y = self:getLinearVelocity() -- Jumping. if self.isJumping and self.jumpTimer > 0 then self:setLinearVelocity(x,-160) diff --git a/not/World.lua b/not/World.lua index 6e57ac1..d234413 100644 --- a/not/World.lua +++ b/not/World.lua @@ -11,7 +11,6 @@ World = { Effects = nil, Rays = nil, camera = nil, - isActive = true, -- cloud generator clouds_delay = 5, -- Map @@ -234,7 +233,6 @@ end -- LÖVE2D callbacks -- Update ZU WARUDO function World:update (dt) - self.world:update(dt) self.camera:update(dt) -- Engine world: Nauts, Grounds (kek) and Decorations - all Animateds (top kek) -- cgit v1.1 From eff39f1f49d5223cb27b5874f8ac29ce8a2ef85f Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 16:28:21 +0200 Subject: Moved damping back to Hero from Player --- not/Hero.lua | 17 +++++++++++++++++ not/Player.lua | 18 ------------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/not/Hero.lua b/not/Hero.lua index 7c2555a..a22cc2e 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -84,6 +84,23 @@ function Hero:update (dt) self.angle = 0 end + -- Custom linear damping. + if not self.isWalking then + local face = nil + local x, y = self:getLinearVelocity() + if x < -12 then + face = 1 + elseif x > 12 then + face = -1 + else + face = 0 + end + self:applyForce(40*face,0) + if not self.inAir then + self:applyForce(80*face,0) + end + end + -- Could you please die? -- TODO: World/Map function for testing if Point is inside playable area. local m = self.world.map diff --git a/not/Player.lua b/not/Player.lua index 30057bb..2a4b2e6 100644 --- a/not/Player.lua +++ b/not/Player.lua @@ -69,24 +69,6 @@ function Player:update (dt) self:applyForce(-250, 0) end end - - -- Limiting walking speed. - if not self:isControlDown("left") and - not self:isControlDown("right") - then - local face = nil - if x < -12 then - face = 1 - elseif x > 12 then - face = -1 - else - face = 0 - end - self:applyForce(40*face,0) - if not self.inAir then - self:applyForce(80*face,0) - end - end end -- Controller callbacks. -- cgit v1.1 From 39426c857b46d01d132f95cd991f5ceff2308d81 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 18:22:06 +0200 Subject: Finally! Readme --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 33ad9f7..26869fa 100644 --- a/readme.md +++ b/readme.md @@ -1,2 +1,2 @@ -# Notnauts -Well, yep. \ No newline at end of file +# Roflnauts 2 +More information available [here](https://www.awesomenauts.com/forum/viewtopic.php?f=12&t=45632). -- cgit v1.1 From 9a5b629d8c1719af62667235c59950862b46b771 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 18:30:42 +0200 Subject: World clean-up init and table --- not/World.lua | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/not/World.lua b/not/World.lua index d234413..579fff2 100644 --- a/not/World.lua +++ b/not/World.lua @@ -2,15 +2,14 @@ -- Used to manage physical world and everything inside it: clouds, platforms, nauts, background etc. -- TODO: Possibly move common parts of `World` and `Menu` to abstract class `Scene`. World = { - -- inside - world = nil, - Nauts = nil, - Platforms = nil, - Clouds = nil, - Decorations = nil, - Effects = nil, - Rays = nil, - camera = nil, + world = --[[love.physics.newWorld]]nil, + Nauts = --[[{not.Hero}]]nil, + Platforms = --[[{not.Platform}]]nil, + Clouds = --[[{not.Cloud}]]nil, + Decorations = --[[{not.Decoration}]]nil, + Effects = --[[{not.Effect}]]nil, + Rays = --[[{not.Ray}]]nil, + camera = --[[not.Camera]]nil, -- cloud generator clouds_delay = 5, -- Map @@ -34,7 +33,6 @@ require "not.Decoration" require "not.Ray" -- Constructor of `World` ZA WARUDO! --- TODO: push stuff to initialization method. function World:new (map, nauts) local o = setmetatable({}, self) o:init(map, nauts) @@ -47,19 +45,13 @@ function World:init (map, nauts) love.physics.setMeter(64) self.world = love.physics.newWorld(0, 9.81*64, true) self.world:setCallbacks(self.beginContact, self.endContact) - -- Tables for entities. TODO: DEAR DEER, do you see it? - local n = {} - self.Nauts = n - local p = {} + -- Tables for entities. TODO: It is still pretty bad! + self.Nauts = {} self.Platforms = {} - local c = {} - self.Clouds = c - local e = {} - self.Effects = e - local d = {} - self.Decorations = d - local r = {} - self.Rays = r + self.Clouds = {} + self.Effects = {} + self.Decorations = {} + self.Rays = {} -- Random init; TODO: use LOVE2D's random. math.randomseed(os.time()) -- Map and misc. -- cgit v1.1 From 4cf1755d05a63452feca03d2e380b149fcaa76c2 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 18:40:27 +0200 Subject: Moved music.lua, cleaned-up its code; Fixed requires for main, World and Menu --- main.lua | 1 - menu.lua | 2 +- music.lua | 27 --------------------------- not/Music.lua | 25 +++++++++++++++++++++++++ not/World.lua | 1 + 5 files changed, 27 insertions(+), 29 deletions(-) delete mode 100644 music.lua create mode 100644 not/Music.lua diff --git a/main.lua b/main.lua index b985648..bdee6a3 100644 --- a/main.lua +++ b/main.lua @@ -28,7 +28,6 @@ require "not.World" require "camera" require "menu" require "controller" -require "music" require "settings" -- Temporary debug diff --git a/menu.lua b/menu.lua index fef46df..47e1b25 100644 --- a/menu.lua +++ b/menu.lua @@ -2,7 +2,7 @@ -- It creates single screen of a menu -- I do know that model I used here and in `World` loading configuration files is not flawless but I did not want to rewrite `World`s one but wanted to keep things similar at least in project scope. -require "music" +require "not.Music" -- Here it begins Menu = { diff --git a/music.lua b/music.lua deleted file mode 100644 index 1ac26bb..0000000 --- a/music.lua +++ /dev/null @@ -1,27 +0,0 @@ --- `Music` --- Simple music player object that plays and loops selected track in single Scene. - --- WHOLE CODE HAS FLAG OF "need a cleanup" - --- Metatable of `Music` --- nils initialized in constructor -Music = { - track = nil, - source = nil -} -function Music:new(track) - -- Meta - local o = {} - setmetatable(o, self) - self.__index = self - -- Init - o.track = track - o.source = love.audio.newSource("assets/music/" .. o.track) - o.source:setLooping(true) - o.source:setVolume(.7) - o.source:play() - return o -end -function Music:delete() - self.source:stop() -end \ No newline at end of file diff --git a/not/Music.lua b/not/Music.lua new file mode 100644 index 0000000..ee930f4 --- /dev/null +++ b/not/Music.lua @@ -0,0 +1,25 @@ +--- `Music` +-- Simple music player object that plays and loops selected track in single Scene. +Music = { + source = --[[love.audio.newSource]]nil +} + +Music.__index = Music + +function Music:new (trackName) + local o = setmetatable({}, self) + o:init(trackName) + return o +end + +-- TODO: trackName should be passed without file extension. +function Music:init (trackName) + self.source = love.audio.newSource("assets/music/" .. trackName) + self.source:setLooping(true) + self.source:setVolume(.7) + self.source:play() +end + +function Music:delete () + self.source:stop() +end \ No newline at end of file diff --git a/not/World.lua b/not/World.lua index 579fff2..2a6106c 100644 --- a/not/World.lua +++ b/not/World.lua @@ -31,6 +31,7 @@ require "not.Cloud" require "not.Effect" require "not.Decoration" require "not.Ray" +require "not.Music" -- Constructor of `World` ZA WARUDO! function World:new (map, nauts) -- cgit v1.1 From 93d3257ff23331c308fb32940557911a29ca608b Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 19:22:26 +0200 Subject: Menu cleaned-up and moved to /not/ Menu is now similar to new code Menu.load => Menu.open --- config/menucredits.lua | 2 +- config/menuhost.lua | 4 +- config/menumain.lua | 6 +- config/menuselect.lua | 2 +- config/menusettings.lua | 2 +- main.lua | 2 +- menu.lua | 140 ---------------------------------------------- not/Menu.lua | 144 ++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 153 insertions(+), 149 deletions(-) delete mode 100644 menu.lua create mode 100644 not/Menu.lua diff --git a/config/menucredits.lua b/config/menucredits.lua index 9d38da4..0510333 100644 --- a/config/menucredits.lua +++ b/config/menucredits.lua @@ -11,7 +11,7 @@ return { :setText("Go back") :setPosition(bx,144) :set("active", function (self) - self.parent:load("menumain") + self.parent:open("menumain") end) , element:new(menu) diff --git a/config/menuhost.lua b/config/menuhost.lua index 64ce0e7..ae5e3dd 100644 --- a/config/menuhost.lua +++ b/config/menuhost.lua @@ -29,14 +29,14 @@ return { end) :set("active", function (self) MAP = map_selector:getFullSelection(true)[1][1] -- please, don't kill me for this, kek - self.parent:load("menuselect") + self.parent:open("menuselect") end) , button:new(menu) :setText("Go back") :setPosition(bx,117) :set("active", function (self) - self.parent:load("menumain") + self.parent:open("menumain") end) , } \ No newline at end of file diff --git a/config/menumain.lua b/config/menumain.lua index 50b3d56..4e5ef1f 100644 --- a/config/menumain.lua +++ b/config/menumain.lua @@ -14,7 +14,7 @@ return { :setText("Start") :setPosition(bx, 80) :set("active", function (self) - self.parent:load("menuhost") + self.parent:open("menuhost") end) , button:new(menu) @@ -28,14 +28,14 @@ return { :setText("Settings") :setPosition(bx, 112) :set("active", function (self) - self.parent:load("menusettings") + self.parent:open("menusettings") end) , button:new(menu) :setText("Credits") :setPosition(bx, 128) :set("active", function (self) - self.parent:load("menucredits") + self.parent:open("menucredits") end) , button:new(menu) diff --git a/config/menuselect.lua b/config/menuselect.lua index 19f46ab..7b9f073 100644 --- a/config/menuselect.lua +++ b/config/menuselect.lua @@ -41,7 +41,7 @@ return { :setText("Go back") :setPosition(bx,150) :set("active", function (self) - self.parent:load("menuhost") + self.parent:open("menuhost") end) , element:new(menu) diff --git a/config/menusettings.lua b/config/menusettings.lua index 1631e4f..19f952e 100644 --- a/config/menusettings.lua +++ b/config/menusettings.lua @@ -105,7 +105,7 @@ local a = { :setText("Go back") :setPosition(bx,144) :set("active", function (self) - self.parent:load("menumain") + self.parent:open("menumain") end) , dimmer diff --git a/main.lua b/main.lua index bdee6a3..eed787f 100644 --- a/main.lua +++ b/main.lua @@ -26,7 +26,7 @@ end -- Require require "not.World" require "camera" -require "menu" +require "not.Menu" require "controller" require "settings" diff --git a/menu.lua b/menu.lua deleted file mode 100644 index 47e1b25..0000000 --- a/menu.lua +++ /dev/null @@ -1,140 +0,0 @@ --- `Menu` (Scene) --- It creates single screen of a menu --- I do know that model I used here and in `World` loading configuration files is not flawless but I did not want to rewrite `World`s one but wanted to keep things similar at least in project scope. - -require "not.Music" - --- Here it begins -Menu = { - scale = getScale(), - elements, --table - active = 1, - music, - sprite, - background, - asteroids, - stars, - asteroids_bounce = 0, - stars_frame = 1, - stars_delay = 0.8, - allowMove = true, - quads = { - button = { - normal = love.graphics.newQuad(0, 0, 58,15, 80,130), - active = love.graphics.newQuad(0, 0, 58,15, 80,130) - }, - portrait = { - normal = love.graphics.newQuad( 0, 15, 32,32, 80,130), - active = love.graphics.newQuad(32, 15, 32,32, 80,130) - }, - panorama = { - normal = love.graphics.newQuad(0,47, 80,42, 80,130), - active = love.graphics.newQuad(0,88, 80,42, 80,130) - }, - arrow_l = love.graphics.newQuad(68, 0, 6, 6, 80,130), - arrow_r = love.graphics.newQuad(74, 0, 6, 6, 80,130), - stars = { - love.graphics.newQuad( 0, 0, 320, 200, 640,200), - love.graphics.newQuad(320, 0, 320, 200, 640,200) - }, - } -} -function Menu:new(name) - local o = {} - setmetatable(o, self) - self.__index = self - self.sprite = love.graphics.newImage("assets/menu.png") - self.background = love.graphics.newImage("assets/backgrounds/menu.png") - self.asteroids = love.graphics.newImage("assets/asteroids.png") - self.stars = love.graphics.newImage("assets/stars.png") - o.elements = {} - o:load(name) - o.music = Music:new("menu.ogg") - return o -end -function Menu:delete() - self.music:delete() -end - --- Load menu from file -function Menu:load(name) - local name = "config/" .. (name or "menumain") .. ".lua" - local menu = love.filesystem.load(name) - self.active = 1 - self.elements = menu(self) - self.elements[self.active]:focus() -end - --- Return reference to quads table and menu sprite -function Menu:getSheet() - return self.sprite, self.quads -end - --- Cycle elements -function Menu:next() - self.elements[self.active]:blur() - self.active = (self.active%#self.elements)+1 - if not self.elements[self.active]:focus() then - self:next() - end -end -function Menu:previous() - self.elements[self.active]:blur() - if self.active == 1 then - self.active = #self.elements - else - self.active = self.active - 1 - end - if not self.elements[self.active]:focus() then - self:previous() - end -end - --- LÖVE2D callbacks -function Menu:update(dt) - for _,element in pairs(self.elements) do - element:update(dt) - end - self.asteroids_bounce = self.asteroids_bounce + dt*0.1 - if self.asteroids_bounce > 2 then self.asteroids_bounce = self.asteroids_bounce - 2 end - self.stars_delay = self.stars_delay - dt - if self.stars_delay < 0 then - self.stars_delay = self.stars_delay + Menu.stars_delay --Menu.stars_delay is initial - if self.stars_frame == 2 then - self.stars_frame = 1 - else - self.stars_frame = 2 - end - end -end -function Menu:draw() - local scale = self.scale - local scaler = getRealScale() - love.graphics.draw(self.background, 0, 0, 0, scaler, scaler) - love.graphics.draw(self.stars, self.quads.stars[self.stars_frame], 0, 0, 0, scaler, scaler) - love.graphics.draw(self.asteroids, 0, math.floor(64+math.sin(self.asteroids_bounce*math.pi)*4)*scaler, 0, scaler, scaler) - love.graphics.setFont(Font) - for _,element in pairs(self.elements) do - element:draw(scale) - end -end - --- Controller callbacks -function Menu:controlpressed(set, action, key) - if self.allowMove then - if action == "down" then - self:next() - end - if action == "up" then - self:previous() - end - end - for _,element in pairs(self.elements) do - element:controlpressed(set, action, key) - end -end -function Menu:controlreleased(set, action, key) - for _,element in pairs(self.elements) do - element:controlreleased(set, action, key) - end -end \ No newline at end of file diff --git a/not/Menu.lua b/not/Menu.lua new file mode 100644 index 0000000..1be6f00 --- /dev/null +++ b/not/Menu.lua @@ -0,0 +1,144 @@ +--- `Menu` +-- It creates single screen of a menu +-- I do know that model I used here and in `World` loading configuration files is not flawless but I did not want to rewrite `World`s one but wanted to keep things similar at least in project scope. +Menu = { + scale = getScale(), + elements = --[[{not.Element}]]nil, + active = 1, + music = --[[not.Music]]nil, + sprite = --[[love.graphics.newImage]]nil, + background = --[[love.graphics.newImage]]nil, + asteroids = --[[love.graphics.newImage]]nil, + stars = --[[love.graphics.newImage]]nil, + asteroids_bounce = 0, + stars_frame = 1, + stars_delay = 0.8, + allowMove = true, + quads = { -- TODO: Could be moved to config file or perhaps QuadManager to manage all quads for animations etc. + button = { + normal = love.graphics.newQuad(0, 0, 58,15, 80,130), + active = love.graphics.newQuad(0, 0, 58,15, 80,130) + }, + portrait = { + normal = love.graphics.newQuad( 0, 15, 32,32, 80,130), + active = love.graphics.newQuad(32, 15, 32,32, 80,130) + }, + panorama = { + normal = love.graphics.newQuad(0,47, 80,42, 80,130), + active = love.graphics.newQuad(0,88, 80,42, 80,130) + }, + arrow_l = love.graphics.newQuad(68, 0, 6, 6, 80,130), + arrow_r = love.graphics.newQuad(74, 0, 6, 6, 80,130), + stars = { + love.graphics.newQuad( 0, 0, 320, 200, 640,200), + love.graphics.newQuad(320, 0, 320, 200, 640,200) + }, + } +} + +Menu.__index = Menu + +require "not.Music" + +function Menu:new (name) + local o = setmetatable({}, self) + -- Load statically. + if self.sprite == nil then + self.sprite = love.graphics.newImage("assets/menu.png") + self.background = love.graphics.newImage("assets/backgrounds/menu.png") + self.asteroids = love.graphics.newImage("assets/asteroids.png") + self.stars = love.graphics.newImage("assets/stars.png") + end + o:init(name) + return o +end + +function Menu:init (name) + self.music = Music:new("menu.ogg") + self:open(name) +end + +function Menu:delete () + self.music:delete() +end + +function Menu:open (name) + local name = name or "menumain" + self.active = Menu.active --Menu.active is initial + self.elements = love.filesystem.load(string.format("config/%s.lua", name))(self) + self.elements[self.active]:focus() +end + +-- Return reference to quads table and menu sprite +function Menu:getSheet () + return self.sprite, self.quads +end + +-- Cycle elements +function Menu:next () + self.elements[self.active]:blur() + self.active = (self.active%#self.elements)+1 + if not self.elements[self.active]:focus() then + self:next() + end +end +function Menu:previous () + self.elements[self.active]:blur() + if self.active == 1 then + self.active = #self.elements + else + self.active = self.active - 1 + end + if not self.elements[self.active]:focus() then + self:previous() + end +end + +-- LÖVE2D callbacks +function Menu:update (dt) + for _,element in pairs(self.elements) do + element:update(dt) + end + self.asteroids_bounce = self.asteroids_bounce + dt*0.1 + if self.asteroids_bounce > 2 then self.asteroids_bounce = self.asteroids_bounce - 2 end + self.stars_delay = self.stars_delay - dt + if self.stars_delay < 0 then + self.stars_delay = self.stars_delay + Menu.stars_delay --Menu.stars_delay is initial + if self.stars_frame == 2 then + self.stars_frame = 1 + else + self.stars_frame = 2 + end + end +end +function Menu:draw () + local scale = self.scale + local scaler = getRealScale() + love.graphics.draw(self.background, 0, 0, 0, scaler, scaler) + love.graphics.draw(self.stars, self.quads.stars[self.stars_frame], 0, 0, 0, scaler, scaler) + love.graphics.draw(self.asteroids, 0, math.floor(64+math.sin(self.asteroids_bounce*math.pi)*4)*scaler, 0, scaler, scaler) + love.graphics.setFont(Font) + for _,element in pairs(self.elements) do + element:draw(scale) + end +end + +-- Controller callbacks +function Menu:controlpressed (set, action, key) + if self.allowMove then + if action == "down" then + self:next() + end + if action == "up" then + self:previous() + end + end + for _,element in pairs(self.elements) do + element:controlpressed(set, action, key) + end +end +function Menu:controlreleased (set, action, key) + for _,element in pairs(self.elements) do + element:controlreleased(set, action, key) + end +end \ No newline at end of file -- cgit v1.1 From 8190d59e7bbac7835e9cecf5229247900b21f84a Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 19:29:33 +0200 Subject: Added todos from Discord --- mapicons.lua | 2 +- selector.lua | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mapicons.lua b/mapicons.lua index 4893da7..8729a56 100644 --- a/mapicons.lua +++ b/mapicons.lua @@ -1,5 +1,5 @@ -- Maps icons list generation file --- REWORK NEEDED, it is so similar to `nautsicons.lua` they could be merged together into one function that returns icon quad sequences. +-- TODO: it is so similar to `nautsicons.lua` they could be merged together into one function that returns icon quad sequences (`createIconList(image, width, number, mask...) --[[ body ]] return image, icons, list end` or similar). On the other hand extended lists with maps/nauts in config would be enough. local maps = require "maplist" local w, h = 532, 37 local icons = {} diff --git a/selector.lua b/selector.lua index 61401e7..03be918 100644 --- a/selector.lua +++ b/selector.lua @@ -275,6 +275,7 @@ function Selector:update(dt) end -- Controller callbacks +-- TODO: Add action to perform when key is pressed and selector is locked in e.g. to move into character selection from map selection. function Selector:controlpressed(set, action, key) if set and self.focused then local n = self:checkNumber(set) -- cgit v1.1 From a013d70115171764ce0941fbbe18a5447447a7eb Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 19:59:51 +0200 Subject: Settings moved to /not/, cleaned-up a bit --- main.lua | 2 +- not/Settings.lua | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ settings.lua | 66 --------------------------------------------------- 3 files changed, 73 insertions(+), 67 deletions(-) create mode 100644 not/Settings.lua delete mode 100644 settings.lua diff --git a/main.lua b/main.lua index eed787f..7e1232e 100644 --- a/main.lua +++ b/main.lua @@ -28,7 +28,7 @@ require "not.World" require "camera" require "not.Menu" require "controller" -require "settings" +require "not.Settings" -- Temporary debug debug = false diff --git a/not/Settings.lua b/not/Settings.lua new file mode 100644 index 0000000..e3316f9 --- /dev/null +++ b/not/Settings.lua @@ -0,0 +1,72 @@ +--- `Settings` +-- Stores, loads, saves and changes game settings including Controller sets. +Settings = { + current = {} +} + +function Settings.load() + if Controller then + if not love.filesystem.exists("settings") then + local def = love.filesystem.newFile("settings.default") + local new = love.filesystem.newFile("settings") + new:open("w") def:open("r") + new:write(def:read()) + new:close() def:close() + end + local getSettings = love.filesystem.load("settings") + Settings.current = getSettings() + Controller.reset() + local joysticksList = love.joystick.getJoysticks() -- local list for editing + for _,set in pairs(Settings.current) do + local isJoystick = set[7] + local joystick + if isJoystick then + -- take and remove first joystick from list + joystick = joysticksList[1] + table.remove(joysticksList, 1) + end + if not isJoystick or joystick then + Controller.registerSet(set[1], set[2], set[3], set[4], set[5], set[6], joystick) + end + end + end +end + +function Settings.save() + local new = love.filesystem.newFile("settings") + local sets = Settings.current + local string = "return {\n" + for i,set in pairs(sets) do + string = string .. "\t{" + for j,word in pairs(set) do + if j ~= 7 then + string = string .. "\"" .. word .. "\", " + else + if word then + string = string .. "true" + else + string = string .. "false" + end + end + end + string = string .. "},\n" + end + string = string .. "}" + new:open("w") + new:write(string) + new:close() +end + +function Settings.change(n, left, right, up, down, attack, jump, joystick) + local bool + if joystick then + bool = true + else + bool = false + end + -- Save current settings + Settings.current[n] = {left, right, up, down, attack, jump, bool} + Settings.save() + -- Load settings + Settings.load() +end diff --git a/settings.lua b/settings.lua deleted file mode 100644 index e73b997..0000000 --- a/settings.lua +++ /dev/null @@ -1,66 +0,0 @@ -Settings = {} -Settings.current = {} -function Settings.load() - if Controller then - if not love.filesystem.exists("settings") then - local def = love.filesystem.newFile("settings.default") - local new = love.filesystem.newFile("settings") - new:open("w") def:open("r") - new:write(def:read()) - new:close() def:close() - end - local getSettings = love.filesystem.load("settings") - Settings.current = getSettings() - Controller.reset() - local joysticksList = love.joystick.getJoysticks() -- local list for editing - for _,set in pairs(Settings.current) do - local isJoystick = set[7] - local joystick - if isJoystick then - -- take and remove first joystick from list - joystick = joysticksList[1] - table.remove(joysticksList, 1) - end - if not isJoystick or joystick then - Controller.registerSet(set[1], set[2], set[3], set[4], set[5], set[6], joystick) - end - end - end -end -function Settings.save() - local new = love.filesystem.newFile("settings") - local sets = Settings.current - local string = "return {\n" - for i,set in pairs(sets) do - string = string .. "\t{" - for j,word in pairs(set) do - if j ~= 7 then - string = string .. "\"" .. word .. "\", " - else - if word then - string = string .. "true" - else - string = string .. "false" - end - end - end - string = string .. "},\n" - end - string = string .. "}" - new:open("w") - new:write(string) - new:close() -end -function Settings.change(n, left, right, up, down, attack, jump, joystick) - local bool - if joystick then - bool = true - else - bool = false - end - -- Save current settings - Settings.current[n] = {left, right, up, down, attack, jump, bool} - Settings.save() - -- Load settings - Settings.load() -end \ No newline at end of file -- cgit v1.1 From 33b3a93138a9eee40727e9f56373b434ceab1cef Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 20:03:17 +0200 Subject: Controller moved to /not/ and cleaned-up a bit. --- controller.lua | 203 ----------------------------------------------------- main.lua | 2 +- not/Controller.lua | 201 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 202 insertions(+), 204 deletions(-) delete mode 100644 controller.lua create mode 100644 not/Controller.lua diff --git a/controller.lua b/controller.lua deleted file mode 100644 index f035162..0000000 --- a/controller.lua +++ /dev/null @@ -1,203 +0,0 @@ --- `Controller` --- Module to manage player input. --- It uses `love.keypressed`, `love.keyreleased`, `love.gamepadreleased`, `love.gamepadpressed`, `love.joystickadded`, so be sure not to use them by yourself. --- Rather than that use functions provided by this module: `Controller.controlpressed` and `Controller.controlreleased`. --- For information on additional functions, look below. - --- Namespace -Controller = {} -Controller.sets = {} -Controller.axes = {} -Controller.deadzone = .3 - --- Declared to avoid calling nil. Be sure to define yours after this line is performed. -function Controller.controlpressed(set, action, key) end -function Controller.controlreleased(set, action, key) end - --- Create new controls set. -function Controller.registerSet(left, right, up, down, attack, jump, joystick) - if not Controller.isJoystickUnique(joystick) then return end - local set = {} - set.left = left or "left" - set.right = right or "right" - set.up = up or "up" - set.down = down or "down" - set.attack = attack or "return" - set.jump = jump or "rshift" - set.joystick = joystick - table.insert(Controller.sets, set) - print(set, left, right, up, down, attack, jump, joystick) - return set -end - --- Reset table of controls sets. -function Controller.reset() - local t = {} - Controller.sets = t -end - --- Get table of controls sets. -function Controller.getSets() - return Controller.sets -end - --- Checks if given joystick is unique in current set of Controller sets -function Controller.isJoystickUnique(joystick) - if joystick ~= nil then - for _,set in pairs(Controller.sets) do - if set.joystick == joystick then return false end - end - end - return true -end - --- Tests all sets if they have control assigned to given key and joystick. -function Controller.testSets(key, joystick) - for i,set in pairs(Controller.sets) do - local action = Controller.testControl(set, key, joystick) - if action ~= nil then - return set, action - end - end - return nil, nil -end - --- Tests given set if it has controll assigned to given key and joystick. -function Controller.testControl(set, key, joystick) - -- First test if it is joystick and if it is correct one - if joystick == set.joystick then - if key == set.left then - return "left" - elseif key == set.right then - return "right" - elseif key == set.up then - return "up" - elseif key == set.down then - return "down" - elseif key == set.attack then - return "attack" - elseif key == set.jump then - return "jump" - end - end -end - --- Checks if given action of given set is down -function Controller.isDown(set, action) - if set ~= nil then - if set.joystick == nil then - return love.keyboard.isDown(set[action]) - else - if not Controller.isAxis(set[action]) then - return set.joystick:isGamepadDown(set[action]) - else - return Controller.getAxisState(set.joystick, set[action]) - end - end - end -end - --- Return key name from given axis and value -function Controller.createAxisName(axis, value) - local key = "axis:"..axis - if value == 0 then - key = key.."0" - elseif value > 0 then - key = key.."+" - else - key = key.."-" - end - return key -end - --- Checks if given key is an axis -function Controller.isAxis(key) - if string.find(key, "axis:") then - return true - else - return false - end -end - --- Checks state of key assigned to axis of given joystick -function Controller.getAxisState(joystick, key) - if Controller.axes[joystick] then - local state = Controller.axes[joystick][key] - if state ~= nil then - return state - else - return false - end - end -end - --- Sets state of key assigned to axis of given joystick -function Controller.setAxisState(joystick, key, state) - if Controller.axes[joystick] == nil then - Controller.axes[joystick] = {} - end - Controller.axes[joystick][key] = state -end - --- Simulate pressing key on an axis -function Controller.axisPress(joystick, axis, value) - local key = Controller.createAxisName(axis, value) - local set, action = Controller.testSets(key, joystick) - local state = Controller.getAxisState(joystick, key) - if not state then - print(joystick, set, action, key) - Controller.setAxisState(joystick, key, true) - Controller.controlpressed(set, action, key) - end -end - --- Simulate releasing key on an axis -function Controller.axisRelease(joystick, axis, value) - local key = Controller.createAxisName(axis, value) - local set, action = Controller.testSets(key, joystick) - local state = Controller.getAxisState(joystick, key) - if state then - Controller.setAxisState(joystick, key,false) - Controller.controlreleased(set, action, key) - end -end - --- Callbacks from LÖVE2D --- Load gamepad mappings from db file and init module -function Controller.load() - love.joystick.loadGamepadMappings("gamecontrollerdb.txt") -end - --- Gamepad input callbacks -function Controller.gamepadaxis(joystick, axis, value) - if value ~= 0 then - if math.abs(value) > Controller.deadzone then - Controller.axisPress(joystick, axis, value) - else - Controller.axisRelease(joystick, axis, value) - end - else - Controller.axisRelease(joystick, axis, 1) - Controller.axisRelease(joystick, axis, -1) - end -end -function Controller.gamepadpressed(joystick, key) - local set, action = Controller.testSets(key, joystick) - print(joystick, set, action, key) - Controller.controlpressed(set, action, key) -end -function Controller.gamepadreleased(joystick, key) - local set, action = Controller.testSets(key, joystick) - Controller.controlreleased(set, action, key) -end - --- Keyboard input callbacks -function Controller.keypressed(key) - local set, action = Controller.testSets(key, nil) - print(nil, set, action, key) - Controller.controlpressed(set, action, key) -end -function Controller.keyreleased(key) - local set, action = Controller.testSets(key, nil) - Controller.controlreleased(set, action, key) -end \ No newline at end of file diff --git a/main.lua b/main.lua index 7e1232e..b905de6 100644 --- a/main.lua +++ b/main.lua @@ -27,7 +27,7 @@ end require "not.World" require "camera" require "not.Menu" -require "controller" +require "not.Controller" require "not.Settings" -- Temporary debug diff --git a/not/Controller.lua b/not/Controller.lua new file mode 100644 index 0000000..8a2a863 --- /dev/null +++ b/not/Controller.lua @@ -0,0 +1,201 @@ +--- `Controller` +-- Module to manage player input. +-- It uses `love.keypressed`, `love.keyreleased`, `love.gamepadreleased`, `love.gamepadpressed`, `love.joystickadded`, so be sure not to use them by yourself. +-- Rather than that use functions provided by this module: `Controller.controlpressed` and `Controller.controlreleased`. +Controller = { + sets = {}, + axes = {}, + deadzone = .3 +} + +-- Declared to avoid calling nil. Be sure to define yours after this line is performed. +function Controller.controlpressed(set, action, key) end +function Controller.controlreleased(set, action, key) end + +-- Create new controls set. +function Controller.registerSet(left, right, up, down, attack, jump, joystick) + if not Controller.isJoystickUnique(joystick) then return end + local set = {} + set.left = left or "left" + set.right = right or "right" + set.up = up or "up" + set.down = down or "down" + set.attack = attack or "return" + set.jump = jump or "rshift" + set.joystick = joystick + table.insert(Controller.sets, set) + print(set, left, right, up, down, attack, jump, joystick) + return set +end + +-- Reset table of controls sets. +function Controller.reset() + local t = {} + Controller.sets = t +end + +-- Get table of controls sets. +function Controller.getSets() + return Controller.sets +end + +-- Checks if given joystick is unique in current set of Controller sets +function Controller.isJoystickUnique(joystick) + if joystick ~= nil then + for _,set in pairs(Controller.sets) do + if set.joystick == joystick then return false end + end + end + return true +end + +-- Tests all sets if they have control assigned to given key and joystick. +function Controller.testSets(key, joystick) + for i,set in pairs(Controller.sets) do + local action = Controller.testControl(set, key, joystick) + if action ~= nil then + return set, action + end + end + return nil, nil +end + +-- Tests given set if it has controll assigned to given key and joystick. +function Controller.testControl(set, key, joystick) + -- First test if it is joystick and if it is correct one + if joystick == set.joystick then + if key == set.left then + return "left" + elseif key == set.right then + return "right" + elseif key == set.up then + return "up" + elseif key == set.down then + return "down" + elseif key == set.attack then + return "attack" + elseif key == set.jump then + return "jump" + end + end +end + +-- Checks if given action of given set is down +function Controller.isDown(set, action) + if set ~= nil then + if set.joystick == nil then + return love.keyboard.isDown(set[action]) + else + if not Controller.isAxis(set[action]) then + return set.joystick:isGamepadDown(set[action]) + else + return Controller.getAxisState(set.joystick, set[action]) + end + end + end +end + +-- Return key name from given axis and value +function Controller.createAxisName(axis, value) + local key = "axis:"..axis + if value == 0 then + key = key.."0" + elseif value > 0 then + key = key.."+" + else + key = key.."-" + end + return key +end + +-- Checks if given key is an axis +function Controller.isAxis(key) + if string.find(key, "axis:") then + return true + else + return false + end +end + +-- Checks state of key assigned to axis of given joystick +function Controller.getAxisState(joystick, key) + if Controller.axes[joystick] then + local state = Controller.axes[joystick][key] + if state ~= nil then + return state + else + return false + end + end +end + +-- Sets state of key assigned to axis of given joystick +function Controller.setAxisState(joystick, key, state) + if Controller.axes[joystick] == nil then + Controller.axes[joystick] = {} + end + Controller.axes[joystick][key] = state +end + +-- Simulate pressing key on an axis +function Controller.axisPress(joystick, axis, value) + local key = Controller.createAxisName(axis, value) + local set, action = Controller.testSets(key, joystick) + local state = Controller.getAxisState(joystick, key) + if not state then + print(joystick, set, action, key) + Controller.setAxisState(joystick, key, true) + Controller.controlpressed(set, action, key) + end +end + +-- Simulate releasing key on an axis +function Controller.axisRelease(joystick, axis, value) + local key = Controller.createAxisName(axis, value) + local set, action = Controller.testSets(key, joystick) + local state = Controller.getAxisState(joystick, key) + if state then + Controller.setAxisState(joystick, key,false) + Controller.controlreleased(set, action, key) + end +end + +-- Callbacks from LÖVE2D +-- Load gamepad mappings from db file and init module +function Controller.load() + love.joystick.loadGamepadMappings("gamecontrollerdb.txt") +end + +-- Gamepad input callbacks +function Controller.gamepadaxis(joystick, axis, value) + if value ~= 0 then + if math.abs(value) > Controller.deadzone then + Controller.axisPress(joystick, axis, value) + else + Controller.axisRelease(joystick, axis, value) + end + else + Controller.axisRelease(joystick, axis, 1) + Controller.axisRelease(joystick, axis, -1) + end +end +function Controller.gamepadpressed(joystick, key) + local set, action = Controller.testSets(key, joystick) + print(joystick, set, action, key) + Controller.controlpressed(set, action, key) +end +function Controller.gamepadreleased(joystick, key) + local set, action = Controller.testSets(key, joystick) + Controller.controlreleased(set, action, key) +end + +-- Keyboard input callbacks +function Controller.keypressed(key) + local set, action = Controller.testSets(key, nil) + print(nil, set, action, key) + Controller.controlpressed(set, action, key) +end +function Controller.keyreleased(key) + local set, action = Controller.testSets(key, nil) + Controller.controlreleased(set, action, key) +end \ No newline at end of file -- cgit v1.1 From e9396447537e0c6dedfb55e9a7ffc1e99575d860 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 20:06:12 +0200 Subject: Camera moved to /not/ and cleaned-up a bit --- camera.lua | 147 --------------------------------------------------------- main.lua | 2 +- not/Camera.lua | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 146 insertions(+), 148 deletions(-) delete mode 100644 camera.lua create mode 100644 not/Camera.lua diff --git a/camera.lua b/camera.lua deleted file mode 100644 index 2ae7c78..0000000 --- a/camera.lua +++ /dev/null @@ -1,147 +0,0 @@ --- `Camera` --- Used in drawing. - --- Metatable of `Camera` -Camera = { - x = 0, - y = 0, - dest_x = 0, - dest_y = 0, - scale = getScale(), - scaler = getRealScale(), - shake = 0, - timer = 0, - delay = 0, - origin_x = 0, - origin_y = 0, - shake_x = 0, - shake_y = 0, - world = nil, -- game world -} - --- Constructor of `Camera` -function Camera:new (world) - local o = {} - setmetatable(o, self) - self.__index = self - o.world = world - o:setPosition(o:follow()) - o:setDestination(o:follow()) - return o -end - --- Drawing offsets -function Camera:getOffsets () - return -self.x,-self.y -end - --- Position -function Camera:setPosition (x, y) - local x = x or 0 - local y = y or 0 - self.x, self.y = x, y -end - -function Camera:getPosition () - return self.x, self.y -end - -function Camera:getPositionScaled () - return self.x*self.scale, self.y*self.scale -end - --- Destination -function Camera:setDestination (x, y) - local x = x or 0 - local y = y or 0 - self.dest_x, self.dest_y = x, y -end - -function Camera:getDestination () - return self.dest_x, self.dest_y -end - --- Translate points -function Camera:translatePosition(x, y) - local x = x or 0 - local y = y or 0 - return (x-self.x)*self.scale, (y-self.y)*self.scale -end - -function Camera:translatePoints(...) - local a = {...} - local r = {} - local x,y = self:getOffsets() - for k,v in pairs(a) do - if k%2 == 1 then - table.insert(r, (v + x) * self.scale) - else - table.insert(r, (v + y) * self.scale) - end - end - return r -end - --- Shake it --- Really bad script, but for now it works -function Camera:shake () - if self.shake_x == 0 then - self.shake_x = math.random(-10, 10) * 2 - elseif self.shake_x > 0 then - self.shake_x = math.random(-10, -1) * 2 - elseif self.shake_x < 0 then - self.shake_x = math.random(10, 1) * 2 - end - if self.shake_y == 0 then - self.shake_y = math.random(-10, 10) * 2 - elseif self.shake_y > 0 then - self.shake_y = math.random(-10, -1) * 2 - elseif self.shake_y < 0 then - self.shake_y = math.random(10, 1) * 2 - end - local x = self.origin_x + self.shake_x - local y = self.origin_y + self.shake_y - self:setDestination(x, y) -end - -function Camera:startShake () - self.timer = 0.3 - self.origin_x, self.origin_y = self:getPosition() -end - --- Move follow -function Camera:follow () - local map = self.world.map - local sum_x,sum_y,i = map.center_x, map.center_y, 1 - for k,naut in pairs(self.world.Nauts) do - local naut_x,naut_y = naut:getPosition() - if math.abs(naut_x - map.center_x) < map.width/2 and - math.abs(naut_y - map.center_y) < map.height/2 then - i = i + 1 - sum_x = naut_x + sum_x - sum_y = naut_y + sum_y - end - end - local x = sum_x / i - love.graphics.getWidth()/self.scale/2 - local y = sum_y / i - love.graphics.getHeight()/self.scale/2 + 4*self.scale -- hotfix - return x,y -end - --- Update -function Camera:update (dt) - if self.timer > 0 then - self.timer = self.timer - dt - if self.delay <= 0 then - self:shake() - self.delay = 0.02 - else - self.delay = self.delay - dt - end - else - self:setDestination(self:follow()) - end - local dx, dy = self:getDestination() - dx = (dx - self.x) * 6 * dt - dy = (dy - self.y) * 6 * dt - self:setPosition(self.x + dx, self.y + dy) -end diff --git a/main.lua b/main.lua index b905de6..05eb9e2 100644 --- a/main.lua +++ b/main.lua @@ -25,7 +25,7 @@ end -- Require require "not.World" -require "camera" +require "not.Camera" require "not.Menu" require "not.Controller" require "not.Settings" diff --git a/not/Camera.lua b/not/Camera.lua new file mode 100644 index 0000000..63489f3 --- /dev/null +++ b/not/Camera.lua @@ -0,0 +1,145 @@ +--- `Camera` +-- Used in drawing. +Camera = { + x = 0, + y = 0, + dest_x = 0, + dest_y = 0, + scale = getScale(), + scaler = getRealScale(), + shake = 0, + timer = 0, + delay = 0, + origin_x = 0, + origin_y = 0, + shake_x = 0, + shake_y = 0, + world = --[[not.World]]nil, +} + +-- Constructor of `Camera` +function Camera:new (world) + local o = {} + setmetatable(o, self) + self.__index = self + o.world = world + o:setPosition(o:follow()) + o:setDestination(o:follow()) + return o +end + +-- Drawing offsets +function Camera:getOffsets () + return -self.x,-self.y +end + +-- Position +function Camera:setPosition (x, y) + local x = x or 0 + local y = y or 0 + self.x, self.y = x, y +end + +function Camera:getPosition () + return self.x, self.y +end + +function Camera:getPositionScaled () + return self.x*self.scale, self.y*self.scale +end + +-- Destination +function Camera:setDestination (x, y) + local x = x or 0 + local y = y or 0 + self.dest_x, self.dest_y = x, y +end + +function Camera:getDestination () + return self.dest_x, self.dest_y +end + +-- Translate points +function Camera:translatePosition (x, y) + local x = x or 0 + local y = y or 0 + return (x-self.x)*self.scale, (y-self.y)*self.scale +end + +function Camera:translatePoints(...) + local a = {...} + local r = {} + local x,y = self:getOffsets() + for k,v in pairs(a) do + if k%2 == 1 then + table.insert(r, (v + x) * self.scale) + else + table.insert(r, (v + y) * self.scale) + end + end + return r +end + +-- Shake it +-- Really bad script, but for now it works +function Camera:shake () + if self.shake_x == 0 then + self.shake_x = math.random(-10, 10) * 2 + elseif self.shake_x > 0 then + self.shake_x = math.random(-10, -1) * 2 + elseif self.shake_x < 0 then + self.shake_x = math.random(10, 1) * 2 + end + if self.shake_y == 0 then + self.shake_y = math.random(-10, 10) * 2 + elseif self.shake_y > 0 then + self.shake_y = math.random(-10, -1) * 2 + elseif self.shake_y < 0 then + self.shake_y = math.random(10, 1) * 2 + end + local x = self.origin_x + self.shake_x + local y = self.origin_y + self.shake_y + self:setDestination(x, y) +end + +function Camera:startShake () + self.timer = 0.3 + self.origin_x, self.origin_y = self:getPosition() +end + +-- Move follow +function Camera:follow () + local map = self.world.map + local sum_x,sum_y,i = map.center_x, map.center_y, 1 + for k,naut in pairs(self.world.Nauts) do + local naut_x,naut_y = naut:getPosition() + if math.abs(naut_x - map.center_x) < map.width/2 and + math.abs(naut_y - map.center_y) < map.height/2 then + i = i + 1 + sum_x = naut_x + sum_x + sum_y = naut_y + sum_y + end + end + local x = sum_x / i - love.graphics.getWidth()/self.scale/2 + local y = sum_y / i - love.graphics.getHeight()/self.scale/2 + 4*self.scale -- hotfix + return x,y +end + +-- Update +function Camera:update (dt) + if self.timer > 0 then + self.timer = self.timer - dt + if self.delay <= 0 then + self:shake() + self.delay = 0.02 + else + self.delay = self.delay - dt + end + else + self:setDestination(self:follow()) + end + local dx, dy = self:getDestination() + dx = (dx - self.x) * 6 * dt + dy = (dy - self.y) * 6 * dt + self:setPosition(self.x + dx, self.y + dy) +end -- cgit v1.1 From 20770db3aba953585495d21bfe0a2e430485b038 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 23:03:50 +0200 Subject: First steps in cleaning-up menu. Selector, Button and Header extend Element now. --- button.lua | 56 +++++++++++++++++++++---------------------- element.lua | 50 ++++++++++++++++++++++---------------- header.lua | 45 ++++++++++++++--------------------- selector.lua | 78 ++++++++++++++++++++++++------------------------------------ 4 files changed, 105 insertions(+), 124 deletions(-) diff --git a/button.lua b/button.lua index c5681b2..7afc8e9 100644 --- a/button.lua +++ b/button.lua @@ -1,51 +1,48 @@ --- `Button` --- Button used in `Menu` - +--- `Button` +-- Menu element that can be activated by user. Button = { - text = "", - focused = false, + parent = --[[not.Menu]]nil, x = 0, y = 0, + text = "", + focused = false, sprite, quads, delay = 2, parent, } -function Button:new(parent) - local o = {} - setmetatable(o, self) - self.__index = self +-- `Button` is a child of `Element`. +require "element" +Button.__index = Button +setmetatable(Button, Element) + +function Button:new (parent) + local o = setmetatable({}, self) o.parent = parent o.sprite, o.quads = parent:getSheet() return o end -function Button:setText(text) + +function Button:setText (text) self.text = text or "" return self end -function Button:setPosition(x, y) - self.x = x or 0 - self.y = y or 0 - return self -end -function Button:getPosition() return self.x,self.y end + function Button:focus(next) self.focused = true return true end -function Button:blur() +function Button:blur () self.focused = false end -function Button:active() end -function Button:isEnabled() return true end -function Button:set(name, func) - if type(name) == "string" and type(func) == "function" then - self[name] = func - end - return self + +function Button:active () end +function Button:isEnabled () + return true end -function Button:draw(scale) + +function Button:draw (scale) local x,y = self:getPosition() local quad = self.quads local sprite = self.sprite @@ -62,17 +59,18 @@ function Button:draw(scale) love.graphics.setFont(Font) love.graphics.printf(self.text, (x+2)*scale, (y+4)*scale, 54, "center", 0, scale, scale) end -function Button:update(dt) + +function Button:update (dt) self.delay = self.delay + dt if self.delay > Button.delay then -- Button.delay is initial self.delay = self.delay - Button.delay end end -function Button:controlpressed(set, action, key) + +function Button:controlpressed (set, action, key) if action == "attack" and self.focused and self:isEnabled() then self:active() end end -function Button:controlreleased(set, action, key) end -return Button \ No newline at end of file +return Button diff --git a/element.lua b/element.lua index f9d1c3d..e6d91da 100644 --- a/element.lua +++ b/element.lua @@ -1,42 +1,50 @@ --- `Element` --- Empty element for `Menu` creation. Can be anything. +--- `Element` +-- Empty element used inside `Menu`. Element = { + parent = --[[not.Menu]]nil, x = 0, - y = 0, - parent + y = 0 } -function Element:new(parent) - local o = {} - setmetatable(o, self) - self.__index = self + +Element.__index = Element + +function Element:new (parent) + local o = setmetatable({}, self) o.parent = parent return o end -function Element:delete() end -- deletes Element -function Element:getPosition() return self.x, self.y end -- gives x,y of Element -function Element:setPosition(x,y) - self.x, self.y = x, y + +function Element:delete () end -- deletes Element + +function Element:getPosition () + return self.x, self.y +end +function Element:setPosition (x, y) + self.x = x or 0 + self.y = y or 0 return self end -function Element:set(name, func) + +function Element:set (name, func) if type(name) == "string" and func ~= nil then self[name] = func end return self end --- Menu callbacks -function Element:focus() -- Called when Element gains focus +-- Called when menu tries to focus on this element. +-- If it will return false then menu will skip element and go to next in list. +function Element:focus () return false end -function Element:blur() end -- Called when Element loses focus +function Element:blur () end -- Called when Element loses focus. -- LÖVE2D callbacks -function Element:draw(scale) end -function Element:update(dt) end +function Element:draw (scale) end +function Element:update (dt) end -- Controller callbacks -function Element:controlpressed(set, action, key) end -function Element:controlreleased(set, action, key) end +function Element:controlpressed (set, action, key) end +function Element:controlreleased (set, action, key) end -return Element \ No newline at end of file +return Element diff --git a/header.lua b/header.lua index d67e582..9c18bf1 100644 --- a/header.lua +++ b/header.lua @@ -1,41 +1,36 @@ --- `Header` --- It dances! - +--- `Header` +-- Swinging title. Header = { + parent = --[[not.Menu]]nil, x = 0, y = 0, text = "", - parent, bounce = 2, } -function Header:new(parent) - local o = {} - setmetatable(o, self) - self.__index = self + +-- `Header` is a child of `Element`. +require "element" +Header.__index = Header +setmetatable(Header, Element) + +function Header:new (parent) + local o = setmetatable({}, self) o.parent = parent return o end -function Header:setText(text) + +function Header:setText (text) self.text = text or "" return self end -function Header:setPosition(x, y) - self.x = x or 0 - self.y = y or 0 - return self -end -function Header:getBounce(f) + +function Header:getBounce (f) local f = f or 1 return math.sin(self.bounce*f*math.pi) end -function Header:getPosition() return self.x,self.y end -- gives x,y of Element -function Header:focus() - return false -end -function Header:blur() end -- Called when Element loses focus -- LÖVE2D callbacks -function Header:draw(scale) +function Header:draw (scale) local angle = self:getBounce(2) local dy = self:getBounce()*4 local x,y = self:getPosition() @@ -43,15 +38,11 @@ function Header:draw(scale) love.graphics.setFont(Bold) love.graphics.printf(string.upper(self.text),x*scale,(y+dy)*scale,400,"center",(angle*5)*math.pi/180,scale,scale,200,12) end -function Header:update(dt) +function Header:update (dt) self.bounce = self.bounce + dt*0.7 if self.bounce > Header.bounce then -- Header.bounce is initial self.bounce = self.bounce - Header.bounce end end --- Controller callbacks -function Header:controlpressed(set, action, key) end -function Header:controlreleased(set, action, key) end - -return Header \ No newline at end of file +return Header diff --git a/selector.lua b/selector.lua index 03be918..1a449ed 100644 --- a/selector.lua +++ b/selector.lua @@ -1,4 +1,4 @@ --- `Selector` (Element) +--- `Selector` -- Used in Menu for selecting various things from list. Works for each Controller set or globally. --[[ How to use `Selector` in `Menu` config file? @@ -12,9 +12,8 @@ selector:new(menu) :set("global", false) -- true: single selector; false: selector for each controller set present :init() ]] - Selector = { - parent, + parent = --[[not.Menu]]nil, x = 0, y = 0, width = 0, @@ -35,53 +34,39 @@ Selector = { icons_q } +-- `Selector` is a child of `Element`. +require "element" +Selector.__index = Selector +setmetatable(Selector, Element) + -- Constructor -function Selector:new(parent) - local o = {} - setmetatable(o, self) - self.__index = self +function Selector:new (parent) + local o = setmetatable({}, self) o.parent = parent o.sprite, o.quads = parent:getSheet() return o end --- Position -function Selector:getPosition() - return self.x, self.y -end -function Selector:setPosition(x,y) - self.x, self.y = x, y - return self -end - -- Size of single block -function Selector:getSize() +function Selector:getSize () return self.width, self.height end -function Selector:setSize(width, height) +function Selector:setSize (width, height) self.width, self.height = width, height return self end -- Spacing between two blocks -function Selector:getMargin() +function Selector:getMargin () return self.margin end -function Selector:setMargin(margin) +function Selector:setMargin (margin) self.margin = margin return self end --- General setter for Menu configuration files -function Selector:set(name, func) - if type(name) == "string" and func ~= nil then - self[name] = func - end - return self -end - -- Initialize Selector with current settings. -function Selector:init() +function Selector:init () -- Make sure that there is list present if self.list == nil then self.list = {} @@ -105,17 +90,17 @@ function Selector:init() end -- Cycle through list on given number -function Selector:next(n) +function Selector:next (n) local current = self.selections[n] self:setSelection(n, current + 1) end -function Selector:previous(n) +function Selector:previous (n) local current = self.selections[n] self:setSelection(n, current - 1) end -- Get number associated with a given set -function Selector:checkNumber(set) +function Selector:checkNumber (set) if self.global then return 1 end -- For global Selector for n,check in pairs(self.sets) do if check == set then return n end @@ -123,13 +108,13 @@ function Selector:checkNumber(set) end -- Check if given number is locked -function Selector:isLocked(n) +function Selector:isLocked (n) local n = n or 1 return self.locks[n] end -- Sets value of selection of given number. Returns old. -function Selector:setSelection(n, new) +function Selector:setSelection (n, new) -- Functception. It sounds like fun but it isn't. local function limit(new, total) if new > total then @@ -147,18 +132,18 @@ function Selector:setSelection(n, new) end -- Get value of selection of given number -function Selector:getSelection(n) +function Selector:getSelection (n) local n = n or 1 return self.selections[n] end -- Get value from list by selection -function Selector:getListValue(i) +function Selector:getListValue (i) return self.list[i] end -- Checks if selection of given number is unique within Selector scope. -function Selector:isUnique(n) +function Selector:isUnique (n) local selection = self:getSelection(n) for fn,v in pairs(self.selections) do if fn ~= n and self:isLocked(fn) and v == selection then @@ -169,7 +154,7 @@ function Selector:isUnique(n) end -- Get list of selections, checks if not locked are allowed. -function Selector:getFullSelection(allowed) +function Selector:getFullSelection (allowed) local allowed = allowed if allowed == nil then allowed = false end local t = {} @@ -186,7 +171,7 @@ function Selector:getFullSelection(allowed) end -- Rolls and returns random selection from list that is not locked. -function Selector:rollRandom(avoids) +function Selector:rollRandom (avoids) -- Me: You should make it simpler. -- Inner me: Nah, it works. Leave it. -- Me: Ok, let's leave it as it is. @@ -209,7 +194,7 @@ function Selector:rollRandom(avoids) end -- Draw single block of Selector -function Selector:drawBlock(n, x, y, scale) +function Selector:drawBlock (n, x, y, scale) if self.quads == nil or self.sprite == nil then return end local x, y = x or 0, y or 0 local name = self:getListValue(self:getSelection(n)) @@ -249,16 +234,16 @@ function Selector:drawBlock(n, x, y, scale) end -- Menu callbacks -function Selector:focus() -- Called when Element gains focus +function Selector:focus () -- Called when Element gains focus self.focused = true return true end -function Selector:blur() -- Called when Element loses focus +function Selector:blur () -- Called when Element loses focus self.focused = false end -- LÖVE2D callbacks -function Selector:draw(scale) +function Selector:draw (scale) local x,y = self:getPosition() local margin = self:getMargin() local width = self:getSize() @@ -267,7 +252,7 @@ function Selector:draw(scale) self:drawBlock(n, x+(margin+width)*(n-1)+margin*n, y, scale) end end -function Selector:update(dt) +function Selector:update (dt) self.delay = self.delay + dt if self.delay > Selector.delay then -- Selector.delay is initial self.delay = self.delay - Selector.delay @@ -276,7 +261,7 @@ end -- Controller callbacks -- TODO: Add action to perform when key is pressed and selector is locked in e.g. to move into character selection from map selection. -function Selector:controlpressed(set, action, key) +function Selector:controlpressed (set, action, key) if set and self.focused then local n = self:checkNumber(set) local locked = self:isLocked(n) @@ -301,6 +286,5 @@ function Selector:controlpressed(set, action, key) end end end -function Selector:controlreleased(set, action, key) end -return Selector \ No newline at end of file +return Selector -- cgit v1.1 From 37767d6c54ea6af0b4631b5ce838ee584603895e Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 7 Apr 2017 02:53:36 +0200 Subject: Moved menu configs to subdirectory --- config/menucredits.lua | 24 ---------- config/menuhost.lua | 42 ----------------- config/menumain.lua | 59 ------------------------ config/menus/credits.lua | 24 ++++++++++ config/menus/host.lua | 42 +++++++++++++++++ config/menus/main.lua | 59 ++++++++++++++++++++++++ config/menus/select.lua | 73 +++++++++++++++++++++++++++++ config/menus/settings.lua | 114 ++++++++++++++++++++++++++++++++++++++++++++++ config/menuselect.lua | 73 ----------------------------- config/menusettings.lua | 114 ---------------------------------------------- not/Menu.lua | 4 +- 11 files changed, 314 insertions(+), 314 deletions(-) delete mode 100644 config/menucredits.lua delete mode 100644 config/menuhost.lua delete mode 100644 config/menumain.lua create mode 100644 config/menus/credits.lua create mode 100644 config/menus/host.lua create mode 100644 config/menus/main.lua create mode 100644 config/menus/select.lua create mode 100644 config/menus/settings.lua delete mode 100644 config/menuselect.lua delete mode 100644 config/menusettings.lua diff --git a/config/menucredits.lua b/config/menucredits.lua deleted file mode 100644 index 0510333..0000000 --- a/config/menucredits.lua +++ /dev/null @@ -1,24 +0,0 @@ -local menu = ... - -local button = require "button" -local element = require "element" - -local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() -local bx = width/2-29 - -return { - button:new(menu) - :setText("Go back") - :setPosition(bx,144) - :set("active", function (self) - self.parent:open("menumain") - end) - , - element:new(menu) - :setPosition(width/2, 30) - :set("draw", function (self, scale) - local x,y = self:getPosition() - love.graphics.printf("A game by the Awesomenauts community including:\nSeltzy, PlasmaWisp, ParaDoX, MilkingChicken, Burningdillo, Bronkey and Aki.\n\n04font was used.\n\nBased on a game by Jan Willem Nijman, Paul Veer and Bits_Beats XOXO.\n\nAwesomenauts is property of Ronimo Games.", (x-110)*scale, (y+10)*scale, 220, "left", 0, scale, scale) - end) - , -} \ No newline at end of file diff --git a/config/menuhost.lua b/config/menuhost.lua deleted file mode 100644 index ae5e3dd..0000000 --- a/config/menuhost.lua +++ /dev/null @@ -1,42 +0,0 @@ -local menu = ... - -local button = require "button" -local selector = require "selector" - -local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale() -local bx = width/2-29 - -local map_selector = selector:new(menu) - -return { - map_selector - :setPosition(width/2, 40) - :setSize(80, 42) - :setMargin(0) - :set("global", true) - :set("first", true) - :set("list", require "maplist") - :set("icons_i", love.graphics.newImage("assets/maps.png")) - :set("icons_q", require "mapicons") - :set("shape", "panorama") - :init() - , - button:new(menu) - :setText("Next") - :setPosition(bx,101) - :set("isEnabled", function () - return map_selector:isLocked() - end) - :set("active", function (self) - MAP = map_selector:getFullSelection(true)[1][1] -- please, don't kill me for this, kek - self.parent:open("menuselect") - end) - , - button:new(menu) - :setText("Go back") - :setPosition(bx,117) - :set("active", function (self) - self.parent:open("menumain") - end) - , -} \ No newline at end of file diff --git a/config/menumain.lua b/config/menumain.lua deleted file mode 100644 index 4e5ef1f..0000000 --- a/config/menumain.lua +++ /dev/null @@ -1,59 +0,0 @@ -local menu = ... - -local button = require "button" -local header = require "header" -local element = require "element" - -local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale() -local bx = width/2-29 - -local awesometwo = love.graphics.newImage("assets/two.png") - -return { - button:new(menu) - :setText("Start") - :setPosition(bx, 80) - :set("active", function (self) - self.parent:open("menuhost") - end) - , - button:new(menu) - :setText("Join") - :setPosition(bx, 96) - :set("isEnabled", function (self) - return false - end) - , - button:new(menu) - :setText("Settings") - :setPosition(bx, 112) - :set("active", function (self) - self.parent:open("menusettings") - end) - , - button:new(menu) - :setText("Credits") - :setPosition(bx, 128) - :set("active", function (self) - self.parent:open("menucredits") - end) - , - button:new(menu) - :setText("Exit") - :setPosition(bx, 144) - :set("active", love.event.quit) - , - element:new(menu) - :setPosition(width/2, 15) - :set("draw", function (self, scale) - local x,y = self:getPosition() - love.graphics.setColor(255, 255, 255, 255) - love.graphics.setFont(Bold) - love.graphics.draw(awesometwo, x*scale, y*scale, 0, scale, scale, 35) - end) - , - header:new(menu) - :setText("Roflnauts") - :setPosition(width/2,40) - , -} \ No newline at end of file diff --git a/config/menus/credits.lua b/config/menus/credits.lua new file mode 100644 index 0000000..6ba04b3 --- /dev/null +++ b/config/menus/credits.lua @@ -0,0 +1,24 @@ +local menu = ... + +local button = require "button" +local element = require "element" + +local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() +local bx = width/2-29 + +return { + button:new(menu) + :setText("Go back") + :setPosition(bx,144) + :set("active", function (self) + self.parent:open("main") + end) + , + element:new(menu) + :setPosition(width/2, 30) + :set("draw", function (self, scale) + local x,y = self:getPosition() + love.graphics.printf("A game by the Awesomenauts community including:\nSeltzy, PlasmaWisp, ParaDoX, MilkingChicken, Burningdillo, Bronkey and Aki.\n\n04font was used.\n\nBased on a game by Jan Willem Nijman, Paul Veer and Bits_Beats XOXO.\n\nAwesomenauts is property of Ronimo Games.", (x-110)*scale, (y+10)*scale, 220, "left", 0, scale, scale) + end) + , +} \ No newline at end of file diff --git a/config/menus/host.lua b/config/menus/host.lua new file mode 100644 index 0000000..47aaa5e --- /dev/null +++ b/config/menus/host.lua @@ -0,0 +1,42 @@ +local menu = ... + +local button = require "button" +local selector = require "selector" + +local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale() +local bx = width/2-29 + +local map_selector = selector:new(menu) + +return { + map_selector + :setPosition(width/2, 40) + :setSize(80, 42) + :setMargin(0) + :set("global", true) + :set("first", true) + :set("list", require "maplist") + :set("icons_i", love.graphics.newImage("assets/maps.png")) + :set("icons_q", require "mapicons") + :set("shape", "panorama") + :init() + , + button:new(menu) + :setText("Next") + :setPosition(bx,101) + :set("isEnabled", function () + return map_selector:isLocked() + end) + :set("active", function (self) + MAP = map_selector:getFullSelection(true)[1][1] -- please, don't kill me for this, kek + self.parent:open("select") + end) + , + button:new(menu) + :setText("Go back") + :setPosition(bx,117) + :set("active", function (self) + self.parent:open("main") + end) + , +} \ No newline at end of file diff --git a/config/menus/main.lua b/config/menus/main.lua new file mode 100644 index 0000000..661299c --- /dev/null +++ b/config/menus/main.lua @@ -0,0 +1,59 @@ +local menu = ... + +local button = require "button" +local header = require "header" +local element = require "element" + +local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale() +local bx = width/2-29 + +local awesometwo = love.graphics.newImage("assets/two.png") + +return { + button:new(menu) + :setText("Start") + :setPosition(bx, 80) + :set("active", function (self) + self.parent:open("host") + end) + , + button:new(menu) + :setText("Join") + :setPosition(bx, 96) + :set("isEnabled", function (self) + return false + end) + , + button:new(menu) + :setText("Settings") + :setPosition(bx, 112) + :set("active", function (self) + self.parent:open("settings") + end) + , + button:new(menu) + :setText("Credits") + :setPosition(bx, 128) + :set("active", function (self) + self.parent:open("credits") + end) + , + button:new(menu) + :setText("Exit") + :setPosition(bx, 144) + :set("active", love.event.quit) + , + element:new(menu) + :setPosition(width/2, 15) + :set("draw", function (self, scale) + local x,y = self:getPosition() + love.graphics.setColor(255, 255, 255, 255) + love.graphics.setFont(Bold) + love.graphics.draw(awesometwo, x*scale, y*scale, 0, scale, scale, 35) + end) + , + header:new(menu) + :setText("Roflnauts") + :setPosition(width/2,40) + , +} \ No newline at end of file diff --git a/config/menus/select.lua b/config/menus/select.lua new file mode 100644 index 0000000..452a3bf --- /dev/null +++ b/config/menus/select.lua @@ -0,0 +1,73 @@ +local menu = ... + +local button = require "button" +local selector = require "selector" +local element = require "element" + +local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale() +local bx = width/2-29 + +local naut_selector = selector:new(menu) +local start_button = button:new(menu) + +return { + naut_selector + :setPosition(width/2,60) + :setMargin(8) + :setSize(32, 32) + :set("list", require "nautslist") + :set("global", false) + :set("icons_i", love.graphics.newImage("assets/portraits.png")) + :set("icons_q", require "nautsicons") + :init() + , + start_button + :setText("Force start") + :setPosition(bx,134) + :set("isEnabled", function () + if #naut_selector:getFullSelection(false) > 1 then + return true + end + return false + end) + :set("active", function (self) + local nauts = naut_selector:getFullSelection(false) + if #nauts > 1 then + changeScene(World:new(MAP, nauts)) + end + end) + , + button:new(menu) + :setText("Go back") + :setPosition(bx,150) + :set("active", function (self) + self.parent:open("host") + end) + , + element:new(menu) + :setPosition(bx, 101) + :set("the_final_countdown", 9) + :set("draw", function (self, scale) + if self.the_final_countdown ~= 9 then + local x,y = self:getPosition() + local countdown = math.max(1, math.ceil(self.the_final_countdown)) + love.graphics.setColor(255, 255, 255, 255) + love.graphics.setFont(Font) + love.graphics.print("Autostart in:", (x-16)*scale, (y+10)*scale, 0, scale, scale) + love.graphics.setFont(Bold) + love.graphics.printf(countdown, (x+40)*scale, (y)*scale, 36, "center", 0, scale, scale) + end + end) + :set("update", function (self, dt) + local total = #naut_selector:getFullSelection(false) + if total > 1 then + self.the_final_countdown = self.the_final_countdown - dt + else + self.the_final_countdown = 9 + end + if self.the_final_countdown < 0 then + start_button:active() + end + end) + , +} \ No newline at end of file diff --git a/config/menus/settings.lua b/config/menus/settings.lua new file mode 100644 index 0000000..bfdfc6e --- /dev/null +++ b/config/menus/settings.lua @@ -0,0 +1,114 @@ +local menu = ... + +local button = require "button" +local selector = require "selector" +local element = require "element" + +local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() +local bx = width/2-29 + +local keys = {"Left", "Right", "Up", "Down", "Attack", "Jump"} + +local dimmer = element:new(menu) + :setPosition(width/2, 15) + :set("visible", false) + :set("currentControl", "Left") -- it actually means control that is being set CURRENTLY + :set("previousControl", "") -- it actually means key that was set as this control PREVIOUSLY + :set("draw", function (self, scale) + if self.visible then + love.graphics.setColor(0, 0, 0, 210) + love.graphics.rectangle("fill",0,0,width*getRealScale(),height*getRealScale()) + love.graphics.setColor(120, 255, 120, 255) + love.graphics.printf("Press new key for: \n> " .. self.currentControl .. " <", (width/2-110)*scale, (height/2-4)*scale, 220, "center", 0, scale, scale) + love.graphics.setColor(120, 120, 120, 255) + love.graphics.printf("Old: " .. self.previousControl .. "", (width/2-110)*scale, (height/2+16)*scale, 220, "center", 0, scale, scale) + love.graphics.setColor(255, 255, 255, 255) + end + end) + +-- CHANGER functions +local isEnabled = function (self) + if Controller.getSets()[self.setNumber()] and not self.inProgress then + return true + else + return false + end +end +local startChange = function (self) + dimmer:set("visible", true):set("currentControl", "Left") + self.parent.allowMove = false + self.inProgress = true + self.currentKey = 0 + -- Displaying old key should be done less tricky; REWORK NEEDED + dimmer:set("previousControl", Controller.sets[self.setNumber()][string.lower(keys[self.currentKey+1])]) + self.newSet = {} +end +local controlreleased = function(self, set, action, key) + if self.inProgress then + if self.currentKey > 0 and self.currentKey < 7 then + table.insert(self.newSet, key) + dimmer:set("currentControl", keys[self.currentKey+1]) + end + -- There is something wrong with this `if` statements... I mean, look at these numbers. + if self.currentKey > 5 then + dimmer:set("visible", false) + self.parent.allowMove = true + self.inProgress = false + table.insert(self.newSet, Controller.getSets()[self.setNumber()].joystick) + print(self.newSet[7]) + Settings.change(self.setNumber(), self.newSet[1], self.newSet[2], self.newSet[3], self.newSet[4], self.newSet[5], self.newSet[6], self.newSet[7]) + else + dimmer:set("previousControl", Controller.sets[self.setNumber()][string.lower(keys[self.currentKey+1])]) + self.currentKey = self.currentKey + 1 + end + end +end + +local a = { + button:new(menu) + :setText("Keyboard 1") + :setPosition(bx,80) + :set("setNumber", function () return 1 end) + :set("isEnabled", isEnabled) + :set("controlreleased", controlreleased) + :set("stopChange", stopChange) + :set("active", startChange) + , + button:new(menu) + :setText("Keyboard 2") + :setPosition(bx,96) + :set("setNumber", function () return 2 end) + :set("isEnabled", isEnabled) + :set("controlreleased", controlreleased) + :set("stopChange", stopChange) + :set("active", startChange) + , + button:new(menu) + :setText("Gamepad 1") + :setPosition(bx,112) + :set("setNumber", function () return 3 end) + :set("isEnabled", isEnabled) + :set("controlreleased", controlreleased) + :set("stopChange", stopChange) + :set("active", startChange) + , + button:new(menu) + :setText("Gamepad 2") + :setPosition(bx,128) + :set("setNumber", function () return 4 end) + :set("isEnabled", isEnabled) + :set("controlreleased", controlreleased) + :set("stopChange", stopChange) + :set("active", startChange) + , + button:new(menu) + :setText("Go back") + :setPosition(bx,144) + :set("active", function (self) + self.parent:open("main") + end) + , + dimmer +} + +return a \ No newline at end of file diff --git a/config/menuselect.lua b/config/menuselect.lua deleted file mode 100644 index 7b9f073..0000000 --- a/config/menuselect.lua +++ /dev/null @@ -1,73 +0,0 @@ -local menu = ... - -local button = require "button" -local selector = require "selector" -local element = require "element" - -local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale() -local bx = width/2-29 - -local naut_selector = selector:new(menu) -local start_button = button:new(menu) - -return { - naut_selector - :setPosition(width/2,60) - :setMargin(8) - :setSize(32, 32) - :set("list", require "nautslist") - :set("global", false) - :set("icons_i", love.graphics.newImage("assets/portraits.png")) - :set("icons_q", require "nautsicons") - :init() - , - start_button - :setText("Force start") - :setPosition(bx,134) - :set("isEnabled", function () - if #naut_selector:getFullSelection(false) > 1 then - return true - end - return false - end) - :set("active", function (self) - local nauts = naut_selector:getFullSelection(false) - if #nauts > 1 then - changeScene(World:new(MAP, nauts)) - end - end) - , - button:new(menu) - :setText("Go back") - :setPosition(bx,150) - :set("active", function (self) - self.parent:open("menuhost") - end) - , - element:new(menu) - :setPosition(bx, 101) - :set("the_final_countdown", 9) - :set("draw", function (self, scale) - if self.the_final_countdown ~= 9 then - local x,y = self:getPosition() - local countdown = math.max(1, math.ceil(self.the_final_countdown)) - love.graphics.setColor(255, 255, 255, 255) - love.graphics.setFont(Font) - love.graphics.print("Autostart in:", (x-16)*scale, (y+10)*scale, 0, scale, scale) - love.graphics.setFont(Bold) - love.graphics.printf(countdown, (x+40)*scale, (y)*scale, 36, "center", 0, scale, scale) - end - end) - :set("update", function (self, dt) - local total = #naut_selector:getFullSelection(false) - if total > 1 then - self.the_final_countdown = self.the_final_countdown - dt - else - self.the_final_countdown = 9 - end - if self.the_final_countdown < 0 then - start_button:active() - end - end) - , -} \ No newline at end of file diff --git a/config/menusettings.lua b/config/menusettings.lua deleted file mode 100644 index 19f952e..0000000 --- a/config/menusettings.lua +++ /dev/null @@ -1,114 +0,0 @@ -local menu = ... - -local button = require "button" -local selector = require "selector" -local element = require "element" - -local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() -local bx = width/2-29 - -local keys = {"Left", "Right", "Up", "Down", "Attack", "Jump"} - -local dimmer = element:new(menu) - :setPosition(width/2, 15) - :set("visible", false) - :set("currentControl", "Left") -- it actually means control that is being set CURRENTLY - :set("previousControl", "") -- it actually means key that was set as this control PREVIOUSLY - :set("draw", function (self, scale) - if self.visible then - love.graphics.setColor(0, 0, 0, 210) - love.graphics.rectangle("fill",0,0,width*getRealScale(),height*getRealScale()) - love.graphics.setColor(120, 255, 120, 255) - love.graphics.printf("Press new key for: \n> " .. self.currentControl .. " <", (width/2-110)*scale, (height/2-4)*scale, 220, "center", 0, scale, scale) - love.graphics.setColor(120, 120, 120, 255) - love.graphics.printf("Old: " .. self.previousControl .. "", (width/2-110)*scale, (height/2+16)*scale, 220, "center", 0, scale, scale) - love.graphics.setColor(255, 255, 255, 255) - end - end) - --- CHANGER functions -local isEnabled = function (self) - if Controller.getSets()[self.setNumber()] and not self.inProgress then - return true - else - return false - end -end -local startChange = function (self) - dimmer:set("visible", true):set("currentControl", "Left") - self.parent.allowMove = false - self.inProgress = true - self.currentKey = 0 - -- Displaying old key should be done less tricky; REWORK NEEDED - dimmer:set("previousControl", Controller.sets[self.setNumber()][string.lower(keys[self.currentKey+1])]) - self.newSet = {} -end -local controlreleased = function(self, set, action, key) - if self.inProgress then - if self.currentKey > 0 and self.currentKey < 7 then - table.insert(self.newSet, key) - dimmer:set("currentControl", keys[self.currentKey+1]) - end - -- There is something wrong with this `if` statements... I mean, look at these numbers. - if self.currentKey > 5 then - dimmer:set("visible", false) - self.parent.allowMove = true - self.inProgress = false - table.insert(self.newSet, Controller.getSets()[self.setNumber()].joystick) - print(self.newSet[7]) - Settings.change(self.setNumber(), self.newSet[1], self.newSet[2], self.newSet[3], self.newSet[4], self.newSet[5], self.newSet[6], self.newSet[7]) - else - dimmer:set("previousControl", Controller.sets[self.setNumber()][string.lower(keys[self.currentKey+1])]) - self.currentKey = self.currentKey + 1 - end - end -end - -local a = { - button:new(menu) - :setText("Keyboard 1") - :setPosition(bx,80) - :set("setNumber", function () return 1 end) - :set("isEnabled", isEnabled) - :set("controlreleased", controlreleased) - :set("stopChange", stopChange) - :set("active", startChange) - , - button:new(menu) - :setText("Keyboard 2") - :setPosition(bx,96) - :set("setNumber", function () return 2 end) - :set("isEnabled", isEnabled) - :set("controlreleased", controlreleased) - :set("stopChange", stopChange) - :set("active", startChange) - , - button:new(menu) - :setText("Gamepad 1") - :setPosition(bx,112) - :set("setNumber", function () return 3 end) - :set("isEnabled", isEnabled) - :set("controlreleased", controlreleased) - :set("stopChange", stopChange) - :set("active", startChange) - , - button:new(menu) - :setText("Gamepad 2") - :setPosition(bx,128) - :set("setNumber", function () return 4 end) - :set("isEnabled", isEnabled) - :set("controlreleased", controlreleased) - :set("stopChange", stopChange) - :set("active", startChange) - , - button:new(menu) - :setText("Go back") - :setPosition(bx,144) - :set("active", function (self) - self.parent:open("menumain") - end) - , - dimmer -} - -return a \ No newline at end of file diff --git a/not/Menu.lua b/not/Menu.lua index 1be6f00..8ef1861 100644 --- a/not/Menu.lua +++ b/not/Menu.lua @@ -63,9 +63,9 @@ function Menu:delete () end function Menu:open (name) - local name = name or "menumain" + local name = name or "main" self.active = Menu.active --Menu.active is initial - self.elements = love.filesystem.load(string.format("config/%s.lua", name))(self) + self.elements = love.filesystem.load(string.format("config/menus/%s.lua", name))(self) self.elements[self.active]:focus() end -- cgit v1.1 From 54e85dd188af15cd5f3f5e08f5d3e69088a909b1 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 7 Apr 2017 03:06:26 +0200 Subject: Moved map configs to config directory --- config/maps/aiguillon.lua | 58 ++++++++++++++++++++++++++++ config/maps/alpha abyss.lua | 75 ++++++++++++++++++++++++++++++++++++ config/maps/default.lua | 47 +++++++++++++++++++++++ config/maps/readme.md | 82 +++++++++++++++++++++++++++++++++++++++ config/maps/ribbit.lua | 46 ++++++++++++++++++++++ config/maps/rill.lua | 73 +++++++++++++++++++++++++++++++++++ config/maps/sorona.lua | 53 ++++++++++++++++++++++++++ config/maps/starstorm.lua | 93 +++++++++++++++++++++++++++++++++++++++++++++ maps/aiguillon.lua | 58 ---------------------------- maps/alpha abyss.lua | 75 ------------------------------------ maps/default.lua | 47 ----------------------- maps/readme.md | 82 --------------------------------------- maps/ribbit.lua | 46 ---------------------- maps/rill.lua | 73 ----------------------------------- maps/sorona.lua | 53 -------------------------- maps/starstorm.lua | 93 --------------------------------------------- not/World.lua | 3 +- 17 files changed, 528 insertions(+), 529 deletions(-) create mode 100644 config/maps/aiguillon.lua create mode 100644 config/maps/alpha abyss.lua create mode 100644 config/maps/default.lua create mode 100644 config/maps/readme.md create mode 100644 config/maps/ribbit.lua create mode 100644 config/maps/rill.lua create mode 100644 config/maps/sorona.lua create mode 100644 config/maps/starstorm.lua delete mode 100644 maps/aiguillon.lua delete mode 100644 maps/alpha abyss.lua delete mode 100644 maps/default.lua delete mode 100644 maps/readme.md delete mode 100644 maps/ribbit.lua delete mode 100644 maps/rill.lua delete mode 100644 maps/sorona.lua delete mode 100644 maps/starstorm.lua diff --git a/config/maps/aiguillon.lua b/config/maps/aiguillon.lua new file mode 100644 index 0000000..40d3928 --- /dev/null +++ b/config/maps/aiguillon.lua @@ -0,0 +1,58 @@ +return { + -- CENTER AND SIZE + name = "aiguillon", + theme = "aiguillon.ogg", + center_x = 0, + center_y = 10, + width = 370, + height = 290, + -- RESPAWN POINTS + respawns = { + {x = 0, y = -80}, + {x = 0, y = -80}, + {x = 0, y = -80}, + {x = 0, y = -80}, + }, + -- GRAPHICS + clouds = false, + background = "assets/backgrounds/aiguillon.png", + platforms = { + { + x = -108, + y = 22, + shape = {1,0, 212,0, 212,12, 206,18, 14,18, 1,12}, + sprite = "assets/platforms/aiguillon-wide.png" + }, + { + x = -46, + y = -19, + shape = {1,0, 87,0, 87,18, 14,18, 1,12}, + sprite = "assets/platforms/aiguillon-middle.png" + }, + { + x = -141, + y = -57, + shape = {1,0, 50,0, 50,18, 5,18, 1,13}, + sprite = "assets/platforms/aiguillon-left-big.png" + }, + { + x = -132, + y = 84, + shape = {1,0, 25,0, 25,18, 1,18}, + sprite = "assets/platforms/aiguillon-left-small.png" + }, + { + x = 77, + y = -57, + shape = {1,0, 50,0, 50,12, 37,18, 1,18}, + sprite = "assets/platforms/aiguillon-right-big.png" + }, + { + x = 103, + y = 84, + shape = {1,0, 25,0, 25,18, 1,18}, + sprite = "assets/platforms/aiguillon-right-small.png" + } + }, + decorations = {} +} diff --git a/config/maps/alpha abyss.lua b/config/maps/alpha abyss.lua new file mode 100644 index 0000000..0dd2c61 --- /dev/null +++ b/config/maps/alpha abyss.lua @@ -0,0 +1,75 @@ +-- The abyss of the alpha. +-- Animations +local animations_small = { + default = { + frames = 20, + repeated = true + } +} +local animations_big = { + default = { + frames = 20, + repeated = true + } +} +for i=1,10 do + local a = love.graphics.newQuad(i*118-118, 0, 118,51, 1180,51) + animations_big.default[i*2-1] = a + animations_big.default[i*2] = a + local a = love.graphics.newQuad(i*60-60, 0, 60,20, 600,20) + animations_small.default[i*2-1] = a + animations_small.default[i*2] = a +end +-- Map data +return { + -- GENERAL + name = "alpha abyss", + theme = "alpha.ogg", + center_x = 0, + center_y = -80, + width = 360, + height = 240, + -- RESPAWN POINTS + respawns = { + {x = -30, y = 0}, + {x = 30, y = 0}, + {x = 0, y = 0}, + {x = -120, y = -50}, + {x = 120, y = -50}, + {x = 0, y = -75} + }, + -- GRAPHICS + clouds = false, + background = "assets/backgrounds/alpha-1.png", + platforms = { + { + x = -60, + y = 0, + shape = {0,0, 117,0, 101,50, 16,50}, + sprite = "assets/platforms/alpha-big.png", + animations = animations_big + }, + { + x = -145, + y = -50, + shape = {0,0, 59,0, 59,19, 0,19}, + sprite = "assets/platforms/alpha-small.png", + animations = animations_small + }, + { + x = 85, + y = -50, + shape = {0,0, 59,0, 59,19, 0,19}, + sprite = "assets/platforms/alpha-small.png", + animations = animations_small + }, + { + x = -30, + y = -80, + shape = {0,0, 59,0, 59,19, 0,19}, + sprite = "assets/platforms/alpha-small.png", + animations = animations_small + } + }, + decorations = {} +} diff --git a/config/maps/default.lua b/config/maps/default.lua new file mode 100644 index 0000000..05b8dc9 --- /dev/null +++ b/config/maps/default.lua @@ -0,0 +1,47 @@ +-- Default map from original roflnauts +return { + -- GENERAL + name = "default", + theme = "default.ogg", + center_x = 0, + center_y = 0, + width = 360, + height = 240, + -- RESPAWN POINTS + respawns = { + {x = -15, y = -80}, + {x = -5, y = -80}, + {x = 5, y = -80}, + {x = 15, y = -80} + }, + -- GRAPHICS + clouds = true, + background = "assets/backgrounds/default.png", + platforms = { + { + x = -91, + y = 0, + shape = {0,1, 180,1, 180,10, 95,76, 86,76, 0,10}, + sprite = "assets/platforms/default-big.png" + }, + { + x = 114, + y = 50, + shape = {0,1, 51,1, 51,18, 0,18}, + sprite = "assets/platforms/default-side.png" + }, + { + x = -166, + y = 50, + shape = {0,1, 51,1, 51,18, 0,18}, + sprite = "assets/platforms/default-side.png" + }, + { + x = -17, + y = -50, + shape = {0,1, 33,1, 33,14, 0,14}, + sprite = "assets/platforms/default-top.png" + } + }, + decorations = {} +} diff --git a/config/maps/readme.md b/config/maps/readme.md new file mode 100644 index 0000000..dc139ad --- /dev/null +++ b/config/maps/readme.md @@ -0,0 +1,82 @@ +# Mapmaking +*Hugs Emo* + +### Name (string) +Name of the map. Should be same as the filename. *I think*. +```lua +name = "default" +``` + +### Center (int) +Coordinates of center of the map. Camera zone and death zone are placed relative to it. +```lua +center_x = 0, +center_y = 0 +``` + +### Size (int) +Width and height of playground. Camera zone and death zone sizes are calculated based on map size. +```lua +width = 360, +height = 240 +``` + +### Respawns (table, int) +Table of possible respawn points. Players will randomly spawn on one of these points. +```lua +respawns = { + {x = -15, y = -80}, + {x = -5, y = -80}, + {x = 5, y = -80}, + {x = 15, y = -80} +} +``` + +### Clouds (bool) +Presence of clouds. Clouds will spawn if set to **true**. +```lua +clouds = true +``` + +### Background (string) +Path to background image in the game structure. It will be used as fixed background. +```lua +background = "assets/background-default.png" +``` + +### Platforms (table, int, string) +Platforms on which player can stand. They will be placed on given coordinates with given sprite and shape. +Shape are points placed relatively to platform's coordinates. Shape points are connected in given order. On top of that last point is connected with first one. +```lua +platforms = { + { + x = -91, + y = 0, + shape = {0,1, 181,1, 181,10, 96,76, 86,76, 0,10}, + sprite = "assets/platform_big.png" + }, + { + x = 114, + y = 50, + shape = {0,1, 52,1, 52,30, 0,30}, + sprite = "assets/platform_small.png" + } +} +``` + +### Decoration (table, int, string) +Decorations are objects in the background which are not fixed but move alongside with foreground objects (platforms, players, clouds). They do not have physical body. +```lua +decorations = { + { + x = -80, + y = 10, + sprite = "assets/decoration_big.png" + }, + { + x = 50, + y = 50, + sprite = "assets/decoration_small.png" + } +} +``` \ No newline at end of file diff --git a/config/maps/ribbit.lua b/config/maps/ribbit.lua new file mode 100644 index 0000000..c3f5c78 --- /dev/null +++ b/config/maps/ribbit.lua @@ -0,0 +1,46 @@ +return { + -- GENERAL + name = "ribbit", + theme = "ribbit.ogg", + center_x = 0, + center_y = 50, + width = 360, + height = 240, + -- RESPAWN POINTS + respawns = { + {x = -15, y = -80}, + {x = -5, y = -80}, + {x = 5, y = -80}, + {x = 15, y = -80} + }, + -- GRAPHICS + clouds = false, + background = "assets/backgrounds/ribbit.png", + platforms = { + { + x = -154, + y = 10, + shape = {1,12, 48,12, 48,32, 1,32}, + sprite = "assets/platforms/ribbit-left.png" + }, + { + x = 67, + y = 7, + shape = {36,14, 83,14, 83,29, 36,29}, + sprite = "assets/platforms/ribbit-right.png" + }, + { + x = -70, + y = -5, + shape = {0,3, 139,3, 134,24, 5,24}, + sprite = "assets/platforms/ribbit-top.png" + }, + { + x = -54, + y = 63, + shape = {0,3, 107,3, 75,44, 32,44}, + sprite = "assets/platforms/ribbit-bottom.png" + } + }, + decorations = {} +} \ No newline at end of file diff --git a/config/maps/rill.lua b/config/maps/rill.lua new file mode 100644 index 0000000..83c02f2 --- /dev/null +++ b/config/maps/rill.lua @@ -0,0 +1,73 @@ +return { + -- CENTER AND SIZE + name = "rill", + theme = "rill.ogg", + center_x = 0, + center_y = 75, + width = 400, + height = 260, + -- RESPAWN POINTS + respawns = { + {x = -135, y = 10}, + {x = -135, y = 10}, + {x = 135, y = 10}, + {x = 135, y = 10} + }, + -- GRAPHICS + clouds = false, + background = "assets/backgrounds/rill.png", + platforms = { + { + x = -151, + y = 25, + shape = {0,0, 55,0, 55,11, 0,11}, + sprite = "assets/platforms/rill-flat-left.png" + }, + { + x = 93, + y = 25, + shape = {0,0, 55,0, 55,11, 0,11}, + sprite = "assets/platforms/rill-flat-right.png" + }, + { + x = -24, + y = 55, + shape = {0,0, 48,0, 47,15, 1,15}, + sprite = "assets/platforms/rill-center.png" + }, + { + x = -112, + y = 80, + shape = {77,30, 17,0, 0,0, 0,7, 77,44}, + sprite = "assets/platforms/rill-slope-left.png" + }, + { + x = 35, + y = 80, + shape = {0,30, 60,0, 77,0, 77,7, 0,44}, + sprite = "assets/platforms/rill-slope-right.png" + } + }, + decorations = { + { + x = 98, + y = -20, + sprite = "assets/decorations/rill-lollipop-big-purple.png" + }, + { + x = 127, + y = 4, + sprite = "assets/decorations/rill-lollipop-small-green.png" + }, + { + x = -152, + y = -20, + sprite = "assets/decorations/rill-lollipop-big-orange.png" + }, + { + x = -121, + y = 4, + sprite = "assets/decorations/rill-lollipop-small-blue.png" + }, + } +} diff --git a/config/maps/sorona.lua b/config/maps/sorona.lua new file mode 100644 index 0000000..8ec4727 --- /dev/null +++ b/config/maps/sorona.lua @@ -0,0 +1,53 @@ +-- Sorona, but with the worms and such. +return { + -- GENERAL + name = "sorona", + theme = "sorona.ogg", + center_x = 0, + center_y = 0, + width = 360, + height = 240, + -- RESPAWN POINTS + respawns = { + {x = -98, y = -70}, + {x = 70, y = -70}, + {x = -30, y = -20}, + {x = -90, y = 40}, + }, + -- GRAPHICS + clouds = false, + background = "assets/backgrounds/sorona.png", + platforms = { + { + x = -60, + y = 0, + shape = {0,1, 59,1, 59,17, 0,17}, + sprite = "assets/platforms/sorona-center.png" + }, + { + x = -40, + y = 55, + shape = {3,0, 180,0, 180,20, 3,20}, + sprite = "assets/platforms/sorona-right-bottom.png" + }, + { + x = -120, + y = 55, + shape = {3,0, 62,0, 62,23, 3,23}, + sprite = "assets/platforms/sorona-left-bottom.png" + }, + { + x = 0, + y = -50, + shape = {1,1, 140,1, 1,17, 140,17}, + sprite = "assets/platforms/sorona-right-top.png" + }, + { + x = -150, + y = -55, + shape = {1,9, 106,9, 40,27, 1,27}, + sprite = "assets/platforms/sorona-left-top.png" + } + }, + decorations = {} +} diff --git a/config/maps/starstorm.lua b/config/maps/starstorm.lua new file mode 100644 index 0000000..7f00633 --- /dev/null +++ b/config/maps/starstorm.lua @@ -0,0 +1,93 @@ +return { + -- CENTER AND SIZE + name = "starstorm", + theme = "starstorm.ogg", + center_x = 0, + center_y = -20, + width = 400, + height = 260, + -- RESPAWN POINTS + respawns = { + {x = 100, y = 45}, + {x = -100, y = 45}, + {x = -90, y = -25}, + {x = 90, y = -25}, + {x = -110, y = -70}, + {x = 110, y = -70} + }, + -- GRAPHICS + clouds = false, + background = "assets/backgrounds/starstorm.png", + platforms = { + { + x = -170, + y = -55, + shape = { + {0,1, 33,1, 39,6, 39,21, 31,21, 0,21}, + {40,6, 115,6, 115,14, 40,14} + }, + sprite = "assets/platforms/starstorm-left-top.png" + }, + { + x = -156, + y = -2, + shape = {0,0, 109,0, 109,20, 0,20}, + sprite = "assets/platforms/starstorm-left-middle.png" + }, + { + x = -160, + y = 69, + shape = {0,4, 8,4, 13,1, 102,1, 102,16, 19,16, 0,11}, + sprite = "assets/platforms/starstorm-left-bottom.png" + }, + { + x = 52, + y = -55, + shape = { + {115,1, 82,1, 76,6, 76,21, 84,21, 115,21}, + {75,6, 0,6, 0,14, 75,14} + }, + sprite = "assets/platforms/starstorm-right-top.png" + }, + { + x = 44, + y = -2, + shape = {109,0, 0,0, 0,20, 109,20}, + sprite = "assets/platforms/starstorm-right-middle.png" + }, + { + x = 55, + y = 69, + shape = {102,4, 94,4, 89,1, 0,1, 0,16, 83,16, 102,11}, + sprite = "assets/platforms/starstorm-right-bottom.png" + }, + { + x = -27, + y = 40, + shape = {0,6, 53,6, 53,14, 0,14}, + sprite = "assets/platforms/starstorm-center.png" + } + }, + decorations = { + { + x = -166, + y = -37, + sprite = "assets/decorations/starstorm-left-top.png" + }, + { + x = -163, + y = 19, + sprite = "assets/decorations/starstorm-left-bottom.png" + }, + { + x = 119, + y = -37, + sprite = "assets/decorations/starstorm-right-top.png" + }, + { + x = 52+77, + y = 19, + sprite = "assets/decorations/starstorm-right-bottom.png" + } + } +} diff --git a/maps/aiguillon.lua b/maps/aiguillon.lua deleted file mode 100644 index 40d3928..0000000 --- a/maps/aiguillon.lua +++ /dev/null @@ -1,58 +0,0 @@ -return { - -- CENTER AND SIZE - name = "aiguillon", - theme = "aiguillon.ogg", - center_x = 0, - center_y = 10, - width = 370, - height = 290, - -- RESPAWN POINTS - respawns = { - {x = 0, y = -80}, - {x = 0, y = -80}, - {x = 0, y = -80}, - {x = 0, y = -80}, - }, - -- GRAPHICS - clouds = false, - background = "assets/backgrounds/aiguillon.png", - platforms = { - { - x = -108, - y = 22, - shape = {1,0, 212,0, 212,12, 206,18, 14,18, 1,12}, - sprite = "assets/platforms/aiguillon-wide.png" - }, - { - x = -46, - y = -19, - shape = {1,0, 87,0, 87,18, 14,18, 1,12}, - sprite = "assets/platforms/aiguillon-middle.png" - }, - { - x = -141, - y = -57, - shape = {1,0, 50,0, 50,18, 5,18, 1,13}, - sprite = "assets/platforms/aiguillon-left-big.png" - }, - { - x = -132, - y = 84, - shape = {1,0, 25,0, 25,18, 1,18}, - sprite = "assets/platforms/aiguillon-left-small.png" - }, - { - x = 77, - y = -57, - shape = {1,0, 50,0, 50,12, 37,18, 1,18}, - sprite = "assets/platforms/aiguillon-right-big.png" - }, - { - x = 103, - y = 84, - shape = {1,0, 25,0, 25,18, 1,18}, - sprite = "assets/platforms/aiguillon-right-small.png" - } - }, - decorations = {} -} diff --git a/maps/alpha abyss.lua b/maps/alpha abyss.lua deleted file mode 100644 index 0dd2c61..0000000 --- a/maps/alpha abyss.lua +++ /dev/null @@ -1,75 +0,0 @@ --- The abyss of the alpha. --- Animations -local animations_small = { - default = { - frames = 20, - repeated = true - } -} -local animations_big = { - default = { - frames = 20, - repeated = true - } -} -for i=1,10 do - local a = love.graphics.newQuad(i*118-118, 0, 118,51, 1180,51) - animations_big.default[i*2-1] = a - animations_big.default[i*2] = a - local a = love.graphics.newQuad(i*60-60, 0, 60,20, 600,20) - animations_small.default[i*2-1] = a - animations_small.default[i*2] = a -end --- Map data -return { - -- GENERAL - name = "alpha abyss", - theme = "alpha.ogg", - center_x = 0, - center_y = -80, - width = 360, - height = 240, - -- RESPAWN POINTS - respawns = { - {x = -30, y = 0}, - {x = 30, y = 0}, - {x = 0, y = 0}, - {x = -120, y = -50}, - {x = 120, y = -50}, - {x = 0, y = -75} - }, - -- GRAPHICS - clouds = false, - background = "assets/backgrounds/alpha-1.png", - platforms = { - { - x = -60, - y = 0, - shape = {0,0, 117,0, 101,50, 16,50}, - sprite = "assets/platforms/alpha-big.png", - animations = animations_big - }, - { - x = -145, - y = -50, - shape = {0,0, 59,0, 59,19, 0,19}, - sprite = "assets/platforms/alpha-small.png", - animations = animations_small - }, - { - x = 85, - y = -50, - shape = {0,0, 59,0, 59,19, 0,19}, - sprite = "assets/platforms/alpha-small.png", - animations = animations_small - }, - { - x = -30, - y = -80, - shape = {0,0, 59,0, 59,19, 0,19}, - sprite = "assets/platforms/alpha-small.png", - animations = animations_small - } - }, - decorations = {} -} diff --git a/maps/default.lua b/maps/default.lua deleted file mode 100644 index 05b8dc9..0000000 --- a/maps/default.lua +++ /dev/null @@ -1,47 +0,0 @@ --- Default map from original roflnauts -return { - -- GENERAL - name = "default", - theme = "default.ogg", - center_x = 0, - center_y = 0, - width = 360, - height = 240, - -- RESPAWN POINTS - respawns = { - {x = -15, y = -80}, - {x = -5, y = -80}, - {x = 5, y = -80}, - {x = 15, y = -80} - }, - -- GRAPHICS - clouds = true, - background = "assets/backgrounds/default.png", - platforms = { - { - x = -91, - y = 0, - shape = {0,1, 180,1, 180,10, 95,76, 86,76, 0,10}, - sprite = "assets/platforms/default-big.png" - }, - { - x = 114, - y = 50, - shape = {0,1, 51,1, 51,18, 0,18}, - sprite = "assets/platforms/default-side.png" - }, - { - x = -166, - y = 50, - shape = {0,1, 51,1, 51,18, 0,18}, - sprite = "assets/platforms/default-side.png" - }, - { - x = -17, - y = -50, - shape = {0,1, 33,1, 33,14, 0,14}, - sprite = "assets/platforms/default-top.png" - } - }, - decorations = {} -} diff --git a/maps/readme.md b/maps/readme.md deleted file mode 100644 index dc139ad..0000000 --- a/maps/readme.md +++ /dev/null @@ -1,82 +0,0 @@ -# Mapmaking -*Hugs Emo* - -### Name (string) -Name of the map. Should be same as the filename. *I think*. -```lua -name = "default" -``` - -### Center (int) -Coordinates of center of the map. Camera zone and death zone are placed relative to it. -```lua -center_x = 0, -center_y = 0 -``` - -### Size (int) -Width and height of playground. Camera zone and death zone sizes are calculated based on map size. -```lua -width = 360, -height = 240 -``` - -### Respawns (table, int) -Table of possible respawn points. Players will randomly spawn on one of these points. -```lua -respawns = { - {x = -15, y = -80}, - {x = -5, y = -80}, - {x = 5, y = -80}, - {x = 15, y = -80} -} -``` - -### Clouds (bool) -Presence of clouds. Clouds will spawn if set to **true**. -```lua -clouds = true -``` - -### Background (string) -Path to background image in the game structure. It will be used as fixed background. -```lua -background = "assets/background-default.png" -``` - -### Platforms (table, int, string) -Platforms on which player can stand. They will be placed on given coordinates with given sprite and shape. -Shape are points placed relatively to platform's coordinates. Shape points are connected in given order. On top of that last point is connected with first one. -```lua -platforms = { - { - x = -91, - y = 0, - shape = {0,1, 181,1, 181,10, 96,76, 86,76, 0,10}, - sprite = "assets/platform_big.png" - }, - { - x = 114, - y = 50, - shape = {0,1, 52,1, 52,30, 0,30}, - sprite = "assets/platform_small.png" - } -} -``` - -### Decoration (table, int, string) -Decorations are objects in the background which are not fixed but move alongside with foreground objects (platforms, players, clouds). They do not have physical body. -```lua -decorations = { - { - x = -80, - y = 10, - sprite = "assets/decoration_big.png" - }, - { - x = 50, - y = 50, - sprite = "assets/decoration_small.png" - } -} -``` \ No newline at end of file diff --git a/maps/ribbit.lua b/maps/ribbit.lua deleted file mode 100644 index c3f5c78..0000000 --- a/maps/ribbit.lua +++ /dev/null @@ -1,46 +0,0 @@ -return { - -- GENERAL - name = "ribbit", - theme = "ribbit.ogg", - center_x = 0, - center_y = 50, - width = 360, - height = 240, - -- RESPAWN POINTS - respawns = { - {x = -15, y = -80}, - {x = -5, y = -80}, - {x = 5, y = -80}, - {x = 15, y = -80} - }, - -- GRAPHICS - clouds = false, - background = "assets/backgrounds/ribbit.png", - platforms = { - { - x = -154, - y = 10, - shape = {1,12, 48,12, 48,32, 1,32}, - sprite = "assets/platforms/ribbit-left.png" - }, - { - x = 67, - y = 7, - shape = {36,14, 83,14, 83,29, 36,29}, - sprite = "assets/platforms/ribbit-right.png" - }, - { - x = -70, - y = -5, - shape = {0,3, 139,3, 134,24, 5,24}, - sprite = "assets/platforms/ribbit-top.png" - }, - { - x = -54, - y = 63, - shape = {0,3, 107,3, 75,44, 32,44}, - sprite = "assets/platforms/ribbit-bottom.png" - } - }, - decorations = {} -} \ No newline at end of file diff --git a/maps/rill.lua b/maps/rill.lua deleted file mode 100644 index 83c02f2..0000000 --- a/maps/rill.lua +++ /dev/null @@ -1,73 +0,0 @@ -return { - -- CENTER AND SIZE - name = "rill", - theme = "rill.ogg", - center_x = 0, - center_y = 75, - width = 400, - height = 260, - -- RESPAWN POINTS - respawns = { - {x = -135, y = 10}, - {x = -135, y = 10}, - {x = 135, y = 10}, - {x = 135, y = 10} - }, - -- GRAPHICS - clouds = false, - background = "assets/backgrounds/rill.png", - platforms = { - { - x = -151, - y = 25, - shape = {0,0, 55,0, 55,11, 0,11}, - sprite = "assets/platforms/rill-flat-left.png" - }, - { - x = 93, - y = 25, - shape = {0,0, 55,0, 55,11, 0,11}, - sprite = "assets/platforms/rill-flat-right.png" - }, - { - x = -24, - y = 55, - shape = {0,0, 48,0, 47,15, 1,15}, - sprite = "assets/platforms/rill-center.png" - }, - { - x = -112, - y = 80, - shape = {77,30, 17,0, 0,0, 0,7, 77,44}, - sprite = "assets/platforms/rill-slope-left.png" - }, - { - x = 35, - y = 80, - shape = {0,30, 60,0, 77,0, 77,7, 0,44}, - sprite = "assets/platforms/rill-slope-right.png" - } - }, - decorations = { - { - x = 98, - y = -20, - sprite = "assets/decorations/rill-lollipop-big-purple.png" - }, - { - x = 127, - y = 4, - sprite = "assets/decorations/rill-lollipop-small-green.png" - }, - { - x = -152, - y = -20, - sprite = "assets/decorations/rill-lollipop-big-orange.png" - }, - { - x = -121, - y = 4, - sprite = "assets/decorations/rill-lollipop-small-blue.png" - }, - } -} diff --git a/maps/sorona.lua b/maps/sorona.lua deleted file mode 100644 index 8ec4727..0000000 --- a/maps/sorona.lua +++ /dev/null @@ -1,53 +0,0 @@ --- Sorona, but with the worms and such. -return { - -- GENERAL - name = "sorona", - theme = "sorona.ogg", - center_x = 0, - center_y = 0, - width = 360, - height = 240, - -- RESPAWN POINTS - respawns = { - {x = -98, y = -70}, - {x = 70, y = -70}, - {x = -30, y = -20}, - {x = -90, y = 40}, - }, - -- GRAPHICS - clouds = false, - background = "assets/backgrounds/sorona.png", - platforms = { - { - x = -60, - y = 0, - shape = {0,1, 59,1, 59,17, 0,17}, - sprite = "assets/platforms/sorona-center.png" - }, - { - x = -40, - y = 55, - shape = {3,0, 180,0, 180,20, 3,20}, - sprite = "assets/platforms/sorona-right-bottom.png" - }, - { - x = -120, - y = 55, - shape = {3,0, 62,0, 62,23, 3,23}, - sprite = "assets/platforms/sorona-left-bottom.png" - }, - { - x = 0, - y = -50, - shape = {1,1, 140,1, 1,17, 140,17}, - sprite = "assets/platforms/sorona-right-top.png" - }, - { - x = -150, - y = -55, - shape = {1,9, 106,9, 40,27, 1,27}, - sprite = "assets/platforms/sorona-left-top.png" - } - }, - decorations = {} -} diff --git a/maps/starstorm.lua b/maps/starstorm.lua deleted file mode 100644 index 7f00633..0000000 --- a/maps/starstorm.lua +++ /dev/null @@ -1,93 +0,0 @@ -return { - -- CENTER AND SIZE - name = "starstorm", - theme = "starstorm.ogg", - center_x = 0, - center_y = -20, - width = 400, - height = 260, - -- RESPAWN POINTS - respawns = { - {x = 100, y = 45}, - {x = -100, y = 45}, - {x = -90, y = -25}, - {x = 90, y = -25}, - {x = -110, y = -70}, - {x = 110, y = -70} - }, - -- GRAPHICS - clouds = false, - background = "assets/backgrounds/starstorm.png", - platforms = { - { - x = -170, - y = -55, - shape = { - {0,1, 33,1, 39,6, 39,21, 31,21, 0,21}, - {40,6, 115,6, 115,14, 40,14} - }, - sprite = "assets/platforms/starstorm-left-top.png" - }, - { - x = -156, - y = -2, - shape = {0,0, 109,0, 109,20, 0,20}, - sprite = "assets/platforms/starstorm-left-middle.png" - }, - { - x = -160, - y = 69, - shape = {0,4, 8,4, 13,1, 102,1, 102,16, 19,16, 0,11}, - sprite = "assets/platforms/starstorm-left-bottom.png" - }, - { - x = 52, - y = -55, - shape = { - {115,1, 82,1, 76,6, 76,21, 84,21, 115,21}, - {75,6, 0,6, 0,14, 75,14} - }, - sprite = "assets/platforms/starstorm-right-top.png" - }, - { - x = 44, - y = -2, - shape = {109,0, 0,0, 0,20, 109,20}, - sprite = "assets/platforms/starstorm-right-middle.png" - }, - { - x = 55, - y = 69, - shape = {102,4, 94,4, 89,1, 0,1, 0,16, 83,16, 102,11}, - sprite = "assets/platforms/starstorm-right-bottom.png" - }, - { - x = -27, - y = 40, - shape = {0,6, 53,6, 53,14, 0,14}, - sprite = "assets/platforms/starstorm-center.png" - } - }, - decorations = { - { - x = -166, - y = -37, - sprite = "assets/decorations/starstorm-left-top.png" - }, - { - x = -163, - y = 19, - sprite = "assets/decorations/starstorm-left-bottom.png" - }, - { - x = 119, - y = -37, - sprite = "assets/decorations/starstorm-right-top.png" - }, - { - x = 52+77, - y = 19, - sprite = "assets/decorations/starstorm-right-bottom.png" - } - } -} diff --git a/not/World.lua b/not/World.lua index 2a6106c..bbceec4 100644 --- a/not/World.lua +++ b/not/World.lua @@ -79,8 +79,7 @@ end -- TODO: Change current map model to function-based one. function World:loadMap (name) local name = name or "default" - name = "maps/" .. name .. ".lua" - local map = love.filesystem.load(name) + local map = love.filesystem.load(string.format("config/maps/%s.lua", name)) self.map = map() -- Platforms for _,platform in pairs(self.map.platforms) do -- cgit v1.1 From d1a19fea50aefc9d7fb52568a5bdcfb56d75eccf Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 7 Apr 2017 03:24:40 +0200 Subject: Moved menu elements to /not/ --- button.lua | 76 ------------ config/menus/credits.lua | 4 +- config/menus/host.lua | 4 +- config/menus/main.lua | 6 +- config/menus/select.lua | 6 +- config/menus/settings.lua | 6 +- element.lua | 50 -------- header.lua | 48 -------- not/Button.lua | 76 ++++++++++++ not/Element.lua | 50 ++++++++ not/Header.lua | 48 ++++++++ not/Selector.lua | 290 ++++++++++++++++++++++++++++++++++++++++++++++ selector.lua | 290 ---------------------------------------------- 13 files changed, 477 insertions(+), 477 deletions(-) delete mode 100644 button.lua delete mode 100644 element.lua delete mode 100644 header.lua create mode 100644 not/Button.lua create mode 100644 not/Element.lua create mode 100644 not/Header.lua create mode 100644 not/Selector.lua delete mode 100644 selector.lua diff --git a/button.lua b/button.lua deleted file mode 100644 index 7afc8e9..0000000 --- a/button.lua +++ /dev/null @@ -1,76 +0,0 @@ ---- `Button` --- Menu element that can be activated by user. -Button = { - parent = --[[not.Menu]]nil, - x = 0, - y = 0, - text = "", - focused = false, - sprite, - quads, - delay = 2, - parent, -} - --- `Button` is a child of `Element`. -require "element" -Button.__index = Button -setmetatable(Button, Element) - -function Button:new (parent) - local o = setmetatable({}, self) - o.parent = parent - o.sprite, o.quads = parent:getSheet() - return o -end - -function Button:setText (text) - self.text = text or "" - return self -end - -function Button:focus(next) - self.focused = true - return true -end -function Button:blur () - self.focused = false -end - -function Button:active () end -function Button:isEnabled () - return true -end - -function Button:draw (scale) - local x,y = self:getPosition() - local quad = self.quads - local sprite = self.sprite - if self:isEnabled() then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(140, 140, 140, 255) - end - love.graphics.draw(sprite, quad.button.normal, x*scale, y*scale, 0, scale, scale) - if self.focused then - love.graphics.draw(sprite, quad.arrow_l, (x+54+math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) - love.graphics.draw(sprite, quad.arrow_r, (x-2-math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) - end - love.graphics.setFont(Font) - love.graphics.printf(self.text, (x+2)*scale, (y+4)*scale, 54, "center", 0, scale, scale) -end - -function Button:update (dt) - self.delay = self.delay + dt - if self.delay > Button.delay then -- Button.delay is initial - self.delay = self.delay - Button.delay - end -end - -function Button:controlpressed (set, action, key) - if action == "attack" and self.focused and self:isEnabled() then - self:active() - end -end - -return Button diff --git a/config/menus/credits.lua b/config/menus/credits.lua index 6ba04b3..77cba62 100644 --- a/config/menus/credits.lua +++ b/config/menus/credits.lua @@ -1,7 +1,7 @@ local menu = ... -local button = require "button" -local element = require "element" +local button = require "not.Button" +local element = require "not.Element" local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() local bx = width/2-29 diff --git a/config/menus/host.lua b/config/menus/host.lua index 47aaa5e..8a4887e 100644 --- a/config/menus/host.lua +++ b/config/menus/host.lua @@ -1,7 +1,7 @@ local menu = ... -local button = require "button" -local selector = require "selector" +local button = require "not.Button" +local selector = require "not.Selector" local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale() local bx = width/2-29 diff --git a/config/menus/main.lua b/config/menus/main.lua index 661299c..236c011 100644 --- a/config/menus/main.lua +++ b/config/menus/main.lua @@ -1,8 +1,8 @@ local menu = ... -local button = require "button" -local header = require "header" -local element = require "element" +local button = require "not.Button" +local header = require "not.Header" +local element = require "not.Element" local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale() local bx = width/2-29 diff --git a/config/menus/select.lua b/config/menus/select.lua index 452a3bf..e759f40 100644 --- a/config/menus/select.lua +++ b/config/menus/select.lua @@ -1,8 +1,8 @@ local menu = ... -local button = require "button" -local selector = require "selector" -local element = require "element" +local button = require "not.Button" +local selector = require "not.Selector" +local element = require "not.Element" local width, height = love.graphics.getWidth()/getScale(), love.graphics.getHeight()/getScale() local bx = width/2-29 diff --git a/config/menus/settings.lua b/config/menus/settings.lua index bfdfc6e..ae0403d 100644 --- a/config/menus/settings.lua +++ b/config/menus/settings.lua @@ -1,8 +1,8 @@ local menu = ... -local button = require "button" -local selector = require "selector" -local element = require "element" +local button = require "not.Button" +local selector = require "not.Selector" +local element = require "not.Element" local width, height = love.graphics.getWidth()/getRealScale(), love.graphics.getHeight()/getRealScale() local bx = width/2-29 diff --git a/element.lua b/element.lua deleted file mode 100644 index e6d91da..0000000 --- a/element.lua +++ /dev/null @@ -1,50 +0,0 @@ ---- `Element` --- Empty element used inside `Menu`. -Element = { - parent = --[[not.Menu]]nil, - x = 0, - y = 0 -} - -Element.__index = Element - -function Element:new (parent) - local o = setmetatable({}, self) - o.parent = parent - return o -end - -function Element:delete () end -- deletes Element - -function Element:getPosition () - return self.x, self.y -end -function Element:setPosition (x, y) - self.x = x or 0 - self.y = y or 0 - return self -end - -function Element:set (name, func) - if type(name) == "string" and func ~= nil then - self[name] = func - end - return self -end - --- Called when menu tries to focus on this element. --- If it will return false then menu will skip element and go to next in list. -function Element:focus () - return false -end -function Element:blur () end -- Called when Element loses focus. - --- LÖVE2D callbacks -function Element:draw (scale) end -function Element:update (dt) end - --- Controller callbacks -function Element:controlpressed (set, action, key) end -function Element:controlreleased (set, action, key) end - -return Element diff --git a/header.lua b/header.lua deleted file mode 100644 index 9c18bf1..0000000 --- a/header.lua +++ /dev/null @@ -1,48 +0,0 @@ ---- `Header` --- Swinging title. -Header = { - parent = --[[not.Menu]]nil, - x = 0, - y = 0, - text = "", - bounce = 2, -} - --- `Header` is a child of `Element`. -require "element" -Header.__index = Header -setmetatable(Header, Element) - -function Header:new (parent) - local o = setmetatable({}, self) - o.parent = parent - return o -end - -function Header:setText (text) - self.text = text or "" - return self -end - -function Header:getBounce (f) - local f = f or 1 - return math.sin(self.bounce*f*math.pi) -end - --- LÖVE2D callbacks -function Header:draw (scale) - local angle = self:getBounce(2) - local dy = self:getBounce()*4 - local x,y = self:getPosition() - love.graphics.setColor(255,255,255,255) - love.graphics.setFont(Bold) - love.graphics.printf(string.upper(self.text),x*scale,(y+dy)*scale,400,"center",(angle*5)*math.pi/180,scale,scale,200,12) -end -function Header:update (dt) - self.bounce = self.bounce + dt*0.7 - if self.bounce > Header.bounce then -- Header.bounce is initial - self.bounce = self.bounce - Header.bounce - end -end - -return Header diff --git a/not/Button.lua b/not/Button.lua new file mode 100644 index 0000000..91aca45 --- /dev/null +++ b/not/Button.lua @@ -0,0 +1,76 @@ +--- `Button` +-- Menu element that can be activated by user. +Button = { + parent = --[[not.Menu]]nil, + x = 0, + y = 0, + text = "", + focused = false, + sprite, + quads, + delay = 2, + parent, +} + +-- `Button` is a child of `Element`. +require "not.Element" +Button.__index = Button +setmetatable(Button, Element) + +function Button:new (parent) + local o = setmetatable({}, self) + o.parent = parent + o.sprite, o.quads = parent:getSheet() + return o +end + +function Button:setText (text) + self.text = text or "" + return self +end + +function Button:focus(next) + self.focused = true + return true +end +function Button:blur () + self.focused = false +end + +function Button:active () end +function Button:isEnabled () + return true +end + +function Button:draw (scale) + local x,y = self:getPosition() + local quad = self.quads + local sprite = self.sprite + if self:isEnabled() then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(140, 140, 140, 255) + end + love.graphics.draw(sprite, quad.button.normal, x*scale, y*scale, 0, scale, scale) + if self.focused then + love.graphics.draw(sprite, quad.arrow_l, (x+54+math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) + love.graphics.draw(sprite, quad.arrow_r, (x-2-math.floor(self.delay))*scale, (y+5)*scale, 0, scale, scale) + end + love.graphics.setFont(Font) + love.graphics.printf(self.text, (x+2)*scale, (y+4)*scale, 54, "center", 0, scale, scale) +end + +function Button:update (dt) + self.delay = self.delay + dt + if self.delay > Button.delay then -- Button.delay is initial + self.delay = self.delay - Button.delay + end +end + +function Button:controlpressed (set, action, key) + if action == "attack" and self.focused and self:isEnabled() then + self:active() + end +end + +return Button diff --git a/not/Element.lua b/not/Element.lua new file mode 100644 index 0000000..e6d91da --- /dev/null +++ b/not/Element.lua @@ -0,0 +1,50 @@ +--- `Element` +-- Empty element used inside `Menu`. +Element = { + parent = --[[not.Menu]]nil, + x = 0, + y = 0 +} + +Element.__index = Element + +function Element:new (parent) + local o = setmetatable({}, self) + o.parent = parent + return o +end + +function Element:delete () end -- deletes Element + +function Element:getPosition () + return self.x, self.y +end +function Element:setPosition (x, y) + self.x = x or 0 + self.y = y or 0 + return self +end + +function Element:set (name, func) + if type(name) == "string" and func ~= nil then + self[name] = func + end + return self +end + +-- Called when menu tries to focus on this element. +-- If it will return false then menu will skip element and go to next in list. +function Element:focus () + return false +end +function Element:blur () end -- Called when Element loses focus. + +-- LÖVE2D callbacks +function Element:draw (scale) end +function Element:update (dt) end + +-- Controller callbacks +function Element:controlpressed (set, action, key) end +function Element:controlreleased (set, action, key) end + +return Element diff --git a/not/Header.lua b/not/Header.lua new file mode 100644 index 0000000..a563ab2 --- /dev/null +++ b/not/Header.lua @@ -0,0 +1,48 @@ +--- `Header` +-- Swinging title. +Header = { + parent = --[[not.Menu]]nil, + x = 0, + y = 0, + text = "", + bounce = 2, +} + +-- `Header` is a child of `Element`. +require "not.Element" +Header.__index = Header +setmetatable(Header, Element) + +function Header:new (parent) + local o = setmetatable({}, self) + o.parent = parent + return o +end + +function Header:setText (text) + self.text = text or "" + return self +end + +function Header:getBounce (f) + local f = f or 1 + return math.sin(self.bounce*f*math.pi) +end + +-- LÖVE2D callbacks +function Header:draw (scale) + local angle = self:getBounce(2) + local dy = self:getBounce()*4 + local x,y = self:getPosition() + love.graphics.setColor(255,255,255,255) + love.graphics.setFont(Bold) + love.graphics.printf(string.upper(self.text),x*scale,(y+dy)*scale,400,"center",(angle*5)*math.pi/180,scale,scale,200,12) +end +function Header:update (dt) + self.bounce = self.bounce + dt*0.7 + if self.bounce > Header.bounce then -- Header.bounce is initial + self.bounce = self.bounce - Header.bounce + end +end + +return Header diff --git a/not/Selector.lua b/not/Selector.lua new file mode 100644 index 0000000..8e03457 --- /dev/null +++ b/not/Selector.lua @@ -0,0 +1,290 @@ +--- `Selector` +-- Used in Menu for selecting various things from list. Works for each Controller set or globally. +--[[ +How to use `Selector` in `Menu` config file? +selector:new(menu) + :setPosition(x, y) + :setMargin(8) -- each block has marigin on both sides; they do stack + :setSize(32, 32) -- size of single graphics frame + :set("list", require "nautslist") + :set("icons_i", love.graphics.newImage("assets/portraits.png")) + :set("icons_q", require "portraits") + :set("global", false) -- true: single selector; false: selector for each controller set present + :init() +]] +Selector = { + parent = --[[not.Menu]]nil, + x = 0, + y = 0, + width = 0, + height = 0, + margin = 0, + focused = false, + global = false, + delay = 2, + first = false, + list, + sets, + locks, + selections, + shape = "portrait", + sprite, + quads, + icons_i, + icons_q +} + +-- `Selector` is a child of `Element`. +require "not.Element" +Selector.__index = Selector +setmetatable(Selector, Element) + +-- Constructor +function Selector:new (parent) + local o = setmetatable({}, self) + o.parent = parent + o.sprite, o.quads = parent:getSheet() + return o +end + +-- Size of single block +function Selector:getSize () + return self.width, self.height +end +function Selector:setSize (width, height) + self.width, self.height = width, height + return self +end + +-- Spacing between two blocks +function Selector:getMargin () + return self.margin +end +function Selector:setMargin (margin) + self.margin = margin + return self +end + +-- Initialize Selector with current settings. +function Selector:init () + -- Make sure that there is list present + if self.list == nil then + self.list = {} + end + -- Initialize global Selector + if self.global then + self.sets = {} + self.locks = {false} + self.selections = {1} + -- Initialize Selector for Controllers + else + self.sets = Controller.getSets() + self.locks = {} + self.selections = {} + for n=1,#self.sets do + self.locks[n] = false + self.selections[n] = 1 + end + end + return self +end + +-- Cycle through list on given number +function Selector:next (n) + local current = self.selections[n] + self:setSelection(n, current + 1) +end +function Selector:previous (n) + local current = self.selections[n] + self:setSelection(n, current - 1) +end + +-- Get number associated with a given set +function Selector:checkNumber (set) + if self.global then return 1 end -- For global Selector + for n,check in pairs(self.sets) do + if check == set then return n end + end +end + +-- Check if given number is locked +function Selector:isLocked (n) + local n = n or 1 + return self.locks[n] +end + +-- Sets value of selection of given number. Returns old. +function Selector:setSelection (n, new) + -- Functception. It sounds like fun but it isn't. + local function limit(new, total) + if new > total then + return limit(new - total, total) + elseif new < 1 then + return limit(total + new, total) + else + return new + end + end + local n = n or 1 + local old = self.selections[n] + self.selections[n] = limit(new, #self.list) + return old +end + +-- Get value of selection of given number +function Selector:getSelection (n) + local n = n or 1 + return self.selections[n] +end + +-- Get value from list by selection +function Selector:getListValue (i) + return self.list[i] +end + +-- Checks if selection of given number is unique within Selector scope. +function Selector:isUnique (n) + local selection = self:getSelection(n) + for fn,v in pairs(self.selections) do + if fn ~= n and self:isLocked(fn) and v == selection then + return false + end + end + return true +end + +-- Get list of selections, checks if not locked are allowed. +function Selector:getFullSelection (allowed) + local allowed = allowed + if allowed == nil then allowed = false end + local t = {} + for n,v in pairs(self.selections) do + local name = self:getListValue(self:getSelection(n)) + local locked = self:isLocked(n) + if locked or allowed then + local a = {name} + if self.sets[n] then table.insert(a, self.sets[n]) end + table.insert(t, a) + end + end + return t +end + +-- Rolls and returns random selection from list that is not locked. +function Selector:rollRandom (avoids) + -- Me: You should make it simpler. + -- Inner me: Nah, it works. Leave it. + -- Me: Ok, let's leave it as it is. + local avoids = avoids or {} + local total = #self.list + local random = love.math.random(1, total) + local eligible = true + for _,avoid in ipairs(avoids) do + if random == avoid then + eligible = false + break + end + end + if not eligible or self:isLocked(random) then + table.insert(avoids, random) + return self:rollRandom(avoid) + else + return random + end +end + +-- Draw single block of Selector +function Selector:drawBlock (n, x, y, scale) + if self.quads == nil or self.sprite == nil then return end + local x, y = x or 0, y or 0 + local name = self:getListValue(self:getSelection(n)) + local locked = self:isLocked(n) + local sprite = self.sprite + local quad = self.quads + local icon = self.icons_i + local iconq = self.icons_q[name] + local w,h = self:getSize() + local unique = self:isUnique(n) + if unique then + love.graphics.setColor(255, 255, 255, 255) + else + love.graphics.setColor(140, 140, 140, 255) + end + if not locked then + love.graphics.draw(sprite, quad[self.shape].normal, x*scale, y*scale, 0, scale, scale) + else + love.graphics.draw(sprite, quad[self.shape].active, x*scale, y*scale, 0, scale, scale) + end + love.graphics.draw(icon, iconq, (x+2)*scale, (y+3)*scale, 0, scale, scale) + if self.focused then + local dy = (h-6)/2 + if not locked then + love.graphics.draw(sprite, quad.arrow_l, (x+0-2-math.floor(self.delay))* scale, (y+dy)*scale, 0, scale, scale) + love.graphics.draw(sprite, quad.arrow_r, (x+w-4+math.floor(self.delay))*scale, (y+dy)*scale, 0, scale, scale) + else + love.graphics.draw(sprite, quad.arrow_r, (x+0-2-math.floor(self.delay))* scale, (y+dy)*scale, 0, scale, scale) + love.graphics.draw(sprite, quad.arrow_l, (x+w-4+math.floor(self.delay))*scale, (y+dy)*scale, 0, scale, scale) + end + end + if (self:getSelection(n) ~= 1 or self.first) then + love.graphics.setFont(Font) + love.graphics.setColor(255, 255, 255, 255) + love.graphics.printf(string.upper(name), (x-w)*scale, (y+h+1)*scale, w*3, "center", 0, scale, scale) + end +end + +-- Menu callbacks +function Selector:focus () -- Called when Element gains focus + self.focused = true + return true +end +function Selector:blur () -- Called when Element loses focus + self.focused = false +end + +-- LÖVE2D callbacks +function Selector:draw (scale) + local x,y = self:getPosition() + local margin = self:getMargin() + local width = self:getSize() + x = x - #self.selections*0.5*(margin+margin+width) + for n=1,#self.selections do + self:drawBlock(n, x+(margin+width)*(n-1)+margin*n, y, scale) + end +end +function Selector:update (dt) + self.delay = self.delay + dt + if self.delay > Selector.delay then -- Selector.delay is initial + self.delay = self.delay - Selector.delay + end +end + +-- Controller callbacks +-- TODO: Add action to perform when key is pressed and selector is locked in e.g. to move into character selection from map selection. +function Selector:controlpressed (set, action, key) + if set and self.focused then + local n = self:checkNumber(set) + local locked = self:isLocked(n) + if action == "left" and not locked then self:previous(n) end + if action == "right" and not locked then self:next(n) end + if action == "attack" then + local name = self:getListValue(self:getSelection(n)) + if name == "random" then + self:setSelection(n, self:rollRandom({1,2})) -- avoid empty naut + self.locks[n] = true + else + -- If not empty or if first is allowed. Additionaly must be unique selection. + if (self:getSelection(n) ~= 1 or self.first) and self:isUnique(n) then + self.locks[n] = true + end + end + end + if action == "jump" then + if locked then + self.locks[n] = false + end + end + end +end + +return Selector diff --git a/selector.lua b/selector.lua deleted file mode 100644 index 1a449ed..0000000 --- a/selector.lua +++ /dev/null @@ -1,290 +0,0 @@ ---- `Selector` --- Used in Menu for selecting various things from list. Works for each Controller set or globally. ---[[ -How to use `Selector` in `Menu` config file? -selector:new(menu) - :setPosition(x, y) - :setMargin(8) -- each block has marigin on both sides; they do stack - :setSize(32, 32) -- size of single graphics frame - :set("list", require "nautslist") - :set("icons_i", love.graphics.newImage("assets/portraits.png")) - :set("icons_q", require "portraits") - :set("global", false) -- true: single selector; false: selector for each controller set present - :init() -]] -Selector = { - parent = --[[not.Menu]]nil, - x = 0, - y = 0, - width = 0, - height = 0, - margin = 0, - focused = false, - global = false, - delay = 2, - first = false, - list, - sets, - locks, - selections, - shape = "portrait", - sprite, - quads, - icons_i, - icons_q -} - --- `Selector` is a child of `Element`. -require "element" -Selector.__index = Selector -setmetatable(Selector, Element) - --- Constructor -function Selector:new (parent) - local o = setmetatable({}, self) - o.parent = parent - o.sprite, o.quads = parent:getSheet() - return o -end - --- Size of single block -function Selector:getSize () - return self.width, self.height -end -function Selector:setSize (width, height) - self.width, self.height = width, height - return self -end - --- Spacing between two blocks -function Selector:getMargin () - return self.margin -end -function Selector:setMargin (margin) - self.margin = margin - return self -end - --- Initialize Selector with current settings. -function Selector:init () - -- Make sure that there is list present - if self.list == nil then - self.list = {} - end - -- Initialize global Selector - if self.global then - self.sets = {} - self.locks = {false} - self.selections = {1} - -- Initialize Selector for Controllers - else - self.sets = Controller.getSets() - self.locks = {} - self.selections = {} - for n=1,#self.sets do - self.locks[n] = false - self.selections[n] = 1 - end - end - return self -end - --- Cycle through list on given number -function Selector:next (n) - local current = self.selections[n] - self:setSelection(n, current + 1) -end -function Selector:previous (n) - local current = self.selections[n] - self:setSelection(n, current - 1) -end - --- Get number associated with a given set -function Selector:checkNumber (set) - if self.global then return 1 end -- For global Selector - for n,check in pairs(self.sets) do - if check == set then return n end - end -end - --- Check if given number is locked -function Selector:isLocked (n) - local n = n or 1 - return self.locks[n] -end - --- Sets value of selection of given number. Returns old. -function Selector:setSelection (n, new) - -- Functception. It sounds like fun but it isn't. - local function limit(new, total) - if new > total then - return limit(new - total, total) - elseif new < 1 then - return limit(total + new, total) - else - return new - end - end - local n = n or 1 - local old = self.selections[n] - self.selections[n] = limit(new, #self.list) - return old -end - --- Get value of selection of given number -function Selector:getSelection (n) - local n = n or 1 - return self.selections[n] -end - --- Get value from list by selection -function Selector:getListValue (i) - return self.list[i] -end - --- Checks if selection of given number is unique within Selector scope. -function Selector:isUnique (n) - local selection = self:getSelection(n) - for fn,v in pairs(self.selections) do - if fn ~= n and self:isLocked(fn) and v == selection then - return false - end - end - return true -end - --- Get list of selections, checks if not locked are allowed. -function Selector:getFullSelection (allowed) - local allowed = allowed - if allowed == nil then allowed = false end - local t = {} - for n,v in pairs(self.selections) do - local name = self:getListValue(self:getSelection(n)) - local locked = self:isLocked(n) - if locked or allowed then - local a = {name} - if self.sets[n] then table.insert(a, self.sets[n]) end - table.insert(t, a) - end - end - return t -end - --- Rolls and returns random selection from list that is not locked. -function Selector:rollRandom (avoids) - -- Me: You should make it simpler. - -- Inner me: Nah, it works. Leave it. - -- Me: Ok, let's leave it as it is. - local avoids = avoids or {} - local total = #self.list - local random = love.math.random(1, total) - local eligible = true - for _,avoid in ipairs(avoids) do - if random == avoid then - eligible = false - break - end - end - if not eligible or self:isLocked(random) then - table.insert(avoids, random) - return self:rollRandom(avoid) - else - return random - end -end - --- Draw single block of Selector -function Selector:drawBlock (n, x, y, scale) - if self.quads == nil or self.sprite == nil then return end - local x, y = x or 0, y or 0 - local name = self:getListValue(self:getSelection(n)) - local locked = self:isLocked(n) - local sprite = self.sprite - local quad = self.quads - local icon = self.icons_i - local iconq = self.icons_q[name] - local w,h = self:getSize() - local unique = self:isUnique(n) - if unique then - love.graphics.setColor(255, 255, 255, 255) - else - love.graphics.setColor(140, 140, 140, 255) - end - if not locked then - love.graphics.draw(sprite, quad[self.shape].normal, x*scale, y*scale, 0, scale, scale) - else - love.graphics.draw(sprite, quad[self.shape].active, x*scale, y*scale, 0, scale, scale) - end - love.graphics.draw(icon, iconq, (x+2)*scale, (y+3)*scale, 0, scale, scale) - if self.focused then - local dy = (h-6)/2 - if not locked then - love.graphics.draw(sprite, quad.arrow_l, (x+0-2-math.floor(self.delay))* scale, (y+dy)*scale, 0, scale, scale) - love.graphics.draw(sprite, quad.arrow_r, (x+w-4+math.floor(self.delay))*scale, (y+dy)*scale, 0, scale, scale) - else - love.graphics.draw(sprite, quad.arrow_r, (x+0-2-math.floor(self.delay))* scale, (y+dy)*scale, 0, scale, scale) - love.graphics.draw(sprite, quad.arrow_l, (x+w-4+math.floor(self.delay))*scale, (y+dy)*scale, 0, scale, scale) - end - end - if (self:getSelection(n) ~= 1 or self.first) then - love.graphics.setFont(Font) - love.graphics.setColor(255, 255, 255, 255) - love.graphics.printf(string.upper(name), (x-w)*scale, (y+h+1)*scale, w*3, "center", 0, scale, scale) - end -end - --- Menu callbacks -function Selector:focus () -- Called when Element gains focus - self.focused = true - return true -end -function Selector:blur () -- Called when Element loses focus - self.focused = false -end - --- LÖVE2D callbacks -function Selector:draw (scale) - local x,y = self:getPosition() - local margin = self:getMargin() - local width = self:getSize() - x = x - #self.selections*0.5*(margin+margin+width) - for n=1,#self.selections do - self:drawBlock(n, x+(margin+width)*(n-1)+margin*n, y, scale) - end -end -function Selector:update (dt) - self.delay = self.delay + dt - if self.delay > Selector.delay then -- Selector.delay is initial - self.delay = self.delay - Selector.delay - end -end - --- Controller callbacks --- TODO: Add action to perform when key is pressed and selector is locked in e.g. to move into character selection from map selection. -function Selector:controlpressed (set, action, key) - if set and self.focused then - local n = self:checkNumber(set) - local locked = self:isLocked(n) - if action == "left" and not locked then self:previous(n) end - if action == "right" and not locked then self:next(n) end - if action == "attack" then - local name = self:getListValue(self:getSelection(n)) - if name == "random" then - self:setSelection(n, self:rollRandom({1,2})) -- avoid empty naut - self.locks[n] = true - else - -- If not empty or if first is allowed. Additionaly must be unique selection. - if (self:getSelection(n) ~= 1 or self.first) and self:isUnique(n) then - self.locks[n] = true - end - end - end - if action == "jump" then - if locked then - self.locks[n] = false - end - end - end -end - -return Selector -- cgit v1.1 From 8b886eeb75f79fb5f5e59af6993ed9d6dcbefe92 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 7 Apr 2017 03:29:29 +0200 Subject: Makefile for new tree --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 62c3c9d..5f17a9c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: - zip not-nautz not/*.lua maps/*.lua config/*.lua assets/*.png assets/sounds/*.ogg assets/platforms/*.png assets/nauts/*.png assets/music/*.ogg assets/decorations/*.png assets/backgrounds/*.png *.lua gamecontrollerdb.txt settings.default + zip not-nautz not/*.lua config/maps/*.lua config/menus/*.lua config/*.lua assets/*.png assets/sounds/*.ogg assets/platforms/*.png assets/nauts/*.png assets/music/*.ogg assets/decorations/*.png assets/backgrounds/*.png *.lua gamecontrollerdb.txt settings.default mv not-nautz.zip ../not-nautz.love clean: - $(RM) ../not-nautz.love \ No newline at end of file + rm ../not-nautz.love \ No newline at end of file -- cgit v1.1 From 612a14474c9d3c28b6512aef4845e52579d7d9c9 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 7 Apr 2017 05:15:23 +0200 Subject: Clean-up main.lua a little bit --- main.lua | 51 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) diff --git a/main.lua b/main.lua index 05eb9e2..0c20b34 100644 --- a/main.lua +++ b/main.lua @@ -1,13 +1,11 @@ --- "NOTNAUTS" --- WHOLE CODE HAS FLAG OF "need a cleanup" - +--- Roflnauts 2 -- TODO: Any lua source file in root directory that is not `main` (this file), `conf` should be moved to a proper directory. Its name should be changed to show what it contains. -- Pretend you didn't see this -- This is work for scene manager -- TODO: Create SceneManager or similar class. Scene = nil -function changeScene(scene) +function changeScene (scene) if Scene ~= nil then Scene:delete() end @@ -16,10 +14,11 @@ end -- Should be moved to scene/camera -- TODO: move following functions to `Camera`. -function getScale() +function getScale () return math.max(1, math.floor(math.max(love.graphics.getWidth() / 320, love.graphics.getHeight() / 180))) end -function getRealScale() + +function getRealScale () return math.max(1, math.max(love.graphics.getWidth() / 320, love.graphics.getHeight() / 180)) end @@ -34,25 +33,20 @@ require "not.Settings" debug = false -- LÖVE2D callbacks -function love.load() - -- Graphics +function love.load () love.graphics.setBackgroundColor(90, 90, 90) love.graphics.setDefaultFilter("nearest", "nearest") - -- Font + -- TODO: Move fonts somewhere else out of global scope. Font = love.graphics.newImageFont("assets/font-normal.png", " 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.,:;-_/\\!@#$%^&*?=+~`|'\"()[]{}<>", -1) Bold = love.graphics.newImageFont("assets/font-big.png", " 0123456789AEFILNORSTUW", -2) Font:setLineHeight(9/16) - love.graphics.setFont(Font) - -- Modules + love.graphics.setFont(Font) Controller.load() Settings.load() - -- Scene Scene = Menu:new() end -function love.update(dt) - Scene:update(dt) -end -function love.draw() + +function love.draw () Scene:draw() if debug then local scale = getScale() @@ -63,21 +57,20 @@ function love.draw() love.graphics.print("Current FPS: "..tostring(love.timer.getFPS()), 10, 10+9*scale, 0, scale, scale) end end -function love.quit() - Settings.save() -end + +function love.update (dt) Scene:update(dt) end +function love.quit () Settings.save() end + -- Pass input to Controller -function love.gamepadaxis(joystick, axis, value) Controller.gamepadaxis(joystick, axis, value) end -function love.gamepadpressed(joystick, key) Controller.gamepadpressed(joystick, key) end -function love.gamepadreleased(joystick, key) Controller.gamepadreleased(joystick, key) end -function love.keypressed(key) Controller.keypressed(key) end -function love.keyreleased(key) Controller.keyreleased(key) end +function love.gamepadaxis (joystick, axis, value) Controller.gamepadaxis(joystick, axis, value) end +function love.gamepadpressed (joystick, key) Controller.gamepadpressed(joystick, key) end +function love.gamepadreleased (joystick, key) Controller.gamepadreleased(joystick, key) end +function love.keypressed (key) Controller.keypressed(key) end +function love.keyreleased (key) Controller.keyreleased(key) end -- Controller callbacks -function Controller.controlpressed(set, action, key) - -- pass to current Scene +function Controller.controlpressed (set, action, key) Scene:controlpressed(set, action, key) - -- globals if key == "escape" then love.event.quit() end @@ -85,7 +78,7 @@ function Controller.controlpressed(set, action, key) debug = not debug end end -function Controller.controlreleased(set, action, key) - -- pass to current Scene + +function Controller.controlreleased (set, action, key) Scene:controlreleased(set, action, key) end \ No newline at end of file -- cgit v1.1 From 1c3040de93f9d5a164ccb06194eacc28eead0234 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 7 Apr 2017 21:05:41 +0200 Subject: Maps and nauts list moved to config Implemented functions to create icons list for them Changed so game uses these functions now --- config/maps.lua | 9 +++++++++ config/menus/host.lua | 7 +++++-- config/menus/select.lua | 7 +++++-- config/nauts.lua | 40 ++++++++++++++++++++++++++++++++++++++++ iconsList.lua | 37 +++++++++++++++++++++++++++++++++++++ main.lua | 1 + mapicons.lua | 12 ------------ maplist.lua | 9 --------- nautsicons.lua | 11 ----------- nautslist.lua | 35 ----------------------------------- not/Hero.lua | 2 +- 11 files changed, 98 insertions(+), 72 deletions(-) create mode 100644 config/maps.lua create mode 100644 config/nauts.lua create mode 100644 iconsList.lua delete mode 100644 mapicons.lua delete mode 100644 maplist.lua delete mode 100644 nautsicons.lua delete mode 100644 nautslist.lua diff --git a/config/maps.lua b/config/maps.lua new file mode 100644 index 0000000..32e89a5 --- /dev/null +++ b/config/maps.lua @@ -0,0 +1,9 @@ +return { + "default", + "rill", + "ribbit", + "starstorm", + "aiguillon", + "sorona", + "alpha abyss" +} diff --git a/config/menus/host.lua b/config/menus/host.lua index 8a4887e..b318a5b 100644 --- a/config/menus/host.lua +++ b/config/menus/host.lua @@ -8,6 +8,9 @@ local bx = width/2-29 local map_selector = selector:new(menu) +require "iconsList" +local icons, maps = getMapsIconsList() + return { map_selector :setPosition(width/2, 40) @@ -15,9 +18,9 @@ return { :setMargin(0) :set("global", true) :set("first", true) - :set("list", require "maplist") + :set("list", maps) :set("icons_i", love.graphics.newImage("assets/maps.png")) - :set("icons_q", require "mapicons") + :set("icons_q", icons) :set("shape", "panorama") :init() , diff --git a/config/menus/select.lua b/config/menus/select.lua index e759f40..804b4eb 100644 --- a/config/menus/select.lua +++ b/config/menus/select.lua @@ -10,15 +10,18 @@ local bx = width/2-29 local naut_selector = selector:new(menu) local start_button = button:new(menu) +require "iconsList" +local nautsIcons, nautsList = getNautsIconsList() + return { naut_selector :setPosition(width/2,60) :setMargin(8) :setSize(32, 32) - :set("list", require "nautslist") + :set("list", nautsList) :set("global", false) :set("icons_i", love.graphics.newImage("assets/portraits.png")) - :set("icons_q", require "nautsicons") + :set("icons_q", nautsIcons) :init() , start_button diff --git a/config/nauts.lua b/config/nauts.lua new file mode 100644 index 0000000..2eea71a --- /dev/null +++ b/config/nauts.lua @@ -0,0 +1,40 @@ +-- List of characters with empty character included +-- icons list is generated from this file +return { + "empty", -- empty + "random", --random + "froggo", -- froggy + "cowboy", -- lonestar + "honic", -- leon + "gelato", -- scoop + "veno", -- gnaw + "lady", -- raelynn + "girl", -- ayla + "megoman", -- clunk + "brainos", -- voltar + "woman", -- coco + "bison", -- skolldir + "bobito", -- yuri + "slugzor", -- derpl + "capone", -- vinnie + "nemo", -- spike + "bug", -- genji + "calamari", -- swiggins + "quack", -- rocco + "scissors", -- ksenia + "link", -- ix + "marine", -- ted + "scooter", -- penny + "phonebooth", -- sentry + "weed", -- skree + "gummybear", -- nibbs + "gramps", -- yoolip + "biker", -- chucho + "vrooom", -- lux + "shutter", -- max + "disco", -- esc rocco + "yarr", -- ted pirate + "blblal", -- blabl zork + "kong", -- ronimo + "rock", -- rock +} diff --git a/iconsList.lua b/iconsList.lua new file mode 100644 index 0000000..4a384dc --- /dev/null +++ b/iconsList.lua @@ -0,0 +1,37 @@ +-- TODO: These should be part of non-existent AssetsManager or something similar. +local function testAvoidList (i, avoidList) + for key,value in pairs(avoidList) do + if i == value then + table.remove(avoidList, key) + return false + end + end + return true +end + +function createIconsList (sheetWidth, sheetHeight, iconWidth, keysList, avoidList) + local avoidList = avoidList or {} + local iconsList, newKeysList = {}, {} + local iconsNumber = math.floor(sheetWidth / iconWidth) + local iconHeight = sheetHeight + for i=1,iconsNumber do + if testAvoidList(i, avoidList) then + iconsList[keysList[i]] = love.graphics.newQuad((i-1)*iconWidth, 0, iconWidth, iconHeight, sheetWidth, sheetHeight) + table.insert(newKeysList, keysList[i]) + end + end + return iconsList, newKeysList +end + +function getNautsIconsList (avoidList) + local avoidList = avoidList or {32,33,34,35,36} + local keysList = require "config.nauts" + local iconsList, newKeysList = createIconsList(1008, 27, 28, keysList, avoidList) + return iconsList, newKeysList +end + +function getMapsIconsList (avoidList) + local keysList = require "config.maps" + local iconsList, newKeysList = createIconsList(532, 37, 76, keysList, avoidList) + return iconsList, newKeysList +end diff --git a/main.lua b/main.lua index 0c20b34..11e4d95 100644 --- a/main.lua +++ b/main.lua @@ -23,6 +23,7 @@ function getRealScale () end -- Require +require "iconsList" require "not.World" require "not.Camera" require "not.Menu" diff --git a/mapicons.lua b/mapicons.lua deleted file mode 100644 index 8729a56..0000000 --- a/mapicons.lua +++ /dev/null @@ -1,12 +0,0 @@ --- Maps icons list generation file --- TODO: it is so similar to `nautsicons.lua` they could be merged together into one function that returns icon quad sequences (`createIconList(image, width, number, mask...) --[[ body ]] return image, icons, list end` or similar). On the other hand extended lists with maps/nauts in config would be enough. -local maps = require "maplist" -local w, h = 532, 37 -local icons = {} - -local i = 0 -for _,map in pairs(maps) do - icons[map] = love.graphics.newQuad(i*76, 0, 76, 37, w, h) - i = i + 1 -end -return icons diff --git a/maplist.lua b/maplist.lua deleted file mode 100644 index 32e89a5..0000000 --- a/maplist.lua +++ /dev/null @@ -1,9 +0,0 @@ -return { - "default", - "rill", - "ribbit", - "starstorm", - "aiguillon", - "sorona", - "alpha abyss" -} diff --git a/nautsicons.lua b/nautsicons.lua deleted file mode 100644 index 6c09a8f..0000000 --- a/nautsicons.lua +++ /dev/null @@ -1,11 +0,0 @@ --- Spritesheet for character portraits -local nauts = require "nautslist" -local w, h = 1008, 27 -local icons = {} - -local i = 0 -for _,naut in pairs(nauts) do - icons[naut] = love.graphics.newQuad(i*28, 0, 28, 27, w, h) - i = i + 1 -end -return icons diff --git a/nautslist.lua b/nautslist.lua deleted file mode 100644 index d0c7a61..0000000 --- a/nautslist.lua +++ /dev/null @@ -1,35 +0,0 @@ --- List of characters with empty character included --- icons list is generated from this file -return { - "empty", -- empty - "random", --random - "froggo", -- froggy - "cowboy", -- lonestar - "honic", -- leon - "gelato", -- scoop - "veno", -- gnaw - "lady", -- raelynn - "girl", -- ayla - "megoman", -- clunk - "brainos", -- voltar - "woman", -- coco - "bison", -- skolldir - "bobito", -- yuri - "slugzor", -- derpl - "capone", -- vinnie - "nemo", -- spike - "bug", -- genji - "calamari", -- swiggins - "quack", -- rocco - "scissors", -- ksenia - "link", -- ix - "marine", -- ted - "scooter", -- penny - "phonebooth", -- sentry - "weed", -- skree - "gummybear", -- nibbs - "gramps", -- yoolip - "biker", -- chucho - "vrooom", -- lux - "shutter", -- max -} diff --git a/not/Hero.lua b/not/Hero.lua index a22cc2e..4150024 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -26,7 +26,7 @@ Hero = { -- Statics portrait_sprite = nil, portrait_frame = nil, - portrait_sheet = require "nautsicons", + portrait_sheet = getNautsIconsList(), portrait_box = love.graphics.newQuad( 0, 15, 32,32, 80,130), sfx = require "sounds", } -- cgit v1.1 From a03c1125f10fbbad253a0efc4727072fcbd55345 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 8 Apr 2017 20:38:45 +0200 Subject: Moved configs from root directory to config directory --- animations.lua | 48 --------------------------- config/animations/effects.lua | 76 +++++++++++++++++++++++++++++++++++++++++++ config/animations/hero.lua | 48 +++++++++++++++++++++++++++ config/sounds.lua | 9 +++++ effects.lua | 76 ------------------------------------------- not/Effect.lua | 2 +- not/Hero.lua | 4 +-- sounds.lua | 9 ----- 8 files changed, 136 insertions(+), 136 deletions(-) delete mode 100644 animations.lua create mode 100644 config/animations/effects.lua create mode 100644 config/animations/hero.lua create mode 100644 config/sounds.lua delete mode 100644 effects.lua delete mode 100644 sounds.lua diff --git a/animations.lua b/animations.lua deleted file mode 100644 index 881da49..0000000 --- a/animations.lua +++ /dev/null @@ -1,48 +0,0 @@ --- Animations spritesheet array for `Player` --- Basic spritesheet size is 376x26. Each frame is 24x24 and has 1px border around it. --- From the left: default (walk0), walk1, walk2, walk3, attack0, attack1, attack3, attack_up0, attack_up1, attack_up2, attack_down0, attack_down1, attack_down2, damage0, damage1 -local animations = { - default = { - [1] = love.graphics.newQuad( 1, 1, 24,24, 376,26), - frames = 1, - repeated = true - }, - walk = { - [1] = love.graphics.newQuad( 1, 1, 24,24, 376,26), - [2] = love.graphics.newQuad( 26, 1, 24,24, 376,26), - [3] = love.graphics.newQuad( 51, 1, 24,24, 376,26), - [4] = love.graphics.newQuad( 76, 1, 24,24, 376,26), - frames = 4, - repeated = true - }, - attack = { - [1] = love.graphics.newQuad(101, 1, 24,24, 376,26), - [2] = love.graphics.newQuad(126, 1, 24,24, 376,26), - [3] = love.graphics.newQuad(151, 1, 24,24, 376,26), - frames = 3, - repeated = false - }, - attack_up = { - [1] = love.graphics.newQuad(176, 1, 24,24, 376,26), - [2] = love.graphics.newQuad(201, 1, 24,24, 376,26), - [3] = love.graphics.newQuad(226, 1, 24,24, 376,26), - frames = 3, - repeated = false - }, - attack_down = { - [1] = love.graphics.newQuad(251, 1, 24,24, 376,26), - [2] = love.graphics.newQuad(276, 1, 24,24, 376,26), - [3] = love.graphics.newQuad(301, 1, 24,24, 376,26), - frames = 3, - repeated = false - }, - damage = { - [1] = love.graphics.newQuad(326, 1, 24,24, 376,26), - [2] = love.graphics.newQuad(351, 1, 24,24, 376,26), - [3] = love.graphics.newQuad(326, 1, 24,24, 376,26), - [4] = love.graphics.newQuad(351, 1, 24,24, 376,26), - frames = 4, - repeated = false - }, -} -return animations \ No newline at end of file diff --git a/config/animations/effects.lua b/config/animations/effects.lua new file mode 100644 index 0000000..dd6d55e --- /dev/null +++ b/config/animations/effects.lua @@ -0,0 +1,76 @@ +-- Animations spritesheet array for `Effect` +-- Size of sprie atlas is 168px x 120px + +-- NAME :POSITION :SIZE :FRAMES +-- jump :x 0 y 0: 24px: 4 +-- doublejump:x 0 y 24: 24px: 4 +-- land :x 0 y 48: 24px: 5 +-- respawn :x 0 y 72: 24px: 7 +-- clash :x 0 y 96: 24px: 6 +-- trail :x104 y 0: 16px: 4 +-- hit :x106 y 18: 16px: 3 + +local quads = { + jump = { + [1] = love.graphics.newQuad( 0, 0, 24,24, 168,120), + [2] = love.graphics.newQuad( 24, 0, 24,24, 168,120), + [3] = love.graphics.newQuad( 48, 0, 24,24, 168,120), + [4] = love.graphics.newQuad( 72, 0, 24,24, 168,120), + frames = 4, + repeated = false + }, + doublejump = { + [1] = love.graphics.newQuad( 0, 24, 24,24, 168,120), + [2] = love.graphics.newQuad( 24, 24, 24,24, 168,120), + [3] = love.graphics.newQuad( 48, 24, 24,24, 168,120), + [4] = love.graphics.newQuad( 72, 24, 24,24, 168,120), + frames = 4, + repeated = false + }, + land = { + [1] = love.graphics.newQuad( 0, 48, 24,24, 168,120), + [2] = love.graphics.newQuad( 24, 48, 24,24, 168,120), + [3] = love.graphics.newQuad( 48, 48, 24,24, 168,120), + [4] = love.graphics.newQuad( 72, 48, 24,24, 168,120), + [5] = love.graphics.newQuad( 96, 48, 24,24, 168,120), + frames = 5, + repeated = false + }, + respawn = { + [1] = love.graphics.newQuad( 0, 72, 24,24, 168,120), + [2] = love.graphics.newQuad( 24, 72, 24,24, 168,120), + [3] = love.graphics.newQuad( 48, 72, 24,24, 168,120), + [4] = love.graphics.newQuad( 72, 72, 24,24, 168,120), + [5] = love.graphics.newQuad( 96, 72, 24,24, 168,120), + [6] = love.graphics.newQuad(120, 72, 24,24, 168,120), + [7] = love.graphics.newQuad(144, 72, 24,24, 168,120), + frames = 7, + repeated = false + }, + clash = { + [1] = love.graphics.newQuad( 0, 96, 24,24, 168,120), + [2] = love.graphics.newQuad( 24, 96, 24,24, 168,120), + [3] = love.graphics.newQuad( 48, 96, 24,24, 168,120), + [4] = love.graphics.newQuad( 72, 96, 24,24, 168,120), + [5] = love.graphics.newQuad( 96, 96, 24,24, 168,120), + [6] = love.graphics.newQuad(120, 96, 24,24, 168,120), + frames = 6, + repeated = false + }, + trail = { + [1] = love.graphics.newQuad(104, 0, 16,16, 168,120), + [2] = love.graphics.newQuad(120, 0, 16,16, 168,120), + [3] = love.graphics.newQuad(136, 0, 16,16, 168,120), + [4] = love.graphics.newQuad(152, 0, 16,16, 168,120), + frames = 4, + repeated = false + }, + hit = { + [1] = love.graphics.newQuad(106, 18, 16,16, 168,120), + [2] = love.graphics.newQuad(122, 18, 16,16, 168,120), + [3] = love.graphics.newQuad(138, 18, 16,16, 168,120), + frames = 3, + repeated = false + } +} +return quads \ No newline at end of file diff --git a/config/animations/hero.lua b/config/animations/hero.lua new file mode 100644 index 0000000..881da49 --- /dev/null +++ b/config/animations/hero.lua @@ -0,0 +1,48 @@ +-- Animations spritesheet array for `Player` +-- Basic spritesheet size is 376x26. Each frame is 24x24 and has 1px border around it. +-- From the left: default (walk0), walk1, walk2, walk3, attack0, attack1, attack3, attack_up0, attack_up1, attack_up2, attack_down0, attack_down1, attack_down2, damage0, damage1 +local animations = { + default = { + [1] = love.graphics.newQuad( 1, 1, 24,24, 376,26), + frames = 1, + repeated = true + }, + walk = { + [1] = love.graphics.newQuad( 1, 1, 24,24, 376,26), + [2] = love.graphics.newQuad( 26, 1, 24,24, 376,26), + [3] = love.graphics.newQuad( 51, 1, 24,24, 376,26), + [4] = love.graphics.newQuad( 76, 1, 24,24, 376,26), + frames = 4, + repeated = true + }, + attack = { + [1] = love.graphics.newQuad(101, 1, 24,24, 376,26), + [2] = love.graphics.newQuad(126, 1, 24,24, 376,26), + [3] = love.graphics.newQuad(151, 1, 24,24, 376,26), + frames = 3, + repeated = false + }, + attack_up = { + [1] = love.graphics.newQuad(176, 1, 24,24, 376,26), + [2] = love.graphics.newQuad(201, 1, 24,24, 376,26), + [3] = love.graphics.newQuad(226, 1, 24,24, 376,26), + frames = 3, + repeated = false + }, + attack_down = { + [1] = love.graphics.newQuad(251, 1, 24,24, 376,26), + [2] = love.graphics.newQuad(276, 1, 24,24, 376,26), + [3] = love.graphics.newQuad(301, 1, 24,24, 376,26), + frames = 3, + repeated = false + }, + damage = { + [1] = love.graphics.newQuad(326, 1, 24,24, 376,26), + [2] = love.graphics.newQuad(351, 1, 24,24, 376,26), + [3] = love.graphics.newQuad(326, 1, 24,24, 376,26), + [4] = love.graphics.newQuad(351, 1, 24,24, 376,26), + frames = 4, + repeated = false + }, +} +return animations \ No newline at end of file diff --git a/config/sounds.lua b/config/sounds.lua new file mode 100644 index 0000000..c30af16 --- /dev/null +++ b/config/sounds.lua @@ -0,0 +1,9 @@ +return { + love.sound.newSoundData("assets/sounds/death.ogg"), + love.sound.newSoundData("assets/sounds/hit.ogg"), + love.sound.newSoundData("assets/sounds/step.ogg"), + love.sound.newSoundData("assets/sounds/attack.ogg"), + love.sound.newSoundData("assets/sounds/cheer.ogg"), + love.sound.newSoundData("assets/sounds/jump.ogg"), + love.sound.newSoundData("assets/sounds/spawn.ogg"), +} \ No newline at end of file diff --git a/effects.lua b/effects.lua deleted file mode 100644 index dd6d55e..0000000 --- a/effects.lua +++ /dev/null @@ -1,76 +0,0 @@ --- Animations spritesheet array for `Effect` --- Size of sprie atlas is 168px x 120px - --- NAME :POSITION :SIZE :FRAMES --- jump :x 0 y 0: 24px: 4 --- doublejump:x 0 y 24: 24px: 4 --- land :x 0 y 48: 24px: 5 --- respawn :x 0 y 72: 24px: 7 --- clash :x 0 y 96: 24px: 6 --- trail :x104 y 0: 16px: 4 --- hit :x106 y 18: 16px: 3 - -local quads = { - jump = { - [1] = love.graphics.newQuad( 0, 0, 24,24, 168,120), - [2] = love.graphics.newQuad( 24, 0, 24,24, 168,120), - [3] = love.graphics.newQuad( 48, 0, 24,24, 168,120), - [4] = love.graphics.newQuad( 72, 0, 24,24, 168,120), - frames = 4, - repeated = false - }, - doublejump = { - [1] = love.graphics.newQuad( 0, 24, 24,24, 168,120), - [2] = love.graphics.newQuad( 24, 24, 24,24, 168,120), - [3] = love.graphics.newQuad( 48, 24, 24,24, 168,120), - [4] = love.graphics.newQuad( 72, 24, 24,24, 168,120), - frames = 4, - repeated = false - }, - land = { - [1] = love.graphics.newQuad( 0, 48, 24,24, 168,120), - [2] = love.graphics.newQuad( 24, 48, 24,24, 168,120), - [3] = love.graphics.newQuad( 48, 48, 24,24, 168,120), - [4] = love.graphics.newQuad( 72, 48, 24,24, 168,120), - [5] = love.graphics.newQuad( 96, 48, 24,24, 168,120), - frames = 5, - repeated = false - }, - respawn = { - [1] = love.graphics.newQuad( 0, 72, 24,24, 168,120), - [2] = love.graphics.newQuad( 24, 72, 24,24, 168,120), - [3] = love.graphics.newQuad( 48, 72, 24,24, 168,120), - [4] = love.graphics.newQuad( 72, 72, 24,24, 168,120), - [5] = love.graphics.newQuad( 96, 72, 24,24, 168,120), - [6] = love.graphics.newQuad(120, 72, 24,24, 168,120), - [7] = love.graphics.newQuad(144, 72, 24,24, 168,120), - frames = 7, - repeated = false - }, - clash = { - [1] = love.graphics.newQuad( 0, 96, 24,24, 168,120), - [2] = love.graphics.newQuad( 24, 96, 24,24, 168,120), - [3] = love.graphics.newQuad( 48, 96, 24,24, 168,120), - [4] = love.graphics.newQuad( 72, 96, 24,24, 168,120), - [5] = love.graphics.newQuad( 96, 96, 24,24, 168,120), - [6] = love.graphics.newQuad(120, 96, 24,24, 168,120), - frames = 6, - repeated = false - }, - trail = { - [1] = love.graphics.newQuad(104, 0, 16,16, 168,120), - [2] = love.graphics.newQuad(120, 0, 16,16, 168,120), - [3] = love.graphics.newQuad(136, 0, 16,16, 168,120), - [4] = love.graphics.newQuad(152, 0, 16,16, 168,120), - frames = 4, - repeated = false - }, - hit = { - [1] = love.graphics.newQuad(106, 18, 16,16, 168,120), - [2] = love.graphics.newQuad(122, 18, 16,16, 168,120), - [3] = love.graphics.newQuad(138, 18, 16,16, 168,120), - frames = 3, - repeated = false - } -} -return quads \ No newline at end of file diff --git a/not/Effect.lua b/not/Effect.lua index 4051b92..dd7570a 100644 --- a/not/Effect.lua +++ b/not/Effect.lua @@ -24,7 +24,7 @@ end -- Initializer of `Effect`. function Effect:init (name, x, y) Decoration.init(self, x, y, nil) - self:setAnimationsList(require("effects")) + self:setAnimationsList(require("config.animations.effects")) self:setAnimation(name) end diff --git a/not/Hero.lua b/not/Hero.lua index 4150024..feb61da 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -28,7 +28,7 @@ Hero = { portrait_frame = nil, portrait_sheet = getNautsIconsList(), portrait_box = love.graphics.newQuad( 0, 15, 32,32, 80,130), - sfx = require "sounds", + sfx = require "config.sounds", } -- `Hero` is a child of `PhysicalBody`. @@ -68,7 +68,7 @@ function Hero:init (name, world, x, y) self.world = world self.punchCooldown = 0 self.name = name - self:setAnimationsList(require("animations")) + self:setAnimationsList(require("config.animations.hero")) self:createEffect("respawn") end diff --git a/sounds.lua b/sounds.lua deleted file mode 100644 index c30af16..0000000 --- a/sounds.lua +++ /dev/null @@ -1,9 +0,0 @@ -return { - love.sound.newSoundData("assets/sounds/death.ogg"), - love.sound.newSoundData("assets/sounds/hit.ogg"), - love.sound.newSoundData("assets/sounds/step.ogg"), - love.sound.newSoundData("assets/sounds/attack.ogg"), - love.sound.newSoundData("assets/sounds/cheer.ogg"), - love.sound.newSoundData("assets/sounds/jump.ogg"), - love.sound.newSoundData("assets/sounds/spawn.ogg"), -} \ No newline at end of file -- cgit v1.1