From d667be2b2538b22458a13efdc3aff6996e161947 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 2 Sep 2017 20:06:07 +0200 Subject: Deleted obsolete nilinitializers in World --- not/World.lua | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index c73a3da..55ea1d1 100644 --- a/not/World.lua +++ b/not/World.lua @@ -3,20 +3,6 @@ -- TODO: Possibly move common parts of `World` and `Menu` to abstract class `Scene`. World = require "not.Scene":extends() -World.world =--[[love.physics.newWorld]]nil -World.Nauts =--[[{not.Hero}]]nil -World.Platforms =--[[{not.Platform}]]nil -World.Clouds =--[[{not.Cloud}]]nil -World.Decorations =--[[{not.Decoration}]]nil -World.Effects =--[[{not.Effect}]]nil -World.Rays =--[[{not.Ray}]]nil -World.camera =--[[not.Camera]]nil -World.music =--[[not.Music]]nil -World.clouds_delay = 5 -World.map =--[[config.maps.*]]nil -World.background =--[[image?]]nil -World.lastNaut = false - require "not.Platform" require "not.Player" require "not.Cloud" @@ -31,6 +17,7 @@ function World:new (map, nauts) self.world = love.physics.newWorld(0, 9.81*64, true) self.world:setCallbacks(self.beginContact, self.endContact) -- Tables for entities. TODO: It is still pretty bad! + self.lastNaut = false self.Nauts = {} self.Platforms = {} self.Clouds = {} -- cgit v1.1 From eaa78e7d697108b0a3b224835ce28d8e8e5874f2 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 2 Sep 2017 20:09:51 +0200 Subject: Empty delete function for Object just in case --- not/Object.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'not') diff --git a/not/Object.lua b/not/Object.lua index 30b91b5..352e9e3 100644 --- a/not/Object.lua +++ b/not/Object.lua @@ -1,3 +1,8 @@ --- Wrapping library to game's hierarchy in a shameless way. +--- Wrapping library to game's hierarchy in a shameless way. Object = require "lib.object.Object" + +--- Called before Object references are removed from parent. +-- This is not called when Object is garbage collected. +function Object:delete () end + return Object -- cgit v1.1 From 27a1d0de613a360912d1e9f3a5db7ab044a0b450 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 2 Sep 2017 21:16:30 +0200 Subject: Center_* changed to center.* (table) --- not/Camera.lua | 6 +++--- not/Hero.lua | 4 ++-- not/Ray.lua | 2 +- not/World.lua | 14 +++++++------- 4 files changed, 13 insertions(+), 13 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index aa4df5b..183a323 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -108,11 +108,11 @@ end -- Move follow function Camera:follow () local map = self.world.map - local sum_x,sum_y,i = map.center_x, map.center_y, 1 + 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 + 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 diff --git a/not/Hero.lua b/not/Hero.lua index 039aeb8..71cfb5b 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -87,8 +87,8 @@ function Hero:update (dt) -- TODO: World/Map function for testing if Point is inside playable area. local m = self.world.map 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 + 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.isAlive then self:die() diff --git a/not/Ray.lua b/not/Ray.lua index 16a9bee..3c80440 100644 --- a/not/Ray.lua +++ b/not/Ray.lua @@ -35,7 +35,7 @@ function Ray:draw (offset_x, offset_y, scale) local x, y = self.naut:getPosition() local m = self.world.map local dy = m.height - if y > m.center_y then + 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) diff --git a/not/World.lua b/not/World.lua index 55ea1d1..7d40476 100644 --- a/not/World.lua +++ b/not/World.lua @@ -120,11 +120,11 @@ function World:randomizeCloud (outside) local x,y,t,v local m = self.map if outside then - x = m.center_x-m.width*1.2+love.math.random(-50,20) + x = m.center.x-m.width*1.2+love.math.random(-50,20) else - x = love.math.random(m.center_x-m.width/2,m.center_x+m.width/2) + x = love.math.random(m.center.x-m.width/2,m.center.x+m.width/2) end - y = love.math.random(m.center_y-m.height/2, m.center_y+m.height/2) + y = love.math.random(m.center.y-m.height/2, m.center.y+m.height/2) t = love.math.random(1,3) v = love.math.random(8,18) self:createCloud(x, y, t, v) @@ -284,11 +284,11 @@ function World:draw () 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) + 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) + 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) -- cgit v1.1 From 2757fa1de92f2eff8be080721a7f777086afa072 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 2 Sep 2017 22:30:32 +0200 Subject: Separated platforms' configs from maps' configs --- not/World.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 7d40476..d4d933f 100644 --- a/not/World.lua +++ b/not/World.lua @@ -52,7 +52,8 @@ function World:loadMap (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) + local config = love.filesystem.load(string.format("config/platforms/%s.lua", platform.config))() + self:createPlatform(platform.x, platform.y, config.shape, config.sprite, platform.animations) end -- Decorations for _,decoration in pairs(self.map.decorations) do -- cgit v1.1 From d2ba9f3c87589f167e715b17f6740977e1c29dff Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 3 Sep 2017 01:55:35 +0200 Subject: More map config and loading changes Decorations, platforms and background are now created and stored in config together --- not/World.lua | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index d4d933f..8a6ba09 100644 --- a/not/World.lua +++ b/not/World.lua @@ -47,21 +47,23 @@ end -- Load map from file -- TODO: Change current map model to function-based one. function World:loadMap (name) - local name = name or "default" - local map = love.filesystem.load(string.format("config/maps/%s.lua", name)) - self.map = map() - -- Platforms - for _,platform in pairs(self.map.platforms) do - local config = love.filesystem.load(string.format("config/platforms/%s.lua", platform.config))() - self:createPlatform(platform.x, platform.y, config.shape, config.sprite, platform.animations) - end - -- Decorations - for _,decoration in pairs(self.map.decorations) do - self:createDecoration(decoration.x, decoration.y, decoration.sprite) + local map = string.format("config/maps/%s.lua", name or "default") + self.map = love.filesystem.load(map)() + + for _,op in pairs(self.map.create) do + if op.platform then + local path = string.format("config/platforms/%s.lua", op.platform) + local config = love.filesystem.load(path)() + self:createPlatform(op.x, op.y, config.shape, config.sprite, config.animations) + end + if op.decoration then + self:createDecoration(op.x, op.y, op.decoration) + end + if op.background then + self.background = love.graphics.newImage(op.background) + end end - -- Background - self.background = love.graphics.newImage(self.map.background) - -- Clouds + if self.map.clouds then for i=1,6 do self:randomizeCloud(false) -- cgit v1.1 From 1b7f0c58c0090a1ccab884b84156fa19a8e4747a Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 3 Sep 2017 02:03:42 +0200 Subject: Background as Decoration, no layers with scroll ratio yet --- not/World.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 8a6ba09..6a71fd9 100644 --- a/not/World.lua +++ b/not/World.lua @@ -44,8 +44,7 @@ function World:delete () self.world:destroy() end --- Load map from file --- TODO: Change current map model to function-based one. +--- Loads table from selected map config file located in `config/maps/` directory. function World:loadMap (name) local map = string.format("config/maps/%s.lua", name or "default") self.map = love.filesystem.load(map)() @@ -60,7 +59,10 @@ function World:loadMap (name) self:createDecoration(op.x, op.y, op.decoration) end if op.background then - self.background = love.graphics.newImage(op.background) + local image = love.graphics.newImage(op.background) + local x = image:getWidth() / -2 + local y = image:getHeight() / -2 + self:createDecoration(x, y, op.background) -- TODO: Decoration does not allow Image instead of filePath! end end @@ -245,7 +247,7 @@ function World:draw () local scaler = getRealScale() -- Background - love.graphics.draw(self.background, 0, 0, 0, scaler, scaler) + -- love.graphics.draw(self.background, 0, 0, 0, scaler, scaler) -- TODO: this needs to be reworked! -- Draw clouds -- cgit v1.1 From c1ddde657f57f51d4a41d23e5d5d0bd4e9356ab3 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 3 Sep 2017 19:49:38 +0200 Subject: Cleaned up comments, background position based on map center --- not/World.lua | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 6a71fd9..c3fec11 100644 --- a/not/World.lua +++ b/not/World.lua @@ -10,13 +10,14 @@ require "not.Effect" require "not.Decoration" require "not.Ray" --- Constructor of `World` ZA WARUDO! +--- ZA WARUDO! +-- TODO: Missing documentation on most of World's methods. function World:new (map, nauts) - -- Box2D physical world. 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: It is still pretty bad! + -- Tables for entities. + -- TODO: Move all entities into single table. self.lastNaut = false self.Nauts = {} self.Platforms = {} @@ -25,6 +26,7 @@ function World:new (map, nauts) self.Decorations = {} self.Rays = {} -- Map and misc. + -- TODO: `map` could be table from config file rather than just string. local map = map or "default" self:loadMap(map) self:spawnNauts(nauts) @@ -60,8 +62,8 @@ function World:loadMap (name) end if op.background then local image = love.graphics.newImage(op.background) - local x = image:getWidth() / -2 - local y = image:getHeight() / -2 + local x = self.map.center.x - (image:getWidth() / 2) + local y = self.map.center.y - (image:getHeight() / 2) self:createDecoration(x, y, op.background) -- TODO: Decoration does not allow Image instead of filePath! end end @@ -88,33 +90,34 @@ function World:getSpawnPosition () return self.map.respawns[n].x, self.map.respawns[n].y end --- Add new platform to the world --- TODO: it would be nice if function parameters would be same as `not.Platform.new`. +-- TODO: Standardize `create*` methods with corresponding constructors. Pay attention to both params' order and names. function World:createPlatform (x, y, polygon, sprite, animations) table.insert(self.Platforms, Platform(animations, polygon, x, y, self, sprite)) end --- Add new naut to the world --- TODO: separate two methods for `not.Hero` and `not.Player`. function World:createNaut (x, y, name) local naut = Player(name, x, y, self) table.insert(self.Nauts, naut) return naut end --- Add new decoration to the world --- 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(x, y, self, 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`. +-- TODO: Extend names of variables related to Clouds to provide better readability. See also: `not/Cloud`. function World:createCloud (x, y, t, v) table.insert(self.Clouds, Cloud(x, y, t, v, self)) end +function World:createEffect (name, x, y) + table.insert(self.Effects, Effect(name, x, y, self)) +end + +function World:createRay (naut) + table.insert(self.Rays, Ray(naut, self)) +end + -- Randomize Cloud creation function World:randomizeCloud (outside) if outside == nil then @@ -135,18 +138,6 @@ function World:randomizeCloud (outside) self:createCloud(x, y, t, v) 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(name, x, y, self)) -end - --- Add a ray -function World:createRay (naut) - table.insert(self.Rays, Ray(naut, self)) -end - -- get Nauts functions -- more than -1 lives function World:getNautsPlayable () @@ -209,6 +200,7 @@ function World:update (dt) decoration:update(dt) end -- Clouds + -- TODO: possibly create new class for Clouds generation. Do it along with Cloud cleaning. if self.map.clouds then -- generator local n = table.getn(self.Clouds) @@ -323,9 +315,8 @@ function World:draw () end -- Box2D callbacks --- TODO: Rather than here, these contacts should be in `Hero` (most likely). --- TODO: Explode these into more functions.\ --- TODO: Stop using magical numbers: +-- TODO: Review current state of Box2D callbacks. +-- TODO: Stop using magical numbers in Box2D callbacks. -- [1] -> Platform -- [2] -> Hero -- [3] -> Punch sensor @@ -367,7 +358,6 @@ 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 db0d49b4a41a36b47979d0935316c26ae77c260a Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 3 Sep 2017 19:54:10 +0200 Subject: Moved default variables to constructor in Element --- not/Element.lua | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'not') diff --git a/not/Element.lua b/not/Element.lua index 24576e6..6ac83d6 100644 --- a/not/Element.lua +++ b/not/Element.lua @@ -1,15 +1,11 @@ -require "not.Object" - --- `Element` -- Empty element used inside `Menu`. -Element = Object:extends() - -Element.parent = --[[not.Menu]]nil -Element.x = 0 -Element.y = 0 +Element = require "not.Object":extends() function Element:new (parent) self.parent = parent + self.x = 0 + self.y = 0 end function Element:delete () end -- deletes Element -- cgit v1.1 From 95d168815633f55b884cddc9d1364ae25497d882 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 3 Sep 2017 19:54:32 +0200 Subject: Deleted (hehe) misleading comment --- not/Element.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not') diff --git a/not/Element.lua b/not/Element.lua index 6ac83d6..44f8ac3 100644 --- a/not/Element.lua +++ b/not/Element.lua @@ -8,7 +8,7 @@ function Element:new (parent) self.y = 0 end -function Element:delete () end -- deletes Element +function Element:delete () end function Element:getPosition () return self.x, self.y -- cgit v1.1 From 20d03d8917ba38568fc56dc53576efb22c1d459c Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 3 Sep 2017 19:59:32 +0200 Subject: Variables initialized in constructor --- not/Selector.lua | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index ef78778..5e54f6e 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -1,5 +1,3 @@ -require "not.Element" - --- `Selector` -- Used in Menu for selecting various things from list. Works for each Controller set or globally. --[[ @@ -14,29 +12,19 @@ selector:new(menu) :set("global", false) -- true: single selector; false: selector for each controller set present :init() ]] -Selector = Element:extends() - -Selector.width = 0 -Selector.height = 0 -Selector.margin = 0 -Selector.focused = false -Selector.global = false -Selector.delay = 2 -Selector.first = false -Selector.list = --[[]]nil -Selector.sets = --[[]]nil -Selector.locks = --[[]]nil -Selector.selections = --[[]]nil -Selector.shape = "portrait" -Selector.sprite = --[[]]nil -Selector.quads = --[[]]nil -Selector.icons_i = --[[]]nil -Selector.icons_q = --[[]]nil +Selector = require "not.Element":extends() --- Constructor function Selector:new (parent) Selector.__super.new(self, parent) self.sprite, self.quads = parent:getSheet() + self.width = 0 + self.height = 0 + self.margin = 0 + self.focused = false + self.global = false + self.delay = 2 + self.first = false + self.shape = "portrait" end -- Size of single block -- cgit v1.1 From ecf44e285df0dc5bfae26db50b274cf49ce46576 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 3 Sep 2017 20:01:34 +0200 Subject: Default delay static for Selector --- not/Selector.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index 5e54f6e..11e88d3 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -14,6 +14,8 @@ selector:new(menu) ]] Selector = require "not.Element":extends() +Selector.DEFAULT_DELAY = 2 + function Selector:new (parent) Selector.__super.new(self, parent) self.sprite, self.quads = parent:getSheet() @@ -22,7 +24,7 @@ function Selector:new (parent) self.margin = 0 self.focused = false self.global = false - self.delay = 2 + self.delay = Selector.DEFAULT_DELAY self.first = false self.shape = "portrait" end @@ -234,8 +236,8 @@ function Selector:draw (scale) 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 + if self.delay > Selector.DEFAULT_DELAY then + self.delay = self.delay - Selector.DEFAULT_DELAY end end -- cgit v1.1 From 7afcf7efbead72263d97da376de802e553bfb7eb Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 03:47:49 +0200 Subject: New menu element Demultiplexer --- not/Demultiplexer.lua | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 not/Demultiplexer.lua (limited to 'not') diff --git a/not/Demultiplexer.lua b/not/Demultiplexer.lua new file mode 100644 index 0000000..468f007 --- /dev/null +++ b/not/Demultiplexer.lua @@ -0,0 +1,63 @@ +--- Element used for grouping elements and demultiplexing input of different controller sets. +Demultiplexer = require "not.Element":extends() + +function Demultiplexer:new (parent) + Demultiplexer.__super.new(self, parent) + self.children = {} +end + +--- Calls function with parameters for each child. +-- @param func key of function to call +-- @param ... parameters passed to function +-- @return table with calls' results +function Demultiplexer:callEach (func, ...) + local results = {} + for _,child in ipairs(self.children) do + if type(child[func]) == "function" then + table.insert(results, child[func](child, ...)) + end + end + return results +end + +--- Calls function with parameters for one child based on controller set. +-- @param set controller set +-- @param func key of function to call +-- @param ... parameters passed to function +function Demultiplexer:callOne (set, func, ...) + for i,test in ipairs(Controller.getSets()) do + if test == set then + self.children[i][func](...) + return nil + end + end +end + +function Demultiplexer:focus () + self:callEach("focus") + self.focused = true + return true +end + +function Demultiplexer:blur () + self:callEach("blur") + self.focused = false +end + +function Demultiplexer:draw (scale) + self:callEach("draw", scale) +end + +function Demultiplexer:update (dt) + self:callEach("update", dt) +end + +function Demultiplexer:controlpressed (set, action, key) + self:callOne(set, "controlpressed", set, action, key) +end + +function Demultiplexer:controlreleased (set, action, key) + self:callOne(set, "controlreleased", set, action, key) +end + +return Demultiplexer -- cgit v1.1 From ea71f94e6c7f4727393063d1324b70d7bbf4922f Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 03:51:16 +0200 Subject: Demux passes controller callbacks only if focused --- not/Demultiplexer.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'not') diff --git a/not/Demultiplexer.lua b/not/Demultiplexer.lua index 468f007..ee6cbc9 100644 --- a/not/Demultiplexer.lua +++ b/not/Demultiplexer.lua @@ -53,11 +53,15 @@ function Demultiplexer:update (dt) end function Demultiplexer:controlpressed (set, action, key) - self:callOne(set, "controlpressed", set, action, key) + if self.focused then + self:callOne(set, "controlpressed", set, action, key) + end end function Demultiplexer:controlreleased (set, action, key) - self:callOne(set, "controlreleased", set, action, key) + if self.focused then + self:callOne(set, "controlreleased", set, action, key) + end end return Demultiplexer -- cgit v1.1 From 727a4f0996383031c02977e448b15b8e83b6a9ad Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 03:55:52 +0200 Subject: Renamed demux method --- not/Demultiplexer.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'not') diff --git a/not/Demultiplexer.lua b/not/Demultiplexer.lua index ee6cbc9..c2b2272 100644 --- a/not/Demultiplexer.lua +++ b/not/Demultiplexer.lua @@ -24,7 +24,7 @@ end -- @param set controller set -- @param func key of function to call -- @param ... parameters passed to function -function Demultiplexer:callOne (set, func, ...) +function Demultiplexer:callWithSet (set, func, ...) for i,test in ipairs(Controller.getSets()) do if test == set then self.children[i][func](...) @@ -54,13 +54,13 @@ end function Demultiplexer:controlpressed (set, action, key) if self.focused then - self:callOne(set, "controlpressed", set, action, key) + self:callWithSet(set, "controlpressed", set, action, key) end end function Demultiplexer:controlreleased (set, action, key) if self.focused then - self:callOne(set, "controlreleased", set, action, key) + self:callWithSet(set, "controlreleased", set, action, key) end end -- cgit v1.1 From b5beef7510274c53f5b3e5c41e80fb5b338fe93d Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 18:42:29 +0200 Subject: Elements now have getSize by default --- not/Element.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'not') diff --git a/not/Element.lua b/not/Element.lua index 44f8ac3..faa8b12 100644 --- a/not/Element.lua +++ b/not/Element.lua @@ -10,9 +10,14 @@ end function Element:delete () end +function Element:getSize () + return 0, 0 +end + function Element:getPosition () return self.x, self.y end + function Element:setPosition (x, y) self.x = x or 0 self.y = y or 0 @@ -26,12 +31,14 @@ function Element:set (name, func) return self end --- Called when menu tries to focus on this element. +--- 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. +end + +--- Called when Element loses focus. +function Element:blur () end -- LÖVE2D callbacks function Element:draw (scale) end -- cgit v1.1 From 37c89de4d84b3ff5af8b001f9f54537b6e343cb0 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 18:45:15 +0200 Subject: Element uses Object's delete --- not/Element.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'not') diff --git a/not/Element.lua b/not/Element.lua index faa8b12..75d1790 100644 --- a/not/Element.lua +++ b/not/Element.lua @@ -8,8 +8,6 @@ function Element:new (parent) self.y = 0 end -function Element:delete () end - function Element:getSize () return 0, 0 end -- cgit v1.1 From e287689c2a22d82522a5578205bf66f77c51a467 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 18:46:49 +0200 Subject: Note about Element's getSize --- not/Element.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'not') diff --git a/not/Element.lua b/not/Element.lua index 75d1790..3b0d13a 100644 --- a/not/Element.lua +++ b/not/Element.lua @@ -8,6 +8,7 @@ function Element:new (parent) self.y = 0 end +-- TODO: Element's getSize is temporary. Create BoxElement and move it there. function Element:getSize () return 0, 0 end -- cgit v1.1 From 2b15ac7c04211b319c247f7923fe4b5ebfed0516 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 18:47:24 +0200 Subject: Buttons' size just for sake --- not/Button.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'not') diff --git a/not/Button.lua b/not/Button.lua index a2f7a19..3c6042d 100644 --- a/not/Button.lua +++ b/not/Button.lua @@ -15,6 +15,9 @@ function Button:new (parent) self.sprite, self.quads = parent:getSheet() end +function Button:getSize () + return 58, 15 + function Button:setText (text) self.text = text or "" return self -- cgit v1.1 From 5d141eae2bfb196597a8743bc2409ac20308e45e Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 19:06:00 +0200 Subject: There was no end to it --- not/Button.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'not') diff --git a/not/Button.lua b/not/Button.lua index 3c6042d..3493a84 100644 --- a/not/Button.lua +++ b/not/Button.lua @@ -17,6 +17,7 @@ end function Button:getSize () return 58, 15 +end function Button:setText (text) self.text = text or "" -- cgit v1.1 From f98ca666a8cdc2c179b2daed280d36ca03d32860 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 19:10:09 +0200 Subject: Fixed callWithSet --- not/Demultiplexer.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'not') diff --git a/not/Demultiplexer.lua b/not/Demultiplexer.lua index c2b2272..cbbbcef 100644 --- a/not/Demultiplexer.lua +++ b/not/Demultiplexer.lua @@ -27,8 +27,10 @@ end function Demultiplexer:callWithSet (set, func, ...) for i,test in ipairs(Controller.getSets()) do if test == set then - self.children[i][func](...) - return nil + local child = self.children[i] + if child then + return child[func](child, ...) + end end end end -- cgit v1.1 From de2ee3b44373da6e3c110d00644d04c78f2efa24 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 20:07:12 +0200 Subject: No more dank name: Demux => Group --- not/Demultiplexer.lua | 69 --------------------------------------------------- not/Group.lua | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 69 deletions(-) delete mode 100644 not/Demultiplexer.lua create mode 100644 not/Group.lua (limited to 'not') diff --git a/not/Demultiplexer.lua b/not/Demultiplexer.lua deleted file mode 100644 index cbbbcef..0000000 --- a/not/Demultiplexer.lua +++ /dev/null @@ -1,69 +0,0 @@ ---- Element used for grouping elements and demultiplexing input of different controller sets. -Demultiplexer = require "not.Element":extends() - -function Demultiplexer:new (parent) - Demultiplexer.__super.new(self, parent) - self.children = {} -end - ---- Calls function with parameters for each child. --- @param func key of function to call --- @param ... parameters passed to function --- @return table with calls' results -function Demultiplexer:callEach (func, ...) - local results = {} - for _,child in ipairs(self.children) do - if type(child[func]) == "function" then - table.insert(results, child[func](child, ...)) - end - end - return results -end - ---- Calls function with parameters for one child based on controller set. --- @param set controller set --- @param func key of function to call --- @param ... parameters passed to function -function Demultiplexer:callWithSet (set, func, ...) - for i,test in ipairs(Controller.getSets()) do - if test == set then - local child = self.children[i] - if child then - return child[func](child, ...) - end - end - end -end - -function Demultiplexer:focus () - self:callEach("focus") - self.focused = true - return true -end - -function Demultiplexer:blur () - self:callEach("blur") - self.focused = false -end - -function Demultiplexer:draw (scale) - self:callEach("draw", scale) -end - -function Demultiplexer:update (dt) - self:callEach("update", dt) -end - -function Demultiplexer:controlpressed (set, action, key) - if self.focused then - self:callWithSet(set, "controlpressed", set, action, key) - end -end - -function Demultiplexer:controlreleased (set, action, key) - if self.focused then - self:callWithSet(set, "controlreleased", set, action, key) - end -end - -return Demultiplexer diff --git a/not/Group.lua b/not/Group.lua new file mode 100644 index 0000000..5dedc9a --- /dev/null +++ b/not/Group.lua @@ -0,0 +1,69 @@ +--- Element used for grouping elements and passing input to selected child based on controller set. +Group = require "not.Element":extends() + +function Group:new (parent) + Group.__super.new(self, parent) + self.children = {} +end + +--- Calls function with parameters for each child. +-- @param func key of function to call +-- @param ... parameters passed to function +-- @return table with calls' results +function Group:callEach (func, ...) + local results = {} + for _,child in ipairs(self.children) do + if type(child[func]) == "function" then + table.insert(results, child[func](child, ...)) + end + end + return results +end + +--- Calls function with parameters for one child based on controller set. +-- @param set controller set +-- @param func key of function to call +-- @param ... parameters passed to function +function Group:callWithSet (set, func, ...) + for i,test in ipairs(Controller.getSets()) do + if test == set then + local child = self.children[i] + if child then + return child[func](child, ...) + end + end + end +end + +function Group:focus () + self:callEach("focus") + self.focused = true + return true +end + +function Group:blur () + self:callEach("blur") + self.focused = false +end + +function Group:draw (scale) + self:callEach("draw", scale) +end + +function Group:update (dt) + self:callEach("update", dt) +end + +function Group:controlpressed (set, action, key) + if self.focused then + self:callWithSet(set, "controlpressed", set, action, key) + end +end + +function Group:controlreleased (set, action, key) + if self.focused then + self:callWithSet(set, "controlreleased", set, action, key) + end +end + +return Group -- cgit v1.1 From 994768edaf706c890bcad6d6cdecedaf0f4bdec1 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 21:00:16 +0200 Subject: Added callEachBut method --- not/Group.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'not') diff --git a/not/Group.lua b/not/Group.lua index 5dedc9a..d9c0b9c 100644 --- a/not/Group.lua +++ b/not/Group.lua @@ -20,10 +20,28 @@ function Group:callEach (func, ...) return results end +--- Calls function with parameters for each but one child. +-- @param avoid child to avoid calling +-- @param func key of function to call +-- @param ... parameters passed to function +-- @return table with calls' results +function Group:callEachBut (avoid, func, ...) + local results = {} + for _,child in ipairs(self.children) do + if child ~= avoid then + if type(child[func]) == "function" then + table.insert(results, child[func](child, ...)) + end + end + end + return results +end + --- Calls function with parameters for one child based on controller set. -- @param set controller set -- @param func key of function to call -- @param ... parameters passed to function +-- @return results of called function function Group:callWithSet (set, func, ...) for i,test in ipairs(Controller.getSets()) do if test == set then -- cgit v1.1 From 4f0a5df7c5a681a153967aca5142bdef65102a62 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 21:03:04 +0200 Subject: First steps in Selector rewrite --- not/Selector.lua | 288 ++++++++++--------------------------------------------- 1 file changed, 52 insertions(+), 236 deletions(-) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index 11e88d3..896f98f 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -1,272 +1,88 @@ --- `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() -]] +-- Element for selecting variable from list. Selector = require "not.Element":extends() Selector.DEFAULT_DELAY = 2 +Selector.SHAPE_PORTRAIT = 1 +Selector.SHAPE_PANORAMA = 2 -function Selector:new (parent) +function Selector:new (group, parent) Selector.__super.new(self, parent) - self.sprite, self.quads = parent:getSheet() - self.width = 0 - self.height = 0 - self.margin = 0 - self.focused = false - self.global = false + self.atlas, self.quads = parent:getSheet() + self.group = group self.delay = Selector.DEFAULT_DELAY - self.first = false - self.shape = "portrait" + self.shape = Selector.SHAPE_PORTRAIT + self.focused = false + self.locked = false + self.index = 1 end --- Size of single block +-- TODO: See `not/Element@getSize`. 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 = {} + if self.shape == Selector.SHAPE_PORTRAIT then + return 32, 32 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 + if self.shape == Selector.SHAPE_PANORAMA then + return 80, 42 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 +--- Makes sure that n is in <1, total> range. +local +function limit (n, total) + if n > total then + return limit(n - total, total) 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 + if n < 1 then + return limit(n + total, total) end - local n = n or 1 - local old = self.selections[n] - self.selections[n] = limit(new, #self.list) - return old + return n 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 +--- Chooses item with an index. +-- @param index selected item's index +-- @return old index +function Selector:setIndex (index) + local old = self.index + self.index = limit(index, #self.list) + return old 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 +--- Returns selected item's value. +-- @return item selected from list +function Selector:getSelected () + return self.list[self.index] 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 +--- Checks if selection is locked and returns item's value. +-- @return false if not locked, value from list if locked +function Selector:getLocked () + if self.locked then + return self:getSelected() end + return false 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) +--- Checks if Selected value is unique in group's scope. +function Selector:isUnique () + if self.group then + local locked = group:callEachBut(self, "getLocked") + for _,lock in pairs(locked) do + if lock then + return false + end 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 + return true end --- Menu callbacks -function Selector:focus () -- Called when Element gains focus +function Selector: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.DEFAULT_DELAY then - self.delay = self.delay - Selector.DEFAULT_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 +function Selector:blur () + self.focused = false end return Selector -- cgit v1.1 From 87e0b1eb45117ced574df07534f6666470f218a7 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 21:10:43 +0200 Subject: Minor getLocked and isUnique changes --- not/Selector.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index 896f98f..fa00286 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -55,22 +55,21 @@ function Selector:getSelected () end --- Checks if selection is locked and returns item's value. --- @return false if not locked, value from list if locked +-- Nil returning part is there to clarify method's behaviour. +-- @return nil if not locked, value from list if locked function Selector:getLocked () if self.locked then return self:getSelected() end - return false + return nil end --- Checks if Selected value is unique in group's scope. function Selector:isUnique () if self.group then - local locked = group:callEachBut(self, "getLocked") - for _,lock in pairs(locked) do - if lock then - return false - end + -- In this case next is used to determine if table returned by call is empty. + if next(group:callEachBut(self, "getLocked")) then + return false end end return true -- cgit v1.1 From 3f353552da6bb67aa1e7018399e62c7eace9b8c2 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 21:14:36 +0200 Subject: Clearing up getLocked, docs changes --- not/Selector.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index fa00286..9083b24 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -49,22 +49,21 @@ function Selector:setIndex (index) end --- Returns selected item's value. --- @return item selected from list +-- @return item selected from the list function Selector:getSelected () return self.list[self.index] end --- Checks if selection is locked and returns item's value. --- Nil returning part is there to clarify method's behaviour. --- @return nil if not locked, value from list if locked +-- @return item selected from the list if locked, nil otherwise function Selector:getLocked () if self.locked then return self:getSelected() end - return nil end --- Checks if Selected value is unique in group's scope. +-- @return boolean answering question function Selector:isUnique () if self.group then -- In this case next is used to determine if table returned by call is empty. -- cgit v1.1 From fd07ad0d87bc836f14c7be4bcb4042db78afdd95 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 22:00:58 +0200 Subject: Basic draw for Selector --- not/Selector.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index 9083b24..1c13e76 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -74,6 +74,10 @@ function Selector:isUnique () return true end +function Selector:getText () + return tostring(self:getSelected()) +end + function Selector:focus () self.focused = true return true @@ -83,4 +87,23 @@ function Selector:blur () self.focused = false end +-- TODO: Temporary function to determine quad to use. Will be obsolete when BoxElement will be done. See also `not/Element@getSize`. +function Selector:getShapeString () + if self.shape == Selector.SHAPE_PORTRAIT then + return "portrait" + end + if self.shape == Selector.SHAPE_PANORAMA then + return "panorama" + end +end + +function Selector:draw (scale) + local x, y = self:getPosition() + local w, h = self:getSize() + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(self.atlas, self.quads[self:getShapeString()].normal, x*scale, y*scale, 0, scale, scale) + love.graphics.setFont(Font) + love.graphics.printf(self:getText(), (x-w)*scale, (y+h+1)*scale, w*3, "center", 0, scale, scale) +end + return Selector -- cgit v1.1 From 48f8e2e9b19a074306a9db896b84b27b21a2cc99 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 22:23:32 +0200 Subject: Testing new Selector and added update, locked drawing --- not/Selector.lua | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index 1c13e76..d96c2f9 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -6,10 +6,11 @@ Selector.DEFAULT_DELAY = 2 Selector.SHAPE_PORTRAIT = 1 Selector.SHAPE_PANORAMA = 2 -function Selector:new (group, parent) +function Selector:new (list, group, parent) Selector.__super.new(self, parent) self.atlas, self.quads = parent:getSheet() self.group = group + self.list = list self.delay = Selector.DEFAULT_DELAY self.shape = Selector.SHAPE_PORTRAIT self.focused = false @@ -100,10 +101,21 @@ end function Selector:draw (scale) local x, y = self:getPosition() local w, h = self:getSize() + local boxType = "normal" + if self:getLocked() then + boxType = "active" + end love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(self.atlas, self.quads[self:getShapeString()].normal, x*scale, y*scale, 0, scale, scale) + love.graphics.draw(self.atlas, self.quads[self:getShapeString()][boxType], x*scale, y*scale, 0, scale, scale) love.graphics.setFont(Font) love.graphics.printf(self:getText(), (x-w)*scale, (y+h+1)*scale, w*3, "center", 0, scale, scale) end +function Selector:update (dt) + self.delay = self.delay + dt + if self.delay > Selector.DEFAULT_DELAY then + self.delay = self.delay - Selector.DEFAULT_DELAY + end +end + return Selector -- cgit v1.1 From 6d81b4c2e65593218bb2a8ee322d083e362c7ab1 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 22:37:47 +0200 Subject: Basic interaction and changes to lock mechanic --- not/Selector.lua | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index d96c2f9..00cf5a0 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -14,7 +14,7 @@ function Selector:new (list, group, parent) self.delay = Selector.DEFAULT_DELAY self.shape = Selector.SHAPE_PORTRAIT self.focused = false - self.locked = false + self.lock = false self.index = 1 end @@ -56,9 +56,9 @@ function Selector:getSelected () end --- Checks if selection is locked and returns item's value. --- @return item selected from the list if locked, nil otherwise +-- @return item selected from the list if Selector is locked, nil otherwise function Selector:getLocked () - if self.locked then + if self.lock then return self:getSelected() end end @@ -118,4 +118,24 @@ function Selector:update (dt) end end +function Selector:controlpressed (set, action, key) + if set and self.focused then + if not self.lock then + if action == "left" then + self:setIndex(self.index - 1) + end + if action == "right" then + self:setIndex(self.index + 1) + end + if action == "attack" then + self.lock = true + end + end + + if action == "jump" then + self.lock = false + end + end +end + return Selector -- cgit v1.1 From 1392fe0404f19decab197064c88ca4dc0ad9c12d Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 22:58:37 +0200 Subject: Minor interaction changes; draw arrows --- not/Selector.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index 00cf5a0..c6ab810 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -98,15 +98,30 @@ function Selector:getShapeString () end end +-- TODO: Selector draw is missing box content drawing. function Selector:draw (scale) local x, y = self:getPosition() local w, h = self:getSize() + local boxType = "normal" if self:getLocked() then boxType = "active" end + love.graphics.setColor(255, 255, 255, 255) love.graphics.draw(self.atlas, self.quads[self:getShapeString()][boxType], x*scale, y*scale, 0, scale, scale) + + if self.focused then + local dy = (h-6)/2 + local al, ar = self.quads.arrow_r, self.quads.arrow_l + if self.lock then + al, ar = ar, al + end + + love.graphics.draw(self.atlas, ar, (x+0-2-math.floor(self.delay))*scale, (y+dy)*scale, 0, scale, scale) + love.graphics.draw(self.atlas, al, (x+w-4+math.floor(self.delay))*scale, (y+dy)*scale, 0, scale, scale) + end + love.graphics.setFont(Font) love.graphics.printf(self:getText(), (x-w)*scale, (y+h+1)*scale, w*3, "center", 0, scale, scale) end @@ -127,6 +142,7 @@ function Selector:controlpressed (set, action, key) if action == "right" then self:setIndex(self.index + 1) end + -- TODO: Extend functionality on attack action in Selector. if action == "attack" then self.lock = true end -- cgit v1.1 From cc96f0f2fe9af1ef9de0846f9939f3d477e86849 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 23:40:37 +0200 Subject: Fix for empty second parameter in table.insert --- not/Group.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not') diff --git a/not/Group.lua b/not/Group.lua index d9c0b9c..e644e5e 100644 --- a/not/Group.lua +++ b/not/Group.lua @@ -14,7 +14,7 @@ function Group:callEach (func, ...) local results = {} for _,child in ipairs(self.children) do if type(child[func]) == "function" then - table.insert(results, child[func](child, ...)) + table.insert(results, child[func](child, ...) or nil) end end return results -- cgit v1.1 From 168123c5a499d2d103d55bbf403b3a49bc3c28ec Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 4 Sep 2017 23:43:02 +0200 Subject: Fix also in this line --- not/Group.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not') diff --git a/not/Group.lua b/not/Group.lua index e644e5e..45dc474 100644 --- a/not/Group.lua +++ b/not/Group.lua @@ -30,7 +30,7 @@ function Group:callEachBut (avoid, func, ...) for _,child in ipairs(self.children) do if child ~= avoid then if type(child[func]) == "function" then - table.insert(results, child[func](child, ...)) + table.insert(results, child[func](child, ...) or nil) end end end -- cgit v1.1 From c0589d55340b948f107c7317f0f216e6ef408792 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 00:34:06 +0200 Subject: That will draw content for selector's box for now --- not/Selector.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index c6ab810..d6910fe 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -98,7 +98,6 @@ function Selector:getShapeString () end end --- TODO: Selector draw is missing box content drawing. function Selector:draw (scale) local x, y = self:getPosition() local w, h = self:getSize() @@ -111,6 +110,11 @@ function Selector:draw (scale) love.graphics.setColor(255, 255, 255, 255) love.graphics.draw(self.atlas, self.quads[self:getShapeString()][boxType], x*scale, y*scale, 0, scale, scale) + -- TODO: That is one way to draw icon for selected value. Find better one. See: `config/menus/host`. + if self.icons_atlas and self.icons_quads then + love.graphics.draw(self.icons_atlas, self.icons_quads[self.index], (x+2)*scale, (y+3)*scale, 0, scale, scale) + end + if self.focused then local dy = (h-6)/2 local al, ar = self.quads.arrow_r, self.quads.arrow_l -- cgit v1.1 From 8e51db223ed1e8307d1009e48becc618a924749b Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 00:44:32 +0200 Subject: Darken not unique selections --- not/Selector.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index d6910fe..ed1813f 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -67,9 +67,11 @@ end -- @return boolean answering question function Selector:isUnique () if self.group then - -- In this case next is used to determine if table returned by call is empty. - if next(group:callEachBut(self, "getLocked")) then - return false + local locked = self.group:callEachBut(self, "getLocked") + for _,value in pairs(locked) do + if value == self:getSelected() then + return false + end end end return true @@ -108,13 +110,17 @@ function Selector:draw (scale) end love.graphics.setColor(255, 255, 255, 255) + if not self:isUnique() then + love.graphics.setColor(120, 120, 120, 255) + end love.graphics.draw(self.atlas, self.quads[self:getShapeString()][boxType], x*scale, y*scale, 0, scale, scale) - -- TODO: That is one way to draw icon for selected value. Find better one. See: `config/menus/host`. if self.icons_atlas and self.icons_quads then love.graphics.draw(self.icons_atlas, self.icons_quads[self.index], (x+2)*scale, (y+3)*scale, 0, scale, scale) end + love.graphics.setColor(255, 255, 255, 255) + if self.focused then local dy = (h-6)/2 local al, ar = self.quads.arrow_r, self.quads.arrow_l -- cgit v1.1 From b117c29325698e56a4fbd76426739dd48fa154cb Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 01:24:02 +0200 Subject: Map config table is now passed to World rather than map name --- not/World.lua | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index c3fec11..b2dc0e7 100644 --- a/not/World.lua +++ b/not/World.lua @@ -25,12 +25,13 @@ function World:new (map, nauts) self.Effects = {} self.Decorations = {} self.Rays = {} - -- Map and misc. - -- TODO: `map` could be table from config file rather than just string. - local map = map or "default" - self:loadMap(map) + + self.map = map + self:buildMap() self:spawnNauts(nauts) + self.camera = Camera:new(self) + musicPlayer:setTrack(self.map.theme) musicPlayer:play() end @@ -46,11 +47,8 @@ function World:delete () self.world:destroy() end ---- Loads table from selected map config file located in `config/maps/` directory. -function World:loadMap (name) - local map = string.format("config/maps/%s.lua", name or "default") - self.map = love.filesystem.load(map)() - +--- Builds map using one of tables frin config files located in `config/maps/` directory. +function World:buildMap () for _,op in pairs(self.map.create) do if op.platform then local path = string.format("config/platforms/%s.lua", op.platform) -- cgit v1.1 From a866dc8e7d1ec941b96acb7dd12c1636cc3f1a80 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 01:55:14 +0200 Subject: Added addChild, setPosition and getSize to Group --- not/Group.lua | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'not') diff --git a/not/Group.lua b/not/Group.lua index 45dc474..898d7f3 100644 --- a/not/Group.lua +++ b/not/Group.lua @@ -4,6 +4,35 @@ Group = require "not.Element":extends() function Group:new (parent) Group.__super.new(self, parent) self.children = {} + self.marign = 0 +end + +function Group:addChild (element) + table.insert(self.children, element) + return element +end + +-- TODO: Missing semi-important docs on Group's setPosition. +function Group:setPosition (x, y) + local dx = 0 + for _,child in ipairs(self.children) do + child:setPosition(x + dx, y) + dx = dx + child:getSize() + self.marigin + end + return Group.__super.setPosition(self, x, y) +end + +function Group:getSize () + local twidth = -self.marigin + local theight = 0 + for _,child in ipairs(self.children) do + local cwidth, cheight = child:getSize() + twidth = twidth + child:getSize() + self.marigin + if theight < cheight then + theight = cheight + end + end + return twidth, theight end --- Calls function with parameters for each child. -- cgit v1.1 From 0406d5d9617d20b528d2c5135a2474c19e23e9fa Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 02:03:12 +0200 Subject: Fixed typo in Group --- not/Group.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'not') diff --git a/not/Group.lua b/not/Group.lua index 898d7f3..970d3bc 100644 --- a/not/Group.lua +++ b/not/Group.lua @@ -4,7 +4,7 @@ Group = require "not.Element":extends() function Group:new (parent) Group.__super.new(self, parent) self.children = {} - self.marign = 0 + self.margin = 0 end function Group:addChild (element) @@ -17,17 +17,17 @@ function Group:setPosition (x, y) local dx = 0 for _,child in ipairs(self.children) do child:setPosition(x + dx, y) - dx = dx + child:getSize() + self.marigin + dx = dx + child:getSize() + self.margin end return Group.__super.setPosition(self, x, y) end function Group:getSize () - local twidth = -self.marigin + local twidth = -self.margin local theight = 0 for _,child in ipairs(self.children) do local cwidth, cheight = child:getSize() - twidth = twidth + child:getSize() + self.marigin + twidth = twidth + child:getSize() + self.margin if theight < cheight then theight = cheight end -- cgit v1.1 From 7f524270713a558c0538c7d728271121928a60ec Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 02:17:01 +0200 Subject: Map config filepath is now added to map config table; used by debug mode --- not/World.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index b2dc0e7..c4606dd 100644 --- a/not/World.lua +++ b/not/World.lua @@ -358,7 +358,8 @@ end -- Controller callbacks function World:controlpressed (set, action, key) if key == "f6" and debug then - local map = self:getMapName() + local map = love.filesystem.load(self.map.filepath)() + map.filepath = self.map.filepath local nauts = {} for _,naut in pairs(self:getNautsAll()) do table.insert(nauts, {naut.name, naut:getControllerSet()}) -- cgit v1.1 From 975e5663c09f0d74b2d0a18a7a5ce1297362a4a2 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 02:36:08 +0200 Subject: Moved selector's action handlers outside controlpressed method --- not/Selector.lua | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index ed1813f..bd6224b 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -145,23 +145,32 @@ end function Selector:controlpressed (set, action, key) if set and self.focused then - if not self.lock then - if action == "left" then - self:setIndex(self.index - 1) - end - if action == "right" then - self:setIndex(self.index + 1) - end - -- TODO: Extend functionality on attack action in Selector. - if action == "attack" then - self.lock = true - end + local handler = self[action] + if handler then + handler(self) end + end +end - if action == "jump" then - self.lock = false - end +function Selector:left () + if not self.lock then + self:setIndex(self.index - 1) + end +end + +function Selector:right () + if not self.lock then + self:setIndex(self.index + 1) end end +function Selector:attack () + self.lock = true +end + +-- Selector doesn't actually jump, haha, I tricked you! +function Selector:jump () + self.lock = false +end + return Selector -- cgit v1.1 From 84f6ec47be56d397fe140b5707b76078917fe8fb Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 03:49:33 +0200 Subject: Random naut selection is back! --- not/Selector.lua | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'not') diff --git a/not/Selector.lua b/not/Selector.lua index bd6224b..ee6f0e3 100644 --- a/not/Selector.lua +++ b/not/Selector.lua @@ -49,6 +49,23 @@ function Selector:setIndex (index) return old end +function Selector:rollRandom (exclude) + local exclude = exclude or {} + local index = love.math.random(1, #self.list) + local elgible = true + for _,i in ipairs(exclude) do + if index == i then + elgible = false + break + end + end + if not elgible or not self:isUnique(self.list[index]) then + table.insert(exclude, index) + return self:rollRandom(exclude) + end + return index +end + --- Returns selected item's value. -- @return item selected from the list function Selector:getSelected () @@ -64,12 +81,14 @@ function Selector:getLocked () end --- Checks if Selected value is unique in group's scope. +-- @param index optional parameter to fill in place of currently selected item -- @return boolean answering question -function Selector:isUnique () +function Selector:isUnique (item) + local item = item or self:getSelected() if self.group then local locked = self.group:callEachBut(self, "getLocked") for _,value in pairs(locked) do - if value == self:getSelected() then + if value == item then return false end end -- cgit v1.1 From 69eebe12baa0804cacf7285d1fdc20f42334dc27 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 05:01:49 +0200 Subject: CloudGenerator created --- not/CloudGenerator.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 not/CloudGenerator.lua (limited to 'not') diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua new file mode 100644 index 0000000..0620cdd --- /dev/null +++ b/not/CloudGenerator.lua @@ -0,0 +1,12 @@ +--- Generates clouds over time with randomized positions and styles. +CloudGenerator = require "not.Object":extends() + +function CloudGenerator:new (world, styles) + self.world = world +end + +function CloudGenerator:update (dt) + +end + +return CloudGenerator -- cgit v1.1 From dc6fd557ed955fc5f177608c186768e29c7778c6 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 18:32:34 +0200 Subject: Cloud clean-up, moving methods from World to CloudGenerator --- not/Cloud.lua | 84 ++++++++++++++++++++----------------------------- not/CloudGenerator.lua | 54 ++++++++++++++++++++++++++++++-- not/World.lua | 85 ++++++++++++++++++-------------------------------- 3 files changed, 117 insertions(+), 106 deletions(-) (limited to 'not') diff --git a/not/Cloud.lua b/not/Cloud.lua index 25169c0..4851042 100644 --- a/not/Cloud.lua +++ b/not/Cloud.lua @@ -1,61 +1,45 @@ -require "not.Decoration" - --- `Cloud` --- That white thing moving in the background. --- TODO: extends variables names to be readable. -Cloud = Decoration:extends() -Cloud.t = 1 -- type (sprite number) -Cloud.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), - 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, world) - if self:getImage() == nil then - self:setImage(Sprite.newImage("assets/clouds.png")) - end - Cloud.__super.new(self, x, y, world, nil) - self:setAnimationsList(animations) - self:setVelocity(v) - self:setType(t) +-- Moving decorations with limited lifespan. +Cloud = require "not.Decoration":extends() + +function Cloud:new (x, y, world, imagePath) + Cloud.__super.new(self, x, y, world, imagePath) + self.velocity_x = 0 + self.velocity_y = 0 + self.boundary_x = 0 + self.boundary_y = 0 end --- 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 +function Cloud:setVelocity (x, y) + self.velocity_x = x + self.velocity_y = y +end + +function Cloud:setBoundary (x, y) + self.boundary_x = x + self.boundary_y = y end -function Cloud:setVelocity (velocity) - self.v = velocity + +function Cloud:setStyle (style) + self:setAnimation(style) +end + +function Cloud:getStyle () + return self:getAnimation() +end + +function Cloud:testPosition () + if self.x > self.boundary_x or self.y > self.boundary_y then + return true + end end --- Update of `Cloud`, returns x for world to delete cloud after reaching right corner. +-- Cloud will get deleted if this function returns true. function Cloud:update (dt) Cloud.__super.update(self, dt) - self.x = self.x + self.v*dt - return self.x + self.x = self.x + self.velocity_x * dt + self.y = self.y + self.velocity_y * dt + return self:testPosition() end return Cloud diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua index 0620cdd..a26cc77 100644 --- a/not/CloudGenerator.lua +++ b/not/CloudGenerator.lua @@ -1,12 +1,62 @@ --- Generates clouds over time with randomized positions and styles. +-- Also used as factory for Clouds. CloudGenerator = require "not.Object":extends() -function CloudGenerator:new (world, styles) +require "not.Cloud" + +-- TODO: Allow map config to modify cloud styles. +local animations = { + default = { + [1] = love.graphics.newQuad( 1, 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 + } +} + +function CloudGenerator:new (world) self.world = world + self.atlas = "assets/clouds.png" + self.quads = animations +end + +function CloudGenerator:createCloud (x, y) + local cloud = Cloud(x, y, self.world, self.atlas) + cloud:setAnimationsList(self.quads) + cloud:setVelocity(13, 0) + cloud:setBoundary(340, 320) + return cloud +end + +function CloudGenerator:randomize (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+love.math.random(-50,20) + else + x = love.math.random(m.center.x-m.width/2,m.center.x+m.width/2) + end + y = love.math.random(m.center.y-m.height/2, m.center.y+m.height/2) + t = love.math.random(1,3) + v = love.math.random(8,18) end function CloudGenerator:update (dt) - + local count = self.world:getCloudsCount() end return CloudGenerator diff --git a/not/World.lua b/not/World.lua index c4606dd..b97a5b5 100644 --- a/not/World.lua +++ b/not/World.lua @@ -5,10 +5,10 @@ World = require "not.Scene":extends() require "not.Platform" require "not.Player" -require "not.Cloud" require "not.Effect" require "not.Decoration" require "not.Ray" +require "not.CloudGenerator" --- ZA WARUDO! -- TODO: Missing documentation on most of World's methods. @@ -16,7 +16,7 @@ function World:new (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: Move all entities into single table. self.lastNaut = false self.Nauts = {} @@ -28,6 +28,7 @@ function World:new (map, nauts) self.map = map self:buildMap() + self:initClouds() self:spawnNauts(nauts) self.camera = Camera:new(self) @@ -65,11 +66,12 @@ function World:buildMap () self:createDecoration(x, y, op.background) -- TODO: Decoration does not allow Image instead of filePath! end end - +end + +-- TODO: Spawn some clouds after cloudGenerator has been initialized. +function World:initClouds () if self.map.clouds then - for i=1,6 do - self:randomizeCloud(false) - end + self.cloudGenerator = CloudGenerator(self) end end @@ -103,11 +105,6 @@ function World:createDecoration (x, y, sprite) table.insert(self.Decorations, Decoration(x, y, self, sprite)) end --- TODO: Extend names of variables related to Clouds to provide better readability. See also: `not/Cloud`. -function World:createCloud (x, y, t, v) - table.insert(self.Clouds, Cloud(x, y, t, v, self)) -end - function World:createEffect (name, x, y) table.insert(self.Effects, Effect(name, x, y, self)) end @@ -116,24 +113,15 @@ function World:createRay (naut) table.insert(self.Rays, Ray(naut, self)) 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+love.math.random(-50,20) - else - x = love.math.random(m.center.x-m.width/2,m.center.x+m.width/2) - end - y = love.math.random(m.center.y-m.height/2, m.center.y+m.height/2) - t = love.math.random(1,3) - v = love.math.random(8,18) - self:createCloud(x, y, t, v) +-- TODO: Sprites' in general don't take actual Image in constructor. That is not only case of Decoration. +-- TODO: Once entities are stored inside single table create single `insertEntity` method for World. +function World:insertCloud (cloud) + table.insert(self.Clouds, cloud) + return cloud +end + +function World:getCloudsCount () + return #self.Clouds end -- get Nauts functions @@ -187,7 +175,11 @@ end function World:update (dt) self.world:update(dt) self.camera:update(dt) - -- Engine world: Nauts, Grounds (kek) and Decorations - all Animateds (top kek) + + if self.cloudGenerator then + self.cloudGenerator:update(dt) + end + for _,naut in pairs(self.Nauts) do naut:update(dt) end @@ -197,38 +189,23 @@ function World:update (dt) for _,decoration in pairs(self.Decorations) do decoration:update(dt) end - -- Clouds - -- TODO: possibly create new class for Clouds generation. Do it along with Cloud cleaning. - 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 + for key,effect in pairs(self.Effects) do + if effect:update(dt) then + table.remove(self.Effects, key) end end - -- Effects - for _,effect in pairs(self.Effects) do - if effect:update(dt) then - table.remove(self.Effects, _) + for key,cloud in pairs(self.Clouds) do + if cloud:update(dt) then + table.remove(self.Clouds, key) end end - -- Rays - for _,ray in pairs(self.Rays) do + for key,ray in pairs(self.Rays) do if ray:update(dt) then - table.remove(self.Rays, _) + table.remove(self.Rays, key) end end end + -- Draw function World:draw () -- Camera stuff -- cgit v1.1 From de86586e3957be9e0794698e86ce913adc91beea Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 19:13:45 +0200 Subject: That background kept irritating me. Background now follows offset with ratio --- not/Decoration.lua | 9 +++++++++ not/World.lua | 11 ++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'not') diff --git a/not/Decoration.lua b/not/Decoration.lua index 97524f5..6068a61 100644 --- a/not/Decoration.lua +++ b/not/Decoration.lua @@ -21,4 +21,13 @@ function Decoration:setPosition (x, y) self.x, self.y = x, y end +-- TODO: Temporary wrapper for draw to keep background in place. +function Decoration:draw (offset_x, offset_y, scale) + if self.ratio ~= nil then + offset_x = offset_x * self.ratio + offset_y = offset_y * self.ratio + end + Decoration.__super.draw(self, offset_x, offset_y, scale) +end + return Decoration diff --git a/not/World.lua b/not/World.lua index b97a5b5..097b21a 100644 --- a/not/World.lua +++ b/not/World.lua @@ -61,9 +61,8 @@ function World:buildMap () end if op.background then local image = love.graphics.newImage(op.background) - local x = self.map.center.x - (image:getWidth() / 2) - local y = self.map.center.y - (image:getHeight() / 2) - self:createDecoration(x, y, op.background) -- TODO: Decoration does not allow Image instead of filePath! + local bg = self:createDecoration(0, 0, op.background) -- TODO: Decoration does not allow Image instead of filePath! + bg.ratio = op.ratio end end end @@ -102,7 +101,9 @@ function World:createNaut (x, y, name) end function World:createDecoration (x, y, sprite) - table.insert(self.Decorations, Decoration(x, y, self, sprite)) + local deco = Decoration(x, y, self, sprite) + table.insert(self.Decorations, deco) + return deco end function World:createEffect (name, x, y) @@ -175,7 +176,7 @@ end function World:update (dt) self.world:update(dt) self.camera:update(dt) - + if self.cloudGenerator then self.cloudGenerator:update(dt) end -- cgit v1.1 From 463f23bfd4510c95d2290fe0aa5b0ea2998d5786 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 19:15:52 +0200 Subject: Move clouds in front of decorations --- not/World.lua | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 097b21a..f2dc391 100644 --- a/not/World.lua +++ b/not/World.lua @@ -213,21 +213,18 @@ function World:draw () local offset_x, offset_y = self.camera:getOffsets() local scale = getScale() local scaler = getRealScale() - - -- Background - -- love.graphics.draw(self.background, 0, 0, 0, scaler, scaler) - - -- TODO: 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 clouds + -- TODO: hotfix Clouds are drawn in front of decoration to make them in front of background. + for _,cloud in pairs(self.Clouds) do + cloud:draw(offset_x, offset_y, scale) + end + -- Draw effects for _,effect in pairs(self.Effects) do effect:draw(offset_x,offset_y, scale) -- cgit v1.1 From da2c0d100a0b55e627ecdf5eaf5b8af78dd97c1c Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 5 Sep 2017 20:05:45 +0200 Subject: Fresh take on cloud-related random methods --- not/CloudGenerator.lua | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'not') diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua index a26cc77..404be1b 100644 --- a/not/CloudGenerator.lua +++ b/not/CloudGenerator.lua @@ -4,7 +4,6 @@ CloudGenerator = require "not.Object":extends() require "not.Cloud" --- TODO: Allow map config to modify cloud styles. local animations = { default = { [1] = love.graphics.newQuad( 1, 1, 158,47, 478,49), @@ -23,27 +22,33 @@ local animations = { } } +-- TODO: Allow map config to modify cloud styles: maximum cloud count, animations and atlas. function CloudGenerator:new (world) self.world = world self.atlas = "assets/clouds.png" self.quads = animations + self.count = 18 end -function CloudGenerator:createCloud (x, y) +function CloudGenerator:createCloud (x, y, style) local cloud = Cloud(x, y, self.world, self.atlas) cloud:setAnimationsList(self.quads) + cloud:setAnimation(style) cloud:setVelocity(13, 0) cloud:setBoundary(340, 320) return cloud end +function CloudGenerator:getRandomPosition (inside) + return 20, 20 +end + +function CloudGenerator:getRandomStyle () + return "default" +end + +--[[ function CloudGenerator:randomize (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+love.math.random(-50,20) @@ -54,9 +59,20 @@ function CloudGenerator:randomize (outside) t = love.math.random(1,3) v = love.math.random(8,18) end +]] + +function CloudGenerator:run (count, inside) + local count = count or 1 + for i=1,count then + local x, y = self:getRandomPosition(inside) + local style = self:getRandomStyle() + self.world:insertCloud(self:createCloud(x, y, style)) + end +end function CloudGenerator:update (dt) local count = self.world:getCloudsCount() + self:run() end return CloudGenerator -- cgit v1.1 From e223ae4d3495ae6060017bb60b11a322ff39623c Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 6 Sep 2017 01:52:56 +0200 Subject: yer funny aki, arent yer --- not/CloudGenerator.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not') diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua index 404be1b..da5ddb2 100644 --- a/not/CloudGenerator.lua +++ b/not/CloudGenerator.lua @@ -63,7 +63,7 @@ end function CloudGenerator:run (count, inside) local count = count or 1 - for i=1,count then + for i=1,count do local x, y = self:getRandomPosition(inside) local style = self:getRandomStyle() self.world:insertCloud(self:createCloud(x, y, style)) -- cgit v1.1 From 0ef657d12d523f3805422bfc1cb840e1a481af03 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 6 Sep 2017 02:28:52 +0200 Subject: Some actual functionality added to CloudGen --- not/CloudGenerator.lua | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'not') diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua index da5ddb2..fb1b617 100644 --- a/not/CloudGenerator.lua +++ b/not/CloudGenerator.lua @@ -28,6 +28,8 @@ function CloudGenerator:new (world) self.atlas = "assets/clouds.png" self.quads = animations self.count = 18 + self.interval = 6 + self.timer = 0 end function CloudGenerator:createCloud (x, y, style) @@ -39,27 +41,27 @@ function CloudGenerator:createCloud (x, y, style) return cloud end +-- TODO: CloudGen's randomization methods are too static (not configurable). function CloudGenerator:getRandomPosition (inside) - return 20, 20 + local x, y + local map = self.world.map + if not inside then + x = map.center.x - map.width*1.2 + love.math.random(-50, 20) + else + x = love.math.random(map.center.x - map.width / 2, map.center.x + map.width / 2) + end + y = love.math.random(map.center.y - map.height / 2, map.center.y + map.height / 2) + return x, y end function CloudGenerator:getRandomStyle () - return "default" -end - ---[[ -function CloudGenerator:randomize (outside) - local m = self.map - if outside then - x = m.center.x-m.width*1.2+love.math.random(-50,20) - else - x = love.math.random(m.center.x-m.width/2,m.center.x+m.width/2) + local num = love.math.random(1, 3) + local style = "default" + if num > 1 then + style = style .. tostring(num) end - y = love.math.random(m.center.y-m.height/2, m.center.y+m.height/2) - t = love.math.random(1,3) - v = love.math.random(8,18) + return style end -]] function CloudGenerator:run (count, inside) local count = count or 1 @@ -72,7 +74,11 @@ end function CloudGenerator:update (dt) local count = self.world:getCloudsCount() - self:run() + self.timer = self.timer - dt + if self.timer < 0 then + self.timer = self.timer + self.interval + self:run() + end end return CloudGenerator -- cgit v1.1 From 53763cd13314152117a7e29712de81e2bfafee18 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 6 Sep 2017 02:30:24 +0200 Subject: Spawn some Clouds on start --- not/World.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index f2dc391..62988ae 100644 --- a/not/World.lua +++ b/not/World.lua @@ -67,10 +67,10 @@ function World:buildMap () end end --- TODO: Spawn some clouds after cloudGenerator has been initialized. function World:initClouds () if self.map.clouds then self.cloudGenerator = CloudGenerator(self) + self.cloudGenerator:run(6, true) end end -- cgit v1.1 From 234adbc1468d75f829c8d8bfd0345fe0c16a6360 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 6 Sep 2017 02:57:06 +0200 Subject: Some additional info dislayed in debug mode --- not/World.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 62988ae..ebc7d9f 100644 --- a/not/World.lua +++ b/not/World.lua @@ -205,6 +205,9 @@ function World:update (dt) table.remove(self.Rays, key) end end + + -- Some additional debug info. + dbg_msg = string.format("%sMap: %s\nClouds: %d\n", dbg_msg, self.map.filepath, self:getCloudsCount()) end -- Draw -- cgit v1.1 From 0d838536c5fa0f832de796a094a150bd4af73adb Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 6 Sep 2017 02:59:08 +0200 Subject: Tag color fixed --- not/Hero.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'not') diff --git a/not/Hero.lua b/not/Hero.lua index 71cfb5b..93f1614 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -174,6 +174,7 @@ end function Hero:drawTag (offset_x, offset_y, scale) local x,y = self:getPosition() love.graphics.setFont(Font) + love.graphics.setColor(255, 255, 255) love.graphics.printf(string.format("Player %d", math.abs(self.group)), (math.floor(x)+offset_x)*scale, (math.floor(y)+offset_y-26)*scale,100,'center',0,scale,scale,50,0) end -- cgit v1.1 From 37da34f0dbc6f6fe58629e52a7126caed4f10434 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 7 Sep 2017 04:45:33 +0200 Subject: Renamed filepath to filename --- not/World.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index ebc7d9f..0d65d7e 100644 --- a/not/World.lua +++ b/not/World.lua @@ -336,8 +336,9 @@ end -- Controller callbacks function World:controlpressed (set, action, key) if key == "f6" and debug then - local map = love.filesystem.load(self.map.filepath)() - map.filepath = self.map.filepath + local filename = self.map.filename + local map = love.filesystem.load(filename)() + map.filename = filename local nauts = {} for _,naut in pairs(self:getNautsAll()) do table.insert(nauts, {naut.name, naut:getControllerSet()}) -- cgit v1.1 From 41a20f87015d1cc3eaa33e936c9dc1fac19246a9 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 7 Sep 2017 04:46:37 +0200 Subject: Here too --- not/World.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 0d65d7e..782c32f 100644 --- a/not/World.lua +++ b/not/World.lua @@ -207,7 +207,7 @@ function World:update (dt) end -- Some additional debug info. - dbg_msg = string.format("%sMap: %s\nClouds: %d\n", dbg_msg, self.map.filepath, self:getCloudsCount()) + dbg_msg = string.format("%sMap: %s\nClouds: %d\n", dbg_msg, self.map.filename, self:getCloudsCount()) end -- Draw -- cgit v1.1 From 58e6962593cadd4cfc1dd4028ce3b272814fe3f3 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 7 Sep 2017 05:15:35 +0200 Subject: Initial layering for drawing --- not/Ray.lua | 4 +- not/World.lua | 116 ++++++++++++++++++++++++++++++---------------------------- 2 files changed, 63 insertions(+), 57 deletions(-) (limited to 'not') diff --git a/not/Ray.lua b/not/Ray.lua index 3c80440..536ed05 100644 --- a/not/Ray.lua +++ b/not/Ray.lua @@ -26,7 +26,9 @@ function Ray:update (dt) return false end +-- TODO: Whole Ray is dated but `draw` require a lot attention due to layering in World. See `World@new`. function Ray:draw (offset_x, offset_y, scale) + local canvas = love.graphics.getCanvas() love.graphics.setCanvas(self.canvas) love.graphics.clear() love.graphics.setColor(255, 247, 228, 247) @@ -40,7 +42,7 @@ function Ray:draw (offset_x, offset_y, scale) 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.setCanvas(canvas) love.graphics.setLineWidth(1) love.graphics.setColor(255,255,255,255) -- draw on screen diff --git a/not/World.lua b/not/World.lua index 782c32f..5f3ece2 100644 --- a/not/World.lua +++ b/not/World.lua @@ -8,6 +8,7 @@ require "not.Player" require "not.Effect" require "not.Decoration" require "not.Ray" +require "not.Cloud" require "not.CloudGenerator" --- ZA WARUDO! @@ -26,6 +27,18 @@ function World:new (map, nauts) self.Decorations = {} self.Rays = {} + -- TODO: Clean layering. This is prototype. Seriously don't use it in production. + self.entities = {} + local width, height = love.graphics.getDimensions() + self.layers = { + love.graphics.newCanvas(width, height), -- back + love.graphics.newCanvas(width, height), -- cloud + love.graphics.newCanvas(width, height), -- deco + love.graphics.newCanvas(width, height), -- nauts + love.graphics.newCanvas(width, height), -- plats + love.graphics.newCanvas(width, height), -- front + } + self.map = map self:buildMap() self:initClouds() @@ -63,6 +76,7 @@ function World:buildMap () local image = love.graphics.newImage(op.background) local bg = self:createDecoration(0, 0, op.background) -- TODO: Decoration does not allow Image instead of filePath! bg.ratio = op.ratio + bg.layer = 1 end end end @@ -91,33 +105,45 @@ end -- TODO: Standardize `create*` methods with corresponding constructors. Pay attention to both params' order and names. function World:createPlatform (x, y, polygon, sprite, animations) - table.insert(self.Platforms, Platform(animations, polygon, x, y, self, sprite)) + local p = Platform(animations, polygon, x, y, self, sprite) + table.insert(self.Platforms, p) + table.insert(self.entities, p) + return p end function World:createNaut (x, y, name) local naut = Player(name, x, y, self) table.insert(self.Nauts, naut) + table.insert(self.entities, naut) return naut end function World:createDecoration (x, y, sprite) local deco = Decoration(x, y, self, sprite) table.insert(self.Decorations, deco) + table.insert(self.entities, deco) return deco end function World:createEffect (name, x, y) - table.insert(self.Effects, Effect(name, x, y, self)) + local e = Effect(name, x, y, self) + table.insert(self.Effects, e) + table.insert(self.entities, e) + return e end function World:createRay (naut) - table.insert(self.Rays, Ray(naut, self)) + local r = Ray(naut, self) + table.insert(self.Rays, r) + table.insert(self.entities, r) + return r end -- TODO: Sprites' in general don't take actual Image in constructor. That is not only case of Decoration. -- TODO: Once entities are stored inside single table create single `insertEntity` method for World. function World:insertCloud (cloud) table.insert(self.Clouds, cloud) + table.insert(self.entities, cloud) return cloud end @@ -181,28 +207,9 @@ function World:update (dt) self.cloudGenerator:update(dt) end - 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 - for key,effect in pairs(self.Effects) do - if effect:update(dt) then - table.remove(self.Effects, key) - end - end - for key,cloud in pairs(self.Clouds) do - if cloud:update(dt) then - table.remove(self.Clouds, key) - end - end - for key,ray in pairs(self.Rays) do - if ray:update(dt) then - table.remove(self.Rays, key) + for key,entity in pairs(self.entities) do + if entity:update(dt) then + table.remove(self.entities, key) end end @@ -210,45 +217,43 @@ function World:update (dt) dbg_msg = string.format("%sMap: %s\nClouds: %d\n", dbg_msg, self.map.filename, self:getCloudsCount()) end --- Draw function World:draw () - -- Camera stuff local offset_x, offset_y = self.camera:getOffsets() local scale = getScale() local scaler = getRealScale() - -- Draw decorations - for _,decoration in pairs(self.Decorations) do - decoration:draw(offset_x, offset_y, scale) - end - - -- Draw clouds - -- TODO: hotfix Clouds are drawn in front of decoration to make them in front of background. - for _,cloud in pairs(self.Clouds) do - cloud: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) + -- TODO: Prototype of layering. See `World@new`. + for _,entity in pairs(self.entities) do + if entity:is(Decoration) then + if entity.layer == 1 then + love.graphics.setCanvas(self.layers[1]) + else + love.graphics.setCanvas(self.layers[3]) + end + end + if entity:is(Cloud) then + love.graphics.setCanvas(self.layers[2]) + end + if entity:is(Player) then + love.graphics.setCanvas(self.layers[4]) + end + if entity:is(Platform) or entity:is(Effect) then + love.graphics.setCanvas(self.layers[5]) + end + if entity:is(Ray) then + love.graphics.setCanvas(self.layers[6]) + end + entity:draw(offset_x, offset_y, scale, debug) end - -- Draw rays - for _,ray in pairs(self.Rays) do - ray:draw(offset_x, offset_y, scale) + love.graphics.setCanvas() + for _,layer in ipairs(self.layers) do + love.graphics.draw(layer) + love.graphics.setCanvas(layer) + love.graphics.clear() + love.graphics.setCanvas() end - -- draw center if debug then local c = self.camera local w, h = love.graphics.getWidth(), love.graphics.getHeight() @@ -279,7 +284,6 @@ function World:draw () naut:drawTag(offset_x, offset_y, scale) 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 -- cgit v1.1 From b4254d4281cae95d72c5c8ae12119494d97f1802 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 7 Sep 2017 05:25:01 +0200 Subject: Removed tables for specific objects and replaced references with proper method calls --- not/Camera.lua | 2 +- not/Hero.lua | 2 +- not/World.lua | 66 ++++++++++++++++++++++++++++------------------------------ 3 files changed, 34 insertions(+), 36 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index 183a323..6e07372 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -109,7 +109,7 @@ end 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 + for k,naut in pairs(self.world:getNautsAll()) 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 diff --git a/not/Hero.lua b/not/Hero.lua index 93f1614..15cc667 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -27,7 +27,7 @@ function Hero:new (name, x, y, world) Hero.load() Hero.__super.new(self, x, y, world, imagePath) -- Physics - self.group = -1-#world.Nauts + self.group = -1-#world:getNautsAll() self:setBodyType("dynamic") self:setBodyFixedRotation(true) self:newFixture() diff --git a/not/World.lua b/not/World.lua index 5f3ece2..45a5031 100644 --- a/not/World.lua +++ b/not/World.lua @@ -18,14 +18,7 @@ function World:new (map, nauts) self.world = love.physics.newWorld(0, 9.81*64, true) self.world:setCallbacks(self.beginContact, self.endContact) - -- TODO: Move all entities into single table. self.lastNaut = false - self.Nauts = {} - self.Platforms = {} - self.Clouds = {} - self.Effects = {} - self.Decorations = {} - self.Rays = {} -- TODO: Clean layering. This is prototype. Seriously don't use it in production. self.entities = {} @@ -52,11 +45,8 @@ end -- The end of the world function World:delete () - for _,platform in pairs(self.Platforms) do - platform:delete() - end - for _,naut in pairs(self.Nauts) do - naut:delete() + for _,entity in pairs(self.entities) do + entity:delete() end self.world:destroy() end @@ -106,35 +96,30 @@ end -- TODO: Standardize `create*` methods with corresponding constructors. Pay attention to both params' order and names. function World:createPlatform (x, y, polygon, sprite, animations) local p = Platform(animations, polygon, x, y, self, sprite) - table.insert(self.Platforms, p) table.insert(self.entities, p) return p end function World:createNaut (x, y, name) local naut = Player(name, x, y, self) - table.insert(self.Nauts, naut) table.insert(self.entities, naut) return naut end function World:createDecoration (x, y, sprite) local deco = Decoration(x, y, self, sprite) - table.insert(self.Decorations, deco) table.insert(self.entities, deco) return deco end function World:createEffect (name, x, y) local e = Effect(name, x, y, self) - table.insert(self.Effects, e) table.insert(self.entities, e) return e end function World:createRay (naut) local r = Ray(naut, self) - table.insert(self.Rays, r) table.insert(self.entities, r) return r end @@ -142,40 +127,53 @@ end -- TODO: Sprites' in general don't take actual Image in constructor. That is not only case of Decoration. -- TODO: Once entities are stored inside single table create single `insertEntity` method for World. function World:insertCloud (cloud) - table.insert(self.Clouds, cloud) table.insert(self.entities, cloud) return cloud end function World:getCloudsCount () - return #self.Clouds + local count = 0 + for i,entity in ipairs(self.entities) do + if entity:is(Cloud) then + count = count + 1 + end + end + return count +end + +function World:getNautsAll () + local nauts = {} + for i,entity in ipairs(self.entities) do + if entity:is(require("not.Hero")) then + table.insert(nauts, entity) + end + end + return nauts 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) + for i,entity in ipairs(self.entities) do + if entity:is(require("not.Hero")) then + if entity.lives > -1 then + table.insert(nauts, entity) + end end end return nauts end --- are alive + function World:getNautsAlive () local nauts = {} - for _,naut in self.Nauts do - if naut.isAlive then - table.insert(nauts, naut) + for i,entity in ipairs(self.entities) do + if entity:is(require("not.Hero")) then + if entity.isAlive then + table.insert(nauts, entity) + end end end return nauts end --- all of them -function World:getNautsAll () - return self.Nauts -end -- get Map name function World:getMapName () @@ -280,11 +278,11 @@ function World:draw () love.graphics.line(x1,y1,x2,y2) end - for _,naut in pairs(self.Nauts) do + for _,naut in pairs(self:getNautsAlive()) do naut:drawTag(offset_x, offset_y, scale) end - for _,naut in pairs(self.Nauts) do + for _,naut in pairs(self:getNautsAll()) 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 -- cgit v1.1 From cff3a516083df2e43f6936812baba56a622d804a Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 7 Sep 2017 05:32:55 +0200 Subject: Graphics debug stats, coloring for layers to fix bleedin from debug --- not/World.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 45a5031..e1f2d59 100644 --- a/not/World.lua +++ b/not/World.lua @@ -212,7 +212,8 @@ function World:update (dt) end -- Some additional debug info. - dbg_msg = string.format("%sMap: %s\nClouds: %d\n", dbg_msg, self.map.filename, self:getCloudsCount()) + local stats = love.graphics.getStats() + dbg_msg = string.format("%sMap: %s\nClouds: %d\nLoaded: %d\nMB: %.2f", dbg_msg, self.map.filename, self:getCloudsCount(), stats.images, stats.texturememory / 1024 / 1024) end function World:draw () @@ -246,6 +247,7 @@ function World:draw () love.graphics.setCanvas() for _,layer in ipairs(self.layers) do + love.graphics.setColor(255, 255, 255, 255) love.graphics.draw(layer) love.graphics.setCanvas(layer) love.graphics.clear() -- cgit v1.1 From 5ef20afaf6a9aca1999faf8904594d94fcfaaa66 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 8 Sep 2017 15:59:39 +0200 Subject: Created Layer class --- not/Layer.lua | 27 +++++++++++++++++++++++++++ not/World.lua | 32 +++++++++++++++----------------- 2 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 not/Layer.lua (limited to 'not') diff --git a/not/Layer.lua b/not/Layer.lua new file mode 100644 index 0000000..db16175 --- /dev/null +++ b/not/Layer.lua @@ -0,0 +1,27 @@ +--- A little bit more than just a Canvas. +Layer = require "not.Object":extends() + +function Layer:new (width, height) + self.canvas = love.graphics.newCanvas(width, height) +end + +--- Sets this layer as current canvas for drawing with love.graphics functions. +-- @return old canvas used by love +function Layer:setAsCanvas () + local c = love.graphics.getCanvas() + love.graphics.setCanvas(self.canvas) + return c +end + +function Layer:clear () + local c = self:setAsCanvas() + love.graphics.clear() + love.graphics.setCanvas(c) +end + +function Layer:draw () + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(self.canvas) +end + +return Layer diff --git a/not/World.lua b/not/World.lua index e1f2d59..e8b847a 100644 --- a/not/World.lua +++ b/not/World.lua @@ -10,6 +10,7 @@ require "not.Decoration" require "not.Ray" require "not.Cloud" require "not.CloudGenerator" +require "not.Layer" --- ZA WARUDO! -- TODO: Missing documentation on most of World's methods. @@ -24,12 +25,12 @@ function World:new (map, nauts) self.entities = {} local width, height = love.graphics.getDimensions() self.layers = { - love.graphics.newCanvas(width, height), -- back - love.graphics.newCanvas(width, height), -- cloud - love.graphics.newCanvas(width, height), -- deco - love.graphics.newCanvas(width, height), -- nauts - love.graphics.newCanvas(width, height), -- plats - love.graphics.newCanvas(width, height), -- front + Layer(width, height), -- back + Layer(width, height), -- cloud + Layer(width, height), -- deco + Layer(width, height), -- nauts + Layer(width, height), -- plats + Layer(width, height), -- front } self.map = map @@ -225,33 +226,30 @@ function World:draw () for _,entity in pairs(self.entities) do if entity:is(Decoration) then if entity.layer == 1 then - love.graphics.setCanvas(self.layers[1]) + self.layers[1]:setAsCanvas() else - love.graphics.setCanvas(self.layers[3]) + self.layers[3]:setAsCanvas() end end if entity:is(Cloud) then - love.graphics.setCanvas(self.layers[2]) + self.layers[2]:setAsCanvas() end if entity:is(Player) then - love.graphics.setCanvas(self.layers[4]) + self.layers[4]:setAsCanvas() end if entity:is(Platform) or entity:is(Effect) then - love.graphics.setCanvas(self.layers[5]) + self.layers[5]:setAsCanvas() end if entity:is(Ray) then - love.graphics.setCanvas(self.layers[6]) + self.layers[6]:setAsCanvas() end entity:draw(offset_x, offset_y, scale, debug) end love.graphics.setCanvas() for _,layer in ipairs(self.layers) do - love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(layer) - love.graphics.setCanvas(layer) - love.graphics.clear() - love.graphics.setCanvas() + layer:draw() + layer:clear() end if debug then -- cgit v1.1 From 4faecfbd6495c46c2d93ce314252feeb7879e568 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 8 Sep 2017 17:33:28 +0200 Subject: Some additional garbage collecting --- not/Layer.lua | 4 ++++ not/SceneManager.lua | 8 ++++++-- not/World.lua | 4 ++++ 3 files changed, 14 insertions(+), 2 deletions(-) (limited to 'not') diff --git a/not/Layer.lua b/not/Layer.lua index db16175..63c38ac 100644 --- a/not/Layer.lua +++ b/not/Layer.lua @@ -5,6 +5,10 @@ function Layer:new (width, height) self.canvas = love.graphics.newCanvas(width, height) end +function Layer:delete () + self.canvas = nil +end + --- Sets this layer as current canvas for drawing with love.graphics functions. -- @return old canvas used by love function Layer:setAsCanvas () diff --git a/not/SceneManager.lua b/not/SceneManager.lua index c076448..4f9edfd 100644 --- a/not/SceneManager.lua +++ b/not/SceneManager.lua @@ -9,7 +9,10 @@ end -- This function should be removed when multiple scenes will be handled properly by SceneManager and other things. function SceneManager:changeScene (scene) - table.remove(self.scenes, #self.scenes) + local removed = table.remove(self.scenes, #self.scenes) + if removed then + removed:delete() + end return self:addScene(scene) end @@ -20,7 +23,8 @@ end -- Not nice, not nice. function SceneManager:removeTopScene () - table.remove(self.scenes, #self.scenes) + local scene = table.remove(self.scenes, #self.scenes) + scene:delete() end function SceneManager:getAllScenes () diff --git a/not/World.lua b/not/World.lua index e8b847a..2774c92 100644 --- a/not/World.lua +++ b/not/World.lua @@ -49,7 +49,11 @@ function World:delete () for _,entity in pairs(self.entities) do entity:delete() end + for _,layer in pairs(self.layers) do + layer:delete() + end self.world:destroy() + collectgarbage() end --- Builds map using one of tables frin config files located in `config/maps/` directory. -- cgit v1.1 From dc2c3fe3cee67a8473e0d2e952a3ef9f6e0df2d7 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 8 Sep 2017 19:48:17 +0200 Subject: Added renderTo method; clear now uses it --- not/Layer.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'not') diff --git a/not/Layer.lua b/not/Layer.lua index 63c38ac..126b402 100644 --- a/not/Layer.lua +++ b/not/Layer.lua @@ -17,12 +17,16 @@ function Layer:setAsCanvas () return c end -function Layer:clear () +function Layer:renderTo (func, ...) local c = self:setAsCanvas() - love.graphics.clear() + func(...) love.graphics.setCanvas(c) end +function Layer:clear () + self:renderTo(love.graphics.clear) +end + function Layer:draw () love.graphics.setColor(255, 255, 255, 255) love.graphics.draw(self.canvas) -- cgit v1.1 From 15f6efaa556e32dafb72e22545fb7355002c1de3 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 8 Sep 2017 20:21:22 +0200 Subject: Wrapped Box2D callbacks --- not/World.lua | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 2774c92..7ed5707 100644 --- a/not/World.lua +++ b/not/World.lua @@ -17,7 +17,7 @@ require "not.Layer" function World:new (map, nauts) love.physics.setMeter(64) self.world = love.physics.newWorld(0, 9.81*64, true) - self.world:setCallbacks(self.beginContact, self.endContact) + self.world:setCallbacks(self:getContactCallbacks()) self.lastNaut = false @@ -296,13 +296,26 @@ function World:draw () end end --- Box2D callbacks --- TODO: Review current state of Box2D callbacks. +--- Wraps World's beginContact and endContact to functions usable as callbacks for Box2D's world. +-- Only difference in new functions is absence of self as first argument. +-- @return wrapper for beginContact +-- @return wrapper for endContact +function World:getContactCallbacks () + local b = function (a, b, coll) + self:beginContact(a, b, coll) + end + local e = function (a, b, coll) + self:endContact(a, b, coll) + end + return b, e +end + +-- TODO: Review current state of Box2D callbacks (again). -- TODO: Stop using magical numbers in Box2D callbacks. -- [1] -> Platform -- [2] -> Hero -- [3] -> Punch sensor -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 @@ -324,7 +337,7 @@ function World.beginContact (a, b, coll) local x2,y2 = a:getBody():getUserData():getPosition() local x = (x2 - x1) / 2 + x1 - 12 local y = (y2 - y1) / 2 + y1 - 15 - a:getBody():getUserData().world:createEffect("clash", x, y) + self:createEffect("clash", x, y) end end if b:getCategory() == 3 then @@ -333,7 +346,7 @@ function World.beginContact (a, b, coll) end end end -function World.endContact (a, b, coll) +function World:endContact (a, b, coll) if a:getCategory() == 1 then b:getUserData().inAir = true end -- cgit v1.1 From ca8dbe135034f7a72b6b40f6dfd7b772bd51cc39 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 9 Sep 2017 06:17:37 +0200 Subject: Started Camera rework --- not/Camera.lua | 39 +++++++++++++++------------------------ not/World.lua | 4 ++-- 2 files changed, 17 insertions(+), 26 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index 6e07372..79ebd09 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -1,29 +1,20 @@ ---- `Camera` --- Used in drawing. -Camera = { - x = 0, - y = 0, - dest_x = 0, - dest_y = 0, - shake = 0, - timer = 0, - delay = 0, - origin_x = 0, - origin_y = 0, - shake_x = 0, - shake_y = 0, - world = --[[not.World]]nil, -} +--- Used in drawing other stuff in places. +Camera = require "not.Object":extends() --- 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 + self.world = world + self.x = 0 + self.y = 0 + self.dest_y = 0 + self.dest_x = 0 + self.timer = 0 + self.delay = 0 + self.origin_x = 0 + self.origin_y = 0 + self.shake_x = 0 + self.shake_y = 0 + self:setPosition(self:follow()) + self:setDestination(self:follow()) end -- Drawing offsets diff --git a/not/World.lua b/not/World.lua index 7ed5707..c086bd5 100644 --- a/not/World.lua +++ b/not/World.lua @@ -38,7 +38,7 @@ function World:new (map, nauts) self:initClouds() self:spawnNauts(nauts) - self.camera = Camera:new(self) + self.camera = Camera(self) musicPlayer:setTrack(self.map.theme) musicPlayer:play() @@ -212,7 +212,7 @@ function World:update (dt) for key,entity in pairs(self.entities) do if entity:update(dt) then - table.remove(self.entities, key) + table.remove(self.entities, key):delete() end end -- cgit v1.1 From b74e8f712a11cf57462c51873b1cf505d90623e3 Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 9 Sep 2017 06:24:59 +0200 Subject: Shortcut to setTrack in MusicPlayer:play --- not/MusicPlayer.lua | 15 ++++++++------- not/World.lua | 6 ++---- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'not') diff --git a/not/MusicPlayer.lua b/not/MusicPlayer.lua index 4634ed9..17beda4 100644 --- a/not/MusicPlayer.lua +++ b/not/MusicPlayer.lua @@ -1,8 +1,5 @@ -require "not.Object" - ---- `MusicPlayer` --- Simple music player object that plays and loops selected track. -MusicPlayer = Object:extends() +--- Simple music player object that stores, playes and loops tracks.. +MusicPlayer = require "not.Object":extends() function MusicPlayer:new (trackName) self.tracks = {} @@ -13,8 +10,9 @@ function MusicPlayer:new (trackName) end function MusicPlayer:delete () - self.tracks = nil self:stop() + self.tracks = nil + self.source = nil end function MusicPlayer:setTrack (trackName) @@ -40,7 +38,10 @@ function MusicPlayer:getCurrentTrack () end end -function MusicPlayer:play () +function MusicPlayer:play (trackName) + if trackName then + self:setTrack(trackName) + end self.source:play() end diff --git a/not/World.lua b/not/World.lua index c086bd5..ae00b48 100644 --- a/not/World.lua +++ b/not/World.lua @@ -1,5 +1,4 @@ ---- `World` --- Used to manage physical world and everything inside it: clouds, platforms, nauts, background etc. +--- 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 = require "not.Scene":extends() @@ -40,8 +39,7 @@ function World:new (map, nauts) self.camera = Camera(self) - musicPlayer:setTrack(self.map.theme) - musicPlayer:play() + musicPlayer:play(self.map.theme) end -- The end of the world -- cgit v1.1 From e6094cf0fddbd8b66426679d79020b06aacb600a Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 10 Sep 2017 19:47:12 +0200 Subject: Camera now uses love.graphics.translate --- not/Camera.lua | 18 +++++++++--------- not/World.lua | 19 ++++++++++++++----- 2 files changed, 23 insertions(+), 14 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index 79ebd09..cff5d0d 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -1,6 +1,7 @@ --- Used in drawing other stuff in places. Camera = require "not.Object":extends() +-- TODO: Camera would really make use of vec2s (other classes would use them too). function Camera:new (world) self.world = world self.x = 0 @@ -17,12 +18,15 @@ function Camera:new (world) self:setDestination(self:follow()) end --- Drawing offsets -function Camera:getOffsets () - return -self.x,-self.y +function Camera:translate () + love.graphics.push() + love.graphics.translate(-self.x*getScale(), -self.y*getScale()) +end + +function Camera:pop () + love.graphics.pop() end --- Position function Camera:setPosition (x, y) local x = x or 0 local y = y or 0 @@ -37,7 +41,6 @@ function Camera:getPositionScaled () return self.x*getScale(), self.y*getScale() end --- Destination function Camera:setDestination (x, y) local x = x or 0 local y = y or 0 @@ -48,14 +51,13 @@ 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)*getScale(), (y-self.y)*getScale() end -function Camera:translatePoints(...) +function Camera:translatePoints (...) local a = {...} local r = {} local x,y = self:getOffsets() @@ -96,7 +98,6 @@ function Camera:startShake () 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 @@ -114,7 +115,6 @@ function Camera:follow () return x,y end --- Update function Camera:update (dt) if self.timer > 0 then self.timer = self.timer - dt diff --git a/not/World.lua b/not/World.lua index ae00b48..6aee966 100644 --- a/not/World.lua +++ b/not/World.lua @@ -220,11 +220,15 @@ function World:update (dt) end function World:draw () - local offset_x, offset_y = self.camera:getOffsets() + -- TODO: Offests are here to keep compatibility. + local offset_x, offset_y = 0, 0 local scale = getScale() local scaler = getRealScale() -- TODO: Prototype of layering. See `World@new`. + -- TODO: Camera rewrite in progress. + self.camera:translate() + for _,entity in pairs(self.entities) do if entity:is(Decoration) then if entity.layer == 1 then @@ -248,12 +252,21 @@ function World:draw () entity:draw(offset_x, offset_y, scale, debug) end + self.camera:pop() love.graphics.setCanvas() + for _,layer in ipairs(self.layers) do layer:draw() layer:clear() end + -- TODO: Just move heroes' tags to front layer. + self.camera:translate() + for _,naut in pairs(self:getNautsAlive()) do + naut:drawTag(offset_x, offset_y, scale) + end + self.camera:pop() + if debug then local c = self.camera local w, h = love.graphics.getWidth(), love.graphics.getHeight() @@ -280,10 +293,6 @@ function World:draw () love.graphics.line(x1,y1,x2,y2) end - for _,naut in pairs(self:getNautsAlive()) do - naut:drawTag(offset_x, offset_y, scale) - end - for _,naut in pairs(self:getNautsAll()) do -- I have no idea where to place them T_T -- let's do: bottom-left, bottom-right, top-left, top-right -- cgit v1.1 From f251032110f8c7ba337a6ee4196083005c146fbc Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 11 Sep 2017 01:39:18 +0200 Subject: New shaking implementation --- not/Camera.lua | 90 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 38 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index cff5d0d..f2211fa 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -1,26 +1,36 @@ --- Used in drawing other stuff in places. Camera = require "not.Object":extends() +Camera.SHAKE_LENGTH = 0.8 +Camera.SHAKE_INTERVAL = 0.04 + -- TODO: Camera would really make use of vec2s (other classes would use them too). function Camera:new (world) self.world = world + self.x = 0 self.y = 0 self.dest_y = 0 self.dest_x = 0 - self.timer = 0 - self.delay = 0 self.origin_x = 0 self.origin_y = 0 - self.shake_x = 0 - self.shake_y = 0 + self:setPosition(self:follow()) self:setDestination(self:follow()) + + self.shakeTime = 0 + self.shakeInterval = 0 + self.shakeShift = { + theta = love.math.random() * 2, + radius = 0 + } end function Camera:translate () + local x, y = self:getPositionScaled() + local dx, dy = self:getShakeShift() love.graphics.push() - love.graphics.translate(-self.x*getScale(), -self.y*getScale()) + love.graphics.translate(-x - dx, -y - dy) end function Camera:pop () @@ -38,7 +48,8 @@ function Camera:getPosition () end function Camera:getPositionScaled () - return self.x*getScale(), self.y*getScale() + local scale = getScale() + return self.x * scale, self.y * scale end function Camera:setDestination (x, y) @@ -71,31 +82,43 @@ function Camera:translatePoints (...) 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 +function Camera:startShake () + self.shakeTime = Camera.SHAKE_LENGTH +end + +local +function limit (theta) + if theta > 2 then + return limitAngle(theta - 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 + if theta < 0 then + return limitAngle(theta + 2) end - local x = self.origin_x + self.shake_x - local y = self.origin_y + self.shake_y - self:setDestination(x, y) + return theta end -function Camera:startShake () - self.timer = 0.3 - self.origin_x, self.origin_y = self:getPosition() +-- TODO: Magic numbers present in Camera's shake. +function Camera:shake (dt) + if self.shakeTime > 0 then + self.shakeTime = self.shakeTime - dt + if self.shakeInterval < 0 then + self.shakeShift.theta = self.shakeShift.theta - 1.3 + love.math.random() * 0.6 + self.shakeShift.radius = 80 * self.shakeTime + self.shakeInterval = Camera.SHAKE_INTERVAL + else + self.shakeShift.radius = self.shakeShift.radius * 0.66 + self.shakeInterval = self.shakeInterval - dt + end + if self.shakeTime < 0 then + self.shakeShift.radius = 0 + end + end +end + +function Camera:getShakeShift () + local radius = self.shakeShift.radius + local theta = self.shakeShift.theta * math.pi + return radius * math.cos(theta), radius * math.sin(theta) end function Camera:follow () @@ -116,17 +139,8 @@ function Camera:follow () end 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 + self:shake(dt) + self:setDestination(self:follow()) local dx, dy = self:getDestination() dx = (dx - self.x) * 6 * dt dy = (dy - self.y) * 6 * dt -- cgit v1.1 From 6ed92013f8096057e4aad3f5a730e3586d9eb0e6 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 11 Sep 2017 02:17:07 +0200 Subject: Hotfix for Camera's translatePoints --- not/Camera.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index f2211fa..8008a0d 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -71,7 +71,7 @@ end function Camera:translatePoints (...) local a = {...} local r = {} - local x,y = self:getOffsets() + local x,y = 0,0 for k,v in pairs(a) do if k%2 == 1 then table.insert(r, (v + x) * getScale()) -- cgit v1.1 From 9e2ec1aa5abb84d3e46c34ed407934ac54fce331 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 11 Sep 2017 02:39:28 +0200 Subject: Some shake tweaking --- not/Camera.lua | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index 8008a0d..8e74a76 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -1,8 +1,8 @@ --- Used in drawing other stuff in places. Camera = require "not.Object":extends() -Camera.SHAKE_LENGTH = 0.8 -Camera.SHAKE_INTERVAL = 0.04 +Camera.SHAKE_LENGTH = 0.6 +Camera.SHAKE_INTERVAL = 0.03 -- TODO: Camera would really make use of vec2s (other classes would use them too). function Camera:new (world) @@ -28,7 +28,7 @@ end function Camera:translate () local x, y = self:getPositionScaled() - local dx, dy = self:getShakeShift() + local dx, dy = self:getShakeScaled() love.graphics.push() love.graphics.translate(-x - dx, -y - dy) end @@ -103,7 +103,7 @@ function Camera:shake (dt) self.shakeTime = self.shakeTime - dt if self.shakeInterval < 0 then self.shakeShift.theta = self.shakeShift.theta - 1.3 + love.math.random() * 0.6 - self.shakeShift.radius = 80 * self.shakeTime + self.shakeShift.radius = 70 * self.shakeTime self.shakeInterval = Camera.SHAKE_INTERVAL else self.shakeShift.radius = self.shakeShift.radius * 0.66 @@ -115,12 +115,18 @@ function Camera:shake (dt) end end -function Camera:getShakeShift () +function Camera:getShake () local radius = self.shakeShift.radius local theta = self.shakeShift.theta * math.pi return radius * math.cos(theta), radius * math.sin(theta) end +function Camera:getShakeScaled () + local x, y = self:getShake() + local scale = getScale() + return x * scale, y * scale +end + function Camera:follow () local map = self.world.map local sum_x,sum_y,i = map.center.x, map.center.y, 1 -- cgit v1.1 From 9ddacd0f6481661cdaeab8abf2000b45a296faee Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 11 Sep 2017 06:17:29 +0200 Subject: Camera methods have some funky names. New following implementation --- not/Camera.lua | 80 ++++++++++++++++++++++++++++------------------------------ not/World.lua | 8 +++++- 2 files changed, 46 insertions(+), 42 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index 8e74a76..76f36ed 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -5,19 +5,14 @@ Camera.SHAKE_LENGTH = 0.6 Camera.SHAKE_INTERVAL = 0.03 -- TODO: Camera would really make use of vec2s (other classes would use them too). -function Camera:new (world) +function Camera:new (x, y, world) self.world = world + self:setPosition(x, y) + self:resetSum() + self:initShake() +end - self.x = 0 - self.y = 0 - self.dest_y = 0 - self.dest_x = 0 - self.origin_x = 0 - self.origin_y = 0 - - self:setPosition(self:follow()) - self:setDestination(self:follow()) - +function Camera:initShake () self.shakeTime = 0 self.shakeInterval = 0 self.shakeShift = { @@ -30,7 +25,7 @@ function Camera:translate () local x, y = self:getPositionScaled() local dx, dy = self:getShakeScaled() love.graphics.push() - love.graphics.translate(-x - dx, -y - dy) + love.graphics.translate(160*getScale() - x - dx, 100*getScale() - y - dy) end function Camera:pop () @@ -52,16 +47,6 @@ function Camera:getPositionScaled () return self.x * scale, self.y * scale end -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 - function Camera:translatePosition (x, y) local x = x or 0 local y = y or 0 @@ -103,7 +88,7 @@ function Camera:shake (dt) self.shakeTime = self.shakeTime - dt if self.shakeInterval < 0 then self.shakeShift.theta = self.shakeShift.theta - 1.3 + love.math.random() * 0.6 - self.shakeShift.radius = 70 * self.shakeTime + self.shakeShift.radius = 50 * self.shakeTime self.shakeInterval = Camera.SHAKE_INTERVAL else self.shakeShift.radius = self.shakeShift.radius * 0.66 @@ -127,28 +112,41 @@ function Camera:getShakeScaled () return x * scale, y * scale end -function Camera:follow () +function Camera:resetSum () + self.sumX = 0 + self.sumY = 0 + self.sumI = 0 +end + +function Camera:sum (x, y) 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:getNautsAll()) 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 + if math.abs(x - map.center.x) < map.width/2 and + math.abs(y - map.center.y) < map.height/2 then + self.sumX = self.sumX + x + self.sumY = self.sumY + y + self.sumI = self.sumI + 1 + end +end + +function Camera:getSumPostion () + if self.sumI > 0 then + return self.sumX / self.sumI, self.sumY / self.sumI + end + return 0, 0 +end + +function Camera:step (dt) + local x, y = self:getSumPostion() + local dx, dy = (x - self.x), (y - self.y) + if math.abs(dx) > 0.4 or math.abs(dy) > 0.4 then + x = self.x + (x - self.x) * dt * 6 + y = self.y + (y - self.y) * dt * 6 end - local x = sum_x / i - love.graphics.getWidth()/getScale()/2 - local y = sum_y / i - love.graphics.getHeight()/getScale()/2 + 4*getScale() -- hotfix - return x,y + self:setPosition(x, y) end function Camera:update (dt) + self:step(dt) self:shake(dt) - self:setDestination(self:follow()) - 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) + self:resetSum() end diff --git a/not/World.lua b/not/World.lua index 6aee966..aeed245 100644 --- a/not/World.lua +++ b/not/World.lua @@ -37,7 +37,7 @@ function World:new (map, nauts) self:initClouds() self:spawnNauts(nauts) - self.camera = Camera(self) + self.camera = Camera(self.map.center.x, self.map.center.y, self) musicPlayer:play(self.map.theme) end @@ -203,6 +203,7 @@ end function World:update (dt) self.world:update(dt) self.camera:update(dt) + self.camera:sum(self.map.center.x, self.map.center.y) if self.cloudGenerator then self.cloudGenerator:update(dt) @@ -214,6 +215,11 @@ function World:update (dt) end end + -- TODO: Weird Camera following Heroes. + for _,hero in pairs(self:getNautsAll()) do + self.camera:sum(hero:getPosition()) + end + -- Some additional debug info. local stats = love.graphics.getStats() dbg_msg = string.format("%sMap: %s\nClouds: %d\nLoaded: %d\nMB: %.2f", dbg_msg, self.map.filename, self:getCloudsCount(), stats.images, stats.texturememory / 1024 / 1024) -- cgit v1.1 From 81ec1a6509b0f349c145dd1b4d40029d141cbd6e Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 11 Sep 2017 19:22:18 +0200 Subject: Debug drawing changed to use new Camera properly --- not/Camera.lua | 32 ++++++++++++++++++-------------- not/PhysicalBody.lua | 3 ++- not/World.lua | 36 +++++++++++++----------------------- 3 files changed, 33 insertions(+), 38 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index 76f36ed..025e9e5 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -21,6 +21,7 @@ function Camera:initShake () } end +-- TODO: Even more magic numbers present in Camera. Translate method. function Camera:translate () local x, y = self:getPositionScaled() local dx, dy = self:getShakeScaled() @@ -47,22 +48,25 @@ function Camera:getPositionScaled () return self.x * scale, self.y * scale end -function Camera:translatePosition (x, y) - local x = x or 0 - local y = y or 0 - return (x-self.x)*getScale(), (y-self.y)*getScale() +-- TODO: Magic numbers present in camera's boundaries. +function Camera:getBoundaries () + local x, y = self:getPosition() + return x - 160, y - 100, x + 160, y + 100 end -function Camera:translatePoints (...) - local a = {...} - local r = {} - local x,y = 0,0 - for k,v in pairs(a) do - if k%2 == 1 then - table.insert(r, (v + x) * getScale()) - else - table.insert(r, (v + y) * getScale()) - end +function Camera:getBoundariesScaled () + local x, y = self:getPositionScaled() + local width, height = love.graphics.getDimensions() + width = width / 2 + height = height / 2 + return x - width, y - height, x + width, y + height +end + +-- TODO: Camera@scalePoints is left because PhysicalBody still uses it as love.graphics.scale is not used yet. +function Camera:scalePoints (...) + local a, r, scale = {...}, {}, getScale() + for _,v in pairs(a) do + table.insert(r, v * scale) end return r end diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 804c706..c9b7300 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -77,7 +77,8 @@ function PhysicalBody:draw (offset_x, offset_y, scale, debug) if category == 3 then love.graphics.setColor(137, 0, 255, 40) end - love.graphics.polygon("fill", self.world.camera:translatePoints(self.body:getWorldPoints(fixture:getShape():getPoints()))) + local camera = self.world.camera + love.graphics.polygon("fill", camera:scalePoints(self.body:getWorldPoints(fixture:getShape():getPoints()))) end end end diff --git a/not/World.lua b/not/World.lua index aeed245..63d1182 100644 --- a/not/World.lua +++ b/not/World.lua @@ -147,7 +147,7 @@ end function World:getNautsAll () local nauts = {} for i,entity in ipairs(self.entities) do - if entity:is(require("not.Hero")) then + if entity:is(require("not.Hero")) and not entity.body:isDestroyed() then table.insert(nauts, entity) end end @@ -271,33 +271,23 @@ function World:draw () for _,naut in pairs(self:getNautsAlive()) do naut:drawTag(offset_x, offset_y, scale) end - self.camera:pop() - + 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) + local center = self.map.center + local ax, ay, bx, by = self.camera:getBoundariesScaled() + 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(130,130,130) + love.graphics.line(ax,center.y,bx,center.y) + love.graphics.line(center.x,ay,center.x,by) + 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) + love.graphics.line(ax,0,bx,0) + love.graphics.line(0,ay,0,by) end + self.camera:pop() for _,naut in pairs(self:getNautsAll()) do -- I have no idea where to place them T_T -- cgit v1.1 From 4490b5b5fcaddbf55fb229caeb93c879fe254292 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 11 Sep 2017 19:54:14 +0200 Subject: Layer displacement ratio added to new Camera and to World for tests --- not/Camera.lua | 8 +++++++- not/World.lua | 28 +++++++++++++++++----------- 2 files changed, 24 insertions(+), 12 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index 025e9e5..4f57327 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -22,9 +22,15 @@ function Camera:initShake () end -- TODO: Even more magic numbers present in Camera. Translate method. -function Camera:translate () +function Camera:translate (ratio) local x, y = self:getPositionScaled() local dx, dy = self:getShakeScaled() + if ratio then + dx = dx * ratio + dy = dy * ratio + x = x * ratio + y = y * ratio + end love.graphics.push() love.graphics.translate(160*getScale() - x - dx, 100*getScale() - y - dy) end diff --git a/not/World.lua b/not/World.lua index 63d1182..ca061c1 100644 --- a/not/World.lua +++ b/not/World.lua @@ -31,6 +31,7 @@ function World:new (map, nauts) Layer(width, height), -- plats Layer(width, height), -- front } + self.layers[1].ratio = 0 self.map = map self:buildMap() @@ -67,7 +68,9 @@ function World:buildMap () end if op.background then local image = love.graphics.newImage(op.background) - local bg = self:createDecoration(0, 0, op.background) -- TODO: Decoration does not allow Image instead of filePath! + local x = image:getWidth() / -2 + local y = image:getHeight() / -2 + local bg = self:createDecoration(x, y, op.background) -- TODO: Decoration does not allow Image instead of filePath! bg.ratio = op.ratio bg.layer = 1 end @@ -233,32 +236,35 @@ function World:draw () -- TODO: Prototype of layering. See `World@new`. -- TODO: Camera rewrite in progress. - self.camera:translate() - for _,entity in pairs(self.entities) do + local layer if entity:is(Decoration) then if entity.layer == 1 then - self.layers[1]:setAsCanvas() + layer = self.layers[1] else - self.layers[3]:setAsCanvas() + layer = self.layers[3] end end if entity:is(Cloud) then - self.layers[2]:setAsCanvas() + layer = self.layers[2] end if entity:is(Player) then - self.layers[4]:setAsCanvas() + layer = self.layers[4] end if entity:is(Platform) or entity:is(Effect) then - self.layers[5]:setAsCanvas() + layer = self.layers[5] end if entity:is(Ray) then - self.layers[6]:setAsCanvas() + layer = self.layers[6] + end + + if layer then + self.camera:translate(layer.ratio) + layer:renderTo(entity.draw, entity, 0, 0, scale, debug) + self.camera:pop() end - entity:draw(offset_x, offset_y, scale, debug) end - self.camera:pop() love.graphics.setCanvas() for _,layer in ipairs(self.layers) do -- cgit v1.1 From c2dbd963a243b237df48b409f855ef4099f710c9 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 11 Sep 2017 19:54:41 +0200 Subject: Removed obsolete wrapper for ratioed Decoration --- not/Decoration.lua | 9 --------- 1 file changed, 9 deletions(-) (limited to 'not') diff --git a/not/Decoration.lua b/not/Decoration.lua index 6068a61..97524f5 100644 --- a/not/Decoration.lua +++ b/not/Decoration.lua @@ -21,13 +21,4 @@ function Decoration:setPosition (x, y) self.x, self.y = x, y end --- TODO: Temporary wrapper for draw to keep background in place. -function Decoration:draw (offset_x, offset_y, scale) - if self.ratio ~= nil then - offset_x = offset_x * self.ratio - offset_y = offset_y * self.ratio - end - Decoration.__super.draw(self, offset_x, offset_y, scale) -end - return Decoration -- cgit v1.1 From 844a4a14e14ae427ba595f04b1a7d46372952669 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 11 Sep 2017 19:58:15 +0200 Subject: It seems I wasn't working in 16:10 --- not/Camera.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index 4f57327..1fa01d3 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -32,7 +32,7 @@ function Camera:translate (ratio) y = y * ratio end love.graphics.push() - love.graphics.translate(160*getScale() - x - dx, 100*getScale() - y - dy) + love.graphics.translate(160*getScale() - x - dx, 90*getScale() - y - dy) end function Camera:pop () @@ -57,7 +57,7 @@ end -- TODO: Magic numbers present in camera's boundaries. function Camera:getBoundaries () local x, y = self:getPosition() - return x - 160, y - 100, x + 160, y + 100 + return x - 160, y - 90, x + 160, y + 90 end function Camera:getBoundariesScaled () -- cgit v1.1 From bdfa62ab1df4df00b57913a3ce2ec1fc3f112c78 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 11 Sep 2017 21:01:43 +0200 Subject: Generalized methods for entities. Wrappers for frequently used ones --- not/World.lua | 71 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 28 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index ca061c1..6833d87 100644 --- a/not/World.lua +++ b/not/World.lua @@ -137,48 +137,63 @@ function World:insertCloud (cloud) return cloud end -function World:getCloudsCount () +--- Verbose wrapper for inserting entities into entities table. +-- @param entity entity to insert +function World:insertEntity (entity) + if entity then + table.insert(self.entities, entity) + return entity + end +end + +--- Searches entities for those which return true with filtering function. +-- @param filter function with entity as parameter +-- @return table containing results of search +function World:getEntities (filter) + local result = {} + for _,entity in pairs(self.entities) do + if filter(entity) then + table.insert(result, entity) + end + end + return result +end + +--- Counts entities returning true with filtering function. +-- @param filter function with entity as parameter +-- @return entity count +function World:countEntities (filter) local count = 0 - for i,entity in ipairs(self.entities) do - if entity:is(Cloud) then + for _,entity in pairs(self.entities) do + if filter(entity) then count = count + 1 end end return count end +function World:getCloudsCount () + return self:countEntities(function (entity) + return entity:is(Cloud) + end) +end + function World:getNautsAll () - local nauts = {} - for i,entity in ipairs(self.entities) do - if entity:is(require("not.Hero")) and not entity.body:isDestroyed() then - table.insert(nauts, entity) - end - end - return nauts + return self:getEntities(function (entity) + return entity:is(require("not.Hero")) and not entity.body:isDestroyed() + end) end function World:getNautsPlayable () - local nauts = {} - for i,entity in ipairs(self.entities) do - if entity:is(require("not.Hero")) then - if entity.lives > -1 then - table.insert(nauts, entity) - end - end - end - return nauts + return self:getEntities(function (entity) + return entity:is(require("not.Hero")) and entity.lives > -1 + end) end function World:getNautsAlive () - local nauts = {} - for i,entity in ipairs(self.entities) do - if entity:is(require("not.Hero")) then - if entity.isAlive then - table.insert(nauts, entity) - end - end - end - return nauts + return self:getEntities(function (entity) + return entity:is(require("not.Hero")) and entity.isAlive + end) end -- get Map name -- cgit v1.1 From 1632826dc0b2ad4e2e1f750e872a39a39d8c98d2 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 11 Sep 2017 21:15:06 +0200 Subject: Layers references in entities --- not/World.lua | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 6833d87..2cb6bb8 100644 --- a/not/World.lua +++ b/not/World.lua @@ -71,8 +71,7 @@ function World:buildMap () local x = image:getWidth() / -2 local y = image:getHeight() / -2 local bg = self:createDecoration(x, y, op.background) -- TODO: Decoration does not allow Image instead of filePath! - bg.ratio = op.ratio - bg.layer = 1 + bg.layer = self.layers[1] end end end @@ -103,30 +102,35 @@ end function World:createPlatform (x, y, polygon, sprite, animations) local p = Platform(animations, polygon, x, y, self, sprite) table.insert(self.entities, p) + p.layer = self.layers[5] return p end function World:createNaut (x, y, name) - local naut = Player(name, x, y, self) - table.insert(self.entities, naut) - return naut + local h = Player(name, x, y, self) + table.insert(self.entities, h) + h.layer = self.layers[4] + return h end function World:createDecoration (x, y, sprite) - local deco = Decoration(x, y, self, sprite) - table.insert(self.entities, deco) - return deco + local d = Decoration(x, y, self, sprite) + table.insert(self.entities, d) + d.layer = self.layers[3] + return d end function World:createEffect (name, x, y) local e = Effect(name, x, y, self) table.insert(self.entities, e) + e.layer = self.layers[5] return e end function World:createRay (naut) local r = Ray(naut, self) table.insert(self.entities, r) + r.layer = self.layers[6] return r end @@ -134,6 +138,7 @@ end -- TODO: Once entities are stored inside single table create single `insertEntity` method for World. function World:insertCloud (cloud) table.insert(self.entities, cloud) + cloud.layer = self.layers[2] return cloud end @@ -252,30 +257,9 @@ function World:draw () -- TODO: Prototype of layering. See `World@new`. -- TODO: Camera rewrite in progress. for _,entity in pairs(self.entities) do - local layer - if entity:is(Decoration) then - if entity.layer == 1 then - layer = self.layers[1] - else - layer = self.layers[3] - end - end - if entity:is(Cloud) then - layer = self.layers[2] - end - if entity:is(Player) then - layer = self.layers[4] - end - if entity:is(Platform) or entity:is(Effect) then - layer = self.layers[5] - end - if entity:is(Ray) then - layer = self.layers[6] - end - - if layer then - self.camera:translate(layer.ratio) - layer:renderTo(entity.draw, entity, 0, 0, scale, debug) + if entity.draw and entity.layer then + self.camera:translate(entity.layer.ratio) + entity.layer:renderTo(entity.draw, entity, 0, 0, scale, debug) self.camera:pop() end end -- cgit v1.1 From 9544249897d47fa40fa833b8e57fda1c54d8e26d Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 11 Sep 2017 21:20:10 +0200 Subject: World's draw small clean-up --- not/World.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 2cb6bb8..88b15cc 100644 --- a/not/World.lua +++ b/not/World.lua @@ -249,17 +249,14 @@ function World:update (dt) end function World:draw () - -- TODO: Offests are here to keep compatibility. - local offset_x, offset_y = 0, 0 local scale = getScale() - local scaler = getRealScale() -- TODO: Prototype of layering. See `World@new`. -- TODO: Camera rewrite in progress. for _,entity in pairs(self.entities) do if entity.draw and entity.layer then self.camera:translate(entity.layer.ratio) - entity.layer:renderTo(entity.draw, entity, 0, 0, scale, debug) + entity.layer:renderTo(entity.draw, entity, 0, 0, scale, debug) -- TODO: Offsets are passed as zeroes in World@draw for compatibility reasons. Remove them. self.camera:pop() end end @@ -274,7 +271,7 @@ function World:draw () -- TODO: Just move heroes' tags to front layer. self.camera:translate() for _,naut in pairs(self:getNautsAlive()) do - naut:drawTag(offset_x, offset_y, scale) + naut:drawTag(0, 0, scale) -- TODO: Offsets passed. See `World@draw`. end if debug then -- cgit v1.1 From 947fb92b43cbe191123c376bb62b5489c19b40be Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 11 Sep 2017 22:41:43 +0200 Subject: Tags moved to a Layer More layering and drawing clean-ups --- not/World.lua | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 88b15cc..b386598 100644 --- a/not/World.lua +++ b/not/World.lua @@ -23,14 +23,10 @@ function World:new (map, nauts) -- TODO: Clean layering. This is prototype. Seriously don't use it in production. self.entities = {} local width, height = love.graphics.getDimensions() - self.layers = { - Layer(width, height), -- back - Layer(width, height), -- cloud - Layer(width, height), -- deco - Layer(width, height), -- nauts - Layer(width, height), -- plats - Layer(width, height), -- front - } + self.layers = {} + for i=1,7 do + table.insert(self.layers, Layer(width, height)) + end self.layers[1].ratio = 0 self.map = map @@ -130,7 +126,7 @@ end function World:createRay (naut) local r = Ray(naut, self) table.insert(self.entities, r) - r.layer = self.layers[6] + r.layer = self.layers[7] return r end @@ -259,25 +255,23 @@ function World:draw () entity.layer:renderTo(entity.draw, entity, 0, 0, scale, debug) -- TODO: Offsets are passed as zeroes in World@draw for compatibility reasons. Remove them. self.camera:pop() end + if entity.drawTag then + self.camera:translate() + self.layers[6]:renderTo(entity.drawTag, entity, 0, 0, scale) -- TODO: Offsets passed. See `World@draw`. + self.camera:pop() + end end - love.graphics.setCanvas() - for _,layer in ipairs(self.layers) do layer:draw() layer:clear() end - - -- TODO: Just move heroes' tags to front layer. - self.camera:translate() - for _,naut in pairs(self:getNautsAlive()) do - naut:drawTag(0, 0, scale) -- TODO: Offsets passed. See `World@draw`. - end if debug then local center = self.map.center local ax, ay, bx, by = self.camera:getBoundariesScaled() - + + self.camera:translate() love.graphics.setLineWidth(1) love.graphics.setLineStyle("rough") @@ -288,9 +282,10 @@ function World:draw () love.graphics.setColor(200,200,200) love.graphics.line(ax,0,bx,0) love.graphics.line(0,ay,0,by) - end - self.camera:pop() + self.camera:pop() + end + for _,naut in pairs(self:getNautsAll()) do -- I have no idea where to place them T_T -- let's do: bottom-left, bottom-right, top-left, top-right -- cgit v1.1 From fac7abd6ebe81ee483b1a98aaf02caa1ac6a71df Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 01:43:26 +0200 Subject: Ray experimenting --- not/Ray.lua | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) (limited to 'not') diff --git a/not/Ray.lua b/not/Ray.lua index 536ed05..e820dfb 100644 --- a/not/Ray.lua +++ b/not/Ray.lua @@ -1,21 +1,10 @@ -require "not.Object" +--- That awesome effect that blinks when player dies! +Ray = require "not.Object":extends() ---- `Ray` --- That awesome effect that blinks when player dies! -Ray = Object:extends() - -Ray.naut =--[[not.Hero]]nil -Ray.world =--[[not.World]]nil -Ray.canvas =--[[love.graphics.newCanvas]]nil -Ray.delay = 0.3 - -function Ray:new (naut, world) - self.naut = naut +function Ray:new (source, world) + self.source = source self.world = world - -- Cavas, this is temporary, I believe. - local scale = getScale() - local w, h = love.graphics.getWidth(), love.graphics.getHeight() - self.canvas = love.graphics.newCanvas(w/scale, h/scale) + self.delay = 1.2 end function Ray:update (dt) @@ -26,27 +15,26 @@ function Ray:update (dt) return false end +-- TODO: Ray is work-in-progress. -- TODO: Whole Ray is dated but `draw` require a lot attention due to layering in World. See `World@new`. -function Ray:draw (offset_x, offset_y, scale) - local canvas = love.graphics.getCanvas() - love.graphics.setCanvas(self.canvas) - love.graphics.clear() +function Ray:draw () love.graphics.setColor(255, 247, 228, 247) love.graphics.setLineStyle("rough") love.graphics.setLineWidth(self.delay*160) - local x, y = self.naut:getPosition() + + local x, y = self.source:getPosition() local m = self.world.map local dy = m.height + if y > m.center.y then dy = -dy end + + local offset_x, offset_y = 0, 0 + + -- love.graphics.rectangle("fill", 0, 0, 200, 200) + 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(canvas) - 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 return Ray -- cgit v1.1 From 9b047199eb4b90c16101b70dcd2405e0d37f7283 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 01:44:57 +0200 Subject: Scaled Layers prototype --- not/World.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index b386598..118346b 100644 --- a/not/World.lua +++ b/not/World.lua @@ -24,10 +24,20 @@ function World:new (map, nauts) self.entities = {} local width, height = love.graphics.getDimensions() self.layers = {} - for i=1,7 do + for i=1,6 do table.insert(self.layers, Layer(width, height)) end self.layers[1].ratio = 0 + -- TODO: Scaled layers for Rays and future extensions. + do + local layer = Layer(320, 180) + layer.ratio = 0 + layer.draw = function (self) + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(self.canvas, 0, 0, 0, getScale(), getScale()) + end + table.insert(self.layers, layer) -- 7 + end self.map = map self:buildMap() -- cgit v1.1 From 44bc9aa6fa62c1b23d1e98de8729c72132a88abc Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 01:45:36 +0200 Subject: Proper Camera scaling introduction --- not/Camera.lua | 20 ++++++++++++++------ not/World.lua | 14 ++++++++++---- 2 files changed, 24 insertions(+), 10 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index 1fa01d3..c3aaae6 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -21,18 +21,26 @@ function Camera:initShake () } end +function Camera:push () + love.graphics.push() +end + +function Camera:scale (scale) + scale = scale or getScale() + love.graphics.scale(scale, scale) +end + -- TODO: Even more magic numbers present in Camera. Translate method. function Camera:translate (ratio) - local x, y = self:getPositionScaled() - local dx, dy = self:getShakeScaled() + local px, py = self:getPosition() + local dx, dy = self:getShake() if ratio then dx = dx * ratio dy = dy * ratio - x = x * ratio - y = y * ratio + px = px * ratio + py = py * ratio end - love.graphics.push() - love.graphics.translate(160*getScale() - x - dx, 90*getScale() - y - dy) + love.graphics.translate(160 - px - dx, 90 - py - dy) end function Camera:pop () diff --git a/not/World.lua b/not/World.lua index 118346b..b9e89d3 100644 --- a/not/World.lua +++ b/not/World.lua @@ -255,17 +255,23 @@ function World:update (dt) end function World:draw () - local scale = getScale() + local scale = 1 -- TODO: Prototype of layering. See `World@new`. -- TODO: Camera rewrite in progress. for _,entity in pairs(self.entities) do - if entity.draw and entity.layer then + if entity:is(Ray) then + entity.layer:renderTo(entity.draw, entity) + elseif entity.draw and entity.layer then + self.camera:push() + self.camera:scale() self.camera:translate(entity.layer.ratio) entity.layer:renderTo(entity.draw, entity, 0, 0, scale, debug) -- TODO: Offsets are passed as zeroes in World@draw for compatibility reasons. Remove them. self.camera:pop() end if entity.drawTag then + self.camera:push() + self.camera:scale() self.camera:translate() self.layers[6]:renderTo(entity.drawTag, entity, 0, 0, scale) -- TODO: Offsets passed. See `World@draw`. self.camera:pop() @@ -280,7 +286,8 @@ function World:draw () if debug then local center = self.map.center local ax, ay, bx, by = self.camera:getBoundariesScaled() - + + self.camera:push() self.camera:translate() love.graphics.setLineWidth(1) love.graphics.setLineStyle("rough") @@ -292,7 +299,6 @@ function World:draw () love.graphics.setColor(200,200,200) love.graphics.line(ax,0,bx,0) love.graphics.line(0,ay,0,by) - self.camera:pop() end -- cgit v1.1 From 20eb4aa0ecd165b727cbb5bb3f3a7aad6a49ebce Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 01:53:03 +0200 Subject: Draw debugging utilities using scaled camera --- not/PhysicalBody.lua | 2 +- not/World.lua | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'not') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index c9b7300..1b2e90d 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -78,7 +78,7 @@ function PhysicalBody:draw (offset_x, offset_y, scale, debug) love.graphics.setColor(137, 0, 255, 40) end local camera = self.world.camera - love.graphics.polygon("fill", camera:scalePoints(self.body:getWorldPoints(fixture:getShape():getPoints()))) + love.graphics.polygon("fill", self.body:getWorldPoints(fixture:getShape():getPoints())) end end end diff --git a/not/World.lua b/not/World.lua index b9e89d3..0a3ce30 100644 --- a/not/World.lua +++ b/not/World.lua @@ -285,12 +285,14 @@ function World:draw () if debug then local center = self.map.center - local ax, ay, bx, by = self.camera:getBoundariesScaled() + local ax, ay, bx, by = self.camera:getBoundaries() + + love.graphics.setLineWidth(1 / getScale()) + love.graphics.setLineStyle("rough") self.camera:push() + self.camera:scale() self.camera:translate() - love.graphics.setLineWidth(1) - love.graphics.setLineStyle("rough") love.graphics.setColor(130,130,130) love.graphics.line(ax,center.y,bx,center.y) -- cgit v1.1 From ae2e4b139f4c1e9e84ad1bca0b1e6044162aec01 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 01:58:22 +0200 Subject: Individual layer scaling and scaled down layers --- not/World.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 0a3ce30..37b6dbe 100644 --- a/not/World.lua +++ b/not/World.lua @@ -32,6 +32,7 @@ function World:new (map, nauts) do local layer = Layer(320, 180) layer.ratio = 0 + layer.scale = 1 layer.draw = function (self) love.graphics.setColor(255, 255, 255, 255) love.graphics.draw(self.canvas, 0, 0, 0, getScale(), getScale()) @@ -255,25 +256,21 @@ function World:update (dt) end function World:draw () - local scale = 1 - -- TODO: Prototype of layering. See `World@new`. -- TODO: Camera rewrite in progress. for _,entity in pairs(self.entities) do - if entity:is(Ray) then - entity.layer:renderTo(entity.draw, entity) - elseif entity.draw and entity.layer then + if entity.draw and entity.layer then self.camera:push() - self.camera:scale() + self.camera:scale(entity.layer.scale) self.camera:translate(entity.layer.ratio) - entity.layer:renderTo(entity.draw, entity, 0, 0, scale, debug) -- TODO: Offsets are passed as zeroes in World@draw for compatibility reasons. Remove them. + entity.layer:renderTo(entity.draw, entity, 0, 0, 1, debug) -- TODO: Offsets and Scale are passed as 0,0,1 in World@draw for compatibility reasons. Remove them. self.camera:pop() end if entity.drawTag then self.camera:push() self.camera:scale() self.camera:translate() - self.layers[6]:renderTo(entity.drawTag, entity, 0, 0, scale) -- TODO: Offsets passed. See `World@draw`. + self.layers[6]:renderTo(entity.drawTag, entity, 0, 0, 1) -- TODO: Offsets and Scale passed. See `World@draw`. self.camera:pop() end end @@ -304,6 +301,8 @@ function World:draw () self.camera:pop() end + -- TODO: Draw method beyond this point is a very, very dark place. + local scale = getScale() for _,naut in pairs(self:getNautsAll()) do -- I have no idea where to place them T_T -- let's do: bottom-left, bottom-right, top-left, top-right -- cgit v1.1 From 343ad9fcafc062dc7ddf181992863d6137628ceb Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 02:03:14 +0200 Subject: Removed obsolete scaled methods from Camera --- not/Camera.lua | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index c3aaae6..c5449d3 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -57,33 +57,12 @@ function Camera:getPosition () return self.x, self.y end -function Camera:getPositionScaled () - local scale = getScale() - return self.x * scale, self.y * scale -end - -- TODO: Magic numbers present in camera's boundaries. function Camera:getBoundaries () local x, y = self:getPosition() return x - 160, y - 90, x + 160, y + 90 end -function Camera:getBoundariesScaled () - local x, y = self:getPositionScaled() - local width, height = love.graphics.getDimensions() - width = width / 2 - height = height / 2 - return x - width, y - height, x + width, y + height -end - --- TODO: Camera@scalePoints is left because PhysicalBody still uses it as love.graphics.scale is not used yet. -function Camera:scalePoints (...) - local a, r, scale = {...}, {}, getScale() - for _,v in pairs(a) do - table.insert(r, v * scale) - end - return r -end function Camera:startShake () self.shakeTime = Camera.SHAKE_LENGTH @@ -124,12 +103,6 @@ function Camera:getShake () return radius * math.cos(theta), radius * math.sin(theta) end -function Camera:getShakeScaled () - local x, y = self:getShake() - local scale = getScale() - return x * scale, y * scale -end - function Camera:resetSum () self.sumX = 0 self.sumY = 0 -- cgit v1.1 From 2b2c4b06ec483e02bda201548ab89a6d0d116c19 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 03:23:57 +0200 Subject: Rays working almost properly with new Camera --- not/Ray.lua | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'not') diff --git a/not/Ray.lua b/not/Ray.lua index e820dfb..9591591 100644 --- a/not/Ray.lua +++ b/not/Ray.lua @@ -4,7 +4,7 @@ Ray = require "not.Object":extends() function Ray:new (source, world) self.source = source self.world = world - self.delay = 1.2 + self.delay = 0.3 end function Ray:update (dt) @@ -15,26 +15,40 @@ function Ray:update (dt) return false end --- TODO: Ray is work-in-progress. --- TODO: Whole Ray is dated but `draw` require a lot attention due to layering in World. See `World@new`. +-- TODO: For some reason ray needs these 50s on camera boundaries. +-- TODO: Ray draw should be cleaned-up and exploded into methods if possible. function Ray:draw () love.graphics.setColor(255, 247, 228, 247) love.graphics.setLineStyle("rough") love.graphics.setLineWidth(self.delay*160) - local x, y = self.source:getPosition() - local m = self.world.map - local dy = m.height + -- point b top-left + -- point c bottom-right + -- point d ray start + -- point e ray end - if y > m.center.y then - dy = -dy + local x, y = self.source:getPosition() + local bx, by, cx, cy = self.world.camera:getBoundaries() + local a = y / x + + bx = bx - 50 + by = by - 50 + cx = cx + 50 + cy = cy + 50 + + local dy, dx = bx * a, bx + if dy < by or dy > cy then + dy = by + dx = by / a end - local offset_x, offset_y = 0, 0 - - -- love.graphics.rectangle("fill", 0, 0, 200, 200) + local ey, ex = cx * a, cx + if ey < by or ey > cy then + ey = cy + ex = cy / a + end - love.graphics.line(-x+offset_x,-y+offset_y-dy*0.7,x+offset_x,y+dy*0.7+offset_y) + love.graphics.line(dx, dy, ex, ey) end return Ray -- cgit v1.1 From 9e29f6127fc27e58a5680a8aa6bea7336add4755 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 03:34:23 +0200 Subject: Added renderToWith to shorten using Camera with Layers --- not/Layer.lua | 10 ++++++++++ not/World.lua | 12 ++---------- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'not') diff --git a/not/Layer.lua b/not/Layer.lua index 126b402..6be61c4 100644 --- a/not/Layer.lua +++ b/not/Layer.lua @@ -3,6 +3,8 @@ Layer = require "not.Object":extends() function Layer:new (width, height) self.canvas = love.graphics.newCanvas(width, height) + self.scale = false + self.ratio = false end function Layer:delete () @@ -23,6 +25,14 @@ function Layer:renderTo (func, ...) love.graphics.setCanvas(c) end +function Layer:renderToWith (camera, func, ...) + camera:push() + camera:scale(self.scale) + camera:translate(self.ratio) + self:renderTo(func, ...) + camera:pop() +end + function Layer:clear () self:renderTo(love.graphics.clear) end diff --git a/not/World.lua b/not/World.lua index 37b6dbe..d7b69b2 100644 --- a/not/World.lua +++ b/not/World.lua @@ -260,18 +260,10 @@ function World:draw () -- TODO: Camera rewrite in progress. for _,entity in pairs(self.entities) do if entity.draw and entity.layer then - self.camera:push() - self.camera:scale(entity.layer.scale) - self.camera:translate(entity.layer.ratio) - entity.layer:renderTo(entity.draw, entity, 0, 0, 1, debug) -- TODO: Offsets and Scale are passed as 0,0,1 in World@draw for compatibility reasons. Remove them. - self.camera:pop() + entity.layer:renderToWith(self.camera, entity.draw, entity, 0, 0, 1, debug) -- TODO: Offsets and Scale are passed as 0,0,1 in World@draw for compatibility reasons. Remove them. end if entity.drawTag then - self.camera:push() - self.camera:scale() - self.camera:translate() - self.layers[6]:renderTo(entity.drawTag, entity, 0, 0, 1) -- TODO: Offsets and Scale passed. See `World@draw`. - self.camera:pop() + self.layers[6]:renderToWith(self.camera, entity.drawTag, entity, 0, 0, 1) -- TODO: Offsets and Scale passed. See `World@draw`. end end -- cgit v1.1 From 939a4dacec3bb1f7acff18f07eff74224ce8ad2c Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 05:48:21 +0200 Subject: Background now should accept animations --- not/World.lua | 3 +++ 1 file changed, 3 insertions(+) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index d7b69b2..d3f126f 100644 --- a/not/World.lua +++ b/not/World.lua @@ -78,6 +78,9 @@ function World:buildMap () local x = image:getWidth() / -2 local y = image:getHeight() / -2 local bg = self:createDecoration(x, y, op.background) -- TODO: Decoration does not allow Image instead of filePath! + if op.animations then + bg:setAnimationsList(op.animations) + end bg.layer = self.layers[1] end end -- cgit v1.1 From 55cf1f028e58c7d3a3b996c96adea484363abe54 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 17:40:53 +0200 Subject: Simplified Ray for now --- not/Ray.lua | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'not') diff --git a/not/Ray.lua b/not/Ray.lua index 9591591..4ae640a 100644 --- a/not/Ray.lua +++ b/not/Ray.lua @@ -15,40 +15,16 @@ function Ray:update (dt) return false end --- TODO: For some reason ray needs these 50s on camera boundaries. --- TODO: Ray draw should be cleaned-up and exploded into methods if possible. +-- TODO: Ray should use Camera boundaries just-in-case. +-- TODO: Ray uses magic numbers. function Ray:draw () love.graphics.setColor(255, 247, 228, 247) love.graphics.setLineStyle("rough") love.graphics.setLineWidth(self.delay*160) - -- point b top-left - -- point c bottom-right - -- point d ray start - -- point e ray end - local x, y = self.source:getPosition() - local bx, by, cx, cy = self.world.camera:getBoundaries() - local a = y / x - - bx = bx - 50 - by = by - 50 - cx = cx + 50 - cy = cy + 50 - - local dy, dx = bx * a, bx - if dy < by or dy > cy then - dy = by - dx = by / a - end - - local ey, ex = cx * a, cx - if ey < by or ey > cy then - ey = cy - ex = cy / a - end - love.graphics.line(dx, dy, ex, ey) + love.graphics.line(x, y, -x, -y) end return Ray -- cgit v1.1 From 6094b7eb9cbe915e02e02908b77549223f585014 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 19:14:11 +0200 Subject: Scaled Layers drawing (slow) --- not/Layer.lua | 6 +++++- not/World.lua | 4 ---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'not') diff --git a/not/Layer.lua b/not/Layer.lua index 6be61c4..0446599 100644 --- a/not/Layer.lua +++ b/not/Layer.lua @@ -38,8 +38,12 @@ function Layer:clear () end function Layer:draw () + local scale = 1 + if self.scale then + scale = getScale() / self.scale + end love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(self.canvas) + love.graphics.draw(self.canvas, 0, 0, 0, scale, scale) end return Layer diff --git a/not/World.lua b/not/World.lua index d3f126f..08b9710 100644 --- a/not/World.lua +++ b/not/World.lua @@ -33,10 +33,6 @@ function World:new (map, nauts) local layer = Layer(320, 180) layer.ratio = 0 layer.scale = 1 - layer.draw = function (self) - love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(self.canvas, 0, 0, 0, getScale(), getScale()) - end table.insert(self.layers, layer) -- 7 end -- cgit v1.1 From c201bef4950138bd8c475d9b8cd1c26e0615145a Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 12 Sep 2017 19:27:32 +0200 Subject: Removed obsolete offsets and scale from draw of Sprites and children --- not/Hero.lua | 10 +++++----- not/PhysicalBody.lua | 4 ++-- not/Sprite.lua | 14 ++++++-------- not/World.lua | 4 ++-- 4 files changed, 15 insertions(+), 17 deletions(-) (limited to 'not') diff --git a/not/Hero.lua b/not/Hero.lua index 15cc667..66bc511 100644 --- a/not/Hero.lua +++ b/not/Hero.lua @@ -165,17 +165,17 @@ function Hero:getOffset () return 12,15 end --- Draw of `Hero` -function Hero:draw (offset_x, offset_y, scale, debug) +function Hero:draw (debug) if not self.isAlive then return end - Hero.__super.draw(self, offset_x, offset_y, scale, debug) + Hero.__super.draw(self, debug) end -function Hero:drawTag (offset_x, offset_y, scale) +-- TODO: Hero@drawTag's printf is not readable. +function Hero:drawTag () local x,y = self:getPosition() love.graphics.setFont(Font) love.graphics.setColor(255, 255, 255) - love.graphics.printf(string.format("Player %d", math.abs(self.group)), (math.floor(x)+offset_x)*scale, (math.floor(y)+offset_y-26)*scale,100,'center',0,scale,scale,50,0) + love.graphics.printf(string.format("Player %d", math.abs(self.group)), math.floor(x), math.floor(y)-26 ,100,'center',0,1,1,50,0) end -- Draw HUD of `Hero` diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 1b2e90d..01a725b 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -63,8 +63,8 @@ function PhysicalBody:update (dt) end -- Draw of `PhysicalBody`. -function PhysicalBody:draw (offset_x, offset_y, scale, debug) - PhysicalBody.__super.draw(self, offset_x, offset_y, scale) +function PhysicalBody:draw (debug) + PhysicalBody.__super.draw(self, debug) if debug then for _,fixture in pairs(self.body:getFixtureList()) do local category = fixture:getCategory() diff --git a/not/Sprite.lua b/not/Sprite.lua index 3951e6e..a4346f6 100644 --- a/not/Sprite.lua +++ b/not/Sprite.lua @@ -84,24 +84,22 @@ 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: Sprite@draw requires a serious review! -- 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) - local offset_x = offset_x or 0 - local offset_y = offset_y or 0 - +function Sprite:draw (debug) 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) + local scaleX = self:getHorizontalMirror() + local scaleY = self:getVerticalMirror() -- 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 + local draw_y = approx(y) + local draw_x = math.floor(x) if i then love.graphics.setColor(255,255,255,255) diff --git a/not/World.lua b/not/World.lua index 08b9710..e75880f 100644 --- a/not/World.lua +++ b/not/World.lua @@ -259,10 +259,10 @@ function World:draw () -- TODO: Camera rewrite in progress. for _,entity in pairs(self.entities) do if entity.draw and entity.layer then - entity.layer:renderToWith(self.camera, entity.draw, entity, 0, 0, 1, debug) -- TODO: Offsets and Scale are passed as 0,0,1 in World@draw for compatibility reasons. Remove them. + entity.layer:renderToWith(self.camera, entity.draw, entity, debug) -- TODO: Offsets and Scale are passed as 0,0,1 in World@draw for compatibility reasons. Remove them. end if entity.drawTag then - self.layers[6]:renderToWith(self.camera, entity.drawTag, entity, 0, 0, 1) -- TODO: Offsets and Scale passed. See `World@draw`. + self.layers[6]:renderToWith(self.camera, entity.drawTag, entity, debug) -- TODO: Offsets and Scale passed. See `World@draw`. end end -- cgit v1.1 From 6b9942d1f9a4ac58d92d16a0db13a09c9488df71 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 01:42:33 +0200 Subject: Layers initialization moved to separate method --- not/World.lua | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index e75880f..529af2a 100644 --- a/not/World.lua +++ b/not/World.lua @@ -19,24 +19,10 @@ function World:new (map, nauts) self.world:setCallbacks(self:getContactCallbacks()) self.lastNaut = false - - -- TODO: Clean layering. This is prototype. Seriously don't use it in production. self.entities = {} - local width, height = love.graphics.getDimensions() - self.layers = {} - for i=1,6 do - table.insert(self.layers, Layer(width, height)) - end - self.layers[1].ratio = 0 - -- TODO: Scaled layers for Rays and future extensions. - do - local layer = Layer(320, 180) - layer.ratio = 0 - layer.scale = 1 - table.insert(self.layers, layer) -- 7 - end - self.map = map + + self:initLayers() self:buildMap() self:initClouds() self:spawnNauts(nauts) @@ -58,6 +44,23 @@ function World:delete () collectgarbage() end +-- TODO: Clean layering. This isn't for stable release, yet. +function World:initLayers () + local width, height = love.graphics.getDimensions() + self.layers = {} + for i=1,6 do + table.insert(self.layers, Layer(width, height)) + end + self.layers[1].ratio = 0 + -- TODO: Scaled layers for Rays and future extensions. + do + local layer = Layer(320, 180) + layer.ratio = 0 + layer.scale = 1 + table.insert(self.layers, layer) -- 7 + end +end + --- Builds map using one of tables frin config files located in `config/maps/` directory. function World:buildMap () for _,op in pairs(self.map.create) do @@ -119,6 +122,7 @@ function World:createNaut (x, y, name) return h end +-- TODO: Sprites' in general don't take actual Image in constructor. That is not only case of Decoration. function World:createDecoration (x, y, sprite) local d = Decoration(x, y, self, sprite) table.insert(self.entities, d) @@ -140,8 +144,6 @@ function World:createRay (naut) return r end --- TODO: Sprites' in general don't take actual Image in constructor. That is not only case of Decoration. --- TODO: Once entities are stored inside single table create single `insertEntity` method for World. function World:insertCloud (cloud) table.insert(self.entities, cloud) cloud.layer = self.layers[2] -- cgit v1.1 From bdf2675950e1c149b6fc3539f1c2a798e184b844 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 02:02:10 +0200 Subject: Another clean-up in World. Comments, moving stuff around. --- not/World.lua | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 529af2a..9c90280 100644 --- a/not/World.lua +++ b/not/World.lua @@ -52,7 +52,7 @@ function World:initLayers () table.insert(self.layers, Layer(width, height)) end self.layers[1].ratio = 0 - -- TODO: Scaled layers for Rays and future extensions. + -- TODO: Find a better way to create customized Layers. do local layer = Layer(320, 180) layer.ratio = 0 @@ -76,7 +76,7 @@ function World:buildMap () local image = love.graphics.newImage(op.background) local x = image:getWidth() / -2 local y = image:getHeight() / -2 - local bg = self:createDecoration(x, y, op.background) -- TODO: Decoration does not allow Image instead of filePath! + local bg = self:createDecoration(x, y, op.background) if op.animations then bg:setAnimationsList(op.animations) end @@ -234,7 +234,6 @@ end function World:update (dt) self.world:update(dt) self.camera:update(dt) - self.camera:sum(self.map.center.x, self.map.center.y) if self.cloudGenerator then self.cloudGenerator:update(dt) @@ -246,7 +245,8 @@ function World:update (dt) end end - -- TODO: Weird Camera following Heroes. + -- TODO: Possibly rename Camera@sum because this code part in World doesn't make sense without reading further. + self.camera:sum(self.map.center.x, self.map.center.y) for _,hero in pairs(self:getNautsAll()) do self.camera:sum(hero:getPosition()) end @@ -257,14 +257,12 @@ function World:update (dt) end function World:draw () - -- TODO: Prototype of layering. See `World@new`. - -- TODO: Camera rewrite in progress. for _,entity in pairs(self.entities) do if entity.draw and entity.layer then - entity.layer:renderToWith(self.camera, entity.draw, entity, debug) -- TODO: Offsets and Scale are passed as 0,0,1 in World@draw for compatibility reasons. Remove them. + entity.layer:renderToWith(self.camera, entity.draw, entity, debug) end if entity.drawTag then - self.layers[6]:renderToWith(self.camera, entity.drawTag, entity, debug) -- TODO: Offsets and Scale passed. See `World@draw`. + self.layers[6]:renderToWith(self.camera, entity.drawTag, entity, debug) end end @@ -273,6 +271,7 @@ function World:draw () layer:clear() end + -- TODO: Debug information could possibly get its own layer so it could follow flow of draw method. if debug then local center = self.map.center local ax, ay, bx, by = self.camera:getBoundaries() @@ -294,7 +293,7 @@ function World:draw () self.camera:pop() end - -- TODO: Draw method beyond this point is a very, very dark place. + -- TODO: Draw method beyond this point is a very, very dark place (portraits drawing to review). local scale = getScale() for _,naut in pairs(self:getNautsAll()) do -- I have no idea where to place them T_T -- cgit v1.1 From 5edb3063d1b1465a6b14c5731450c85b825f0f14 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 03:08:53 +0200 Subject: Added named layers for World, added layers iterator, layers are now drawn in reverse order --- not/World.lua | 76 +++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 23 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 9c90280..c18a54a 100644 --- a/not/World.lua +++ b/not/World.lua @@ -37,28 +37,42 @@ function World:delete () for _,entity in pairs(self.entities) do entity:delete() end - for _,layer in pairs(self.layers) do + for layer in self.layers() do layer:delete() end self.world:destroy() collectgarbage() end --- TODO: Clean layering. This isn't for stable release, yet. +--- Custom iterator for layers table. +-- Iterates over elements in reversed order. Doesn't pay attention to any changes in table. +local +function layersIterator (layers) + local i = layers.n + 1 + return function () + i = i - 1 + return layers[i] + end +end + +--- Layers in World may exists as two references. Every reference is stored inside `instance.layers`. +-- First reference is indexed with number, it exists for every layer. +-- Second reference is indexed with string, it exists only for selected layers. +-- Mentioned special layers are initialized in this method. +-- Additionally layer count is stored inside `instance.layers.n`. +-- Layers are drawn in reverse order, meaning that `instance.layers[1]` will be on the top. +-- Calling `instance.layers` will return iterator. function World:initLayers () local width, height = love.graphics.getDimensions() - self.layers = {} - for i=1,6 do - table.insert(self.layers, Layer(width, height)) - end - self.layers[1].ratio = 0 - -- TODO: Find a better way to create customized Layers. - do - local layer = Layer(320, 180) - layer.ratio = 0 - layer.scale = 1 - table.insert(self.layers, layer) -- 7 - end + self.layers = setmetatable({}, {__call = layersIterator}) + self.layers.n = 0 + self.layers.rays = self:addLayer(320, 180, 0, 1) + self.layers.tags = self:addLayer(width, height) + self.layers.platforms = self:addLayer(width, height) + self.layers.effects = self:addLayer(width, height) + self.layers.heroes = self:addLayer(width, height) + self.layers.decorations = self:addLayer(width, height) + self.layers.clouds = self:addLayer(width, height) end --- Builds map using one of tables frin config files located in `config/maps/` directory. @@ -73,6 +87,7 @@ function World:buildMap () self:createDecoration(op.x, op.y, op.decoration) end if op.background then + local width, height = love.graphics.getDimensions() local image = love.graphics.newImage(op.background) local x = image:getWidth() / -2 local y = image:getHeight() / -2 @@ -80,7 +95,7 @@ function World:buildMap () if op.animations then bg:setAnimationsList(op.animations) end - bg.layer = self.layers[1] + bg.layer = self:addLayer(width, height, 0) end end end @@ -107,18 +122,33 @@ function World:getSpawnPosition () return self.map.respawns[n].x, self.map.respawns[n].y end +-- TODO: Possibly automate calculation of new layer's dimensions based on scale. +function World:addLayer (width, height, ratio, scale) + local layer = Layer(width, height) + local n = self.layers.n + 1 + if ratio then + layer.ratio = ratio + end + if scale then + layer.scale = scale + end + self.layers[n] = layer + self.layers.n = n + return layer +end + -- TODO: Standardize `create*` methods with corresponding constructors. Pay attention to both params' order and names. function World:createPlatform (x, y, polygon, sprite, animations) local p = Platform(animations, polygon, x, y, self, sprite) table.insert(self.entities, p) - p.layer = self.layers[5] + p.layer = self.layers.platforms return p end function World:createNaut (x, y, name) local h = Player(name, x, y, self) table.insert(self.entities, h) - h.layer = self.layers[4] + h.layer = self.layers.heroes return h end @@ -126,27 +156,27 @@ end function World:createDecoration (x, y, sprite) local d = Decoration(x, y, self, sprite) table.insert(self.entities, d) - d.layer = self.layers[3] + d.layer = self.layers.decorations return d end function World:createEffect (name, x, y) local e = Effect(name, x, y, self) table.insert(self.entities, e) - e.layer = self.layers[5] + e.layer = self.layers.effects return e end function World:createRay (naut) local r = Ray(naut, self) table.insert(self.entities, r) - r.layer = self.layers[7] + r.layer = self.layers.rays return r end function World:insertCloud (cloud) table.insert(self.entities, cloud) - cloud.layer = self.layers[2] + cloud.layer = self.layers.clouds return cloud end @@ -262,11 +292,11 @@ function World:draw () entity.layer:renderToWith(self.camera, entity.draw, entity, debug) end if entity.drawTag then - self.layers[6]:renderToWith(self.camera, entity.drawTag, entity, debug) + self.layers.tags:renderToWith(self.camera, entity.drawTag, entity, debug) end end - for _,layer in ipairs(self.layers) do + for layer in self.layers() do layer:draw() layer:clear() end -- cgit v1.1 From 534f8f925a5fe389fec15d147b495c416b5b7e77 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 03:11:58 +0200 Subject: Background layers now use ratio from map config --- not/World.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index c18a54a..2a7437f 100644 --- a/not/World.lua +++ b/not/World.lua @@ -95,7 +95,7 @@ function World:buildMap () if op.animations then bg:setAnimationsList(op.animations) end - bg.layer = self:addLayer(width, height, 0) + bg.layer = self:addLayer(width, height, op.ratio) end end end -- cgit v1.1 From f15ace4d5b9f62b6288a2b6750bc48159ebebe00 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 03:55:59 +0200 Subject: CloudGenerator is now treated as Entity --- not/World.lua | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 2a7437f..5d46b5b 100644 --- a/not/World.lua +++ b/not/World.lua @@ -24,7 +24,6 @@ function World:new (map, nauts) self:initLayers() self:buildMap() - self:initClouds() self:spawnNauts(nauts) self.camera = Camera(self.map.center.x, self.map.center.y, self) @@ -97,13 +96,9 @@ function World:buildMap () end bg.layer = self:addLayer(width, height, op.ratio) end - end -end - -function World:initClouds () - if self.map.clouds then - self.cloudGenerator = CloudGenerator(self) - self.cloudGenerator:run(6, true) + if op.clouds then + self:insertEntity(CloudGenerator(self)):run(6, true) + end end end @@ -265,10 +260,6 @@ function World:update (dt) self.world:update(dt) self.camera:update(dt) - if self.cloudGenerator then - self.cloudGenerator:update(dt) - end - for key,entity in pairs(self.entities) do if entity:update(dt) then table.remove(self.entities, key):delete() -- cgit v1.1 From 291e9ffce1151be503f1c4550e6f4ff3230960b9 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 04:07:16 +0200 Subject: CloudGenerator's atlas and quads are loaded from map config --- not/CloudGenerator.lua | 22 ++-------------------- not/World.lua | 6 +++++- 2 files changed, 7 insertions(+), 21 deletions(-) (limited to 'not') diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua index fb1b617..3285938 100644 --- a/not/CloudGenerator.lua +++ b/not/CloudGenerator.lua @@ -4,28 +4,10 @@ CloudGenerator = require "not.Object":extends() require "not.Cloud" -local animations = { - default = { - [1] = love.graphics.newQuad( 1, 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 - } -} - -- TODO: Allow map config to modify cloud styles: maximum cloud count, animations and atlas. -function CloudGenerator:new (world) +function CloudGenerator:new (atlas, animations, world) self.world = world - self.atlas = "assets/clouds.png" + self.atlas = atlas self.quads = animations self.count = 18 self.interval = 6 diff --git a/not/World.lua b/not/World.lua index 5d46b5b..e0febb7 100644 --- a/not/World.lua +++ b/not/World.lua @@ -97,7 +97,11 @@ function World:buildMap () bg.layer = self:addLayer(width, height, op.ratio) end if op.clouds then - self:insertEntity(CloudGenerator(self)):run(6, true) + local animations = op.animations + if type(animations) == "string" then + animations = require("config.animations." .. animations) + end + self:insertEntity(CloudGenerator(op.clouds, animations, self)):run(6, true) end end end -- cgit v1.1 From ed16d208863944f64ce42298132597345cb749bb Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 04:37:07 +0200 Subject: Clouds are now counted, their number is limited and can be configured --- not/CloudGenerator.lua | 13 +++++++------ not/World.lua | 4 +++- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'not') diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua index 3285938..e9d8ed7 100644 --- a/not/CloudGenerator.lua +++ b/not/CloudGenerator.lua @@ -4,16 +4,16 @@ CloudGenerator = require "not.Object":extends() require "not.Cloud" --- TODO: Allow map config to modify cloud styles: maximum cloud count, animations and atlas. -function CloudGenerator:new (atlas, animations, world) +function CloudGenerator:new (atlas, animations, count, world) self.world = world self.atlas = atlas self.quads = animations - self.count = 18 + self.count = count self.interval = 6 self.timer = 0 end +-- TODO: This was a bad idea. Move Cloud creation back to World, pass created Cloud here for configuration. function CloudGenerator:createCloud (x, y, style) local cloud = Cloud(x, y, self.world, self.atlas) cloud:setAnimationsList(self.quads) @@ -46,7 +46,7 @@ function CloudGenerator:getRandomStyle () end function CloudGenerator:run (count, inside) - local count = count or 1 + count = count or 1 for i=1,count do local x, y = self:getRandomPosition(inside) local style = self:getRandomStyle() @@ -56,10 +56,11 @@ end function CloudGenerator:update (dt) local count = self.world:getCloudsCount() - self.timer = self.timer - dt - if self.timer < 0 then + if self.timer < 0 and self.count > count then self.timer = self.timer + self.interval self:run() + else + self.timer = self.timer - dt end end diff --git a/not/World.lua b/not/World.lua index e0febb7..853d75b 100644 --- a/not/World.lua +++ b/not/World.lua @@ -101,7 +101,9 @@ function World:buildMap () if type(animations) == "string" then animations = require("config.animations." .. animations) end - self:insertEntity(CloudGenerator(op.clouds, animations, self)):run(6, true) + local cg = CloudGenerator(op.clouds, animations, op.count, self) + self:insertEntity(cg) + cg:run(op.count, true) end end end -- cgit v1.1 From a0bbf9f36db30b0c6de3480f525ee69698ba18f9 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 04:40:40 +0200 Subject: > inb4 Multiple generators CloudGenerator now counts only clouds spawned by itself --- not/CloudGenerator.lua | 3 ++- not/World.lua | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'not') diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua index e9d8ed7..36ec70f 100644 --- a/not/CloudGenerator.lua +++ b/not/CloudGenerator.lua @@ -20,6 +20,7 @@ function CloudGenerator:createCloud (x, y, style) cloud:setAnimation(style) cloud:setVelocity(13, 0) cloud:setBoundary(340, 320) + cloud.generator = self return cloud end @@ -55,7 +56,7 @@ function CloudGenerator:run (count, inside) end function CloudGenerator:update (dt) - local count = self.world:getCloudsCount() + local count = self.world:getCloudsCountFrom(self) if self.timer < 0 and self.count > count then self.timer = self.timer + self.interval self:run() diff --git a/not/World.lua b/not/World.lua index 853d75b..f576fca 100644 --- a/not/World.lua +++ b/not/World.lua @@ -222,6 +222,12 @@ function World:getCloudsCount () end) end +function World:getCloudsCountFrom (generator) + return self:countEntities(function (entity) + return entity:is(Cloud) and entity.generator == generator + end) +end + function World:getNautsAll () return self:getEntities(function (entity) return entity:is(require("not.Hero")) and not entity.body:isDestroyed() -- cgit v1.1 From 4e3b4358bb3f8280a4739bf6a110823b029acae2 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 04:53:00 +0200 Subject: CloudGenerators now can be configured to use layer with ratio --- not/CloudGenerator.lua | 4 +++- not/World.lua | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'not') diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua index 36ec70f..75fd180 100644 --- a/not/CloudGenerator.lua +++ b/not/CloudGenerator.lua @@ -9,8 +9,9 @@ function CloudGenerator:new (atlas, animations, count, world) self.atlas = atlas self.quads = animations self.count = count - self.interval = 6 + self.interval = 8 self.timer = 0 + self.layer = false end -- TODO: This was a bad idea. Move Cloud creation back to World, pass created Cloud here for configuration. @@ -21,6 +22,7 @@ function CloudGenerator:createCloud (x, y, style) cloud:setVelocity(13, 0) cloud:setBoundary(340, 320) cloud.generator = self + cloud.layer = self.layer return cloud end diff --git a/not/World.lua b/not/World.lua index f576fca..5492c76 100644 --- a/not/World.lua +++ b/not/World.lua @@ -75,6 +75,7 @@ function World:initLayers () end --- Builds map using one of tables frin config files located in `config/maps/` directory. +-- TODO: Clean World@buildMap. Possibly explode into more methods. function World:buildMap () for _,op in pairs(self.map.create) do if op.platform then @@ -97,11 +98,15 @@ function World:buildMap () bg.layer = self:addLayer(width, height, op.ratio) end if op.clouds then + local width, height = love.graphics.getDimensions() local animations = op.animations if type(animations) == "string" then animations = require("config.animations." .. animations) end local cg = CloudGenerator(op.clouds, animations, op.count, self) + if op.ratio then + cg.layer = self:addLayer(width, height, op.ratio) + end self:insertEntity(cg) cg:run(op.count, true) end @@ -177,7 +182,9 @@ end function World:insertCloud (cloud) table.insert(self.entities, cloud) - cloud.layer = self.layers.clouds + if not cloud.layer then + cloud.layer = self.layers.clouds + end return cloud end -- cgit v1.1 From b7af282afe5de671bbd0e72099d8f063ef65b71a Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 05:03:23 +0200 Subject: Clouds now generates a little bit less often and timer won't go down much below 0 --- not/CloudGenerator.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'not') diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua index 75fd180..f9eaf40 100644 --- a/not/CloudGenerator.lua +++ b/not/CloudGenerator.lua @@ -9,8 +9,8 @@ function CloudGenerator:new (atlas, animations, count, world) self.atlas = atlas self.quads = animations self.count = count - self.interval = 8 - self.timer = 0 + self.interval = 12 + self.timer = self.interval self.layer = false end @@ -50,6 +50,7 @@ end function CloudGenerator:run (count, inside) count = count or 1 + print(self, "spawning", count) for i=1,count do local x, y = self:getRandomPosition(inside) local style = self:getRandomStyle() @@ -59,9 +60,11 @@ end function CloudGenerator:update (dt) local count = self.world:getCloudsCountFrom(self) - if self.timer < 0 and self.count > count then - self.timer = self.timer + self.interval - self:run() + if self.timer < 0 then + if self.count > count then + self.timer = self.timer + self.interval + self:run() + end else self.timer = self.timer - dt end -- cgit v1.1 From 25cb85e044c7ee03aef637db8fbbf7d42de64b82 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 05:12:05 +0200 Subject: Notes on cloud positions randomization for future self --- not/CloudGenerator.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'not') diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua index f9eaf40..0fa4271 100644 --- a/not/CloudGenerator.lua +++ b/not/CloudGenerator.lua @@ -27,6 +27,7 @@ function CloudGenerator:createCloud (x, y, style) end -- TODO: CloudGen's randomization methods are too static (not configurable). +-- TODO: Random position for Clouds inside map shouldn't be random. Make them place them where no clouds are present. function CloudGenerator:getRandomPosition (inside) local x, y local map = self.world.map -- cgit v1.1 From 7ca721109c885f3ce56cf8ee355635a00e90420c Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 06:28:28 +0200 Subject: Obsolete print removed from CloudGen --- not/CloudGenerator.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'not') diff --git a/not/CloudGenerator.lua b/not/CloudGenerator.lua index 0fa4271..e72514b 100644 --- a/not/CloudGenerator.lua +++ b/not/CloudGenerator.lua @@ -51,7 +51,6 @@ end function CloudGenerator:run (count, inside) count = count or 1 - print(self, "spawning", count) for i=1,count do local x, y = self:getRandomPosition(inside) local style = self:getRandomStyle() -- cgit v1.1 From befcd00e185fb0c1eb60f28dd5215e1cd88dfa18 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 07:45:40 +0200 Subject: Hotfix for animated backgrounds --- not/World.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 5492c76..a4d0f97 100644 --- a/not/World.lua +++ b/not/World.lua @@ -94,6 +94,7 @@ function World:buildMap () local bg = self:createDecoration(x, y, op.background) if op.animations then bg:setAnimationsList(op.animations) + _,_,width,height = bg:getAnimations()[1]:getViewport() end bg.layer = self:addLayer(width, height, op.ratio) end -- cgit v1.1 From 02864ba303beda496c85e4f0503b3f94d32fd30d Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 07:48:06 +0200 Subject: Viewports dimensions should be scaled --- not/World.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index a4d0f97..e0b64c5 100644 --- a/not/World.lua +++ b/not/World.lua @@ -95,6 +95,8 @@ function World:buildMap () if op.animations then bg:setAnimationsList(op.animations) _,_,width,height = bg:getAnimations()[1]:getViewport() + width = width * getScale() + height = height * getScale() end bg.layer = self:addLayer(width, height, op.ratio) end -- cgit v1.1 From 914049749fc9f6f86b9ba22d5b74a173a2c8a3bc Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 07:49:42 +0200 Subject: Fixed typo --- not/World.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index e0b64c5..5392e18 100644 --- a/not/World.lua +++ b/not/World.lua @@ -94,7 +94,7 @@ function World:buildMap () local bg = self:createDecoration(x, y, op.background) if op.animations then bg:setAnimationsList(op.animations) - _,_,width,height = bg:getAnimations()[1]:getViewport() + _,_,width,height = bg:getAnimation()[1]:getViewport() width = width * getScale() height = height * getScale() end -- cgit v1.1 From 2a0cef0fba687e03fd322ac73c511bbb12b1e31c Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 10:00:59 +0200 Subject: Fixed background bug on non-16:9 screens --- not/Camera.lua | 24 ++++++++++++++++++++---- not/Layer.lua | 3 ++- not/World.lua | 11 +++++++++-- 3 files changed, 31 insertions(+), 7 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index c5449d3..402a32b 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -1,4 +1,5 @@ --- Used in drawing other stuff in places. +-- TODO: Support for real scale translations. Camera = require "not.Object":extends() Camera.SHAKE_LENGTH = 0.6 @@ -25,26 +26,29 @@ function Camera:push () love.graphics.push() end +-- TODO: self._scale usage is temporary, used for real scaling. function Camera:scale (scale) scale = scale or getScale() love.graphics.scale(scale, scale) + self._scale = scale end --- TODO: Even more magic numbers present in Camera. Translate method. function Camera:translate (ratio) local px, py = self:getPosition() local dx, dy = self:getShake() + local ox, oy = self:getHalfViewSize() if ratio then dx = dx * ratio dy = dy * ratio px = px * ratio py = py * ratio end - love.graphics.translate(160 - px - dx, 90 - py - dy) + love.graphics.translate(ox - px - dx, oy - py - dy) end function Camera:pop () love.graphics.pop() + self._scale = nil end function Camera:setPosition (x, y) @@ -57,12 +61,24 @@ function Camera:getPosition () return self.x, self.y end --- TODO: Magic numbers present in camera's boundaries. function Camera:getBoundaries () local x, y = self:getPosition() - return x - 160, y - 90, x + 160, y + 90 + local width, height = self:getHalfViewSize() + return x - width, y - height, x + width, y + height end +-- TODO: Review getViewSize of Camera. +function Camera:getViewSize () + local scale = self._scale or getScale() + local width = love.graphics.getWidth() / scale + local height = love.graphics.getHeight() / scale + return width, height +end + +function Camera:getHalfViewSize () + local width, height = self:getViewSize() + return width / 2, height / 2 +end function Camera:startShake () self.shakeTime = Camera.SHAKE_LENGTH diff --git a/not/Layer.lua b/not/Layer.lua index 0446599..ebfb28e 100644 --- a/not/Layer.lua +++ b/not/Layer.lua @@ -1,4 +1,5 @@ --- A little bit more than just a Canvas. +-- TODO: Scaled and RealScaled support should be extended. Layer = require "not.Object":extends() function Layer:new (width, height) @@ -43,7 +44,7 @@ function Layer:draw () scale = getScale() / self.scale end love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(self.canvas, 0, 0, 0, scale, scale) + love.graphics.draw(self.canvas, nil, nil, nil, scale, scale) end return Layer diff --git a/not/World.lua b/not/World.lua index 5392e18..e3b7695 100644 --- a/not/World.lua +++ b/not/World.lua @@ -76,6 +76,7 @@ end --- Builds map using one of tables frin config files located in `config/maps/` directory. -- TODO: Clean World@buildMap. Possibly explode into more methods. +-- TODO: ScaledLayers and RealScaledLayers should be implemented properly with good Camera support. function World:buildMap () for _,op in pairs(self.map.create) do if op.platform then @@ -98,7 +99,13 @@ function World:buildMap () width = width * getScale() height = height * getScale() end - bg.layer = self:addLayer(width, height, op.ratio) + bg.layer = self:addLayer(width, height, op.ratio, getRealScale()) + print("ayyy", getScale(), getRealScale()) + print("lmao", x, y) + bg.layer.draw = function (self) + love.graphics.setColor(255, 255, 255, 255) + love.graphics.draw(self.canvas) + end end if op.clouds then local width, height = love.graphics.getDimensions() @@ -313,7 +320,7 @@ function World:draw () layer:draw() layer:clear() end - + -- TODO: Debug information could possibly get its own layer so it could follow flow of draw method. if debug then local center = self.map.center -- cgit v1.1 From e8bd3dfd8031930fa3f0169300620e5a0400995d Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 10:19:02 +0200 Subject: Another attempt to fix real scaling bug --- not/Camera.lua | 24 ++++++++++++++++++------ not/World.lua | 20 ++++++++++++++------ 2 files changed, 32 insertions(+), 12 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index 402a32b..b3b8128 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -26,11 +26,9 @@ function Camera:push () love.graphics.push() end --- TODO: self._scale usage is temporary, used for real scaling. function Camera:scale (scale) scale = scale or getScale() love.graphics.scale(scale, scale) - self._scale = scale end function Camera:translate (ratio) @@ -46,6 +44,20 @@ function Camera:translate (ratio) love.graphics.translate(ox - px - dx, oy - py - dy) end +-- TODO: TranslateReal is temporary. +function Camera:translateReal (ratio) + local px, py = self:getPosition() + local dx, dy = self:getShake() + local ox, oy = self:getHalfViewSize(getRealScale()) + if ratio then + dx = dx * ratio + dy = dy * ratio + px = px * ratio + py = py * ratio + end + love.graphics.translate(ox - px - dx, oy - py - dy) +end + function Camera:pop () love.graphics.pop() self._scale = nil @@ -68,15 +80,15 @@ function Camera:getBoundaries () end -- TODO: Review getViewSize of Camera. -function Camera:getViewSize () - local scale = self._scale or getScale() +function Camera:getViewSize (scale) + scale = scale or getScale() local width = love.graphics.getWidth() / scale local height = love.graphics.getHeight() / scale return width, height end -function Camera:getHalfViewSize () - local width, height = self:getViewSize() +function Camera:getHalfViewSize (scale) + local width, height = self:getViewSize(scale) return width / 2, height / 2 end diff --git a/not/World.lua b/not/World.lua index e3b7695..0a560fb 100644 --- a/not/World.lua +++ b/not/World.lua @@ -22,12 +22,12 @@ function World:new (map, nauts) self.entities = {} self.map = map + self.camera = Camera(self.map.center.x, self.map.center.y, self) + self:initLayers() self:buildMap() self:spawnNauts(nauts) - self.camera = Camera(self.map.center.x, self.map.center.y, self) - musicPlayer:play(self.map.theme) end @@ -62,10 +62,13 @@ end -- Layers are drawn in reverse order, meaning that `instance.layers[1]` will be on the top. -- Calling `instance.layers` will return iterator. function World:initLayers () - local width, height = love.graphics.getDimensions() self.layers = setmetatable({}, {__call = layersIterator}) self.layers.n = 0 - self.layers.rays = self:addLayer(320, 180, 0, 1) + + local width, height = self.camera:getViewSize() + self.layers.rays = self:addLayer(width, height, 0, 1) + + local width, height = love.graphics.getDimensions() self.layers.tags = self:addLayer(width, height) self.layers.platforms = self:addLayer(width, height) self.layers.effects = self:addLayer(width, height) @@ -100,8 +103,13 @@ function World:buildMap () height = height * getScale() end bg.layer = self:addLayer(width, height, op.ratio, getRealScale()) - print("ayyy", getScale(), getRealScale()) - print("lmao", x, y) + bg.layer.renderToWith = function (self, camera, func, ...) + camera:push() + camera:scale(self.scale) + camera:translateReal(self.ratio) + self:renderTo(func, ...) + camera:pop() + end bg.layer.draw = function (self) love.graphics.setColor(255, 255, 255, 255) love.graphics.draw(self.canvas) -- cgit v1.1 From f34ec5f8f29ce07d69104e537e87ed357abaf786 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 12:50:46 +0200 Subject: Camera and Layers now properly handle different resolution ratios --- not/Camera.lua | 55 ++++++++++------------------------------------------ not/Layer.lua | 15 +++++---------- not/World.lua | 61 ++++++++++++++++++++++++---------------------------------- 3 files changed, 40 insertions(+), 91 deletions(-) (limited to 'not') diff --git a/not/Camera.lua b/not/Camera.lua index b3b8128..65395cb 100644 --- a/not/Camera.lua +++ b/not/Camera.lua @@ -1,5 +1,5 @@ --- Used in drawing other stuff in places. --- TODO: Support for real scale translations. +-- TODO: Camera is missing documentation on every important method. Camera = require "not.Object":extends() Camera.SHAKE_LENGTH = 0.6 @@ -26,41 +26,19 @@ function Camera:push () love.graphics.push() end -function Camera:scale (scale) - scale = scale or getScale() - love.graphics.scale(scale, scale) -end - -function Camera:translate (ratio) +function Camera:transform (scale, ratio, vw, vh) local px, py = self:getPosition() - local dx, dy = self:getShake() - local ox, oy = self:getHalfViewSize() - if ratio then - dx = dx * ratio - dy = dy * ratio - px = px * ratio - py = py * ratio - end - love.graphics.translate(ox - px - dx, oy - py - dy) -end + local sx, sy = self:getShake() + local dx, dy = (px + sx) * ratio, (py + sy) * ratio --- TODO: TranslateReal is temporary. -function Camera:translateReal (ratio) - local px, py = self:getPosition() - local dx, dy = self:getShake() - local ox, oy = self:getHalfViewSize(getRealScale()) - if ratio then - dx = dx * ratio - dy = dy * ratio - px = px * ratio - py = py * ratio - end - love.graphics.translate(ox - px - dx, oy - py - dy) + vw, vh = vw / scale / 2, vh / scale / 2 + + love.graphics.scale(scale, scale) + love.graphics.translate(vw - dx, vh - dy) end function Camera:pop () love.graphics.pop() - self._scale = nil end function Camera:setPosition (x, y) @@ -73,25 +51,12 @@ function Camera:getPosition () return self.x, self.y end -function Camera:getBoundaries () +function Camera:getBoundaries (scale, vw, vh) local x, y = self:getPosition() - local width, height = self:getHalfViewSize() + local width, height = vw / scale / 2, vh / scale / 2 return x - width, y - height, x + width, y + height end --- TODO: Review getViewSize of Camera. -function Camera:getViewSize (scale) - scale = scale or getScale() - local width = love.graphics.getWidth() / scale - local height = love.graphics.getHeight() / scale - return width, height -end - -function Camera:getHalfViewSize (scale) - local width, height = self:getViewSize(scale) - return width / 2, height / 2 -end - function Camera:startShake () self.shakeTime = Camera.SHAKE_LENGTH end diff --git a/not/Layer.lua b/not/Layer.lua index ebfb28e..14dac32 100644 --- a/not/Layer.lua +++ b/not/Layer.lua @@ -1,11 +1,11 @@ --- A little bit more than just a Canvas. --- TODO: Scaled and RealScaled support should be extended. Layer = require "not.Object":extends() function Layer:new (width, height) self.canvas = love.graphics.newCanvas(width, height) - self.scale = false - self.ratio = false + self.transformScale = getScale() + self.transformRatio = 1 + self.drawScale = 1 end function Layer:delete () @@ -28,8 +28,7 @@ end function Layer:renderToWith (camera, func, ...) camera:push() - camera:scale(self.scale) - camera:translate(self.ratio) + camera:transform(self.transformScale, self.transformRatio, self.canvas:getDimensions()) self:renderTo(func, ...) camera:pop() end @@ -39,12 +38,8 @@ function Layer:clear () end function Layer:draw () - local scale = 1 - if self.scale then - scale = getScale() / self.scale - end love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(self.canvas, nil, nil, nil, scale, scale) + love.graphics.draw(self.canvas, nil, nil, nil, self.drawScale, self.drawScale) end return Layer diff --git a/not/World.lua b/not/World.lua index 0a560fb..92e9ae0 100644 --- a/not/World.lua +++ b/not/World.lua @@ -64,22 +64,27 @@ end function World:initLayers () self.layers = setmetatable({}, {__call = layersIterator}) self.layers.n = 0 - - local width, height = self.camera:getViewSize() - self.layers.rays = self:addLayer(width, height, 0, 1) - - local width, height = love.graphics.getDimensions() - self.layers.tags = self:addLayer(width, height) - self.layers.platforms = self:addLayer(width, height) - self.layers.effects = self:addLayer(width, height) - self.layers.heroes = self:addLayer(width, height) - self.layers.decorations = self:addLayer(width, height) - self.layers.clouds = self:addLayer(width, height) + do + local width, height = love.graphics.getWidth() / getScale(), love.graphics.getHeight() / getScale() + local rays = self:addLayer(width, height) + rays.transformScale = 1 + rays.transformRatio = 0 + rays.drawScale = getScale() + self.layers.rays = rays + end + do + local width, height = love.graphics.getDimensions() + self.layers.tags = self:addLayer(width, height) + self.layers.platforms = self:addLayer(width, height) + self.layers.effects = self:addLayer(width, height) + self.layers.heroes = self:addLayer(width, height) + self.layers.decorations = self:addLayer(width, height) + self.layers.clouds = self:addLayer(width, height) + end end --- Builds map using one of tables frin config files located in `config/maps/` directory. -- TODO: Clean World@buildMap. Possibly explode into more methods. --- TODO: ScaledLayers and RealScaledLayers should be implemented properly with good Camera support. function World:buildMap () for _,op in pairs(self.map.create) do if op.platform then @@ -102,18 +107,9 @@ function World:buildMap () width = width * getScale() height = height * getScale() end - bg.layer = self:addLayer(width, height, op.ratio, getRealScale()) - bg.layer.renderToWith = function (self, camera, func, ...) - camera:push() - camera:scale(self.scale) - camera:translateReal(self.ratio) - self:renderTo(func, ...) - camera:pop() - end - bg.layer.draw = function (self) - love.graphics.setColor(255, 255, 255, 255) - love.graphics.draw(self.canvas) - end + bg.layer = self:addLayer(width, height) + bg.layer.transformRatio = op.ratio + bg.layer.transformScale = getRealScale() end if op.clouds then local width, height = love.graphics.getDimensions() @@ -123,7 +119,8 @@ function World:buildMap () end local cg = CloudGenerator(op.clouds, animations, op.count, self) if op.ratio then - cg.layer = self:addLayer(width, height, op.ratio) + cg.layer = self:addLayer(width, height) + cg.layer.transformRatio = op.ratio end self:insertEntity(cg) cg:run(op.count, true) @@ -146,16 +143,9 @@ function World:getSpawnPosition () return self.map.respawns[n].x, self.map.respawns[n].y end --- TODO: Possibly automate calculation of new layer's dimensions based on scale. -function World:addLayer (width, height, ratio, scale) +function World:addLayer (width, height) local layer = Layer(width, height) local n = self.layers.n + 1 - if ratio then - layer.ratio = ratio - end - if scale then - layer.scale = scale - end self.layers[n] = layer self.layers.n = n return layer @@ -332,14 +322,13 @@ function World:draw () -- TODO: Debug information could possibly get its own layer so it could follow flow of draw method. if debug then local center = self.map.center - local ax, ay, bx, by = self.camera:getBoundaries() + local ax, ay, bx, by = self.camera:getBoundaries(getScale(), love.graphics.getDimensions()) love.graphics.setLineWidth(1 / getScale()) love.graphics.setLineStyle("rough") self.camera:push() - self.camera:scale() - self.camera:translate() + self.camera:transform(getScale(), 1, love.graphics.getDimensions()) love.graphics.setColor(130,130,130) love.graphics.line(ax,center.y,bx,center.y) -- cgit v1.1 From ee0438e346d17be68a4b57dec62e7279f40bfefd Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 13 Sep 2017 12:56:07 +0200 Subject: I think this should properly place animated backgrounds --- not/World.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 92e9ae0..07843fe 100644 --- a/not/World.lua +++ b/not/World.lua @@ -103,9 +103,8 @@ function World:buildMap () local bg = self:createDecoration(x, y, op.background) if op.animations then bg:setAnimationsList(op.animations) - _,_,width,height = bg:getAnimation()[1]:getViewport() - width = width * getScale() - height = height * getScale() + _,_,x,y = bg:getAnimation()[1]:getViewport() + bg:setPosition(x / -2, y / -2) end bg.layer = self:addLayer(width, height) bg.layer.transformRatio = op.ratio -- cgit v1.1 From 31c994c223c0a9a63d503d43877254268f52811c Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 14 Sep 2017 16:23:07 +0200 Subject: Added Timer and Trigger classes --- not/Timer.lua | 30 ++++++++++++++++++++++++++++++ not/Trigger.lua | 18 ++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 not/Timer.lua create mode 100644 not/Trigger.lua (limited to 'not') diff --git a/not/Timer.lua b/not/Timer.lua new file mode 100644 index 0000000..3e45b11 --- /dev/null +++ b/not/Timer.lua @@ -0,0 +1,30 @@ +Timer = require "not.Object":extends() + +function Timer:new (trigger, delay) + self.trigger = trigger + self.delay = delay + self.left = 0 + self.active = false + self.restart = false +end + +function Timer:start () + self.left = self.delay + self.active = true +end + +function Timer:update (dt) + if self.active then + if self.left < 0 then + self.trigger:emit() + self.active = false + if self.restart then + self:start() + end + else + self.left = self.left - dt + end + end +end + +return Timer diff --git a/not/Trigger.lua b/not/Trigger.lua new file mode 100644 index 0000000..c6ef7c7 --- /dev/null +++ b/not/Trigger.lua @@ -0,0 +1,18 @@ +Trigger = require "not.Object":extends() + +function Trigger:new () + self.calls = {} +end + +function Trigger:register (func, ...) + local call = {func = func, params = {...}} + table.insert(self.calls, call) +end + +function Trigger:emit () + for _,call in pairs(self.calls) do + call.func(unpack(call.params)) + end +end + +return Trigger -- cgit v1.1 From 0e9ad14e9fcee242a68f695715fa106af99aa76f Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 14 Sep 2017 17:11:54 +0200 Subject: Timer now inherits after Trigger --- not/Timer.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'not') diff --git a/not/Timer.lua b/not/Timer.lua index 3e45b11..6fc4a4c 100644 --- a/not/Timer.lua +++ b/not/Timer.lua @@ -1,7 +1,6 @@ -Timer = require "not.Object":extends() +Timer = require "not.Trigger":extends() -function Timer:new (trigger, delay) - self.trigger = trigger +function Timer:new (delay) self.delay = delay self.left = 0 self.active = false @@ -16,7 +15,7 @@ end function Timer:update (dt) if self.active then if self.left < 0 then - self.trigger:emit() + self:emit() self.active = false if self.restart then self:start() -- cgit v1.1 From 2a65a119ef6cb8f99f7f5580439b0b63dcd85a69 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 14 Sep 2017 17:13:16 +0200 Subject: Added missing super constructor --- not/Timer.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'not') diff --git a/not/Timer.lua b/not/Timer.lua index 6fc4a4c..9ae0de8 100644 --- a/not/Timer.lua +++ b/not/Timer.lua @@ -1,6 +1,7 @@ Timer = require "not.Trigger":extends() function Timer:new (delay) + Timer.__super.new(self) self.delay = delay self.left = 0 self.active = false -- cgit v1.1 From e316bd9c66ab29b424b55003b6565cbf7a7ede45 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 14 Sep 2017 21:09:28 +0200 Subject: Added crude way to toggle Sprite drawing --- not/Sprite.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not') diff --git a/not/Sprite.lua b/not/Sprite.lua index a4346f6..33b8ac8 100644 --- a/not/Sprite.lua +++ b/not/Sprite.lua @@ -101,7 +101,7 @@ function Sprite:draw (debug) local draw_y = approx(y) local draw_x = math.floor(x) - if i then + if i and not self.hidden then love.graphics.setColor(255,255,255,255) if q then love.graphics.draw(i, q, draw_x, draw_y, angle, scaleX, scaleY, self:getOffset()) -- cgit v1.1 From a8a581f3003c49f89eae85b5e57c278e7e3f835a Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 14 Sep 2017 21:10:22 +0200 Subject: Prototyped trap map hazard (flames on 205) --- not/World.lua | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 07843fe..e32c11d 100644 --- a/not/World.lua +++ b/not/World.lua @@ -83,6 +83,68 @@ function World:initLayers () end end +-- TODO: Move flames to separate class `Trap`. +-- TODO: Make collisions for category 3 more customizable or create new category for traps/area effects. +local +function createFlame (self, x, y, mirror, timerIn, timerOut) + local trap = require("not.PhysicalBody")(x, y, self, "assets/decorations/205-flames.png") + trap:setAnimationsList({ + default = { + [1] = love.graphics.newQuad(0, 0, 42, 19, 168, 19), + [2] = love.graphics.newQuad(42, 0, 42, 19, 168, 19), + frames = 2, + repeated = true + }, + fadein = { + [1] = love.graphics.newQuad(84, 0, 42, 19, 168, 19), + [2] = love.graphics.newQuad(126, 0, 42, 19, 168, 19), + frames = 2, + repeated = false + }, + fadeout = { + [1] = love.graphics.newQuad(126, 0, 42, 19, 168, 19), + [2] = love.graphics.newQuad(84, 0, 42, 19, 168, 19), + frames = 2, + repeated = false + } + }) + + -- hotfix for clash + trap.body:setUserData(trap) + trap.damage = function () end + + local fixture = trap:addFixture({0,0, 41*mirror,0, 41*mirror,18, 0,18}) + fixture:setCategory(3) + fixture:setMask(1) + local direction = "right" + if mirror < 0 then direction = "left" end + fixture:setUserData({0, direction}) + fixture:setSensor(true) + trap:setBodyType("static") + trap.layer = self.layers.decorations + + trap.getHorizontalMirror = function (self) return mirror end + + trap.goToNextFrame = function (self) + if self.current.repeated or not (self.frame == self.current.frames) then + self.frame = (self.frame % self.current.frames) + 1 + elseif self.current == self.animations.fadeout then + self:setAnimation("default") + self.hidden = true + else + self:setAnimation("default") + end + end + + timerIn:register(trap.setBodyActive, trap, true) + timerIn:register(trap.setAnimation, trap, "fadein") + timerIn:register(function (self) trap.hidden = false end, trap) + timerOut:register(trap.setBodyActive, trap, false) + timerOut:register(trap.setAnimation, trap, "fadeout") + + self:insertEntity(trap) +end + --- Builds map using one of tables frin config files located in `config/maps/` directory. -- TODO: Clean World@buildMap. Possibly explode into more methods. function World:buildMap () @@ -124,6 +186,21 @@ function World:buildMap () self:insertEntity(cg) cg:run(op.count, true) end + -- TODO: Make flames and other traps more configurable through map config file. + if op.flames then + local timerIn = require("not.Timer")(10) + local timerOut = require("not.Timer")(5) + + timerIn:register(timerOut.start, timerOut) + timerOut:register(timerIn.start, timerIn) + + createFlame(self, -62, 16, 1, timerIn, timerOut) + createFlame(self, 63, 16, -1, timerIn, timerOut) + + self:insertEntity(timerIn) + self:insertEntity(timerOut) + timerOut:start() + end end end -- cgit v1.1 From cfacf87da639e448699a883c0e3fb4da8b6f6471 Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 19 Sep 2017 17:49:04 +0200 Subject: Added empty Trap class --- not/Trap.lua | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 not/Trap.lua (limited to 'not') diff --git a/not/Trap.lua b/not/Trap.lua new file mode 100644 index 0000000..012561d --- /dev/null +++ b/not/Trap.lua @@ -0,0 +1,3 @@ +Trap = require "not.PhysicalBody":extends() + +return Trap -- cgit v1.1 From 03ccc9890c2b349eb939b0d9fcaa982ead98f0cd Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 20 Sep 2017 01:52:27 +0200 Subject: Moved most important parts from createFlame to Trap --- not/Trap.lua | 56 +++++++++++++++++++++++++++++++++++++++++ not/World.lua | 80 ++++++++++++++--------------------------------------------- 2 files changed, 74 insertions(+), 62 deletions(-) (limited to 'not') diff --git a/not/Trap.lua b/not/Trap.lua index 012561d..25eeb0b 100644 --- a/not/Trap.lua +++ b/not/Trap.lua @@ -1,3 +1,59 @@ Trap = require "not.PhysicalBody":extends() +-- TODO: Move flames' animations to config file. +local animations = { + default = { + [1] = love.graphics.newQuad(0, 0, 42, 19, 168, 19), + [2] = love.graphics.newQuad(42, 0, 42, 19, 168, 19), + frames = 2, + repeated = true + }, + fadein = { + [1] = love.graphics.newQuad(84, 0, 42, 19, 168, 19), + [2] = love.graphics.newQuad(126, 0, 42, 19, 168, 19), + frames = 2, + repeated = false + }, + fadeout = { + [1] = love.graphics.newQuad(126, 0, 42, 19, 168, 19), + [2] = love.graphics.newQuad(84, 0, 42, 19, 168, 19), + frames = 2, + repeated = false + } +} + +function Trap:new (direction, x, y, world, imagePath) + Trap.__super.new(self, x, y, world, imagePath) + self:setAnimationsList(animations) + self:setBodyType("static") + + local mirror = 1 + if direction == "left" then mirror = -1 end + local fixture = Trap.__super.addFixture(self, {0, 0, 41 * mirror, 0, 41 * mirror, 18, 0, 18}) + fixture:setCategory(3) + fixture:setMask(1) + fixture:setUserData({0, direction}) + fixture:setSensor(true) + + self.mirror = mirror +end + +function Trap:getHorizontalMirror () + return self.mirror +end + +function Trap:goToNextFrame () + if self.current.repeated or not (self.frame == self.current.frames) then + self.frame = (self.frame % self.current.frames) + 1 + elseif self.current == self.animations.fadeout then + self:setAnimation("default") + self.hidden = true + else + self:setAnimation("default") + end +end + +-- TODO: Trap@damage is hotfix for clashing. +function Trap:damage () end + return Trap diff --git a/not/World.lua b/not/World.lua index e32c11d..3eec9fd 100644 --- a/not/World.lua +++ b/not/World.lua @@ -10,6 +10,8 @@ require "not.Ray" require "not.Cloud" require "not.CloudGenerator" require "not.Layer" +require "not.Timer" +require "not.Trap" --- ZA WARUDO! -- TODO: Missing documentation on most of World's methods. @@ -83,58 +85,12 @@ function World:initLayers () end end --- TODO: Move flames to separate class `Trap`. -- TODO: Make collisions for category 3 more customizable or create new category for traps/area effects. local -function createFlame (self, x, y, mirror, timerIn, timerOut) - local trap = require("not.PhysicalBody")(x, y, self, "assets/decorations/205-flames.png") - trap:setAnimationsList({ - default = { - [1] = love.graphics.newQuad(0, 0, 42, 19, 168, 19), - [2] = love.graphics.newQuad(42, 0, 42, 19, 168, 19), - frames = 2, - repeated = true - }, - fadein = { - [1] = love.graphics.newQuad(84, 0, 42, 19, 168, 19), - [2] = love.graphics.newQuad(126, 0, 42, 19, 168, 19), - frames = 2, - repeated = false - }, - fadeout = { - [1] = love.graphics.newQuad(126, 0, 42, 19, 168, 19), - [2] = love.graphics.newQuad(84, 0, 42, 19, 168, 19), - frames = 2, - repeated = false - } - }) - - -- hotfix for clash - trap.body:setUserData(trap) - trap.damage = function () end - - local fixture = trap:addFixture({0,0, 41*mirror,0, 41*mirror,18, 0,18}) - fixture:setCategory(3) - fixture:setMask(1) - local direction = "right" - if mirror < 0 then direction = "left" end - fixture:setUserData({0, direction}) - fixture:setSensor(true) - trap:setBodyType("static") - trap.layer = self.layers.decorations - - trap.getHorizontalMirror = function (self) return mirror end - - trap.goToNextFrame = function (self) - if self.current.repeated or not (self.frame == self.current.frames) then - self.frame = (self.frame % self.current.frames) + 1 - elseif self.current == self.animations.fadeout then - self:setAnimation("default") - self.hidden = true - else - self:setAnimation("default") - end - end +function createFlame (self, x, y, direction, timerIn, timerOut) + local trap = Trap(direction, x, y, self, "assets/decorations/205-flames.png") + + trap.layer = self.layers.platforms timerIn:register(trap.setBodyActive, trap, true) timerIn:register(trap.setAnimation, trap, "fadein") @@ -188,18 +144,18 @@ function World:buildMap () end -- TODO: Make flames and other traps more configurable through map config file. if op.flames then - local timerIn = require("not.Timer")(10) - local timerOut = require("not.Timer")(5) - - timerIn:register(timerOut.start, timerOut) - timerOut:register(timerIn.start, timerIn) - - createFlame(self, -62, 16, 1, timerIn, timerOut) - createFlame(self, 63, 16, -1, timerIn, timerOut) - - self:insertEntity(timerIn) - self:insertEntity(timerOut) - timerOut:start() + local timerIn = Timer(10) + local timerOut = Timer(5) + + timerIn:register(timerOut.start, timerOut) + timerOut:register(timerIn.start, timerIn) + + createFlame(self, -62, 16, "right", timerIn, timerOut) + createFlame(self, 63, 16, "left", timerIn, timerOut) + + self:insertEntity(timerIn) + self:insertEntity(timerOut) + timerOut:start() end end end -- cgit v1.1 From f2979320625eceeaadd594ccf6bad6c6b2543aff Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 20 Sep 2017 13:27:03 +0200 Subject: Added fadein and fadeout methods to Trap --- not/Trap.lua | 17 +++++++++++++++++ not/World.lua | 7 ++----- 2 files changed, 19 insertions(+), 5 deletions(-) (limited to 'not') diff --git a/not/Trap.lua b/not/Trap.lua index 25eeb0b..2ebb4d2 100644 --- a/not/Trap.lua +++ b/not/Trap.lua @@ -38,6 +38,23 @@ function Trap:new (direction, x, y, world, imagePath) self.mirror = mirror end +function Trap:fadeIn () + self.hidden = false + self:setBodyActive(true) + if self.animations.fadein then + self:setAnimation("fadein") + end +end + +function Trap:fadeOut () + self:setBodyActive(false) + if self.animations.fadeout then + self:setAnimation("fadeout") + else + self.hidden = true + end +end + function Trap:getHorizontalMirror () return self.mirror end diff --git a/not/World.lua b/not/World.lua index 3eec9fd..9a37965 100644 --- a/not/World.lua +++ b/not/World.lua @@ -92,11 +92,8 @@ function createFlame (self, x, y, direction, timerIn, timerOut) trap.layer = self.layers.platforms - timerIn:register(trap.setBodyActive, trap, true) - timerIn:register(trap.setAnimation, trap, "fadein") - timerIn:register(function (self) trap.hidden = false end, trap) - timerOut:register(trap.setBodyActive, trap, false) - timerOut:register(trap.setAnimation, trap, "fadeout") + timerIn:register(trap.fadeIn, trap) + timerOut:register(trap.fadeOut, trap) self:insertEntity(trap) end -- cgit v1.1 From cdec3cf410bba80d037fda760da06e9e3ed75945 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 20 Sep 2017 15:43:08 +0200 Subject: Removed obsolete verbose call of addFixture --- not/Trap.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not') diff --git a/not/Trap.lua b/not/Trap.lua index 2ebb4d2..84de5b0 100644 --- a/not/Trap.lua +++ b/not/Trap.lua @@ -29,7 +29,7 @@ function Trap:new (direction, x, y, world, imagePath) local mirror = 1 if direction == "left" then mirror = -1 end - local fixture = Trap.__super.addFixture(self, {0, 0, 41 * mirror, 0, 41 * mirror, 18, 0, 18}) + local fixture = self:addFixture({0, 0, 41 * mirror, 0, 41 * mirror, 18, 0, 18}) fixture:setCategory(3) fixture:setMask(1) fixture:setUserData({0, direction}) -- cgit v1.1 From 69d3ae7be97b177dacb06cec4873b7a27ccb70cb Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 20 Sep 2017 16:53:06 +0200 Subject: buildMap is now a little bit more configurable --- not/World.lua | 68 ++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 22 deletions(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 9a37965..4e5b52f 100644 --- a/not/World.lua +++ b/not/World.lua @@ -12,6 +12,7 @@ require "not.CloudGenerator" require "not.Layer" require "not.Timer" require "not.Trap" +require "not.Entity" --- ZA WARUDO! -- TODO: Missing documentation on most of World's methods. @@ -98,39 +99,62 @@ function createFlame (self, x, y, direction, timerIn, timerOut) self:insertEntity(trap) end +local +function getAnimations (a) + if type(a) == "string" then + return require("config.animations." .. a) + end + if type(a) == "table" then + return a + end +end + --- Builds map using one of tables frin config files located in `config/maps/` directory. -- TODO: Clean World@buildMap. Possibly explode into more methods. function World:buildMap () + local width, height = love.graphics.getDimensions() + for _,op in pairs(self.map.create) do if op.platform then - local path = string.format("config/platforms/%s.lua", op.platform) - local config = love.filesystem.load(path)() - self:createPlatform(op.x, op.y, config.shape, config.sprite, config.animations) + -- TODO: Merge configs imported from other files to currently processed element. + local config = love.filesystem.load(string.format("config/platforms/%s.lua", op.platform))() + local platform = Platform(config.animations, config.shape, op.x, op.y, self, config.sprite) + platform.layer = self.layers.platforms + self:insertEntity(platform) end - if op.decoration then - self:createDecoration(op.x, op.y, op.decoration) - end - if op.background then - local width, height = love.graphics.getDimensions() - local image = love.graphics.newImage(op.background) - local x = image:getWidth() / -2 - local y = image:getHeight() / -2 - local bg = self:createDecoration(x, y, op.background) - if op.animations then - bg:setAnimationsList(op.animations) + if op.decoration or op.background then + local imagePath = op.decoration or op.background + local entity = Decoration(0, 0, self, imagePath) + + local x, y = 0, 0 + if op.x and op.y then + x = op.x + y = op.y + elseif op.animations then + entity:setAnimationsList(getAnimations(op.animations)) _,_,x,y = bg:getAnimation()[1]:getViewport() bg:setPosition(x / -2, y / -2) + else + local image = love.graphics.newImage(imagePath) + x = image:getWidth() / -2 + y = image:getHeight() / -2 + end + entity:setPosition(x, y) + + local layer = self.layers.decorations + if op.ratio then + layer = self:addLayer(width, height) + layer.transformRatio = op.ratio + if op.background then + layer.transformScale = getRealScale() + end end - bg.layer = self:addLayer(width, height) - bg.layer.transformRatio = op.ratio - bg.layer.transformScale = getRealScale() + entity.layer = layer + + self:insertEntity(entity) end if op.clouds then - local width, height = love.graphics.getDimensions() - local animations = op.animations - if type(animations) == "string" then - animations = require("config.animations." .. animations) - end + local animations = getAnimations(op.animations) local cg = CloudGenerator(op.clouds, animations, op.count, self) if op.ratio then cg.layer = self:addLayer(width, height) -- cgit v1.1 From 4d2d55b4fcd22a8a66be1ece5c2d1faad867a788 Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 20 Sep 2017 16:56:51 +0200 Subject: Removed obsolete create methods --- not/Sprite.lua | 1 + not/World.lua | 15 --------------- 2 files changed, 1 insertion(+), 15 deletions(-) (limited to 'not') diff --git a/not/Sprite.lua b/not/Sprite.lua index 33b8ac8..ec23eac 100644 --- a/not/Sprite.lua +++ b/not/Sprite.lua @@ -11,6 +11,7 @@ Sprite.frame = 1 Sprite.delay = .1 -- Constructor of `Sprite`. +-- TODO: Sprites' in general don't take actual Image in constructor. That is not only case of Decoration. function Sprite:new (imagePath) if type(imagePath) == "string" then self:setImage(Sprite.newImage(imagePath)) diff --git a/not/World.lua b/not/World.lua index 4e5b52f..730f696 100644 --- a/not/World.lua +++ b/not/World.lua @@ -205,13 +205,6 @@ function World:addLayer (width, height) end -- TODO: Standardize `create*` methods with corresponding constructors. Pay attention to both params' order and names. -function World:createPlatform (x, y, polygon, sprite, animations) - local p = Platform(animations, polygon, x, y, self, sprite) - table.insert(self.entities, p) - p.layer = self.layers.platforms - return p -end - function World:createNaut (x, y, name) local h = Player(name, x, y, self) table.insert(self.entities, h) @@ -219,14 +212,6 @@ function World:createNaut (x, y, name) return h end --- TODO: Sprites' in general don't take actual Image in constructor. That is not only case of Decoration. -function World:createDecoration (x, y, sprite) - local d = Decoration(x, y, self, sprite) - table.insert(self.entities, d) - d.layer = self.layers.decorations - return d -end - function World:createEffect (name, x, y) local e = Effect(name, x, y, self) table.insert(self.entities, e) -- cgit v1.1 From af3696fd814baa786b66659e4c00410731fe292b Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 21 Sep 2017 16:04:32 +0200 Subject: Yeah, commit for comment --- not/World.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index 730f696..dc856d0 100644 --- a/not/World.lua +++ b/not/World.lua @@ -111,6 +111,7 @@ end --- Builds map using one of tables frin config files located in `config/maps/` directory. -- TODO: Clean World@buildMap. Possibly explode into more methods. +-- TODO: Move buildMap along with getAnimations to Factory. function World:buildMap () local width, height = love.graphics.getDimensions() -- cgit v1.1 From 453095b2e0b34cc4bd24671bc8abe6ff9279a318 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 21 Sep 2017 16:06:53 +0200 Subject: Flames animations moved to separate config file --- not/Trap.lua | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) (limited to 'not') diff --git a/not/Trap.lua b/not/Trap.lua index 84de5b0..47c3f09 100644 --- a/not/Trap.lua +++ b/not/Trap.lua @@ -1,30 +1,8 @@ Trap = require "not.PhysicalBody":extends() --- TODO: Move flames' animations to config file. -local animations = { - default = { - [1] = love.graphics.newQuad(0, 0, 42, 19, 168, 19), - [2] = love.graphics.newQuad(42, 0, 42, 19, 168, 19), - frames = 2, - repeated = true - }, - fadein = { - [1] = love.graphics.newQuad(84, 0, 42, 19, 168, 19), - [2] = love.graphics.newQuad(126, 0, 42, 19, 168, 19), - frames = 2, - repeated = false - }, - fadeout = { - [1] = love.graphics.newQuad(126, 0, 42, 19, 168, 19), - [2] = love.graphics.newQuad(84, 0, 42, 19, 168, 19), - frames = 2, - repeated = false - } -} - function Trap:new (direction, x, y, world, imagePath) Trap.__super.new(self, x, y, world, imagePath) - self:setAnimationsList(animations) + self:setAnimationsList(require("config.animations.flames")) self:setBodyType("static") local mirror = 1 -- cgit v1.1 From f60ee890682b9dbecb7dace030862dcdc46d2dc6 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 21 Sep 2017 17:19:42 +0200 Subject: Changed Trap collision category, added category constants to Box2D callbacks --- not/Trap.lua | 6 +++--- not/World.lua | 39 ++++++++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 16 deletions(-) (limited to 'not') diff --git a/not/Trap.lua b/not/Trap.lua index 47c3f09..2a328d6 100644 --- a/not/Trap.lua +++ b/not/Trap.lua @@ -8,9 +8,9 @@ function Trap:new (direction, x, y, world, imagePath) local mirror = 1 if direction == "left" then mirror = -1 end local fixture = self:addFixture({0, 0, 41 * mirror, 0, 41 * mirror, 18, 0, 18}) - fixture:setCategory(3) - fixture:setMask(1) - fixture:setUserData({0, direction}) + fixture:setCategory(4) + fixture:setMask(1,3,4) + fixture:setUserData({direction}) fixture:setSensor(true) self.mirror = mirror diff --git a/not/World.lua b/not/World.lua index dc856d0..c656ac8 100644 --- a/not/World.lua +++ b/not/World.lua @@ -405,27 +405,29 @@ function World:getContactCallbacks () return b, e end --- TODO: Review current state of Box2D callbacks (again). --- TODO: Stop using magical numbers in Box2D callbacks. --- [1] -> Platform --- [2] -> Hero --- [3] -> Punch sensor +-- TODO: Move these constants to a proper place (I have no idea where proper place is). +local COLL_HERO = 2 +local COLL_PLATFORM = 1 +local COLL_PUNCH = 3 +local COLL_TRAP = 4 + +-- TODO: Review current state of both Box2D callbacks (again). function World:beginContact (a, b, coll) - if a:getCategory() == 1 then + if a:getCategory() == COLL_PLATFORM then local x,y = coll:getNormal() if y < -0.6 then b:getUserData():land() end local vx, vy = b:getUserData().body:getLinearVelocity() - if math.abs(x) == 1 or (y < -0.6 and x == 0) then + if math.abs(x) == COLL_PLATFORM or (y < -0.6 and x == 0) then b:getUserData():playSound(3) end end - if a:getCategory() == 3 then - if b:getCategory() == 2 then + if a:getCategory() == COLL_PUNCH then + if b:getCategory() == COLL_HERO then b:getUserData():damage(a:getUserData()[2]) end - if b:getCategory() == 3 then + if b:getCategory() == COLL_PUNCH then a:getBody():getUserData():damage(b:getUserData()[2]) b:getBody():getUserData():damage(a:getUserData()[2]) local x1,y1 = b:getBody():getUserData():getPosition() @@ -435,14 +437,25 @@ function World:beginContact (a, b, coll) self:createEffect("clash", x, y) end end - if b:getCategory() == 3 then - if a:getCategory() == 2 then + if b:getCategory() == COLL_PUNCH then + if a:getCategory() == COLL_HERO then a:getUserData():damage(b:getUserData()[2]) end end + if a:getCategory() == COLL_TRAP then + if b:getCategory() == COLL_HERO then + b:getUserData():damage(a:getUserData()[1]) + end + end + if b:getCategory() == COLL_TRAP then + if a:getCategory() == COLL_HERO then + a:getUserData():damage(b:getUserData()[1]) + end + end end + function World:endContact (a, b, coll) - if a:getCategory() == 1 then + if a:getCategory() == COLL_PLATFORM then b:getUserData().inAir = true end end -- cgit v1.1 From 99a968d29f580aabc5350e608e545f9162458f0e Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 21 Sep 2017 17:40:34 +0200 Subject: Removed obsolete hotfix for clashes in Traps --- not/Trap.lua | 3 --- 1 file changed, 3 deletions(-) (limited to 'not') diff --git a/not/Trap.lua b/not/Trap.lua index 2a328d6..0867a36 100644 --- a/not/Trap.lua +++ b/not/Trap.lua @@ -48,7 +48,4 @@ function Trap:goToNextFrame () end end --- TODO: Trap@damage is hotfix for clashing. -function Trap:damage () end - return Trap -- cgit v1.1 From 5b69916da9b58818da16841a0213716c55b3f07a Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 21 Sep 2017 17:51:03 +0200 Subject: Debug drawing for Traps --- not/PhysicalBody.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'not') diff --git a/not/PhysicalBody.lua b/not/PhysicalBody.lua index 01a725b..5081836 100644 --- a/not/PhysicalBody.lua +++ b/not/PhysicalBody.lua @@ -62,20 +62,27 @@ function PhysicalBody:update (dt) PhysicalBody.__super.update(self, dt) end --- Draw of `PhysicalBody`. function PhysicalBody:draw (debug) PhysicalBody.__super.draw(self, debug) if debug then for _,fixture in pairs(self.body:getFixtureList()) do local category = fixture:getCategory() + -- TODO: Fixture drawing of PhysicalBodies could take activity into account in every case. if category == 1 then - love.graphics.setColor(255, 69, 0, 140) + love.graphics.setColor(255, 69, 0, 150) end if category == 2 then - love.graphics.setColor(137, 255, 0, 120) + love.graphics.setColor(137, 255, 0, 150) end if category == 3 then - love.graphics.setColor(137, 0, 255, 40) + love.graphics.setColor(137, 0, 255, 50) + end + if category == 4 then + if self.body:isActive() then + love.graphics.setColor(255, 230, 0, 50) + else + love.graphics.setColor(255, 230, 0, 10) + end end local camera = self.world.camera love.graphics.polygon("fill", self.body:getWorldPoints(fixture:getShape():getPoints())) -- cgit v1.1 From b97985def64b8bd8f93a7b391b12333595432e52 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 21 Sep 2017 17:54:02 +0200 Subject: It would work, but it wasn't intended --- not/World.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not') diff --git a/not/World.lua b/not/World.lua index c656ac8..4523efa 100644 --- a/not/World.lua +++ b/not/World.lua @@ -419,7 +419,7 @@ function World:beginContact (a, b, coll) b:getUserData():land() end local vx, vy = b:getUserData().body:getLinearVelocity() - if math.abs(x) == COLL_PLATFORM or (y < -0.6 and x == 0) then + if math.abs(x) == 1 or (y < -0.6 and x == 0) then b:getUserData():playSound(3) end end -- cgit v1.1