/traderous

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

« back to all changes in this revision

Viewing changes to rock.lua

  • Committer: Josh C
  • Date: 2013-06-30 14:59:35 UTC
  • Revision ID: josh@9ix.org-20130630145935-y34o51cg3lsom5bg
"safe" zone on planets - no new enemies will track you if you're there.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
   image = 'data/rock.png',
3
3
   onNew = function(self)
4
4
              --self.velocity = util.shortestVector(self, the.player):normalized() * 10
 
5
 
 
6
              --self.scale = 1
 
7
 
 
8
              self.collider = RockCollider:new{
 
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.rockColliders:add(self.collider)
5
17
           end,
6
 
   onEndFrame = function(self, dt)
 
18
   onUpdate = function(self, dt)
 
19
                 self.collider.x = self.x + self.width / 2 * (1 - self.scale)
 
20
                 self.collider.y = self.y + self.height / 2 * (1 - self.scale)
 
21
                 --self.collider.rotation = self.rotation -- ???
 
22
              end,
 
23
   onEndFrame = function(self)
7
24
                   -- onEndFrame to give a chance to go out of bounds then wrap
8
25
 
9
26
                   if DEBUG and the.console.visible then
11
28
                         self.text = Text:new()
12
29
                         the.view:add(self.text)
13
30
                      end
14
 
                      
 
31
 
15
32
                      local pVec = util.shortestVector(self, the.player)
16
33
                      self.text.text = pVec.x .. ', ' .. pVec.y
17
34
                      self.text.x, self.text.y = self.x, self.y
22
39
                      end
23
40
                   end
24
41
                end
 
42
}
 
43
 
 
44
RockCollider = Fill:extend {
 
45
   fill = {0,0,255},
 
46
   onUpdate = function(self, dt)
 
47
                 self.visible = DEBUG and the.console.visible
 
48
              end,
 
49
   onCollide = function(self, other)
 
50
                  if other:instanceOf(Bullet) then
 
51
                     local b = Boom:new {
 
52
                        x = self.x,
 
53
                        y = self.y,
 
54
                        velocity = {
 
55
                           rotation = util.signOf(self.rock.rotation) * 5
 
56
                        }
 
57
                     }
 
58
                     the.app.view:add(b)
 
59
 
 
60
                     the.rocks:remove(self.rock)
 
61
                     the.rockColliders:remove(self)
 
62
                     self.rock = nil -- break circular reference
 
63
 
 
64
                     the.bullets:remove(other)
 
65
                     other:die()
 
66
                  end
 
67
               end
25
68
}
 
 
b'\\ No newline at end of file'