From 84278ed41f61c586dbb38dd99c45ee33e2f58c77 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 16 Mar 2017 19:05:50 +0100 Subject: Moved ? -> not.?; Renamed Player -> Hero --- not/World.lua | 424 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 424 insertions(+) create mode 100644 not/World.lua (limited to 'not/World.lua') diff --git a/not/World.lua b/not/World.lua new file mode 100644 index 0000000..5afc5bf --- /dev/null +++ b/not/World.lua @@ -0,0 +1,424 @@ +-- `World` +-- Used to manage physical world and everything inside it: clouds, platforms, nauts, background etc. + +-- WHOLE CODE HAS FLAG OF "need a cleanup" + +require "not.Platform" +require "not.Hero" +require "not.Cloud" +require "not.Effect" +require "not.Decoration" +require "ray" + +-- Metatable of `World` +-- nils initialized in constructor +World = { + -- inside + world = nil, + Nauts = nil, + Platforms = nil, + Clouds = nil, + Decorations = nil, + Effects = nil, + Rays = nil, + camera = nil, + -- cloud generator + clouds_delay = 5, + -- Map + map = nil, + background = nil, + -- Gameplay status + lastNaut = false, + -- "WINNER" + win_move = 0, + -- Music + music = nil +} + +-- Constructor of `World` ZA WARUDO! +function World:new(map, nauts) + -- Meta + local o = {} + setmetatable(o, self) + self.__index = self + -- Physical world initialization + love.physics.setMeter(64) + o.world = love.physics.newWorld(0, 9.81*64, true) + o.world:setCallbacks(o.beginContact, o.endContact) + -- Empty tables for objects + local n = {} + o.Nauts = n + local p = {} + o.Platforms = {} + local c = {} + o.Clouds = c + local e = {} + o.Effects = e + local d = {} + o.Decorations = d + local r = {} + o.Rays = r + -- Random init + math.randomseed(os.time()) + -- Map + local map = map or "default" + o:loadMap(map) + -- Nauts + o:spawnNauts(nauts) + -- Create camera + o.camera = Camera:new(o) + -- Play music + o.music = Music:new(o.map.theme) + return o +end + +-- The end of the world +function World:delete() + self.world:destroy() + for _,platform in pairs(self.Platforms) do + platform:delete() + end + for _,naut in pairs(self.Nauts) do + naut:delete() + end + self.music:delete() + self = nil +end + +-- Load map from file +function World:loadMap(name) + local name = name or "default" + name = "maps/" .. name .. ".lua" + local map = love.filesystem.load(name) + self.map = map() + -- Platforms + for _,platform in pairs(self.map.platforms) do + self:createPlatform(platform.x, platform.y, platform.shape, platform.sprite, platform.animations) + end + -- Decorations + for _,decoration in pairs(self.map.decorations) do + self:createDecoration(decoration.x, decoration.y, decoration.sprite) + end + -- Background + self.background = love.graphics.newImage(self.map.background) + -- Clouds + if self.map.clouds then + for i=1,6 do + self:randomizeCloud(false) + end + end +end + +-- Spawn all the nauts for the round +function World:spawnNauts(nauts) + for _,naut in pairs(nauts) do + local x,y = self:getSpawnPosition() + local spawn = self:createNaut(x, y, naut[1]) + spawn:assignControlSet(naut[2]) + end +end + +-- Get respawn location +function World:getSpawnPosition() + local n = math.random(1, #self.map.respawns) + return self.map.respawns[n].x, self.map.respawns[n].y +end + +-- Add new platform to the world +function World:createPlatform(x, y, polygon, sprite, animations) + table.insert(self.Platforms, Platform:new(self, self.world, x, y, polygon, sprite, animations)) +end + +-- Add new naut to the world +function World:createNaut(x, y, name) + local naut = Hero:new(self, self.world, x, y, name) + table.insert(self.Nauts, naut) + return naut +end + +-- Add new decoration to the world +function World:createDecoration(x, y, sprite) + table.insert(self.Decorations, Decoration:new(x, y, sprite)) +end + +-- Add new cloud to the world +function World:createCloud(x, y, t, v) + table.insert(self.Clouds, Cloud:new(x, y, t, v)) +end + +-- Randomize Cloud creation +function World:randomizeCloud(outside) + if outside == nil then + outside = true + else + outside = outside + end + local x,y,t,v + local m = self.map + if outside then + x = m.center_x-m.width*1.2+math.random(-50,20) + else + x = math.random(m.center_x-m.width/2,m.center_x+m.width/2) + end + y = math.random(m.center_y-m.height/2, m.center_y+m.height/2) + t = math.random(1,3) + v = math.random(8,18) + self:createCloud(x, y, t, v) +end + +-- Add an effect behind nauts +function World:createEffect(name, x, y) + table.insert(self.Effects, Effect:new(name, x, y)) +end + +-- Add a ray +function World:createRay(naut) + table.insert(self.Rays, Ray:new(naut, self)) +end + +-- get Nauts functions +-- more than -1 lives +function World:getNautsPlayable() + local nauts = {} + for _,naut in pairs(self.Nauts) do + if naut.lives > -1 then + table.insert(nauts, naut) + end + end + return nauts +end +-- are alive +function World:getNautsAlive() + local nauts = {} + for _,naut in self.Nauts do + if naut.alive then + table.insert(nauts, naut) + end + end + return nauts +end +-- all of them +function World:getNautsAll() + return self.Nauts +end + +-- get Map name +function World:getMapName() + return self.map.name +end + +-- Event: when player is killed +function World:onNautKilled(naut) + self.camera:startShake() + self:createRay(naut) + local nauts = self:getNautsPlayable() + if self.lastNaut then + changeScene(Menu:new()) + elseif #nauts < 2 then + self.lastNaut = true + naut:playSound(5, true) + end +end + +function World:getBounce(f) + local f = f or 1 + return math.sin(self.win_move*f*math.pi) +end + +-- LÖVE2D callbacks +-- Update ZU WARUDO +function World:update(dt) + -- Physical world + self.world:update(dt) + -- Camera + self.camera:update(dt) + -- Engine world: Nauts, Grounds (kek) and Decorations - all Animateds (top kek) + for _,naut in pairs(self.Nauts) do + naut:update(dt) + end + for _,platform in pairs(self.Platforms) do + platform:update(dt) + end + for _,decoration in pairs(self.Decorations) do + decoration:update(dt) + end + -- Clouds + if self.map.clouds then + -- generator + local n = table.getn(self.Clouds) + self.clouds_delay = self.clouds_delay - dt + if self.clouds_delay < 0 and + n < 18 + then + self:randomizeCloud() + self.clouds_delay = self.clouds_delay + World.clouds_delay -- World.clouds_delay is initial + end + -- movement + for _,cloud in pairs(self.Clouds) do + if cloud:update(dt) > 340 then + table.remove(self.Clouds, _) + end + end + end + -- Effects + for _,effect in pairs(self.Effects) do + if effect:update(dt) then + table.remove(self.Effects, _) + end + end + -- Rays + for _,ray in pairs(self.Rays) do + if ray:update(dt) then + table.remove(self.Rays, _) + end + end + -- Bounce `winner` + self.win_move = self.win_move + dt + if self.win_move > 2 then + self.win_move = self.win_move - 2 + end +end +-- Draw +function World:draw() + -- Camera stuff + local offset_x, offset_y = self.camera:getOffsets() + local scale = self.camera.scale + local scaler = self.camera.scaler + + -- Background + love.graphics.draw(self.background, 0, 0, 0, scaler, scaler) + + -- This needs to be reworked! + -- Draw clouds + for _,cloud in pairs(self.Clouds) do + cloud:draw(offset_x, offset_y, scale) + end + + -- Draw decorations + for _,decoration in pairs(self.Decorations) do + decoration:draw(offset_x, offset_y, scale) + end + + -- Draw effects + for _,effect in pairs(self.Effects) do + effect:draw(offset_x,offset_y, scale) + end + + -- Draw player + for _,naut in pairs(self.Nauts) do + naut:draw(offset_x, offset_y, scale, debug) + end + + -- Draw ground + for _,platform in pairs(self.Platforms) do + platform:draw(offset_x, offset_y, scale, debug) + end + + -- Draw rays + for _,ray in pairs(self.Rays) do + ray:draw(offset_x, offset_y, scale) + end + + -- draw center + if debug then + local c = self.camera + local w, h = love.graphics.getWidth(), love.graphics.getHeight() + -- draw map center + love.graphics.setColor(130,130,130) + love.graphics.setLineWidth(1) + love.graphics.setLineStyle("rough") + local cx, cy = c:getPositionScaled() + local x1, y1 = c:translatePosition(self.map.center_x, cy) + local x2, y2 = c:translatePosition(self.map.center_x, cy+h) + love.graphics.line(x1,y1,x2,y2) + local x1, y1 = c:translatePosition(cx, self.map.center_y) + local x2, y2 = c:translatePosition(cx+w, self.map.center_y) + love.graphics.line(x1,y1,x2,y2) + -- draw ox, oy + love.graphics.setColor(200,200,200) + love.graphics.setLineStyle("rough") + local cx, cy = c:getPositionScaled() + local x1, y1 = c:translatePosition(0, cy) + local x2, y2 = c:translatePosition(0, cy+h) + love.graphics.line(x1,y1,x2,y2) + local x1, y1 = c:translatePosition(cx, 0) + local x2, y2 = c:translatePosition(cx+w, 0) + love.graphics.line(x1,y1,x2,y2) + end + + -- Draw HUDs + for _,naut in pairs(self.Nauts) do + -- I have no idea where to place them T_T + -- let's do: bottom-left, bottom-right, top-left, top-right + local w, h = love.graphics.getWidth()/scale, love.graphics.getHeight()/scale + local y, e = 1, 1 + if _ < 3 then y, e = h-33, 0 end + naut:drawHUD(1+(_%2)*(w-34), y, scale, e) + end + + -- Draw winner + if self.lastNaut then + local w, h = love.graphics.getWidth()/scale, love.graphics.getHeight()/scale + local angle = self:getBounce(2) + local dy = self:getBounce()*3 + love.graphics.setFont(Bold) + love.graphics.printf("WINNER",(w/2)*scale,(42+dy)*scale,336,"center",(angle*5)*math.pi/180,scale,scale,168,12) + love.graphics.setFont(Font) + love.graphics.printf("rofl, now kill yourself", w/2*scale, 18*scale, 160, "center", 0, scale, scale, 80, 3) + end +end + +-- Box2D callbacks +-- beginContact +function World.beginContact(a, b, coll) + if a:getCategory() == 1 then + local x,y = coll:getNormal() + if y < -0.6 then + print(b:getUserData().name .. " is not in air") + -- Move them to Hero + b:getUserData().inAir = false + b:getUserData().jumpnumber = 2 + b:getUserData().salto = false + b:getUserData():createEffect("land") + end + local vx, vy = b:getUserData().body:getLinearVelocity() + if math.abs(x) == 1 or (y < -0.6 and x == 0) then + b:getUserData():playSound(3) + end + end + if a:getCategory() == 3 then + b:getUserData():damage(a:getUserData()[2]) + end + if b:getCategory() == 3 then + a:getUserData():damage(b:getUserData()[2]) + end +end +-- endContact +function World.endContact(a, b, coll) + if a:getCategory() == 1 then + print(b:getUserData().name .. " is in air") + -- Move them to Hero + b:getUserData().inAir = true + end +end + +-- Controller callbacks +function World:controlpressed(set, action, key) + if key == "f6" and debug then + local map = self:getMapName() + local nauts = {} + for _,naut in pairs(self:getNautsAll()) do + table.insert(nauts, {naut.name, naut:getControlSet()}) + end + local new = World:new(map, nauts) + changeScene(new) + end + for k,naut in pairs(self:getNautsAll()) do + naut:controlpressed(set, action, key) + end +end +function World:controlreleased(set, action, key) + for k,naut in pairs(self:getNautsAll()) do + naut:controlreleased(set, action, key) + end +end \ No newline at end of file -- cgit v1.1 From c16c1206f5884614157b8f5049e601ff77478d7f Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 17 Mar 2017 18:35:54 +0100 Subject: Ray renamed and moved --- not/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 5afc5bf..6d81918 100644 --- a/not/World.lua +++ b/not/World.lua @@ -8,7 +8,7 @@ require "not.Hero" require "not.Cloud" require "not.Effect" require "not.Decoration" -require "ray" +require "not.Ray" -- Metatable of `World` -- nils initialized in constructor -- cgit v1.1 From b4389dfb590862b50cc6c9ce59d3fcef9bd046b3 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 20:11:21 +0200 Subject: World comments, other comments, todos --- not/World.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'not/World.lua') diff --git a/not/World.lua b/not/World.lua index 6d81918..216f9dd 100644 --- a/not/World.lua +++ b/not/World.lua @@ -1,5 +1,6 @@ -- `World` -- Used to manage physical world and everything inside it: clouds, platforms, nauts, background etc. +-- TODO: Possibly move common parts of `World` and `Menu` to abstract class `Scene`. -- WHOLE CODE HAS FLAG OF "need a cleanup" @@ -36,6 +37,7 @@ World = { } -- Constructor of `World` ZA WARUDO! +-- TODO: push stuff to initialization method. function World:new(map, nauts) -- Meta local o = {} @@ -46,6 +48,7 @@ function World:new(map, nauts) o.world = love.physics.newWorld(0, 9.81*64, true) o.world:setCallbacks(o.beginContact, o.endContact) -- Empty tables for objects + -- TODO: DEAR DEER, do you see it? local n = {} o.Nauts = n local p = {} @@ -58,7 +61,7 @@ function World:new(map, nauts) o.Decorations = d local r = {} o.Rays = r - -- Random init + -- Random init; TODO: use LOVE2D's random. math.randomseed(os.time()) -- Map local map = map or "default" @@ -86,6 +89,7 @@ function World:delete() end -- Load map from file +-- TODO: Change current map model to function-based one. function World:loadMap(name) local name = name or "default" name = "maps/" .. name .. ".lua" @@ -125,11 +129,14 @@ function World:getSpawnPosition() end -- Add new platform to the world +-- TODO: follow new parameters in `not.Platform.new` based on `not.Platform.init`. function World:createPlatform(x, y, polygon, sprite, animations) table.insert(self.Platforms, Platform:new(self, self.world, x, y, polygon, sprite, animations)) end -- Add new naut to the world +-- TODO: separate two methods for `not.Hero` and `not.Player`. +-- TODO: follow new parameters in `not.Player.new` based on `not.Player.init`. function World:createNaut(x, y, name) local naut = Hero:new(self, self.world, x, y, name) table.insert(self.Nauts, naut) @@ -137,11 +144,14 @@ function World:createNaut(x, y, name) end -- Add new decoration to the world +-- TODO: follow new parameters in `not.Decoration.new` based on `not.Decoration.init`. function World:createDecoration(x, y, sprite) table.insert(self.Decorations, Decoration:new(x, y, sprite)) end -- Add new cloud to the world +-- TODO: extend variables names to provide better readability. +-- TODO: follow new parameters in `not.Cloud.new` based on `not.Cloud.init`. function World:createCloud(x, y, t, v) table.insert(self.Clouds, Cloud:new(x, y, t, v)) end @@ -167,6 +177,8 @@ function World:randomizeCloud(outside) end -- Add an effect behind nauts +-- TODO: follow new parameters in `not.Effect.new` based on `not.Effect.init`. +-- TODO: along with `createRay` move this nearer reast of `create*` methods for readability. function World:createEffect(name, x, y) table.insert(self.Effects, Effect:new(name, x, y)) end @@ -288,7 +300,7 @@ function World:draw() -- Background love.graphics.draw(self.background, 0, 0, 0, scaler, scaler) - -- This needs to be reworked! + -- TODO: this needs to be reworked! -- Draw clouds for _,cloud in pairs(self.Clouds) do cloud:draw(offset_x, offset_y, scale) @@ -403,6 +415,7 @@ function World.endContact(a, b, coll) end -- Controller callbacks +-- TODO: names of this methods don't follow naming patterns in this project. See `Controller` and change it. function World:controlpressed(set, action, key) if key == "f6" and debug then local map = self:getMapName() -- cgit v1.1 From cd025014eac8d1adf70bc3238de5c034dea80c78 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 23:56:03 +0200 Subject: Renamed jumping-related variables, removed obsoletes. --- not/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 216f9dd..b7bd48c 100644 --- a/not/World.lua +++ b/not/World.lua @@ -386,10 +386,12 @@ function World.beginContact(a, b, coll) if a:getCategory() == 1 then local x,y = coll:getNormal() if y < -0.6 then + -- TODO: remove debug messages + -- TODO: move landing to `not.Hero` print(b:getUserData().name .. " is not in air") -- Move them to Hero b:getUserData().inAir = false - b:getUserData().jumpnumber = 2 + b:getUserData().jumpCounter = 2 b:getUserData().salto = false b:getUserData():createEffect("land") end -- cgit v1.1 From 5c51b6e4d39bc55887f94dc65e58fd1765d86c1c Mon Sep 17 00:00:00 2001 From: Aki Date: Tue, 4 Apr 2017 14:30:15 +0200 Subject: First steps to move player-input logics into Player from Hero --- not/World.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'not/World.lua') diff --git a/not/World.lua b/not/World.lua index b7bd48c..44923bb 100644 --- a/not/World.lua +++ b/not/World.lua @@ -5,7 +5,7 @@ -- WHOLE CODE HAS FLAG OF "need a cleanup" require "not.Platform" -require "not.Hero" +require "not.Player" require "not.Cloud" require "not.Effect" require "not.Decoration" @@ -136,9 +136,9 @@ end -- Add new naut to the world -- TODO: separate two methods for `not.Hero` and `not.Player`. --- TODO: follow new parameters in `not.Player.new` based on `not.Player.init`. +-- TODO: follow new parameters in `not.(Player/Hero).new` based on `not.(Player/Hero).init`. function World:createNaut(x, y, name) - local naut = Hero:new(self, self.world, x, y, name) + local naut = Player:new(self, self.world, x, y, name) table.insert(self.Nauts, naut) return naut end -- cgit v1.1 From 8e11bf89f1abe547c30f7d5ac39bf0d7ed555f7e Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 5 Apr 2017 18:43:14 +0200 Subject: Some of World's create methods are now following new parameter orders of entities constructors --- not/World.lua | 57 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) (limited to 'not/World.lua') diff --git a/not/World.lua b/not/World.lua index 44923bb..fc5e229 100644 --- a/not/World.lua +++ b/not/World.lua @@ -38,7 +38,7 @@ World = { -- Constructor of `World` ZA WARUDO! -- TODO: push stuff to initialization method. -function World:new(map, nauts) +function World:new (map, nauts) -- Meta local o = {} setmetatable(o, self) @@ -76,7 +76,7 @@ function World:new(map, nauts) end -- The end of the world -function World:delete() +function World:delete () self.world:destroy() for _,platform in pairs(self.Platforms) do platform:delete() @@ -90,7 +90,7 @@ end -- Load map from file -- TODO: Change current map model to function-based one. -function World:loadMap(name) +function World:loadMap (name) local name = name or "default" name = "maps/" .. name .. ".lua" local map = love.filesystem.load(name) @@ -114,7 +114,7 @@ function World:loadMap(name) end -- Spawn all the nauts for the round -function World:spawnNauts(nauts) +function World:spawnNauts (nauts) for _,naut in pairs(nauts) do local x,y = self:getSpawnPosition() local spawn = self:createNaut(x, y, naut[1]) @@ -123,41 +123,40 @@ function World:spawnNauts(nauts) end -- Get respawn location -function World:getSpawnPosition() +function World:getSpawnPosition () local n = math.random(1, #self.map.respawns) return self.map.respawns[n].x, self.map.respawns[n].y end -- Add new platform to the world --- TODO: follow new parameters in `not.Platform.new` based on `not.Platform.init`. -function World:createPlatform(x, y, polygon, sprite, animations) - table.insert(self.Platforms, Platform:new(self, self.world, x, y, polygon, sprite, animations)) +-- TODO: it would be nice if function parameters would be same as `not.Platform.new`. +function World:createPlatform (x, y, polygon, sprite, animations) + table.insert(self.Platforms, Platform:new(animations, polygon, self, x, y, sprite)) end -- Add new naut to the world -- TODO: separate two methods for `not.Hero` and `not.Player`. --- TODO: follow new parameters in `not.(Player/Hero).new` based on `not.(Player/Hero).init`. -function World:createNaut(x, y, name) - local naut = Player:new(self, self.world, x, y, name) +function World:createNaut (x, y, name) + local naut = Player:new(name, self, x, y) table.insert(self.Nauts, naut) return naut end -- Add new decoration to the world --- TODO: follow new parameters in `not.Decoration.new` based on `not.Decoration.init`. -function World:createDecoration(x, y, sprite) +-- TODO: `not.World.create*` functions often have different naming for parameters. It is not ground-breaking but it makes reading code harder for no good reason. +function World:createDecoration (x, y, sprite) table.insert(self.Decorations, Decoration:new(x, y, sprite)) end -- Add new cloud to the world -- TODO: extend variables names to provide better readability. -- TODO: follow new parameters in `not.Cloud.new` based on `not.Cloud.init`. -function World:createCloud(x, y, t, v) +function World:createCloud (x, y, t, v) table.insert(self.Clouds, Cloud:new(x, y, t, v)) end -- Randomize Cloud creation -function World:randomizeCloud(outside) +function World:randomizeCloud (outside) if outside == nil then outside = true else @@ -179,18 +178,18 @@ end -- Add an effect behind nauts -- TODO: follow new parameters in `not.Effect.new` based on `not.Effect.init`. -- TODO: along with `createRay` move this nearer reast of `create*` methods for readability. -function World:createEffect(name, x, y) +function World:createEffect (name, x, y) table.insert(self.Effects, Effect:new(name, x, y)) end -- Add a ray -function World:createRay(naut) +function World:createRay (naut) table.insert(self.Rays, Ray:new(naut, self)) end -- get Nauts functions -- more than -1 lives -function World:getNautsPlayable() +function World:getNautsPlayable () local nauts = {} for _,naut in pairs(self.Nauts) do if naut.lives > -1 then @@ -200,7 +199,7 @@ function World:getNautsPlayable() return nauts end -- are alive -function World:getNautsAlive() +function World:getNautsAlive () local nauts = {} for _,naut in self.Nauts do if naut.alive then @@ -210,17 +209,17 @@ function World:getNautsAlive() return nauts end -- all of them -function World:getNautsAll() +function World:getNautsAll () return self.Nauts end -- get Map name -function World:getMapName() +function World:getMapName () return self.map.name end -- Event: when player is killed -function World:onNautKilled(naut) +function World:onNautKilled (naut) self.camera:startShake() self:createRay(naut) local nauts = self:getNautsPlayable() @@ -232,14 +231,14 @@ function World:onNautKilled(naut) end end -function World:getBounce(f) +function World:getBounce (f) local f = f or 1 return math.sin(self.win_move*f*math.pi) end -- LÖVE2D callbacks -- Update ZU WARUDO -function World:update(dt) +function World:update (dt) -- Physical world self.world:update(dt) -- Camera @@ -291,7 +290,7 @@ function World:update(dt) end end -- Draw -function World:draw() +function World:draw () -- Camera stuff local offset_x, offset_y = self.camera:getOffsets() local scale = self.camera.scale @@ -382,7 +381,7 @@ end -- Box2D callbacks -- beginContact -function World.beginContact(a, b, coll) +function World.beginContact (a, b, coll) if a:getCategory() == 1 then local x,y = coll:getNormal() if y < -0.6 then @@ -408,7 +407,7 @@ function World.beginContact(a, b, coll) end end -- endContact -function World.endContact(a, b, coll) +function World.endContact (a, b, coll) if a:getCategory() == 1 then print(b:getUserData().name .. " is in air") -- Move them to Hero @@ -418,7 +417,7 @@ end -- Controller callbacks -- TODO: names of this methods don't follow naming patterns in this project. See `Controller` and change it. -function World:controlpressed(set, action, key) +function World:controlpressed (set, action, key) if key == "f6" and debug then local map = self:getMapName() local nauts = {} @@ -432,7 +431,7 @@ function World:controlpressed(set, action, key) naut:controlpressed(set, action, key) end end -function World:controlreleased(set, action, key) +function World:controlreleased (set, action, key) for k,naut in pairs(self:getNautsAll()) do naut:controlreleased(set, action, key) end -- cgit v1.1 From 5ed018c810a5433851fefc2c45792de1da7e7ca8 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 01:01:07 +0200 Subject: Controller-related methods and variables in Player renamed --- not/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 fc5e229..8aa9d28 100644 --- a/not/World.lua +++ b/not/World.lua @@ -118,7 +118,7 @@ function World:spawnNauts (nauts) for _,naut in pairs(nauts) do local x,y = self:getSpawnPosition() local spawn = self:createNaut(x, y, naut[1]) - spawn:assignControlSet(naut[2]) + spawn:assignControllerSet(naut[2]) end end -- cgit v1.1 From 2508af1856d4b30678e11fa610c0449bf2135ed0 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 16:09:50 +0200 Subject: Hero.alive -> Hero.isAlive; World.init method --- not/World.lua | 81 ++++++++++++++++++++++++++--------------------------------- 1 file changed, 36 insertions(+), 45 deletions(-) (limited to 'not/World.lua') diff --git a/not/World.lua b/not/World.lua index 8aa9d28..6e57ac1 100644 --- a/not/World.lua +++ b/not/World.lua @@ -1,18 +1,6 @@ --- `World` +--- `World` -- Used to manage physical world and everything inside it: clouds, platforms, nauts, background etc. -- TODO: Possibly move common parts of `World` and `Menu` to abstract class `Scene`. - --- WHOLE CODE HAS FLAG OF "need a cleanup" - -require "not.Platform" -require "not.Player" -require "not.Cloud" -require "not.Effect" -require "not.Decoration" -require "not.Ray" - --- Metatable of `World` --- nils initialized in constructor World = { -- inside world = nil, @@ -23,6 +11,7 @@ World = { Effects = nil, Rays = nil, camera = nil, + isActive = true, -- cloud generator clouds_delay = 5, -- Map @@ -36,48 +25,54 @@ World = { music = nil } +World.__index = World + +require "not.Platform" +require "not.Player" +require "not.Cloud" +require "not.Effect" +require "not.Decoration" +require "not.Ray" + -- Constructor of `World` ZA WARUDO! -- TODO: push stuff to initialization method. function World:new (map, nauts) - -- Meta - local o = {} - setmetatable(o, self) - self.__index = self - -- Physical world initialization + local o = setmetatable({}, self) + o:init(map, nauts) + return o +end + +-- Init za warudo +function World:init (map, nauts) + -- Box2D physical world. love.physics.setMeter(64) - o.world = love.physics.newWorld(0, 9.81*64, true) - o.world:setCallbacks(o.beginContact, o.endContact) - -- Empty tables for objects - -- TODO: DEAR DEER, do you see it? + self.world = love.physics.newWorld(0, 9.81*64, true) + self.world:setCallbacks(self.beginContact, self.endContact) + -- Tables for entities. TODO: DEAR DEER, do you see it? local n = {} - o.Nauts = n + self.Nauts = n local p = {} - o.Platforms = {} + self.Platforms = {} local c = {} - o.Clouds = c + self.Clouds = c local e = {} - o.Effects = e + self.Effects = e local d = {} - o.Decorations = d + self.Decorations = d local r = {} - o.Rays = r + self.Rays = r -- Random init; TODO: use LOVE2D's random. math.randomseed(os.time()) - -- Map + -- Map and misc. local map = map or "default" - o:loadMap(map) - -- Nauts - o:spawnNauts(nauts) - -- Create camera - o.camera = Camera:new(o) - -- Play music - o.music = Music:new(o.map.theme) - return o + self:loadMap(map) + self:spawnNauts(nauts) + self.camera = Camera:new(self) + self.music = Music:new(self.map.theme) end -- The end of the world function World:delete () - self.world:destroy() for _,platform in pairs(self.Platforms) do platform:delete() end @@ -85,7 +80,7 @@ function World:delete () naut:delete() end self.music:delete() - self = nil + self.world:destroy() end -- Load map from file @@ -202,7 +197,7 @@ end function World:getNautsAlive () local nauts = {} for _,naut in self.Nauts do - if naut.alive then + if naut.isAlive then table.insert(nauts, naut) end end @@ -239,9 +234,8 @@ end -- LÖVE2D callbacks -- Update ZU WARUDO function World:update (dt) - -- Physical world + self.world:update(dt) - -- Camera self.camera:update(dt) -- Engine world: Nauts, Grounds (kek) and Decorations - all Animateds (top kek) for _,naut in pairs(self.Nauts) do @@ -385,9 +379,7 @@ function World.beginContact (a, b, coll) if a:getCategory() == 1 then local x,y = coll:getNormal() if y < -0.6 then - -- TODO: remove debug messages -- TODO: move landing to `not.Hero` - print(b:getUserData().name .. " is not in air") -- Move them to Hero b:getUserData().inAir = false b:getUserData().jumpCounter = 2 @@ -409,7 +401,6 @@ end -- endContact function World.endContact (a, b, coll) if a:getCategory() == 1 then - print(b:getUserData().name .. " is in air") -- Move them to Hero b:getUserData().inAir = true end -- cgit v1.1 From 970655737ce7f497f0725d28605fc296c9923a64 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 16:16:05 +0200 Subject: Hotfix for destroyed body crash --- not/World.lua | 2 -- 1 file changed, 2 deletions(-) (limited to 'not/World.lua') diff --git a/not/World.lua b/not/World.lua index 6e57ac1..d234413 100644 --- a/not/World.lua +++ b/not/World.lua @@ -11,7 +11,6 @@ World = { Effects = nil, Rays = nil, camera = nil, - isActive = true, -- cloud generator clouds_delay = 5, -- Map @@ -234,7 +233,6 @@ end -- LÖVE2D callbacks -- Update ZU WARUDO function World:update (dt) - self.world:update(dt) self.camera:update(dt) -- Engine world: Nauts, Grounds (kek) and Decorations - all Animateds (top kek) -- cgit v1.1 From 9a5b629d8c1719af62667235c59950862b46b771 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 18:30:42 +0200 Subject: World clean-up init and table --- not/World.lua | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) (limited to 'not/World.lua') diff --git a/not/World.lua b/not/World.lua index d234413..579fff2 100644 --- a/not/World.lua +++ b/not/World.lua @@ -2,15 +2,14 @@ -- Used to manage physical world and everything inside it: clouds, platforms, nauts, background etc. -- TODO: Possibly move common parts of `World` and `Menu` to abstract class `Scene`. World = { - -- inside - world = nil, - Nauts = nil, - Platforms = nil, - Clouds = nil, - Decorations = nil, - Effects = nil, - Rays = nil, - camera = nil, + world = --[[love.physics.newWorld]]nil, + Nauts = --[[{not.Hero}]]nil, + Platforms = --[[{not.Platform}]]nil, + Clouds = --[[{not.Cloud}]]nil, + Decorations = --[[{not.Decoration}]]nil, + Effects = --[[{not.Effect}]]nil, + Rays = --[[{not.Ray}]]nil, + camera = --[[not.Camera]]nil, -- cloud generator clouds_delay = 5, -- Map @@ -34,7 +33,6 @@ require "not.Decoration" require "not.Ray" -- Constructor of `World` ZA WARUDO! --- TODO: push stuff to initialization method. function World:new (map, nauts) local o = setmetatable({}, self) o:init(map, nauts) @@ -47,19 +45,13 @@ function World:init (map, nauts) love.physics.setMeter(64) self.world = love.physics.newWorld(0, 9.81*64, true) self.world:setCallbacks(self.beginContact, self.endContact) - -- Tables for entities. TODO: DEAR DEER, do you see it? - local n = {} - self.Nauts = n - local p = {} + -- Tables for entities. TODO: It is still pretty bad! + self.Nauts = {} self.Platforms = {} - local c = {} - self.Clouds = c - local e = {} - self.Effects = e - local d = {} - self.Decorations = d - local r = {} - self.Rays = r + self.Clouds = {} + self.Effects = {} + self.Decorations = {} + self.Rays = {} -- Random init; TODO: use LOVE2D's random. math.randomseed(os.time()) -- Map and misc. -- cgit v1.1 From 4cf1755d05a63452feca03d2e380b149fcaa76c2 Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 6 Apr 2017 18:40:27 +0200 Subject: Moved music.lua, cleaned-up its code; Fixed requires for main, World and Menu --- 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 579fff2..2a6106c 100644 --- a/not/World.lua +++ b/not/World.lua @@ -31,6 +31,7 @@ require "not.Cloud" require "not.Effect" require "not.Decoration" require "not.Ray" +require "not.Music" -- Constructor of `World` ZA WARUDO! function World:new (map, nauts) -- cgit v1.1 From 54e85dd188af15cd5f3f5e08f5d3e69088a909b1 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 7 Apr 2017 03:06:26 +0200 Subject: Moved map configs to config directory --- not/World.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'not/World.lua') diff --git a/not/World.lua b/not/World.lua index 2a6106c..bbceec4 100644 --- a/not/World.lua +++ b/not/World.lua @@ -79,8 +79,7 @@ end -- TODO: Change current map model to function-based one. function World:loadMap (name) local name = name or "default" - name = "maps/" .. name .. ".lua" - local map = love.filesystem.load(name) + local map = love.filesystem.load(string.format("config/maps/%s.lua", name)) self.map = map() -- Platforms for _,platform in pairs(self.map.platforms) do -- cgit v1.1