diff options
| author | Eltrac <hi@guhub.cn> | 2025-03-07 22:36:47 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-03-07 22:36:47 +0800 |
| commit | f06fc3435a01f332194f592879a5fa832fbf77d7 (patch) | |
| tree | 6632c750e9d9c2be5bba2f00cc30114cfddaf559 /objects/room.lua | |
| parent | fb8a5d0fbff6fc480a6d507578826690b2585926 (diff) | |
refactor: move initializers to the end
Diffstat (limited to 'objects/room.lua')
| -rw-r--r-- | objects/room.lua | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/objects/room.lua b/objects/room.lua index aa77f8d..1d46acc 100644 --- a/objects/room.lua +++ b/objects/room.lua @@ -134,33 +134,6 @@ function Room:getDoorlessDirections() return doorless end --- initializers - -function Room:initEnemies() - for _, enemy in ipairs(self.enemies) do - local offset = enemy.body.r*2 + G.player.body.r*2 + config.summonMargin - if not enemy.x or not enemy.y then - enemy.x, enemy.y = self:getLocation(enemy.presetLocation or "random", offset) - end - end -end - -function Room:initObstacles() - for _, obstacle in ipairs(self.obstacles) do - local offset = obstacle.body.w + G.player.body.r*2 + config.summonMargin - if not obstacle.x or not obstacle.y then - obstacle.x, obstacle.y = self:getLocation(obstacle.presetLocation or "random", offset) - obstacle.x = obstacle.x - obstacle.body.w / 2 - obstacle.y = obstacle.y - obstacle.body.h / 2 - end - end -end - -function Room:init() - self:initEnemies() - self:initObstacles() -end - -- control functions function Room:addDoor(door) @@ -193,4 +166,31 @@ function Room:connect(anotherRoom, way) return door1, door2 end +-- initializers + +function Room:initEnemies() + for _, enemy in ipairs(self.enemies) do + local offset = enemy.body.r*2 + G.player.body.r*2 + config.summonMargin + if not enemy.x or not enemy.y then + enemy.x, enemy.y = self:getLocation(enemy.presetLocation or "random", offset) + end + end +end + +function Room:initObstacles() + for _, obstacle in ipairs(self.obstacles) do + local offset = obstacle.body.w + G.player.body.r*2 + config.summonMargin + if not obstacle.x or not obstacle.y then + obstacle.x, obstacle.y = self:getLocation(obstacle.presetLocation or "random", offset) + obstacle.x = obstacle.x - obstacle.body.w / 2 + obstacle.y = obstacle.y - obstacle.body.h / 2 + end + end +end + +function Room:init() + self:initEnemies() + self:initObstacles() +end + return Room |
