/traderous

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

« back to all changes in this revision

Viewing changes to main.lua

  • Committer: Josh C
  • Date: 2013-06-25 16:59:14 UTC
  • Revision ID: josh@9ix.org-20130625165914-egx7p44y1v0ulwyj
pause screen

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
GameView = View:extend {
35
35
   onNew = function (self)
36
 
              the.storage = Storage:new{filename = 'world.lua'}
 
36
              the.storage = Storage:new{filename = 'scores.lua'}
37
37
              the.storage:load()
38
38
              --if not the.storage.data.highScore then
39
39
              --   print('initializing storage')
46
46
              the.indicators = Group:new()
47
47
              the.enemies = Group:new()
48
48
 
49
 
              -- init bg before build/load since planets need to know bg size
50
49
              the.bg = Tile:new{
51
50
                 image = 'data/stars3.png',
52
51
                 width = 27320,
54
53
              }
55
54
              self:add(the.bg)
56
55
 
57
 
              if self.newWorld or not the.storage.data.player then
58
 
                 the.storage.data = {planets = {}}
59
 
 
60
 
                 -- build planets from random
61
 
                 for _ = 1, math.random(3, 6) do
62
 
                    local planet = Planet:new{
63
 
                       x = math.random(the.app.width / 2,
64
 
                                       the.bg.width - the.app.width / 2),
65
 
                       y = math.random(the.app.height / 2,
66
 
                                       the.bg.height - the.app.height / 2),
67
 
                       rotation = math.random() * math.pi
68
 
                    }
69
 
                    the.planets:add(planet)
70
 
                    table.insert(the.storage.data.planets, {
71
 
                                    x = planet.x,
72
 
                                    y = planet.y,
73
 
                                    rotation = planet.rotation,
74
 
                                    goods = planet.goods
75
 
                                 })
76
 
                 end
77
 
 
78
 
                 -- build fresh player
79
 
                 local player = SpacePlayer:new{x=the.bg.width / 2, y=the.bg.height / 2}
80
 
                 the.player = player
81
 
                 the.storage.data.player = {x = player.x,
82
 
                                            y = player.y,
83
 
                                            money = player.money,
84
 
                                            goods = player.goods,
85
 
                                            cargoSpace = player.cargoSpace
86
 
                                         }
87
 
 
88
 
                 the.storage:save()
89
 
              else
90
 
                 -- load planets with x, y, goods
91
 
                 for _, planetData in ipairs(the.storage.data.planets) do
92
 
                    the.planets:add(Planet:new(planetData))
93
 
                 end
94
 
 
95
 
                 -- load player with cargo, money, position
96
 
                 the.player = SpacePlayer:new(the.storage.data.player)
97
 
 
98
 
                 -- reload storage as we've turned it all into objects
99
 
                 the.storage:load()
100
 
              end
101
 
 
102
56
              self:add(the.planets)
103
57
 
 
58
              --the.player = CrystalPlayer:new{x=400,y=300}
 
59
              the.player = SpacePlayer:new{x=the.bg.width / 2, y=the.bg.height / 2}
104
60
              self:add(the.player)
105
61
              self:add(the.player.thrust)
106
62
              self:add(the.player.shield)
120
76
              self:add(the.indicators)
121
77
              self:add(the.interface)
122
78
 
 
79
              for _ = 1, math.random(3, 6) do
 
80
                 local planet = Planet:new{
 
81
                    x = math.random(the.app.width / 2,
 
82
                                    the.bg.width - the.app.width / 2),
 
83
                    y = math.random(the.app.height / 2,
 
84
                                    the.bg.height - the.app.height / 2),
 
85
                    rotation = math.random() * math.pi
 
86
                 }
 
87
                 the.planets:add(planet)
 
88
              end
 
89
 
123
90
              the.cursor = Cursor:new()
124
91
              self:add(the.cursor)
125
92
 
201
168
                 self.console:watch('num mirrors', '#the.mirrors.sprites')
202
169
                 self.console:watch('num rocks', '#the.rocks.sprites')
203
170
                 self.console:watch('num planets', '#the.planets.sprites')
204
 
                 self.console:watch('num enemies', 'the.enemies:count()')
205
171
                 --self.console:watch('drawTook', 'the.drawTook')
206
172
 
207
173
                 -- back off that dark overlay a bit