1
local accelLimit = 300 * 2 -- same as the player, yes?
2
local velLimit = 600 -- same as player
3
3
Enemy = Tile:extend {
4
4
image = 'data/enemy.png',
5
5
maxVelocity = {x=velLimit,y=velLimit},
6
6
minVelocity = {x=-velLimit, y=-velLimit},
8
onNew = function (self)
9
self.thrust = Tile:new{image = 'data/thrust.png'}
11
onStartFrame = function (self)
13
local pvec = vector.new(the.player.x - self.x,
14
the.player.y - self.y)
16
self.rotation = math.atan2(pvec.y, pvec.x)
18
local pdist2 = pvec:len2()
20
if pdist2 > 400^2 then -- ... if player dist > 64?
21
self.acceleration = vector.new(300, 0)
22
self.acceleration:rotate_inplace(self.rotation)
23
self.thrust.visible = true
25
self.acceleration = {x=0, y=0}
26
self.thrust.visible = false
30
love.timer.getTime() - self.lastFired > 0.25 then
33
x = self.x + self.width / 2,
34
y = self.y + self.height / 2,
35
rotation = self.rotation
37
self.lastFired = love.timer.getTime()
41
7
onUpdate = function(self)
42
self.thrust.x = self.x - self.width
43
self.thrust.y = self.y
44
self.thrust.rotation = self.rotation
8
-- find where player is relative to us
9
local dx = the.player.x - self.x
10
local dy = the.player.y - self.y
13
if math.abs(dx) > math.abs(accelLimit) then
14
ax = accelLimit * util.signOf(dx)
15
ay = accelLimit * math.abs(dx) / dy
16
elseif math.abs(dy) > math.abs(accelLimit) then
17
ay = accelLimit * util.signOf(dy)
18
ax = accelLimit * math.abs(dy) / dx
21
self.acceleration.x = ax
22
self.acceleration.y = ay
24
self.rotation = math.atan2(self.velocity.y, self.velocity.x)
b'\\ No newline at end of file'