/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-06-15 19:58:24 UTC
  • Revision ID: josh@9ix.org-20130615195824-62r7gwrujgyijmh9
prices, buttons

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
                  end
20
20
}
21
21
 
22
 
local velLimit = 300
 
22
local velLimit = 400
23
23
--local velLimit = 50
24
24
SpacePlayer = Tile:extend{
25
25
   image = 'data/ship.png',
26
26
   maxVelocity = {x=velLimit,y=velLimit},
27
27
   minVelocity = {x=-velLimit, y=-velLimit},
28
28
   lastFired = 0,
29
 
   money = 2000, -- what to use for money symbol? ✪ or ☥ or Ⓐ?
30
 
   goods = {},
31
 
   cargoSpace = 20,
32
29
   onNew = function(self)
33
30
              self.thrust = Tile:new{image = 'data/thrust.png'}
34
 
              self.shield = Shield:new{ship = self}
35
31
           end,
36
32
   onStartFrame = function(self)
37
33
                     --- TAKE 2
62
58
                           b = Bullet:new{
63
59
                              x = self.x + self.width / 2,
64
60
                              y = self.y + self.height / 2,
65
 
                              rotation = self.rotation,
66
 
                              source = self
67
61
                           }
68
62
                           self.lastFired = love.timer.getTime()
69
63
                     end
77
71
                   self:collide(the.rockColliders)
78
72
                end,
79
73
   onCollide = function(self, other)
80
 
                  if other:instanceOf(Bullet) and other.source ~= self then
81
 
                     if self.shield.strength == 0 then
82
 
                        -- die
83
 
                        the.app.view:add( Boom:new {
84
 
                                             x = self.x,
85
 
                                             y = self.y,
86
 
                                             velocity = { rotation = 5 }
87
 
                                          })
88
 
 
89
 
                        self:die()
90
 
                        self.thrust:die()
91
 
                     else
92
 
                        self.shield:onHit()
93
 
                     end
94
 
 
95
 
                     other:die()
96
 
                     the.bullets:remove(other)
97
 
                  end
98
 
 
99
74
                  if other:instanceOf(RockCollider) then
100
75
                     the.app.view:add( Boom:new {
101
76
                                          x = self.x,
105
80
 
106
81
                     self:die()
107
82
                     self.thrust:die()
108
 
                  end
109
83
 
110
 
                  if not self.active then
111
84
                     the.over.visible = true
112
85
                     the.instructions.visible = true
 
86
                     the.app.view:updateScore()
 
87
 
 
88
                     local score = love.timer.getTime() - the.app.view.gameStart
 
89
                     if score > the.storage.data.highScore then
 
90
                        the.storage.data.highScore = score
 
91
                        the.storage:save()
 
92
 
 
93
                        the.highScore.text = string.format(
 
94
                           'High Score: %d:%02d', score / 60, score % 60
 
95
                        )
 
96
                     end
113
97
                  end
114
 
               end,
115
 
   buy = function(self, good, price)
116
 
            if self.money >= price and self:availableSpace() > 0 then
117
 
               self.goods[good] = (self.goods[good] or 0) + 1
118
 
               self.money = self.money - price
119
 
            end
120
 
         end,
121
 
   sell = function(self, good, price)
122
 
             if self.goods[good] and self.goods[good] > 0 then
123
 
                self.goods[good] = self.goods[good] - 1
124
 
                self.money = self.money + price
125
 
             end
126
 
          end,
127
 
   availableSpace = function(self)
128
 
                       local cargo = 0
129
 
                       for _, amt in pairs(self.goods) do
130
 
                          cargo = cargo + amt
131
 
                       end
132
 
 
133
 
                       return self.cargoSpace - cargo
134
 
                    end
 
98
               end
135
99
}
 
 
b'\\ No newline at end of file'