summaryrefslogtreecommitdiff
path: root/entity.lua
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-05-28 21:01:02 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-05-28 21:01:02 -0700
commit16c1140ead99064799113eb3d8ddcf47929bba70 (patch)
tree39222a2af7491afaf0efd7fa9b5771d0283c78cc /entity.lua
parent661156ce988131eb4896a7af4d00a42b520305e7 (diff)
downloaddyl8-main.tar.gz
dyl8-main.zip
Adding debug collision boxes, making bullets hurt you, and be able to kill bullets upon consumptionHEADmain
Diffstat (limited to 'entity.lua')
-rw-r--r--entity.lua15
1 files changed, 11 insertions, 4 deletions
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