summaryrefslogtreecommitdiff
path: root/ai.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 /ai.lua
parent7d415c4958f584c031922ed77a3559d15bf2dc1b (diff)
downloaddyl8-661156ce988131eb4896a7af4d00a42b520305e7.tar.gz
dyl8-661156ce988131eb4896a7af4d00a42b520305e7.zip
This is REAL Artificial Intelligence and definitely REALLY COMPLICATED
Diffstat (limited to 'ai.lua')
-rw-r--r--ai.lua64
1 files changed, 64 insertions, 0 deletions
diff --git a/ai.lua b/ai.lua
new file mode 100644
index 0000000..af1a807
--- /dev/null
+++ b/ai.lua
@@ -0,0 +1,64 @@
+AiController = {}
+AiController.__index = AiController
+
+function AiController:new(controlling)
+ return setmetatable({
+ controlling = controlling,
+ time = 0
+ }, AiController)
+end
+
+function AiController:follow(target)
+ self.target = target
+end
+
+function AiController:update(dt)
+ if self.target ~= nil and not self.target.knockback then
+ diff = self.target.position - self.controlling.position
+ self.controlling.velocity = diff:normal() * 20
+ self.controlling:transition_to(States.Walk)
+ end
+ self.time += dt
+ if self.time >= 5 then
+ self:shoot()
+ self.time = 0
+ end
+end
+
+function gliding_gun()
+ _glider_damage = { amount = 2, knockback = { magnitude = 300, time = 0.080 } }
+ GlidingGunBuilder = EntityBuilder:new(World)
+ function GlidingGunBuilder:transition_state()
+ end
+ return GlidingGunBuilder:b_type(Entities.Bullet)
+ :b_line_of_sight(vec2(1, 0))
+ :b_position(vec2(100, 100))
+ :b_render_order(0)
+ :b_collidable()
+ :b_live_for(25)
+ :b_velocity(vec2(-40, 0))
+ :b_collision_bounds(vec2(3, 4), vec2(5, 6))
+ :b_add_state(
+ States.Active, {
+ animation = {
+ pos_y = { sequence = { 75, 76, 77, 78 }, dt = 0.10 },
+ neg_y = { sequence = { 75, 76, 77, 78 }, dt = 0.10, reflect = vec2(true, true) },
+ pos_x = { sequence = { 75, 76, 77, 78 }, dt = 0.10 },
+ neg_x = { sequence = { 75, 76, 77, 78 }, dt = 0.10, reflect = vec2(true, true) }
+ }
+ }
+ )
+ :b_state(States.Active)
+ :build()
+end
+
+function AiController:shoot()
+ diff = (self.target.position - self.controlling.position):normal() * 50
+ a, b, c = gliding_gun(), gliding_gun(), gliding_gun()
+ a.position = vec2(self.controlling.position)
+ a.velocity = diff:clockwise_rotate(-0.05)
+ b.position = vec2(self.controlling.position)
+ b.velocity = diff:clockwise_rotate(0.05)
+ c.position = vec2(self.controlling.position)
+ c.velocity = diff
+end