Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Private fixes, aesthetics and singleton behaviour.

Private _drawCheck in stage was made a true private.  Singletons can
access each other because after the class is defined, they now instance
themselves and throw away the class reference.
  • Loading branch information...
commit 5fe90846c0e2cc5cbe27c34b0203b18d16afb2bf 1 parent 2142bb6
@camoy camoy authored
View
2  src/helper/collection.lua
@@ -1,7 +1,7 @@
local collection = class('Collection', helper)
function collection:initialize()
- self.zindex = 1
+ self.zindex = 1
self.members = {}
end
View
6 src/helper/mover.lua
@@ -1,9 +1,9 @@
local mover = class('Mover', helper)
function mover:initialize()
- self.preMove = nil
- self.xshift = 0
- self.yshift = 0
+ self.preMove = nil
+ self.xshift = 0
+ self.yshift = 0
self.increment = 10
end
View
6 src/module.lua
@@ -3,7 +3,7 @@
mover = mover,
sprite = sprite,
map = map,
- stage = stage:new(),
- camera = camera:new(),
- controller = controller:new()
+ stage = stage,
+ camera = camera,
+ controller = controller
}
View
26 src/singleton/camera.lua
@@ -1,23 +1,23 @@
local camera = class('Camera', singleton)
function camera:initialize()
- self._move = mover:new()
+ self.move = mover:new()
self.controllable = true
- self.keys = {up = 'up', left = 'left', down = 'down', right = 'right'}
- self.zindex = 1
- self.sx = 1
- self.sy = 1
- self.angle = 0
+ self.keys = {up = 'up', left = 'left', down = 'down', right = 'right'}
+ self.zindex = 1
+ self.sx = 1
+ self.sy = 1
+ self.angle = 0
end
function camera:focus(actor)
-- Check for position loaded
if actor.cimage.x and actor.cimage.y then
- local move = self._move
+ local move = self.move
local sx, sy = self.sx, self.sy
- move.xshift, move.yshift =
- love.graphics.getWidth() / 2 - actor.cimage.x,
- love.graphics.getHeight() / 2 - actor.cimage.y
+
+ move.xshift = love.graphics.getWidth() / 2 - actor.cimage.x
+ move.yshift = love.graphics.getHeight() / 2 - actor.cimage.y
end
end
@@ -33,17 +33,19 @@ function camera:update()
if self.controllable == true then
for k,v in pairs(self.keys) do
if love.keyboard.isDown(k) then
- self._move:move(v)
+ self.move:move(v)
end
end
end
end
function camera:draw()
- local move = self._move
+ local move = self.move
-- Apply Canvas Transformations
love.graphics.translate(move.xshift, move.yshift)
love.graphics.scale(self.sx, self.sy)
love.graphics.rotate(self.angle)
end
+
+camera = camera:new()
View
4 src/singleton/controller.lua
@@ -2,7 +2,7 @@ local controller = class('Controller', singleton)
function controller:initialize()
self.mouseIsDown = {}
- self.keyIsDown = {}
+ self.keyIsDown = {}
end
function controller:update()
@@ -15,3 +15,5 @@ function controller:update()
end
end
end
+
+controller = controller:new()
View
12 src/singleton/stage.lua
@@ -1,10 +1,6 @@
local stage = class('Stage', singleton)
-function stage:initialize()
- self.staged = {}
-end
-
-function stage:_drawCheck(object)
+local function _drawCheck(object)
if object.draw then
object:draw()
else
@@ -12,6 +8,10 @@ function stage:_drawCheck(object)
end
end
+function stage:initialize()
+ self.staged = {}
+end
+
function stage:untrack(...)
local stage = self.staged
for _,object in ipairs {...} do
@@ -66,3 +66,5 @@ function stage:render()
love.graphics.print('FPS: ' .. love.timer.getFPS(), 0, 0)
end
end
+
+stage = stage:new()
Please sign in to comment.
Something went wrong with that request. Please try again.