diff options
| author | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-05-28 21:01:02 -0700 |
|---|---|---|
| committer | Elizabeth Alexander Hunt <me@liz.coffee> | 2026-05-28 21:01:02 -0700 |
| commit | 16c1140ead99064799113eb3d8ddcf47929bba70 (patch) | |
| tree | 39222a2af7491afaf0efd7fa9b5771d0283c78cc /entity.lua | |
| parent | 661156ce988131eb4896a7af4d00a42b520305e7 (diff) | |
| download | dyl8-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.lua | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -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 |
