2021-05-05 08:30:32 +02:00
|
|
|
local World = require "birb.modules.world.world2D"
|
2020-08-01 16:57:12 +02:00
|
|
|
local RPGWorld = World:extend()
|
|
|
|
local objFile = "scenes.overworld.actors"
|
2021-03-23 21:59:33 +01:00
|
|
|
local RPGMap = require "scenes.overworld.map"
|
2020-08-01 16:57:12 +02:00
|
|
|
|
2021-04-02 23:26:22 +02:00
|
|
|
function RPGWorld:new(scene, area, playerx, playery)
|
|
|
|
self.area = area or game.position.area
|
|
|
|
self.playerx = playerx or game.position.x
|
|
|
|
self.playery = playery or game.position.y
|
2021-03-23 21:59:33 +01:00
|
|
|
RPGWorld.super.new(self, scene, objFile, nil, nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
function RPGWorld:createMapController()
|
2021-04-02 23:26:22 +02:00
|
|
|
RPGMap(self, self.area, self.playerx, self.playery)
|
|
|
|
end
|
|
|
|
|
|
|
|
function RPGWorld:savePosition()
|
|
|
|
local x, y = self.players[1].actor.x, self.players[1].actor.y
|
|
|
|
game.position.x = math.floor(x / 16)
|
|
|
|
game.position.y = math.floor(y / 16)
|
|
|
|
game.position.area = self.area
|
2020-08-01 16:57:12 +02:00
|
|
|
end
|
|
|
|
|
2021-04-21 18:46:30 +02:00
|
|
|
function RPGWorld:teleport(area, x, y, charDir)
|
2021-04-03 00:04:22 +02:00
|
|
|
if (area == self.area) then
|
|
|
|
self.players[1].actor.x = x * 16
|
|
|
|
self.players[1].actor.y = y * 16
|
|
|
|
else
|
2021-04-03 10:50:59 +02:00
|
|
|
self.area = area
|
|
|
|
self.playerx = x
|
|
|
|
self.playery = y
|
|
|
|
self:reset()
|
|
|
|
collectgarbage()
|
2021-04-21 18:46:30 +02:00
|
|
|
self.players[1].actor.charDir = charDir
|
2021-04-03 00:04:22 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-02 22:46:37 +02:00
|
|
|
function RPGWorld:restoreActions()
|
|
|
|
self.encounter:destroy()
|
|
|
|
local currentMap = self.map:getMapAtPoint(self.players[1].actor.x, self.players[1].actor.y)
|
|
|
|
self.players[1].actor.xsp = 0
|
|
|
|
self.players[1].actor.ysp = 0
|
|
|
|
self.scene:playMapMusic(currentMap)
|
|
|
|
end
|
|
|
|
|
2020-08-01 16:57:12 +02:00
|
|
|
return RPGWorld
|