/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-16 03:53:05 UTC
  • Revision ID: josh@9ix.org-20130616035305-33ca39wd4q3q4v13
bullets don't go through planets

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
Rock = WrapTile:extend {
2
 
   image = 'data/rock.png'
 
2
   image = 'data/rock.png',
 
3
   onNew = function(self)
 
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)
 
17
           end,
 
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)
 
24
                   -- onEndFrame to give a chance to go out of bounds then wrap
 
25
 
 
26
                   if DEBUG and the.console.visible then
 
27
                      if not self.text then
 
28
                         self.text = Text:new()
 
29
                         the.view:add(self.text)
 
30
                      end
 
31
 
 
32
                      local pVec = util.shortestVector(self, the.player)
 
33
                      self.text.text = pVec.x .. ', ' .. pVec.y
 
34
                      self.text.x, self.text.y = self.x, self.y
 
35
                      self.text.visible = true
 
36
                   else
 
37
                      if self.text then
 
38
                         self.text.visible = false
 
39
                      end
 
40
                   end
 
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
3
68
}
 
 
b'\\ No newline at end of file'