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 |
|
32 |
--print('creating mirror: X='..xMirrorX..' Y='..xMirrorY) |
|
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 } |
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
35 |
the.app.view:add(self.xMirror) |
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 |
43 |
the.app.view:remove(self.xMirror) |
|
44 |
self.xMirror = nil |
|
45 |
-- die? |
|
46 |
end |
|
47 |
||
48 |
if self.y ~= mirrorY then |
|
49 |
if not self.yMirror then |
|
50 |
--print('creating mirror: X='..yMirrorX..' Y='..yMirrorY) |
|
51 |
||
27
by Josh C
try to not spawn rocks where you can see them. not working if screen |
52 |
self.yMirror = Mirror:new{ of = self, image = self.image } |
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
53 |
the.app.view:add(self.yMirror) |
54 |
end |
|
55 |
||
56 |
self.yMirror.x = self.x |
|
57 |
self.yMirror.y = mirrorY |
|
58 |
self.yMirror.rotation = self.rotation |
|
26
by Josh C
rocks! |
59 |
self.yMirror.scale = self.scale |
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
60 |
elseif self.yMirror then |
61 |
the.app.view:remove(self.yMirror) |
|
62 |
self.yMirror = nil |
|
63 |
-- die? |
|
64 |
end |
|
23
by Josh C
and that fixes the corner bug |
65 |
|
66 |
if self.x ~= mirrorX and self.y ~= mirrorY then |
|
67 |
if not self.xyMirror then |
|
68 |
--print('creating mirror: X='..xyMirrorX..' Y='..xyMirrorY) |
|
69 |
||
27
by Josh C
try to not spawn rocks where you can see them. not working if screen |
70 |
self.xyMirror = Mirror:new{ of = self, image = self.image } |
23
by Josh C
and that fixes the corner bug |
71 |
the.app.view:add(self.xyMirror) |
72 |
end |
|
73 |
||
74 |
self.xyMirror.x = mirrorX |
|
75 |
self.xyMirror.y = mirrorY |
|
76 |
self.xyMirror.rotation = self.rotation |
|
26
by Josh C
rocks! |
77 |
self.xyMirror.scale = self.scale |
23
by Josh C
and that fixes the corner bug |
78 |
elseif self.xyMirror then |
79 |
the.app.view:remove(self.xyMirror) |
|
80 |
self.xyMirror = nil |
|
81 |
-- die? |
|
82 |
end |
|
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
83 |
end, |
24
by Josh C
monkey patch group to add onRemove hook. remove mirrors on remove. |
84 |
onRemove = function(self) |
85 |
if self.xMirror then |
|
86 |
the.app.view:remove(self.xMirror) |
|
87 |
end |
|
88 |
||
89 |
if self.yMirror then |
|
90 |
the.app.view:remove(self.yMirror) |
|
91 |
end |
|
92 |
||
93 |
if self.xyMirror then |
|
94 |
the.app.view:remove(self.xyMirror) |
|
95 |
end |
|
96 |
end, |
|
22
by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored? |
97 |
update = function (self, elapsed) |
98 |
Tile.update(self, elapsed) |
|
99 |
||
100 |
self:wrap() |
|
101 |
self:reflect() |
|
102 |
end |
|
103 |
} |