From 2c24af53829edaf2b6473a438d74adcdac1fdc96 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Sun, 16 Mar 2025 21:31:13 +0800 Subject: refactor: clearer initialization code --- objects/Loot.lua | 7 ++++++- objects/Player.lua | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'objects') diff --git a/objects/Loot.lua b/objects/Loot.lua index 1e39211..e0817cc 100644 --- a/objects/Loot.lua +++ b/objects/Loot.lua @@ -1,4 +1,4 @@ -local physics = require "logic.physics" +local heartTypes = require "data.heartTypes" local Loot = {} Loot.__index = Loot @@ -18,6 +18,11 @@ function Loot:new(name, x, y) return obj end +function Loot:random(x, y) + local type = utils.any(heartTypes) + return Loot:new(type, x, y) +end + function Loot:onContact(other) local loots = G.currentRoom.objects.loots if other.objectType == "player" then diff --git a/objects/Player.lua b/objects/Player.lua index 5103b17..2701f53 100644 --- a/objects/Player.lua +++ b/objects/Player.lua @@ -16,7 +16,7 @@ function Player.new() zoom = 1/16, speed = config.player.speed, shieldedTill = 0, - hearts = { "purpleheart", "redheart", "redheart", "redheart", "shinyheart", "shinyheart", "stickyheart" }, + hearts = { "redheart", "redheart", "redheart" }, facing = Direction.DOWN, moving = false, frameTimer = FrameTimer:new(config.frameRate, 2), @@ -29,6 +29,10 @@ function Player.new() return player end +function Player.init(G) + G.player = Player:new() +end + -- placement and location function Player:setX(x) -- cgit v1.2.3