/traderous

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

« back to all changes in this revision

Viewing changes to player.lua

  • Committer: Josh C
  • Date: 2013-10-21 18:31:55 UTC
  • Revision ID: josh@9ix.org-20131021183155-vl7pxaor2u3pw0t0
have enemies disengage when you land

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
   goods = {},
31
31
   cargoSpace = 20,
32
32
   onPlanet = false,
 
33
   kills = 0,
33
34
   onNew = function(self)
34
35
              self.thrust = Tile:new{image = 'data/thrust.png'}
35
36
              self.shield = Shield:new{ship = self}
68
69
                           }
69
70
                           self.lastFired = love.timer.getTime()
70
71
                     end
 
72
 
 
73
                     if the.keys:justPressed('x') then
 
74
                        --self:doHit()
 
75
                     end
71
76
                  end,
72
77
   onUpdate = function(self)
73
78
                 self.thrust.x = self.x - self.width
77
82
   onEndFrame = function(self)
78
83
                   self:collide(the.rockColliders)
79
84
                end,
 
85
   doHit = function(self)
 
86
              if self.shield.strength == 0 then
 
87
                 -- die
 
88
                 the.app.view:add( Boom:new {
 
89
                                      x = self.x,
 
90
                                      y = self.y,
 
91
                                      velocity = { rotation = 5 }
 
92
                                   })
 
93
 
 
94
                 self:die()
 
95
                 self.thrust:die()
 
96
              else
 
97
                 self.shield:onHit()
 
98
              end
 
99
 
 
100
              if not self.active then
 
101
                 the.interface:add(GameOver:new())
 
102
              end
 
103
           end,
80
104
   onCollide = function(self, other)
81
105
                  if other:instanceOf(Bullet) and other.source ~= self then
82
 
                     if self.shield.strength == 0 then
83
 
                        -- die
84
 
                        the.app.view:add( Boom:new {
85
 
                                             x = self.x,
86
 
                                             y = self.y,
87
 
                                             velocity = { rotation = 5 }
88
 
                                          })
89
 
 
90
 
                        self:die()
91
 
                        self.thrust:die()
92
 
                     else
93
 
                        self.shield:onHit()
94
 
                     end
 
106
                     self:doHit()
95
107
 
96
108
                     other:die()
97
109
                     the.bullets:remove(other)
107
119
                     self:die()
108
120
                     self.thrust:die()
109
121
                  end
110
 
 
111
 
                  if not self.active then
112
 
                     the.interface:add(GameOver:new())
113
 
                  end
114
122
               end,
115
123
   buy = function(self, good, price)
116
124
            if self.money >= price and self:availableSpace() > 0 then
131
139
                       end
132
140
 
133
141
                       return self.cargoSpace - cargo
134
 
                    end
 
142
                    end,
 
143
   save = function(self)
 
144
             -- save player data
 
145
             the.storage.data.player = {x = self.x,
 
146
                                        y = self.y,
 
147
                                        money = self.money,
 
148
                                        goods = self.goods,
 
149
                                        cargoSpace = self.cargoSpace
 
150
                                     }
 
151
             the.storage:save()
 
152
          end
135
153
}
 
 
b'\\ No newline at end of file'