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/Cloud.lua | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 not/Cloud.lua (limited to 'not/Cloud.lua') diff --git a/not/Cloud.lua b/not/Cloud.lua new file mode 100644 index 0000000..c12e236 --- /dev/null +++ b/not/Cloud.lua @@ -0,0 +1,63 @@ +-- `Cloud` +-- That white thing moving in the background. + +-- WHOLE CODE HAS FLAG OF "need a cleanup" + +-- Metatable of `Cloud` +-- nils initialized in constructor +Cloud = { + x = 0, -- position horizontal + y = 0, -- position vertical + t = 1, -- type (sprite number) + v = 13, -- velocity + sprite = nil, + quads = { + [1] = love.graphics.newQuad( 1, 1, 158,47, 478,49), + [2] = love.graphics.newQuad(160, 1, 158,47, 478,49), + [3] = love.graphics.newQuad(319, 1, 158,47, 478,49) + } +} + +-- Constructor of `Cloud` +function Cloud:new(x, y, t, v) + -- Meta + local o = {} + setmetatable(o, self) + self.__index = self + -- Load spritesheet to metatable if not yet loaded + if self.sprite == nil then + self.sprite = love.graphics.newImage("assets/clouds.png") + end + -- Init + o.x = x or self.x + o.y = y or self.y + o.t = t or self.t + o.v = v or self.v + return o +end + +-- Position +function Cloud:getPosition() + return self.x, self.y +end + +-- Update of `Cloud`, returns x for world to delete cloud after reaching right corner +function Cloud:update(dt) + self.x = self.x + self.v*dt + return self.x +end + +-- Draw `Cloud` +function Cloud:draw(offset_x, offset_y, scale) + -- locals + local offset_x = offset_x or 0 + local offset_y = offset_y or 0 + local scale = scale or 1 + local x, y = self:getPosition() + -- pixel grid + local draw_x = (math.floor(x) + offset_x) * scale + local draw_y = (math.floor(y) + offset_y) * scale + -- draw + love.graphics.setColor(255,255,255,255) + love.graphics.draw(self.sprite, self.quads[self.t], draw_x, draw_y, 0, scale, scale) +end \ No newline at end of file -- cgit v1.1 From 2e352657813b37d17c2215b85189f18a50c099f9 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 19 Mar 2017 03:29:32 +0100 Subject: Comments, todos, pretty useless --- not/Cloud.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'not/Cloud.lua') diff --git a/not/Cloud.lua b/not/Cloud.lua index c12e236..c9899d5 100644 --- a/not/Cloud.lua +++ b/not/Cloud.lua @@ -5,6 +5,7 @@ -- Metatable of `Cloud` -- nils initialized in constructor +-- TODO: inherit from `not.Decoration` or `not.Sprite`, depending on final result of `not.Sprite`. Cloud = { x = 0, -- position horizontal y = 0, -- position vertical -- cgit v1.1 From e2e4164cda3b4536fcba96f5c5283eb125d2b6b1 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 18:51:51 +0200 Subject: Cloud is now child of Decoration; reworked majority of its content --- not/Cloud.lua | 105 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 49 deletions(-) (limited to 'not/Cloud.lua') diff --git a/not/Cloud.lua b/not/Cloud.lua index c9899d5..2af7d4b 100644 --- a/not/Cloud.lua +++ b/not/Cloud.lua @@ -1,64 +1,71 @@ --- `Cloud` --- That white thing moving in the background. - --- WHOLE CODE HAS FLAG OF "need a cleanup" - --- Metatable of `Cloud` --- nils initialized in constructor --- TODO: inherit from `not.Decoration` or `not.Sprite`, depending on final result of `not.Sprite`. +--- `Cloud` +-- That white thing moving in the background. +-- TODO: extends variables names to be readable. Cloud = { - x = 0, -- position horizontal - y = 0, -- position vertical t = 1, -- type (sprite number) - v = 13, -- velocity - sprite = nil, - quads = { + v = 13 -- velocity +} + +-- TODO: allow maps to use other quads and sprites for clouds +-- TODO: you know this isn't right, don't you? +local animations = { + default = { [1] = love.graphics.newQuad( 1, 1, 158,47, 478,49), - [2] = love.graphics.newQuad(160, 1, 158,47, 478,49), - [3] = love.graphics.newQuad(319, 1, 158,47, 478,49) + frames = 1, + repeated = true + }, + default2 = { + [1] = love.graphics.newQuad(160, 1, 158,47, 478,49), + frames = 1, + repeated = true + }, + default3 = { + [1] = love.graphics.newQuad(319, 1, 158,47, 478,49), + frames = 1, + repeated = true } } --- Constructor of `Cloud` -function Cloud:new(x, y, t, v) - -- Meta - local o = {} - setmetatable(o, self) - self.__index = self - -- Load spritesheet to metatable if not yet loaded - if self.sprite == nil then - self.sprite = love.graphics.newImage("assets/clouds.png") +-- `Cloud` is a child of `Decoration`. +require "not.Decoration" +Cloud.__index = Cloud +setmetatable(Cloud, Decoration) + +-- Constructor of `Cloud`. +function Cloud:new (x, y, t, v) + local o = setmetatable({}, self) + o:init(x, y, t, v) + -- Load spritesheet statically. + if self:getImage() == nil then + self:setImage(Sprite.newImage("assets/clouds.png")) end - -- Init - o.x = x or self.x - o.y = y or self.y - o.t = t or self.t - o.v = v or self.v return o end --- Position -function Cloud:getPosition() - return self.x, self.y +-- Initializator of `Cloud`. +function Cloud:init (x, y, t, v) + Decoration.init(self, x, y, nil) + self:setAnimationsList(animations) + self:setVelocity(v) + self:setType(t) end --- Update of `Cloud`, returns x for world to delete cloud after reaching right corner -function Cloud:update(dt) +-- Setters for cloud type and velocity. +function Cloud:setType (type) + local animation = "default" + if type > 1 then + animation = animation .. type + end + self:setAnimation(animation) + self.t = type +end +function Cloud:setVelocity (velocity) + self.v = velocity +end + +-- Update of `Cloud`, returns x for world to delete cloud after reaching right corner. +function Cloud:update (dt) + Decoration.update(self, dt) self.x = self.x + self.v*dt return self.x end - --- Draw `Cloud` -function Cloud:draw(offset_x, offset_y, scale) - -- locals - local offset_x = offset_x or 0 - local offset_y = offset_y or 0 - local scale = scale or 1 - local x, y = self:getPosition() - -- pixel grid - local draw_x = (math.floor(x) + offset_x) * scale - local draw_y = (math.floor(y) + offset_y) * scale - -- draw - love.graphics.setColor(255,255,255,255) - love.graphics.draw(self.sprite, self.quads[self.t], draw_x, draw_y, 0, scale, scale) -end \ No newline at end of file -- cgit v1.1 From b4389dfb590862b50cc6c9ce59d3fcef9bd046b3 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 3 Apr 2017 20:11:21 +0200 Subject: World comments, other comments, todos --- not/Cloud.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'not/Cloud.lua') diff --git a/not/Cloud.lua b/not/Cloud.lua index 2af7d4b..3bc5377 100644 --- a/not/Cloud.lua +++ b/not/Cloud.lua @@ -42,7 +42,7 @@ function Cloud:new (x, y, t, v) return o end --- Initializator of `Cloud`. +-- Initializer of `Cloud`. function Cloud:init (x, y, t, v) Decoration.init(self, x, y, nil) self:setAnimationsList(animations) -- cgit v1.1