bzr branch
http://9ix.org/bzr/spacey
7
by Josh C
enemy |
1 |
local accelLimit = 300 * 2 -- same as the player, yes? |
2 |
local velLimit = 600 -- same as player |
|
3 |
Enemy = Tile:extend { |
|
4 |
image = 'data/enemy.png', |
|
5 |
maxVelocity = {x=velLimit,y=velLimit}, |
|
6 |
minVelocity = {x=-velLimit, y=-velLimit}, |
|
7 |
onUpdate = function(self) |
|
8 |
-- find where player is relative to us |
|
9 |
local dx = the.player.x - self.x |
|
10 |
local dy = the.player.y - self.y |
|
11 |
||
12 |
local ax, ay = dx, dy |
|
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 |
|
19 |
end |
|
20 |
||
21 |
self.acceleration.x = ax |
|
22 |
self.acceleration.y = ay |
|
23 |
||
24 |
self.rotation = math.atan2(self.velocity.y, self.velocity.x) |
|
25 |
end |
|
26 |
} |