1
WrapTile = Tile:extend {
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
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
15
reflect = function(self)
16
local mirrorX, mirrorY = self.x, self.y
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
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
30
if self.x ~= mirrorX then
31
if not self.xMirror then
32
--print('creating mirror: X='..mirrorX..' Y='..mirrorY)
34
self.xMirror = Mirror:new{ of = self, image = self.image }
35
the.mirrors:add(self.xMirror)
38
self.xMirror.x = mirrorX
39
self.xMirror.y = self.y
40
self.xMirror.rotation = self.rotation
41
self.xMirror.scale = self.scale
42
elseif self.xMirror then
43
if self.type == 'bullet' then
44
--print('pruning bullet')
46
the.mirrors:remove(self.xMirror)
47
self.xMirror.of = nil -- break circular reference
52
if self.y ~= mirrorY then
53
if not self.yMirror then
54
--print('creating mirror: X='..mirrorX..' Y='..mirrorY)
56
self.yMirror = Mirror:new{ of = self, image = self.image }
57
the.mirrors:add(self.yMirror)
60
self.yMirror.x = self.x
61
self.yMirror.y = mirrorY
62
self.yMirror.rotation = self.rotation
63
self.yMirror.scale = self.scale
64
elseif self.yMirror then
65
if self.type == 'bullet' then
66
--print('pruning bullet')
68
the.mirrors:remove(self.yMirror)
69
self.yMirror.of = nil -- break circular reference
74
if self.x ~= mirrorX and self.y ~= mirrorY then
75
if not self.xyMirror then
76
--print('creating mirror: X='..mirrorX..' Y='..mirrorY)
78
self.xyMirror = Mirror:new{ of = self, image = self.image }
79
the.mirrors:add(self.xyMirror)
82
self.xyMirror.x = mirrorX
83
self.xyMirror.y = mirrorY
84
self.xyMirror.rotation = self.rotation
85
self.xyMirror.scale = self.scale
86
elseif self.xyMirror then
87
if self.type == 'bullet' then
88
--print('pruning bullet')
90
the.mirrors:remove(self.xyMirror)
91
self.xyMirror.of = nil -- break circular reference
96
onRemove = function(self)
98
if self.type == 'bullet' then
99
--print('removing bullet, so removing mirror')
101
the.mirrors:remove(self.xMirror)
102
self.xMirror.of = nil -- break circular reference
107
if self.type == 'bullet' then
108
--print('removing bullet, so removing mirror')
110
the.mirrors:remove(self.yMirror)
111
self.yMirror.of = nil -- break circular reference
115
if self.xyMirror then
116
if self.type == 'bullet' then
117
--print('removing bullet, so removing mirror')
119
the.mirrors:remove(self.xyMirror)
120
self.xyMirror.of = nil -- break circular reference
124
update = function (self, elapsed)
125
Tile.update(self, elapsed)
b'\\ No newline at end of file'