/traderous

To get this branch, use:
bzr branch http://66.246.75.32/bzr/traderous
26 by Josh C
rocks!
1
Rock = WrapTile:extend {
27 by Josh C
try to not spawn rocks where you can see them. not working if screen
2
   image = 'data/rock.png',
3
   onNew = function(self)
4
              --self.velocity = util.shortestVector(self, the.player):normalized() * 10
28 by Josh C
prepare a collision box for the rocks
5
6
              --self.scale = 1
7
29 by Josh C
shoot things!
8
              self.collider = RockCollider:new{
28 by Josh C
prepare a collision box for the rocks
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
29 by Josh C
shoot things!
16
              the.rockColliders:add(self.collider)
27 by Josh C
try to not spawn rocks where you can see them. not working if screen
17
           end,
28 by Josh C
prepare a collision box for the rocks
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)
27 by Josh C
try to not spawn rocks where you can see them. not working if screen
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
28 by Josh C
prepare a collision box for the rocks
31
27 by Josh C
try to not spawn rocks where you can see them. not working if screen
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
28 by Josh C
prepare a collision box for the rocks
42
}
29 by Josh C
shoot things!
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
30 by Josh C
explosions
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
32 by Josh C
stick things into layers
60
                     the.rocks:remove(self.rock)
29 by Josh C
shoot things!
61
                     the.rockColliders:remove(self)
62
                     self.rock = nil -- break circular reference
63
64
                     the.bullets:remove(other)
35 by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets).
65
                     other:die()
29 by Josh C
shoot things!
66
                  end
67
               end
68
}