bzr branch
http://9ix.org/bzr/traderous
65
by Josh C
enemy is back |
1 |
-- player = 300 accel, 400 velLimit |
2 |
local accelLimit = 150 |
|
3 |
local velLimit = 200 |
|
7
by Josh C
enemy |
4 |
Enemy = Tile:extend { |
5 |
image = 'data/enemy.png', |
|
6 |
maxVelocity = {x=velLimit,y=velLimit}, |
|
7 |
minVelocity = {x=-velLimit, y=-velLimit}, |
|
65
by Josh C
enemy is back |
8 |
lastFired = 0, |
9 |
onNew = function (self) |
|
10 |
self.thrust = Tile:new{image = 'data/thrust.png'} |
|
66
by Josh C
enemy thrust |
11 |
--the.app.view:add(self.thrust) |
65
by Josh C
enemy is back |
12 |
end, |
13 |
onStartFrame = function (self) |
|
14 |
||
15 |
local pvec = vector.new(the.player.x - self.x, |
|
16 |
the.player.y - self.y) |
|
17 |
||
67
by Josh C
rotate enemy ship slower |
18 |
|
19 |
local pAngle = math.atan2(pvec.y, pvec.x) |
|
20 |
local aDiff = self.rotation - pAngle |
|
21 |
||
22 |
while aDiff < (-math.pi) do |
|
23 |
--print(aDiff .. ' < -π') |
|
24 |
aDiff = aDiff + 2 * math.pi |
|
25 |
end |
|
26 |
while aDiff > math.pi do |
|
27 |
--print(aDiff .. ' > π') |
|
28 |
aDiff = aDiff - 2 * math.pi |
|
29 |
end |
|
30 |
||
31 |
if math.abs(aDiff) > 0.1 then |
|
32 |
-- rotation really shouldn't be negative. I |
|
33 |
-- don't understand why that is. :\ |
|
34 |
self.velocity.rotation = -2 * util.signOf(aDiff) |
|
35 |
else |
|
36 |
--print('not rotating') |
|
37 |
self.velocity.rotation = 0 |
|
38 |
end |
|
65
by Josh C
enemy is back |
39 |
|
40 |
local pdist2 = pvec:len2() |
|
41 |
||
42 |
if pdist2 > 400^2 then -- ... if player dist > 64? |
|
43 |
self.acceleration = vector.new(300, 0) |
|
44 |
self.acceleration:rotate_inplace(self.rotation) |
|
45 |
self.thrust.visible = true |
|
46 |
else |
|
47 |
self.acceleration = {x=0, y=0} |
|
48 |
self.thrust.visible = false |
|
49 |
end |
|
50 |
||
67
by Josh C
rotate enemy ship slower |
51 |
if math.abs(aDiff) < 0.5 * math.pi and |
52 |
pdist2 < 400^2 and |
|
65
by Josh C
enemy is back |
53 |
love.timer.getTime() - self.lastFired > 0.25 then |
54 |
--print('pew') |
|
55 |
b = Bullet:new{ |
|
56 |
x = self.x + self.width / 2, |
|
57 |
y = self.y + self.height / 2, |
|
58 |
rotation = self.rotation |
|
59 |
} |
|
60 |
self.lastFired = love.timer.getTime() |
|
61 |
end |
|
62 |
||
63 |
end, |
|
7
by Josh C
enemy |
64 |
onUpdate = function(self) |
65
by Josh C
enemy is back |
65 |
self.thrust.x = self.x - self.width |
66 |
self.thrust.y = self.y |
|
67 |
self.thrust.rotation = self.rotation |
|
68 |
end, |
|
69 |
||
7
by Josh C
enemy |
70 |
} |