/traderous

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

« back to all changes in this revision

Viewing changes to planet.lua

  • Committer: Josh C
  • Date: 2013-06-30 23:48:52 UTC
  • Revision ID: josh@9ix.org-20130630234852-rja5zhlmup3cp0tm
award bounty

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
Planet = Tile:extend {
2
2
   image = 'data/planet1.png',
3
 
   potentialGoods = {
4
 
      {name = 'Bobble-Headed Dolls',
5
 
       low = 50, med = 100, high = 150,
6
 
       chance = 0.5},
7
 
      {name = 'Alliance Foodstuffs',
8
 
       low = 100, med = 250, high = 400,
9
 
       chance = 0.8},
10
 
      {name = 'Antique Weapons',
11
 
       low = 5000, med = 6000, high = 8000,
12
 
       chance = 0.1}
13
 
   },
14
3
   goods = {},
15
4
   onNew = function (self)
16
5
              self.indicator = Tile:new{ image = 'data/planet1ind.png' }
28
17
                 end
29
18
              end
30
19
 
31
 
              while #self.goods == 0 do
32
 
                 for _, good in ipairs(self.potentialGoods) do
33
 
                    if math.random() < good.chance then
34
 
                       local tier = math.random(4) -- betw 1 and 4
35
 
                       if tier == 1 then
36
 
                          table.insert(self.goods, {good.name, good.low})
37
 
                       elseif tier ==2 then
38
 
                          table.insert(self.goods, {good.name, good.high})
39
 
                       else
40
 
                          -- double chance for med (3 or 4)
41
 
                          table.insert(self.goods, {good.name, good.med})
42
 
                       end
43
 
                    end
44
 
                 end
45
 
              end
46
 
 
47
20
              self.label = Text:new {
48
21
                 text = self.name,
49
22
                 x = self.x,
72
45
                 if pvec:len2() < hw ^ 2 then
73
46
                    self.label.visible = true
74
47
                    self.keyLabel.visible = true
 
48
                    the.player.onPlanet = self
75
49
 
76
50
                    if the.keys:justPressed('l') then
77
51
                       the.player.velocity = {x=0, y=0}
78
52
                       the.player.acceleration = {x=0, y=0}
79
53
 
80
 
                       -- save player data
81
 
                       the.storage.data.player = {x = the.player.x,
82
 
                                                  y = the.player.y,
83
 
                                                  money = the.player.money,
84
 
                                                  goods = the.player.goods,
85
 
                                                  cargoSpace = the.player.cargoSpace
86
 
                                               }
87
 
                       the.storage:save()
 
54
                       the.player:save()
88
55
 
89
56
                       tradeView = TradeView:new{ planet = self }
90
57
                       tradeView:activate()
92
59
                 else
93
60
                    self.label.visible = false
94
61
                    self.keyLabel.visible = false
 
62
                    if the.player.onPlanet == self then
 
63
                       the.player.onPlanet = false
 
64
                    end
95
65
                 end
96
66
              end,
97
67
   onEndFrame = function (self)