summaryrefslogtreecommitdiff
path: root/objects/Enemy.lua
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-03-03 21:14:42 +0800
committerEltrac <hi@guhub.cn>2025-03-03 21:14:42 +0800
commiteae6a38aa6ea4cc44b02a9815d168c32c9aedf53 (patch)
tree04664e5b42208415b106e694ff7d6d5cea227752 /objects/Enemy.lua
parent3453f9af12dcb39cc9d53b2ad22610cc99b4cc55 (diff)
feat: librarian moves fast vertically
Diffstat (limited to 'objects/Enemy.lua')
-rw-r--r--objects/Enemy.lua19
1 files changed, 15 insertions, 4 deletions
diff --git a/objects/Enemy.lua b/objects/Enemy.lua
index a97ec37..06fb7c5 100644
--- a/objects/Enemy.lua
+++ b/objects/Enemy.lua
@@ -18,7 +18,8 @@ function Enemy:new(name, location)
health = data.health or nil,
stunned = false,
frameTimer = FrameTimer:new(config.frameRate,
- (data.sprite and data.sprite.totalFrames) or 1)
+ (data.sprite and data.sprite.totalFrames) or 1),
+ movePattern = data.movePattern or nil,
}
setmetatable(obj, Enemy)
@@ -30,12 +31,18 @@ function Enemy:isBlocked()
end
-function Enemy:moveTowardPlayer(dt)
+function Enemy:move(dt)
if self.stunned and self.stunned > 0 then
self.stunned = self.stunned - dt
return false
end
+ if self.movePattern == "vertical" then
+ self:moveVertical(G.player.x, dt)
+ else self:moveTo(G.player.x, G.player.y, dt)
+ end
+end
+function Enemy:moveTo(x, y, dt)
local dv = self.speed * dt
local dx, dy = 0, 0
@@ -52,13 +59,17 @@ function Enemy:moveTowardPlayer(dt)
return 0
end
- dx = getDirection("x", G.player.x, Direction.RIGHT, "x")
- dy = getDirection("y", G.player.y, Direction.DOWN, "y")
+ dx = getDirection("x", x, Direction.RIGHT, "x")
+ dy = getDirection("y", y, Direction.DOWN, "y")
self.x = self.x + dx * dv
self.y = self.y + dy * dv
end
+function Enemy:moveVertical(toX, dt)
+ self:moveTo(toX, self.y, dt)
+end
+
function Enemy:facing()
local dx = self.x - G.player.x
local dy = self.y - G.player.y