/spacey

To get this branch, use:
bzr branch http://9ix.org/bzr/spacey

« back to all changes in this revision

Viewing changes to wrap_tile.lua

  • Committer: Josh C
  • Date: 2013-05-04 20:47:29 UTC
  • Revision ID: josh@9ix.org-20130504204729-0g2wmw6k4nvsh58s
basecode main.lua

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
34
 
                     self.xMirror = Tile:new{ image = self.image }
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
41
 
               elseif self.xMirror then
42
 
                  the.app.view:remove(self.xMirror)
43
 
                  self.xMirror = nil
44
 
                  -- die?
45
 
               end
46
 
 
47
 
               if self.y ~= mirrorY then
48
 
                  if not self.yMirror then
49
 
                     --print('creating mirror: X='..yMirrorX..' Y='..yMirrorY)
50
 
 
51
 
                     self.yMirror = Tile:new{ image = self.image }
52
 
                     the.app.view:add(self.yMirror)
53
 
                  end
54
 
 
55
 
                  self.yMirror.x = self.x
56
 
                  self.yMirror.y = mirrorY
57
 
                  self.yMirror.rotation = self.rotation
58
 
               elseif self.yMirror then
59
 
                  the.app.view:remove(self.yMirror)
60
 
                  self.yMirror = nil
61
 
                  -- die?
62
 
               end
63
 
 
64
 
               if self.x ~= mirrorX and self.y ~= mirrorY then
65
 
                  if not self.xyMirror then
66
 
                     --print('creating mirror: X='..xyMirrorX..' Y='..xyMirrorY)
67
 
 
68
 
                     self.xyMirror = Tile:new{ image = self.image }
69
 
                     the.app.view:add(self.xyMirror)
70
 
                  end
71
 
 
72
 
                  self.xyMirror.x = mirrorX
73
 
                  self.xyMirror.y = mirrorY
74
 
                  self.xyMirror.rotation = self.rotation
75
 
               elseif self.xyMirror then
76
 
                  the.app.view:remove(self.xyMirror)
77
 
                  self.xyMirror = nil
78
 
                  -- die?
79
 
               end
80
 
            end,
81
 
   update = function (self, elapsed)
82
 
               Tile.update(self, elapsed)
83
 
 
84
 
               self:wrap()
85
 
               self:reflect()
86
 
 
87
 
               -- TODO: make sure mirrors are cleaned up when we are
88
 
               -- killed / removed from view
89
 
            end
90
 
}
 
 
b'\\ No newline at end of file'