diff options
-rw-r--r-- | not/Cloud.lua | 30 | ||||
-rw-r--r-- | not/Decoration.lua | 29 | ||||
-rw-r--r-- | not/Effect.lua | 32 | ||||
-rw-r--r-- | not/Platform.lua | 29 | ||||
-rw-r--r-- | not/World.lua | 8 |
5 files changed, 44 insertions, 84 deletions
diff --git a/not/Cloud.lua b/not/Cloud.lua index 3bc5377..25169c0 100644 --- a/not/Cloud.lua +++ b/not/Cloud.lua @@ -1,10 +1,11 @@ +require "not.Decoration" + --- `Cloud` -- That white thing moving in the background. -- TODO: extends variables names to be readable. -Cloud = { - t = 1, -- type (sprite number) - v = 13 -- velocity -} +Cloud = Decoration:extends() +Cloud.t = 1 -- type (sprite number) +Cloud.v = 13 -- velocity -- TODO: allow maps to use other quads and sprites for clouds -- TODO: you know this isn't right, don't you? @@ -26,25 +27,12 @@ local animations = { } } --- `Cloud` is a child of `Decoration`. -require "not.Decoration" -Cloud.__index = Cloud -setmetatable(Cloud, Decoration) - -- Constructor of `Cloud`. -function Cloud:new (x, y, t, v) - local o = setmetatable({}, self) - o:init(x, y, t, v) - -- Load spritesheet statically. +function Cloud:new (x, y, t, v, world) if self:getImage() == nil then self:setImage(Sprite.newImage("assets/clouds.png")) end - return o -end - --- Initializer of `Cloud`. -function Cloud:init (x, y, t, v) - Decoration.init(self, x, y, nil) + Cloud.__super.new(self, x, y, world, nil) self:setAnimationsList(animations) self:setVelocity(v) self:setType(t) @@ -65,7 +53,9 @@ end -- Update of `Cloud`, returns x for world to delete cloud after reaching right corner. function Cloud:update (dt) - Decoration.update(self, dt) + Cloud.__super.update(self, dt) self.x = self.x + self.v*dt return self.x end + +return Cloud diff --git a/not/Decoration.lua b/not/Decoration.lua index 9dc2bdd..97524f5 100644 --- a/not/Decoration.lua +++ b/not/Decoration.lua @@ -1,26 +1,15 @@ +require "not.Entity" + --- `Decoration` -- Positioned sprite used to decorate maps with additional graphics. -Decoration = { - world = --[[not.World]]nil, - x = 0, - y = 0 -} +Decoration = Entity:extends() --- `Decoration` is a child of `Sprite`. -require "not.Sprite" -Decoration.__index = Decoration -setmetatable(Decoration, Sprite) +Decoration.x = 0 +Decoration.y = 0 -- Constructor of `Decoration`. -function Decoration:new (x, y, imagePath) - local o = setmetatable({}, self) - o:init(x, y, imagePath) - return o -end - --- Initializer of `Decoration`. -function Decoration:init (x, y, imagePath) - Sprite.init(self, imagePath) +function Decoration:new (x, y, world, imagePath) + Decoration.__super.new(self, world, imagePath) self:setPosition(x, y) end @@ -30,4 +19,6 @@ function Decoration:getPosition () end function Decoration:setPosition (x, y) self.x, self.y = x, y -end
\ No newline at end of file +end + +return Decoration diff --git a/not/Effect.lua b/not/Effect.lua index dd7570a..82d6819 100644 --- a/not/Effect.lua +++ b/not/Effect.lua @@ -1,29 +1,19 @@ +require "not.Decoration" + --- `Effect` -- Short animation with graphics that plays in various situation. -- TODO: animation is currently slower than it used to be, check if it is ok; if not then make it possible to change it to 0.06 delay. -Effect = { - finished = false, -} +Effect = Decoration:extends() --- `Effect` is a child of `Decoration`. -require "not.Decoration" -Effect.__index = Effect -setmetatable(Effect, Decoration) +Effect.finished = false -- Constructor of `Effect`. -function Effect:new (name, x, y) - local o = setmetatable({}, self) - o:init(name, x, y) - -- Load spritesheet statically. - if self:getImage() == nil then - self:setImage(Sprite.newImage("assets/effects.png")) +function Effect:new (name, x, y, world) + -- TODO: Load spritesheet statically. Put it to load or somewhere else within non-existent resource manager. + if Effect:getImage() == nil then + Effect:setImage(Sprite.newImage("assets/effects.png")) end - return o -end - --- Initializer of `Effect`. -function Effect:init (name, x, y) - Decoration.init(self, x, y, nil) + Effect.__super.new(self, x, y, world, nil) self:setAnimationsList(require("config.animations.effects")) self:setAnimation(name) end @@ -31,7 +21,7 @@ end -- Update of `Effect`. -- Returns true if animation is finished and effect is ready to be deleted. function Effect:update (dt) - Decoration.update(self, dt) + Effect.__super.update(self, dt) return self.finished end @@ -44,3 +34,5 @@ function Effect:goToNextFrame () self.finished = true end end + +return Effect diff --git a/not/Platform.lua b/not/Platform.lua index 3748c47..a4b3a59 100644 --- a/not/Platform.lua +++ b/not/Platform.lua @@ -1,29 +1,14 @@ +require "not.PhysicalBody" + --- `Platform` -- Static platform physical object with a sprite. `Players` can walk on it. -- Collision category: [1] --- TODO: reformat code to follow new code patterns --- TODO: comment uncovered code parts -Platform = { - world = --[[not.World]]nil, -} - --- `Platform` is a child of `PhysicalBody`. -require "not.PhysicalBody" -Platform.__index = Platform -setmetatable(Platform, PhysicalBody) +Platform = PhysicalBody:extends() -- Constructor of `Platform` -function Platform:new (animations, shape, game, x, y, sprite) - local o = setmetatable({}, self) - o:init(animations, shape, game, x, y, sprite) - return o -end - --- Initializer of `Platform`. -function Platform:init (animations, shape, world, x, y, imagePath) - PhysicalBody.init(self, world, x, y, imagePath) +function Platform:new (animations, shape, x, y, world, imagePath) + Platform.__super.new(self, x, y, world, imagePath) self:setAnimationsList(animations) - self.world = world -- Create table of shapes if single shape is passed. if type(shape[1]) == "number" then shape = {shape} @@ -34,4 +19,6 @@ function Platform:init (animations, shape, world, x, y, imagePath) fixture:setCategory(1) fixture:setFriction(0.2) end -end
\ No newline at end of file +end + +return Platform diff --git a/not/World.lua b/not/World.lua index 38639b7..88be97a 100644 --- a/not/World.lua +++ b/not/World.lua @@ -115,7 +115,7 @@ end -- Add new platform to the world -- 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(animations, polygon, self, x, y, sprite)) + table.insert(self.Platforms, Platform(animations, polygon, x, y, self, sprite)) end -- Add new naut to the world @@ -129,14 +129,14 @@ 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, 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`. function World:createCloud (x, y, t, v) - table.insert(self.Clouds, Cloud(x, y, t, v)) + table.insert(self.Clouds, Cloud(x, y, t, v, self)) end -- Randomize Cloud creation @@ -163,7 +163,7 @@ end -- 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)) + table.insert(self.Effects, Effect(name, x, y, self)) end -- Add a ray |