From 16c1140ead99064799113eb3d8ddcf47929bba70 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Thu, 28 May 2026 21:01:02 -0700 Subject: Adding debug collision boxes, making bullets hurt you, and be able to kill bullets upon consumption --- entity.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'entity.lua') diff --git a/entity.lua b/entity.lua index 5698c77..12d4862 100644 --- a/entity.lua +++ b/entity.lua @@ -68,6 +68,7 @@ function Entity:update(dt) if self.life_time ~= nil then self.life_time -= dt + if self.life_time <= 0 then self:kill() return end end if self.health ~= nil and self.health <= 0 then self:kill() @@ -186,6 +187,10 @@ function _get_animation_key(line_of_sight) return _animation_keys[n_line_of_sight.x + 2] .. "_x" end +function Entity:collision_box() + return {top_left = (self.collision_bounds.top_left + self.position), bottom_right = (self.collision_bounds.bottom_right + self.position) } +end + function Entity:render(screen_position) animation = self.states[self.state].animation if (animation == nil) then return end @@ -263,6 +268,12 @@ function EntityBuilder:b_equipped(equipped) end function EntityBuilder:b_collidable() self.collision = true + if (self.collision_bounds == nil) then + self.collision_bounds = { + top_left = vec2(0, 0), + bottom_right = vec2(SPRITE_DIMS) + } + end return self end function EntityBuilder:b_live_for(t) @@ -286,10 +297,6 @@ function EntityBuilder:b_collision_bounds(top_left, bottom_right) end function EntityBuilder:build() self.equipped = {} - self.collision_bounds = { - top_left = vec2(0, 0), - bottom_right = vec2(SPRITE_DIMS) - } return self.build_context.world.add(setmetatable(self, Entity)) end \ No newline at end of file -- cgit v1.3