1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
-- player = 300 accel, 400 velLimit
local accelLimit = 150
local velLimit = 200
Enemy = Tile:extend {
image = 'data/enemy.png',
maxVelocity = {x=velLimit,y=velLimit},
minVelocity = {x=-velLimit, y=-velLimit},
lastFired = 0,
onNew = function (self)
self.thrust = Tile:new{image = 'data/thrust.png'}
end,
onStartFrame = function (self)
local pvec = vector.new(the.player.x - self.x,
the.player.y - self.y)
self.rotation = math.atan2(pvec.y, pvec.x)
local pdist2 = pvec:len2()
if pdist2 > 400^2 then -- ... if player dist > 64?
self.acceleration = vector.new(300, 0)
self.acceleration:rotate_inplace(self.rotation)
self.thrust.visible = true
else
self.acceleration = {x=0, y=0}
self.thrust.visible = false
end
if pdist2 < 400^2 and
love.timer.getTime() - self.lastFired > 0.25 then
--print('pew')
b = Bullet:new{
x = self.x + self.width / 2,
y = self.y + self.height / 2,
rotation = self.rotation
}
self.lastFired = love.timer.getTime()
end
end,
onUpdate = function(self)
self.thrust.x = self.x - self.width
self.thrust.y = self.y
self.thrust.rotation = self.rotation
end,
}
|