sonic-bluestreak/sonic-bluestreak.love/game/modules/world/parent.lua

75 lines
1.8 KiB
Lua
Raw Permalink Normal View History

2019-12-28 12:15:43 +01:00
local World3D = require "core.modules.world.world3D"
2019-12-28 14:13:19 +01:00
local ParentWorld = World3D:extend()
2019-12-28 12:15:43 +01:00
local customMap = require "game.modules.world.maps"
2019-12-28 14:13:19 +01:00
function ParentWorld:new(scene, maptype, mapname)
local mappath = game.utils.getMapPath("test", "test")
self.customMap = customMap
ParentWorld.super.new(self, scene, "game.modules.world.actors", mappath, maptype)
2019-12-28 12:15:43 +01:00
self.mapname = mapname
2020-02-02 08:27:33 +01:00
self.autorun = false
2019-12-28 12:15:43 +01:00
end
2019-12-28 14:13:19 +01:00
function ParentWorld:createMapController()
customMap.Test(self)
2019-12-28 12:15:43 +01:00
end
2019-12-28 14:13:19 +01:00
function ParentWorld:loadMapObjects()
ParentWorld.super.loadMapObjects(self)
2019-12-28 12:15:43 +01:00
self:addInvisibleWalls()
end
function ParentWorld:newObjFromIndex(id, x, y, z)
self.obj.index[id](self, x, y, z)
end
2019-12-28 14:13:19 +01:00
function ParentWorld:addInvisibleWalls()
2019-12-28 12:15:43 +01:00
local w, h = self:getDimensions()
print(w, h)
self.obj.collisions["invisible"](self, 0, -16, 0, w, 16, 1000)
self.obj.collisions["invisible"](self, 0, h, 0, w, 16, 1000)
self.obj.collisions["invisible"](self, w, 0, 0, 16, h, 1000)
self.obj.collisions["invisible"](self, -16, 0, 0, 16, h, 1000)
end
function ParentWorld:getViewCenter(x, y)
return x, y-16
end
2019-12-28 14:13:19 +01:00
function ParentWorld:draw(dt)
2019-12-28 12:15:43 +01:00
self:drawBackgroundColor()
local camNumber = self.cameras:getViewNumber()
if (camNumber == 0) then
self:drawMap()
self:drawActors()
else
for i=1, camNumber do
self:drawParallax(i)
self.cameras:attachView(i)
self:drawMap(i)
self:drawActors(i)
self.cameras:detachView(i)
end
end
end
2020-01-03 19:41:30 +01:00
function ParentWorld:drawMap(i)
local x, y, w, h = self.cameras:getViewCoordinate(i)
if (self.map ~= nil) then
self.map:draw(x, y, w, h)
end
end
2019-12-28 14:13:19 +01:00
function ParentWorld:drawParallax(i)
2019-12-28 12:15:43 +01:00
local x, y, w, h = self.cameras:getViewCoordinate(i)
if (self.map ~= nil) and (self.maptype ~= "sti") then
self.map:drawParallax(x, y, w, h)
end
end
2019-12-28 14:13:19 +01:00
return ParentWorld