summaryrefslogtreecommitdiff
path: root/entity.lua
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2026-05-17 11:53:35 -0700
committerElizabeth Hunt <me@liz.coffee>2026-05-17 11:54:05 -0700
commit661156ce988131eb4896a7af4d00a42b520305e7 (patch)
tree23b64b8f224f25aeb9c789a54da13f29c22b91c5 /entity.lua
parent7d415c4958f584c031922ed77a3559d15bf2dc1b (diff)
downloaddyl8-661156ce988131eb4896a7af4d00a42b520305e7.tar.gz
dyl8-661156ce988131eb4896a7af4d00a42b520305e7.zip
This is REAL Artificial Intelligence and definitely REALLY COMPLICATED
Diffstat (limited to 'entity.lua')
-rw-r--r--entity.lua46
1 files changed, 33 insertions, 13 deletions
diff --git a/entity.lua b/entity.lua
index 849674e..5698c77 100644
--- a/entity.lua
+++ b/entity.lua
@@ -7,9 +7,11 @@ Entities = {
Wife = 5,
Fire = 6,
Door = 7,
- Block = 8
+ Block = 8,
+ Bullet = 9,
}
- -- TODO: Why are these all in one object. We should have like "SpriteStates", "FireStates", etc.
+
+-- TODO: Why are these all in one object. We should have like "SpriteStates", "FireStates", etc.
States = {
Walk = "walk",
Idle = "idle",
@@ -45,6 +47,10 @@ function Entity:kill()
end
function Entity:update(dt)
+ if self.controller ~= nil then
+ self.controller:update(dt)
+ end
+
self:integrate(dt)
self:update_line_of_sight()
@@ -69,16 +75,20 @@ function Entity:update(dt)
end
function Entity:update_line_of_sight()
- nv = self.velocity:apply(normalize_scalar)
- if nv.y != 0 then
- self.line_of_sight = vec2(0, nv.y)
- elseif nv.x != 0 then
- self.line_of_sight = vec2(nv.x, 0)
+ los = self.velocity:normal():apply(abs)
+ n_los = self.velocity:apply(normalize_scalar)
+ if n_los == vec2(0, 0) then
+ return
+ end
+ if los.y >= los.x then
+ self.line_of_sight = vec2(0, n_los.y)
+ else
+ self.line_of_sight = vec2(n_los.x, 0)
end
end
-- prevent cobblestoning during non-manhattan movement by "lagging" the sprite
--- behind the actual physical position
+-- behind the actual physical position.
-- this part was painful.
function Entity:update_sprite_position()
if self.sprite_position == nil then return end
@@ -119,14 +129,9 @@ function Entity:update_sprite_position()
if dy < 0 then func = ceil end
self.sprite_position.y += func(dy)
end
-
- return self
end
function Entity:take_damage(direction, damage_spec)
- if self.health == nil or self:is_in_iframe() then
- return
- end
self.health -= damage_spec.amount
if damage_spec.knockback ~= nil then
self.knockback = {
@@ -268,8 +273,23 @@ function EntityBuilder:b_line_of_sight(vec)
self.line_of_sight = vec2(vec)
return self
end
+function EntityBuilder:b_velocity(vec)
+ self.velocity = vec2(vec)
+ return self
+end
+function EntityBuilder:b_collision_bounds(top_left, bottom_right)
+ self.collision_bounds = {
+ top_left = vec2(top_left),
+ bottom_right = vec2(bottom_right)
+ }
+ return self
+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