summaryrefslogtreecommitdiff
path: root/entity.lua
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2026-04-25 20:42:30 -0700
committerElizabeth Hunt <me@liz.coffee>2026-04-25 20:42:30 -0700
commita81b080cc830d3073fda40ec777ab24f72cacfb9 (patch)
treeb92a2461993a2aedb3ea946ee10aa09ca7df3c5d /entity.lua
parent24b0469237285a05d9ffc05d18e43cc5dcdef00f (diff)
downloaddyl8-a81b080cc830d3073fda40ec777ab24f72cacfb9.tar.gz
dyl8-a81b080cc830d3073fda40ec777ab24f72cacfb9.zip
Getting a sword slashing animation working
Diffstat (limited to 'entity.lua')
-rw-r--r--entity.lua24
1 files changed, 19 insertions, 5 deletions
diff --git a/entity.lua b/entity.lua
index 945b787..56dcd74 100644
--- a/entity.lua
+++ b/entity.lua
@@ -2,11 +2,13 @@ Entities = {
Player = 0,
Sword = 1,
Enemy = 2,
- Bow = 3
+ Bow = 3,
+ Particle = 4
}
States = {
Walk = "walk",
Idle = "idle",
+ Active = "active",
Equipped = "equipped",
Slashing = "slashing",
Drawing = "drawing",
@@ -51,6 +53,10 @@ function Entity:b_collidable()
self.collision = true
return self
end
+function Entity:b_live_for(t)
+ self.life_time = t
+ return self
+end
function Entity:b_line_of_sight(vec)
self.line_of_sight = vec2(vec)
return self
@@ -69,10 +75,13 @@ function Entity:transition_to(state_name)
self.state = state_name
self.state_stopwatch = 0
end
- print(self.state)
return self
end
+function Entity:kill()
+ self.life_time = -1
+end
+
function Entity:update(dt)
self:integrate(dt)
@@ -86,6 +95,10 @@ function Entity:update(dt)
assert(self.transition_state)
self:transition_state()
+
+ if self.life_time ~= nil then
+ self.life_time -= dt
+ end
end
function Entity:update_line_of_sight()
@@ -147,10 +160,11 @@ function Entity:integrate(dt)
end
_equipped_item_distance = 6
-function Entity:equipped_from(parent)
+function Entity:equipped_from(parent, dist)
+ dist = dist or _equipped_item_distance
self.line_of_sight = vec2(parent.line_of_sight)
- offset = (parent.line_of_sight * _equipped_item_distance)
+ offset = (parent.line_of_sight * dist)
self.position = parent.position + offset
self.sprite_position = parent.sprite_position + offset
@@ -203,5 +217,5 @@ function entity()
collision = false
}, Entity
))
- return World[id]
+ return World.get(id)
end