bzr branch
http://9ix.org/bzr/traderous
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
1 |
WrapTile = Tile:extend { |
2 |
wrap = function(self) |
|
3 |
if self.x < the.app.width / 2 then |
|
4 |
self.x = the.bg.width - the.app.width / 2 |
|
5 |
elseif self.x > the.bg.width - the.app.width / 2 then |
|
6 |
self.x = the.app.width / 2 |
|
7 |
end |
|
8 |
||
9 |
if self.y < the.app.height / 2 then |
|
10 |
self.y = the.bg.height - the.app.height / 2 |
|
11 |
elseif self.y > the.bg.height - the.app.height / 2 then |
|
12 |
self.y = the.app.height / 2 |
|
13 |
end |
|
14 |
end, |
|
15 |
reflect = function(self) |
|
16 |
local mirrorX, mirrorY = self.x, self.y |
|
17 |
||
18 |
if self.x > the.bg.width - the.app.width then |
|
19 |
mirrorX = self.x - the.bg.width + the.app.width |
|
20 |
elseif self.x < the.app.width then |
|
21 |
mirrorX = self.x + the.bg.width - the.app.width |
|
22 |
end |
|
23 |
||
24 |
if self.y > the.bg.height - the.app.height then |
|
25 |
mirrorY = self.y - the.bg.height + the.app.height |
|
26 |
elseif self.y < the.app.height then |
|
27 |
mirrorY = self.y + the.bg.height - the.app.height |
|
28 |
end |
|
29 |
||
30 |
if self.x ~= mirrorX then |
|
31 |
if not self.xMirror then |
|
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
32 |
--print('creating mirror: X='..mirrorX..' Y='..mirrorY) |
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
33 |
|
27
by Josh C
try to not spawn rocks where you can see them. not working if screen |
34 |
self.xMirror = Mirror:new{ of = self, image = self.image } |
32
by Josh C
stick things into layers |
35 |
the.mirrors:add(self.xMirror) |
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
36 |
end |
37 |
||
38 |
self.xMirror.x = mirrorX |
|
39 |
self.xMirror.y = self.y |
|
40 |
self.xMirror.rotation = self.rotation |
|
26
by Josh C
rocks! |
41 |
self.xMirror.scale = self.scale |
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
42 |
elseif self.xMirror then |
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
43 |
if self.type == 'bullet' then |
44 |
--print('pruning bullet') |
|
45 |
end |
|
32
by Josh C
stick things into layers |
46 |
the.mirrors:remove(self.xMirror) |
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
47 |
self.xMirror.of = nil -- break circular reference |
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
48 |
self.xMirror = nil |
49 |
-- die? |
|
50 |
end |
|
51 |
||
52 |
if self.y ~= mirrorY then |
|
53 |
if not self.yMirror then |
|
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
54 |
--print('creating mirror: X='..mirrorX..' Y='..mirrorY) |
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
55 |
|
27
by Josh C
try to not spawn rocks where you can see them. not working if screen |
56 |
self.yMirror = Mirror:new{ of = self, image = self.image } |
32
by Josh C
stick things into layers |
57 |
the.mirrors:add(self.yMirror) |
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
58 |
end |
59 |
||
60 |
self.yMirror.x = self.x |
|
61 |
self.yMirror.y = mirrorY |
|
62 |
self.yMirror.rotation = self.rotation |
|
26
by Josh C
rocks! |
63 |
self.yMirror.scale = self.scale |
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
64 |
elseif self.yMirror then |
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
65 |
if self.type == 'bullet' then |
66 |
--print('pruning bullet') |
|
67 |
end |
|
32
by Josh C
stick things into layers |
68 |
the.mirrors:remove(self.yMirror) |
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
69 |
self.yMirror.of = nil -- break circular reference |
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
70 |
self.yMirror = nil |
71 |
-- die? |
|
72 |
end |
|
23
by Josh C
and that fixes the corner bug |
73 |
|
74 |
if self.x ~= mirrorX and self.y ~= mirrorY then |
|
75 |
if not self.xyMirror then |
|
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
76 |
--print('creating mirror: X='..mirrorX..' Y='..mirrorY) |
23
by Josh C
and that fixes the corner bug |
77 |
|
27
by Josh C
try to not spawn rocks where you can see them. not working if screen |
78 |
self.xyMirror = Mirror:new{ of = self, image = self.image } |
32
by Josh C
stick things into layers |
79 |
the.mirrors:add(self.xyMirror) |
23
by Josh C
and that fixes the corner bug |
80 |
end |
81 |
||
82 |
self.xyMirror.x = mirrorX |
|
83 |
self.xyMirror.y = mirrorY |
|
84 |
self.xyMirror.rotation = self.rotation |
|
26
by Josh C
rocks! |
85 |
self.xyMirror.scale = self.scale |
23
by Josh C
and that fixes the corner bug |
86 |
elseif self.xyMirror then |
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
87 |
if self.type == 'bullet' then |
88 |
--print('pruning bullet') |
|
89 |
end |
|
32
by Josh C
stick things into layers |
90 |
the.mirrors:remove(self.xyMirror) |
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
91 |
self.xyMirror.of = nil -- break circular reference |
23
by Josh C
and that fixes the corner bug |
92 |
self.xyMirror = nil |
93 |
-- die? |
|
94 |
end |
|
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
95 |
end, |
24
by Josh C
monkey patch group to add onRemove hook. remove mirrors on remove. |
96 |
onRemove = function(self) |
97 |
if self.xMirror then |
|
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
98 |
if self.type == 'bullet' then |
99 |
--print('removing bullet, so removing mirror') |
|
100 |
end |
|
32
by Josh C
stick things into layers |
101 |
the.mirrors:remove(self.xMirror) |
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
102 |
self.xMirror.of = nil -- break circular reference |
103 |
self.xMirror = nil |
|
24
by Josh C
monkey patch group to add onRemove hook. remove mirrors on remove. |
104 |
end |
105 |
||
106 |
if self.yMirror then |
|
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
107 |
if self.type == 'bullet' then |
108 |
--print('removing bullet, so removing mirror') |
|
109 |
end |
|
32
by Josh C
stick things into layers |
110 |
the.mirrors:remove(self.yMirror) |
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
111 |
self.yMirror.of = nil -- break circular reference |
112 |
self.yMirror = nil |
|
24
by Josh C
monkey patch group to add onRemove hook. remove mirrors on remove. |
113 |
end |
114 |
||
115 |
if self.xyMirror then |
|
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
116 |
if self.type == 'bullet' then |
117 |
--print('removing bullet, so removing mirror') |
|
118 |
end |
|
32
by Josh C
stick things into layers |
119 |
the.mirrors:remove(self.xyMirror) |
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
120 |
self.xyMirror.of = nil -- break circular reference |
121 |
self.xyMirror = nil |
|
24
by Josh C
monkey patch group to add onRemove hook. remove mirrors on remove. |
122 |
end |
123 |
end, |
|
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
124 |
update = function (self, elapsed) |
125 |
Tile.update(self, elapsed) |
|
126 |
||
127 |
self:wrap() |
|
35
by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets). |
128 |
if self.active then |
129 |
self:reflect() |
|
130 |
end |
|
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
131 |
end |
132 |
} |