74 lines
1.8 KiB
Lua
74 lines
1.8 KiB
Lua
local World2D = require "core.modules.world.world2D"
|
|
local World = World2D:extend()
|
|
|
|
local Obj = require "scenes.levels.entities"
|
|
|
|
local Sti = require "libs.sti"
|
|
|
|
-- INIT FUNCTIONS
|
|
-- All functions to init the world and the map
|
|
|
|
function World:new(scene, mapfile, actorlist)
|
|
self.super.new(self, scene, actorlist, mapfile)
|
|
end
|
|
|
|
function World:getStartPosition()
|
|
local startx, starty
|
|
for k, objectlayer in pairs(self.map.layers) do
|
|
if objectlayer.name == "playerstart" then
|
|
for k, object in pairs(objectlayer.objects) do
|
|
startx = object.x + (object.width/2)
|
|
starty = object.y + (object.height) - 12
|
|
end
|
|
self.map:removeLayer("playerstart")
|
|
end
|
|
end
|
|
return startx, starty
|
|
end
|
|
|
|
-- ACTORS FUNCTIONS
|
|
-- Some Bump2D Wrapper not handled by gamecore
|
|
|
|
function World:changeActorData(actor)
|
|
self.actors:update(actor, actor.x, actor.y, actor.w, actor.h)
|
|
end
|
|
|
|
-- UPDATE FUNCTIONS
|
|
-- All update functions
|
|
|
|
function World:update(dt)
|
|
self.scene.playermanager:update(dt)
|
|
self.super.update(self, dt)
|
|
self.scene.camera:update(dt)
|
|
end
|
|
|
|
-- DRAW FUNCTIONS
|
|
-- All function to draw the map, world and entities
|
|
|
|
function World:draw()
|
|
-- Ona attache puis détache la caméra pour dessiner le monde, afin que celui
|
|
-- reste "fixe" tandis que le jouer bouge.
|
|
self.scene.camera:floorCoord()
|
|
self:drawBackgroundColor()
|
|
self.scene.camera:attach()
|
|
self:drawMap()
|
|
self:drawActors()
|
|
self.scene.camera:detach()
|
|
end
|
|
|
|
function World:drawMap()
|
|
-- Du à la manière dont fonctionne STI, on est obligé de récupérer les info
|
|
-- de position de camera pour afficher la carte par rapport à ces infos
|
|
local tx, ty = self.scene.camera:getCoord()
|
|
local scale = self.scene.camera:getScale()
|
|
local tx = tx
|
|
local ty = ty
|
|
|
|
tx = math.floor(tx)
|
|
ty = math.floor(ty)
|
|
|
|
self.map:draw(-tx, -ty, scale, scale)
|
|
end
|
|
|
|
return World
|