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/World.lua') 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 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/World.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'not/World.lua') 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/World.lua') 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/World.lua') 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/World.lua') 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/World.lua') 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 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/World.lua') 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 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/World.lua') 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 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/World.lua | 85 ++++++++++++++++++++++------------------------------------- 1 file changed, 31 insertions(+), 54 deletions(-) (limited to 'not/World.lua') 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/World.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'not/World.lua') 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/World.lua') 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 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/World.lua') 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/World.lua') 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 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/World.lua') 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/World.lua') 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/World.lua | 116 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 60 insertions(+), 56 deletions(-) (limited to 'not/World.lua') 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/World.lua | 66 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 32 insertions(+), 34 deletions(-) (limited to 'not/World.lua') 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/World.lua') 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/World.lua | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'not/World.lua') 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/World.lua | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'not/World.lua') 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 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/World.lua') 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/World.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'not/World.lua') 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/World.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'not/World.lua') 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/World.lua | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'not/World.lua') 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 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/World.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'not/World.lua') 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/World.lua | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) (limited to 'not/World.lua') 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/World.lua | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'not/World.lua') 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 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/World.lua') 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/World.lua') 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/World.lua') 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/World.lua') 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 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/World.lua') 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/World.lua | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'not/World.lua') 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/World.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'not/World.lua') 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/World.lua') 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 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/World.lua | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'not/World.lua') 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/World.lua') 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 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/World.lua | 4 ---- 1 file changed, 4 deletions(-) (limited to 'not/World.lua') 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/World.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'not/World.lua') 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/World.lua') 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/World.lua') 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/World.lua') 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/World.lua') 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/World.lua') 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/World.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'not/World.lua') 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/World.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'not/World.lua') 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/World.lua | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'not/World.lua') 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/World.lua | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'not/World.lua') 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 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/World.lua') 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/World.lua') 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/World.lua') 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/World.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'not/World.lua') 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/World.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'not/World.lua') 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/World.lua | 61 ++++++++++++++++++++++++----------------------------------- 1 file changed, 25 insertions(+), 36 deletions(-) (limited to 'not/World.lua') 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/World.lua') 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 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/World.lua') 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 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/World.lua | 80 ++++++++++++++--------------------------------------------- 1 file changed, 18 insertions(+), 62 deletions(-) (limited to 'not/World.lua') 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/World.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'not/World.lua') 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 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/World.lua') 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/World.lua | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'not/World.lua') 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/World.lua') 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 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/World.lua | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) (limited to 'not/World.lua') 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 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/World.lua') 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