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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
Rock = WrapTile:extend {
image = 'data/rock.png',
onNew = function(self)
--self.velocity = util.shortestVector(self, the.player):normalized() * 10
--self.scale = 1
self.collider = RockCollider:new{
--x = self.x,
--y = self.y,
width = self.width * self.scale,
height = self.height * self.scale,
rock = self
}
the.rockColliders:add(self.collider)
end,
onUpdate = function(self, dt)
self.collider.x = self.x + self.width / 2 * (1 - self.scale)
self.collider.y = self.y + self.height / 2 * (1 - self.scale)
--self.collider.rotation = self.rotation -- ???
end,
onEndFrame = function(self)
-- onEndFrame to give a chance to go out of bounds then wrap
if DEBUG and the.console.visible then
if not self.text then
self.text = Text:new()
the.view:add(self.text)
end
local pVec = util.shortestVector(self, the.player)
self.text.text = pVec.x .. ', ' .. pVec.y
self.text.x, self.text.y = self.x, self.y
self.text.visible = true
else
if self.text then
self.text.visible = false
end
end
end
}
RockCollider = Fill:extend {
fill = {0,0,255},
onUpdate = function(self, dt)
self.visible = DEBUG and the.console.visible
end,
onCollide = function(self, other)
if other:instanceOf(Bullet) then
local b = Boom:new {
x = self.x,
y = self.y,
velocity = {
rotation = util.signOf(self.rock.rotation) * 5
}
}
the.app.view:add(b)
the.rocks:remove(self.rock)
the.rockColliders:remove(self)
self.rock = nil -- break circular reference
the.bullets:remove(other)
other:die()
end
end
}
|