/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-05-04 22:53:27 UTC
  • Revision ID: josh@9ix.org-20130504225327-dsc1gi3ri96h50s2
trying some movement styles.  derivatives on crystal quest movement.

Show diffs side-by-side

added added

removed removed

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