/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-23 03:10:51 UTC
  • Revision ID: josh@9ix.org-20130623031051-3142chix333jkmqi
pay to fix shield

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
require 'planet'
20
20
require 'trade_view'
21
21
require 'shield'
22
 
require 'pause_view'
23
 
require 'game_over'
24
 
require 'names'
25
22
 
26
23
util = {
27
24
   signOf = function(value)
35
32
 
36
33
GameView = View:extend {
37
34
   onNew = function (self)
38
 
              the.storage = Storage:new{filename = 'world.lua'}
 
35
              the.storage = Storage:new{filename = 'scores.lua'}
39
36
              the.storage:load()
40
37
              --if not the.storage.data.highScore then
41
38
              --   print('initializing storage')
45
42
              the.bullets = Group:new()
46
43
              the.interface = Group:new()
47
44
              the.planets = Group:new()
48
 
              the.planetLabels = Group:new()
49
45
              the.indicators = Group:new()
50
46
              the.enemies = Group:new()
51
47
 
52
 
              -- init bg before build/load since planets need to know bg size
53
48
              the.bg = Tile:new{
54
49
                 image = 'data/stars3.png',
55
50
                 width = 27320,
57
52
              }
58
53
              self:add(the.bg)
59
54
 
60
 
              if self.newWorld or not the.storage.data.player then
61
 
                 the.storage.data = {planets = {}}
62
 
 
63
 
                 -- build planets from random
64
 
                 for _ = 1, math.random(3, 6) do
65
 
                    local planet = Planet:new{
66
 
                       x = math.random(the.app.width / 2,
67
 
                                       the.bg.width - the.app.width / 2),
68
 
                       y = math.random(the.app.height / 2,
69
 
                                       the.bg.height - the.app.height / 2),
70
 
                       rotation = math.random() * math.pi
71
 
                    }
72
 
                    the.planets:add(planet)
73
 
                    table.insert(the.storage.data.planets, {
74
 
                                    x = planet.x,
75
 
                                    y = planet.y,
76
 
                                    rotation = planet.rotation,
77
 
                                    goods = planet.goods,
78
 
                                    name = planet.name
79
 
                                 })
80
 
                 end
81
 
 
82
 
                 -- build fresh player
83
 
                 local player = SpacePlayer:new{x=the.bg.width / 2, y=the.bg.height / 2}
84
 
                 the.player = player
85
 
                 the.storage.data.player = {x = player.x,
86
 
                                            y = player.y,
87
 
                                            money = player.money,
88
 
                                            goods = player.goods,
89
 
                                            cargoSpace = player.cargoSpace
90
 
                                         }
91
 
 
92
 
                 the.storage:save()
93
 
              else
94
 
                 -- load planets with x, y, goods
95
 
                 for _, planetData in ipairs(the.storage.data.planets) do
96
 
                    the.planets:add(Planet:new(planetData))
97
 
                 end
98
 
 
99
 
                 -- load player with cargo, money, position
100
 
                 the.player = SpacePlayer:new(the.storage.data.player)
101
 
 
102
 
                 -- reload storage as we've turned it all into objects
103
 
                 the.storage:load()
104
 
              end
105
 
 
106
55
              self:add(the.planets)
107
 
              self:add(the.planetLabels)
108
56
 
 
57
              --the.player = CrystalPlayer:new{x=400,y=300}
 
58
              the.player = SpacePlayer:new{x=the.bg.width / 2, y=the.bg.height / 2}
109
59
              self:add(the.player)
110
60
              self:add(the.player.thrust)
111
61
              self:add(the.player.shield)
125
75
              self:add(the.indicators)
126
76
              self:add(the.interface)
127
77
 
 
78
              for _ = 1, math.random(3, 6) do
 
79
                 local planet = Planet:new{
 
80
                    x = math.random(the.app.width / 2,
 
81
                                    the.bg.width - the.app.width / 2),
 
82
                    y = math.random(the.app.height / 2,
 
83
                                    the.bg.height - the.app.height / 2),
 
84
                    rotation = math.random() * math.pi
 
85
                 }
 
86
                 the.planets:add(planet)
 
87
              end
 
88
 
128
89
              the.cursor = Cursor:new()
129
90
              self:add(the.cursor)
130
91
 
 
92
              the.over = Text:new{
 
93
                 y = the.app.height / 2,
 
94
                 width = the.app.width,
 
95
                 align = 'center',
 
96
                 font = 25,
 
97
                 text = "Game Over",
 
98
                 visible = false
 
99
              }
 
100
              the.interface:add(the.over)
 
101
 
 
102
 
 
103
              the.instructions = Text:new{
 
104
                 y = the.app.height / 2 + 32,
 
105
                 width = the.app.width,
 
106
                 align = 'center',
 
107
                 font = 12,
 
108
                 text = "Press Enter to start a new game\nPress Q to quit",
 
109
                 visible = false
 
110
              }
 
111
              the.interface:add(the.instructions)
 
112
 
131
113
              love.mouse.setGrab(true)
132
114
              love.mouse.setVisible(false)
133
115
              love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
135
117
              self.focus = the.player
136
118
           end,
137
119
   onUpdate = function(self, dt)
138
 
                 if the.keys:justPressed('escape') then
139
 
                    PauseView:new():activate()
140
 
                 end
141
 
 
142
120
                 the.bullets:collide(the.planets)
143
121
                 the.bullets:collide(the.player)
144
122
                 the.bullets:collide(the.enemies)
185
163
                 self.console:watch('num mirrors', '#the.mirrors.sprites')
186
164
                 self.console:watch('num rocks', '#the.rocks.sprites')
187
165
                 self.console:watch('num planets', '#the.planets.sprites')
188
 
                 self.console:watch('num enemies', 'the.enemies:count()')
189
 
                 self.console:watch('onPlanet', 'the.player.onPlanet')
190
166
                 --self.console:watch('drawTook', 'the.drawTook')
191
167
 
192
168
                 -- back off that dark overlay a bit
195
171
           end,
196
172
   onUpdate = function (self, dt)
197
173
                 if not (DEBUG and the.console.visible) then
198
 
                    if the.keys:justPressed('return') and the.keys:pressed('alt') then
199
 
                       love.graphics.toggleFullscreen()
 
174
                    if the.keys:justPressed('q') then
 
175
                       self.quit()
 
176
                    elseif the.keys:justPressed('return') then
 
177
                       if the.keys:pressed('alt') then
 
178
                          love.graphics.toggleFullscreen()
 
179
                       else
 
180
                          self.view = GameView:new()
 
181
                       end
200
182
                    elseif the.keys:justPressed('f1') then
201
183
                       local ss = love.graphics.newScreenshot()
202
184
                       ss:encode('screenshot-' ..love.timer.getTime()..'.png')