diff options
Diffstat (limited to 'enemy.lua')
| -rw-r--r-- | enemy.lua | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -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 |
