/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 18:23:38 UTC
  • Revision ID: josh@9ix.org-20130625182338-gkx8evr4z93zh9x7
load/save (not working yet)

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 = 'scores.lua'}
 
36
              the.storage = Storage:new{filename = 'world.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
49
50
              the.bg = Tile:new{
50
51
                 image = 'data/stars3.png',
51
52
                 width = 27320,
53
54
              }
54
55
              self:add(the.bg)
55
56
 
 
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
              end
 
98
 
56
99
              self:add(the.planets)
57
100
 
58
 
              --the.player = CrystalPlayer:new{x=400,y=300}
59
 
              the.player = SpacePlayer:new{x=the.bg.width / 2, y=the.bg.height / 2}
60
101
              self:add(the.player)
61
102
              self:add(the.player.thrust)
62
103
              self:add(the.player.shield)
76
117
              self:add(the.indicators)
77
118
              self:add(the.interface)
78
119
 
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
 
 
90
120
              the.cursor = Cursor:new()
91
121
              self:add(the.cursor)
92
122