bzr branch
http://9ix.org/bzr/spacey
26
by Josh C
rocks! |
1 |
Rock = WrapTile:extend { |
27
by Josh C
try to not spawn rocks where you can see them. not working if screen |
2 |
image = 'data/rock.png', |
3 |
onNew = function(self) |
|
4 |
--self.velocity = util.shortestVector(self, the.player):normalized() * 10 |
|
28
by Josh C
prepare a collision box for the rocks |
5 |
|
6 |
--self.scale = 1 |
|
7 |
||
29
by Josh C
shoot things! |
8 |
self.collider = RockCollider:new{ |
28
by Josh C
prepare a collision box for the rocks |
9 |
--x = self.x, |
10 |
--y = self.y, |
|
11 |
width = self.width * self.scale, |
|
12 |
height = self.height * self.scale, |
|
13 |
rock = self |
|
14 |
} |
|
15 |
||
16 |
the.app.view:add(self.collider) |
|
29
by Josh C
shoot things! |
17 |
the.rockColliders:add(self.collider) |
27
by Josh C
try to not spawn rocks where you can see them. not working if screen |
18 |
end, |
28
by Josh C
prepare a collision box for the rocks |
19 |
onUpdate = function(self, dt) |
20 |
self.collider.x = self.x + self.width / 2 * (1 - self.scale) |
|
21 |
self.collider.y = self.y + self.height / 2 * (1 - self.scale) |
|
22 |
--self.collider.rotation = self.rotation -- ??? |
|
23 |
end, |
|
24 |
onEndFrame = function(self) |
|
27
by Josh C
try to not spawn rocks where you can see them. not working if screen |
25 |
-- onEndFrame to give a chance to go out of bounds then wrap |
26 |
||
27 |
if DEBUG and the.console.visible then |
|
28 |
if not self.text then |
|
29 |
self.text = Text:new() |
|
30 |
the.view:add(self.text) |
|
31 |
end |
|
28
by Josh C
prepare a collision box for the rocks |
32 |
|
27
by Josh C
try to not spawn rocks where you can see them. not working if screen |
33 |
local pVec = util.shortestVector(self, the.player) |
34 |
self.text.text = pVec.x .. ', ' .. pVec.y |
|
35 |
self.text.x, self.text.y = self.x, self.y |
|
36 |
self.text.visible = true |
|
37 |
else |
|
38 |
if self.text then |
|
39 |
self.text.visible = false |
|
40 |
end |
|
41 |
end |
|
42 |
end |
|
28
by Josh C
prepare a collision box for the rocks |
43 |
} |
29
by Josh C
shoot things! |
44 |
|
45 |
RockCollider = Fill:extend { |
|
46 |
fill = {0,0,255}, |
|
47 |
onUpdate = function(self, dt) |
|
48 |
self.visible = DEBUG and the.console.visible |
|
49 |
end, |
|
50 |
onCollide = function(self, other) |
|
51 |
if other:instanceOf(Bullet) then |
|
52 |
the.app.view:remove(self.rock) |
|
53 |
the.app.view:remove(self) |
|
54 |
the.rockColliders:remove(self) |
|
55 |
self.rock = nil -- break circular reference |
|
56 |
||
57 |
the.app.view:remove(other) |
|
58 |
the.bullets:remove(other) |
|
59 |
end |
|
60 |
end |
|
61 |
} |