diff --git a/gamecore/modules/world/camera/init.lua b/gamecore/modules/world/camera/init.lua index c04ada6..49ff883 100644 --- a/gamecore/modules/world/camera/init.lua +++ b/gamecore/modules/world/camera/init.lua @@ -27,6 +27,8 @@ local cwd = (...):gsub('%.init$', '') .. "." local CameraSystem = Object:extend() local View = require(cwd .. "libs.hump.camera") +local camutils = require(cwd .. "utils") + local SPLITSCREEN_ISVERTICAL = false local SCREEN_LIMIT = 4 @@ -57,43 +59,7 @@ function CameraSystem:initViews() self.views.basewidth, self.views.baseheight = core.screen:getDimensions() self.views.width, self.views.height = self:getViewsDimensions() - self.views.posList = {} - self.views.posList.dual = {} - self.views.posList.multi = {} - - if (self.verticalSplit) then - self.views.posList.dual[1] = {} - self.views.posList.dual[1].x = 0 - self.views.posList.dual[1].y = (self.views.baseheight/4) - - self.views.posList.dual[2] = {} - self.views.posList.dual[2].x = 0 - self.views.posList.dual[2].y = -(self.views.baseheight/4) - else - self.views.posList.dual[1] = {} - self.views.posList.dual[1].x = -(self.views.basewidth/4) - self.views.posList.dual[1].y = 0 - - self.views.posList.dual[2] = {} - self.views.posList.dual[2].x = (self.views.basewidth/4) - self.views.posList.dual[2].y = 0 - end - - self.views.posList.multi[1] = {} - self.views.posList.multi[1].x = -(self.views.basewidth /4) - self.views.posList.multi[1].y = -(self.views.baseheight/4) - - self.views.posList.multi[2] = {} - self.views.posList.multi[2].x = (self.views.basewidth /4) - self.views.posList.multi[2].y = -(self.views.baseheight/4) - - self.views.posList.multi[3] = {} - self.views.posList.multi[3].x = -(self.views.basewidth /4) - self.views.posList.multi[3].y = (self.views.baseheight/4) - - self.views.posList.multi[4] = {} - self.views.posList.multi[4].x = (self.views.basewidth /4) - self.views.posList.multi[4].y = (self.views.baseheight/4) + self.views.posList = camutils.getViewsPositions(self.views.basewidth, self.views.baseheight, self.verticalSplit) end -- INFO FUNCTIONS diff --git a/gamecore/modules/world/camera/utils.lua b/gamecore/modules/world/camera/utils.lua new file mode 100644 index 0000000..6d47831 --- /dev/null +++ b/gamecore/modules/world/camera/utils.lua @@ -0,0 +1,46 @@ +local camutils = {} + +function camutils.getViewsPositions(basewidth, baseheight, verticalSplit) + local posList = {} + + posList.dual = {} + posList.multi = {} + + if (verticalSplit) then + posList.dual[1] = {} + posList.dual[1].x = 0 + posList.dual[1].y = (baseheight/4) + + posList.dual[2] = {} + posList.dual[2].x = 0 + posList.dual[2].y = -(baseheight/4) + else + posList.dual[1] = {} + posList.dual[1].x = -(basewidth/4) + posList.dual[1].y = 0 + + posList.dual[2] = {} + posList.dual[2].x = (basewidth/4) + posList.dual[2].y = 0 + end + + posList.multi[1] = {} + posList.multi[1].x = -(basewidth /4) + posList.multi[1].y = -(baseheight/4) + + posList.multi[2] = {} + posList.multi[2].x = (basewidth /4) + posList.multi[2].y = -(baseheight/4) + + posList.multi[3] = {} + posList.multi[3].x = -(basewidth /4) + posList.multi[3].y = (baseheight/4) + + posList.multi[4] = {} + posList.multi[4].x = (basewidth /4) + posList.multi[4].y = (baseheight/4) + + return posList +end + +return camutils