summaryrefslogtreecommitdiff
path: root/enemy.lua
diff options
context:
space:
mode:
authorcursed22bc <admin@pixeldawn.org>2026-03-11 12:50:56 +0200
committercursed22bc <admin@pixeldawn.org>2026-03-11 12:50:56 +0200
commit8c5a91acb224312ea511c7ff502c44bb9fe7452b (patch)
tree194a2aee7f92fabbab79cc0ab64f0d2989b7d55e /enemy.lua
parentcd432860828a84aca93852a09cf05fc0e6294bab (diff)
sfx and other polish
Diffstat (limited to 'enemy.lua')
-rw-r--r--enemy.lua15
1 files changed, 12 insertions, 3 deletions
diff --git a/enemy.lua b/enemy.lua
index 152cadf..5c84a49 100644
--- a/enemy.lua
+++ b/enemy.lua
@@ -6,9 +6,12 @@ setmetatable(Enemy, { __index = Entity })
function Enemy.new(spawnX, spawnY, width, height, physicsWidth, physicsHeight)
local self = setmetatable(Entity:new(spawnX or 0, spawnY or 0, width or 16, height or 16, physicsWidth or width or 8, physicsHeight or height or 8), Enemy)
self.isEnemy = true
+ self.texture = love.graphics.newImage("assets/misc/enemy.png")
+ self.texture:setFilter("nearest", "nearest")
self.direction = math.random(1, 2) == 1 and 1 or -1
+ self.facing = self.direction
self.speed = 20
- self.turnDelay = 0.35
+ self.turnDelay = 1
self.turning = false
self.turnTimer = 0
return self
@@ -59,6 +62,8 @@ function Enemy:patrolPlatform(dt)
self.turnTimer = self.turnDelay
end
+ self.facing = self.direction
+
if self.body then
local _, vy = self.body:getLinearVelocity()
self.body:setLinearVelocity(self.speed * self.direction, vy)
@@ -70,8 +75,12 @@ function Enemy:update(dt)
end
function Enemy:draw()
- --bug: texture is drawn shifted by half width to the left
- love.graphics.draw(self.texture, self.x + self.physicsWidth / 2, self.y)
+ local tw = self.texture:getWidth()
+ local th = self.texture:getHeight()
+ local sx = (self.facing == -1) and -1 or 1
+ local cx = self.x + self.physicsWidth
+ local cy = self.y + self.physicsHeight /2
+ love.graphics.draw(self.texture, cx, cy, 0, sx, 1, tw / 2, th / 2)
end
return Enemy \ No newline at end of file