/traderous

To get this branch, use:
bzr branch http://9ix.org/bzr/traderous
3 by Josh C
basecode main.lua
1
STRICT = true
2
DEBUG = true
3
4
require 'zoetrope'
13 by Josh C
constant velocity for bullets. using hump.vector e9b86ef
5
vector = require 'vector'
35 by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets).
6
--inspect = require 'inspect'
3 by Josh C
basecode main.lua
7
24 by Josh C
monkey patch group to add onRemove hook. remove mirrors on remove.
8
require 'group'
9
3 by Josh C
basecode main.lua
10
require 'version'
21 by Josh C
extract wrapping behavior, wrap bullets
11
require 'wrap_tile'
27 by Josh C
try to not spawn rocks where you can see them. not working if screen
12
require 'mirror'
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
13
require 'player'
7 by Josh C
enemy
14
require 'enemy'
8 by Josh C
targeting cursor (manual switch to start)
15
require 'cursor'
11 by Josh C
pew pew!
16
require 'bullet'
26 by Josh C
rocks!
17
require 'rock'
30 by Josh C
explosions
18
require 'boom'
52 by Josh C
break out planet
19
require 'planet'
53 by Josh C
beginnings of trading interface
20
require 'trade_view'
68 by Josh C
shield
21
require 'shield'
78 by Josh C
pause screen
22
require 'pause_view'
84 by Josh C
game over timer & penalty
23
require 'game_over'
87 by Josh C
show planet labels, get better names
24
require 'names'
91 by Josh C
set prices based on distance
25
require 'good'
7 by Josh C
enemy
26
27
util = {
28
   signOf = function(value)
29
               if value >= 0 then
30
                  return 1
31
               else
32
                  return -1
33
               end
27 by Josh C
try to not spawn rocks where you can see them. not working if screen
34
            end,
7 by Josh C
enemy
35
}
3 by Josh C
basecode main.lua
36
37
GameView = View:extend {
38
   onNew = function (self)
81 by Josh C
load/save (not working yet)
39
              the.storage = Storage:new{filename = 'world.lua'}
34 by Josh C
record high scores
40
              the.storage:load()
64 by Josh C
more old code cleanup
41
              --if not the.storage.data.highScore then
42
              --   print('initializing storage')
43
              --   the.storage.data = {highScore = 0}
44
              --end
34 by Josh C
record high scores
45
29 by Josh C
shoot things!
46
              the.bullets = Group:new()
39 by Josh C
some instructions at game over
47
              the.interface = Group:new()
45 by Josh C
add planet, remove rocks
48
              the.planets = Group:new()
87 by Josh C
show planet labels, get better names
49
              the.planetLabels = Group:new()
47 by Josh C
indicators for where the planets are
50
              the.indicators = Group:new()
69 by Josh C
enemy shields and death
51
              the.enemies = Group:new()
28 by Josh C
prepare a collision box for the rocks
52
81 by Josh C
load/save (not working yet)
53
              -- init bg before build/load since planets need to know bg size
19 by Josh C
move player around looping world
54
              the.bg = Tile:new{
55
                 image = 'data/stars3.png',
75 by Josh C
bigger space, slower movement, maintain enemy density
56
                 width = 27320,
57
                 height = 15360
18 by Josh C
starry background
58
              }
19 by Josh C
move player around looping world
59
              self:add(the.bg)
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
60
81 by Josh C
load/save (not working yet)
61
              if self.newWorld or not the.storage.data.player then
62
                 the.storage.data = {planets = {}}
63
64
                 -- build planets from random
92 by Josh C
5-7 planets, tweak some goods
65
                 for _ = 1, math.random(5, 7) do
81 by Josh C
load/save (not working yet)
66
                    local planet = Planet:new{
67
                       x = math.random(the.app.width / 2,
68
                                       the.bg.width - the.app.width / 2),
69
                       y = math.random(the.app.height / 2,
70
                                       the.bg.height - the.app.height / 2),
71
                       rotation = math.random() * math.pi
72
                    }
73
                    the.planets:add(planet)
74
                    table.insert(the.storage.data.planets, {
75
                                    x = planet.x,
76
                                    y = planet.y,
77
                                    rotation = planet.rotation,
86 by Josh C
give planets names
78
                                    goods = planet.goods,
79
                                    name = planet.name
81 by Josh C
load/save (not working yet)
80
                                 })
81
                 end
82
91 by Josh C
set prices based on distance
83
                 Good:stockPlanets()
84
81 by Josh C
load/save (not working yet)
85
                 -- build fresh player
86
                 local player = SpacePlayer:new{x=the.bg.width / 2, y=the.bg.height / 2}
87
                 the.player = player
88
                 the.storage.data.player = {x = player.x,
89
                                            y = player.y,
90
                                            money = player.money,
91
                                            goods = player.goods,
92
                                            cargoSpace = player.cargoSpace
93
                                         }
94
95
                 the.storage:save()
96
              else
97
                 -- load planets with x, y, goods
98
                 for _, planetData in ipairs(the.storage.data.planets) do
99
                    the.planets:add(Planet:new(planetData))
100
                 end
101
102
                 -- load player with cargo, money, position
103
                 the.player = SpacePlayer:new(the.storage.data.player)
83 by Josh C
last fix for saving
104
105
                 -- reload storage as we've turned it all into objects
106
                 the.storage:load()
81 by Josh C
load/save (not working yet)
107
              end
108
45 by Josh C
add planet, remove rocks
109
              self:add(the.planets)
87 by Josh C
show planet labels, get better names
110
              self:add(the.planetLabels)
45 by Josh C
add planet, remove rocks
111
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
112
              self:add(the.player)
41 by Josh C
thrust indicator
113
              self:add(the.player.thrust)
68 by Josh C
shield
114
              self:add(the.player.shield)
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
115
69 by Josh C
enemy shields and death
116
              self:add(the.enemies)
117
75 by Josh C
bigger space, slower movement, maintain enemy density
118
              for _ = 1, 20 do
72 by Josh C
add enemy state switch
119
                 local e = Enemy:new{x = math.random(the.bg.width),
120
                                     y = math.random(the.bg.height)}
121
                 --local e = Enemy:new{x=the.bg.width / 2, y=the.bg.height / 2}
122
                 the.enemies:add(e)
123
                 self:add(e.thrust) -- why doesn't this work in Enemy.new?
124
                 self:add(e.shield)
125
              end
7 by Josh C
enemy
126
32 by Josh C
stick things into layers
127
              self:add(the.bullets)
47 by Josh C
indicators for where the planets are
128
              self:add(the.indicators)
39 by Josh C
some instructions at game over
129
              self:add(the.interface)
32 by Josh C
stick things into layers
130
14 by Josh C
only fire if cursor is in target area. change cursor to reflect this.
131
              the.cursor = Cursor:new()
132
              self:add(the.cursor)
8 by Josh C
targeting cursor (manual switch to start)
133
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
134
              love.mouse.setGrab(true)
8 by Josh C
targeting cursor (manual switch to start)
135
              love.mouse.setVisible(false)
33 by Josh C
keep score, center mouse on start
136
              love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
3 by Josh C
basecode main.lua
137
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
138
              self.focus = the.player
3 by Josh C
basecode main.lua
139
           end,
26 by Josh C
rocks!
140
   onUpdate = function(self, dt)
78 by Josh C
pause screen
141
                 if the.keys:justPressed('escape') then
142
                    PauseView:new():activate()
143
                 end
144
62 by Josh C
clean up some old code, put planet indicators in planet class
145
                 the.bullets:collide(the.planets)
68 by Josh C
shield
146
                 the.bullets:collide(the.player)
69 by Josh C
enemy shields and death
147
                 the.bullets:collide(the.enemies)
26 by Josh C
rocks!
148
              end,
33 by Josh C
keep score, center mouse on start
149
   onEndFrame = function(self)
39 by Josh C
some instructions at game over
150
                   the.interface.translate.x = the.player.x - the.app.width / 2 + the.player.width / 2
151
                   the.interface.translate.y = the.player.y - the.app.height / 2 + the.player.height / 2
33 by Josh C
keep score, center mouse on start
152
                end,
3 by Josh C
basecode main.lua
153
   draw = function (self, x, y)
154
             View.draw(self, x, y)
38 by Josh C
remove fps counter
155
             --love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
37 by Josh C
extract updating score. update score again when you calc high score -
156
          end,
3 by Josh C
basecode main.lua
157
}
158
159
MenuScreen = View:extend {
160
   title = Text:new{text = "Press a key to start", font = 48, wordWrap = false},
161
   --title = Tile:new{image = 'data/title.png', x = 0, y = 0},
162
   onNew = function(self)
163
              self:add(self.title)
164
              self.title:centerAround(400, 200)
165
           end,
166
   onUpdate = function(self, elapsed)
167
                 if the.keys:allJustPressed() then
168
                    the.app.view = GameView:new()
169
                 end
170
              end
171
}
172
173
the.app = App:new {
174
   onRun = function (self)
175
              print('Version: ' .. VERSION)
26 by Josh C
rocks!
176
177
              math.randomseed(os.time())
178
3 by Josh C
basecode main.lua
179
              self.view = GameView:new()
43 by Josh C
try to make setting screen resolution more reliable
180
3 by Josh C
basecode main.lua
181
              if DEBUG then
182
                 self.console:watch('VERSION', 'VERSION')
183
                 self.console:watch('updateTook', 'the.updateTook')
19 by Josh C
move player around looping world
184
                 self.console:watch('the.player.x', 'the.player.x')
185
                 self.console:watch('the.player.y', 'the.player.y')
186
                 self.console:watch('the.app.width', 'the.app.width')
187
                 self.console:watch('the.app.height', 'the.app.height')
35 by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets).
188
                 self.console:watch('num mirrors', '#the.mirrors.sprites')
36 by Josh C
don't keep spawning rocks after death.
189
                 self.console:watch('num rocks', '#the.rocks.sprites')
46 by Josh C
bigger area, more planets
190
                 self.console:watch('num planets', '#the.planets.sprites')
80 by Josh C
respawn enemies
191
                 self.console:watch('num enemies', 'the.enemies:count()')
89 by Josh C
"safe" zone on planets - no new enemies will track you if you're there.
192
                 self.console:watch('onPlanet', 'the.player.onPlanet')
3 by Josh C
basecode main.lua
193
                 --self.console:watch('drawTook', 'the.drawTook')
22 by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored?
194
195
                 -- back off that dark overlay a bit
196
                 self.console.fill.fill[4] = 75
3 by Josh C
basecode main.lua
197
              end
198
           end,
199
   onUpdate = function (self, dt)
46 by Josh C
bigger area, more planets
200
                 if not (DEBUG and the.console.visible) then
78 by Josh C
pause screen
201
                    if the.keys:justPressed('return') and the.keys:pressed('alt') then
202
                       love.graphics.toggleFullscreen()
46 by Josh C
bigger area, more planets
203
                    elseif the.keys:justPressed('f1') then
204
                       local ss = love.graphics.newScreenshot()
205
                       ss:encode('screenshot-' ..love.timer.getTime()..'.png')
206
                    elseif the.keys:justPressed('f11') then
44 by Josh C
toggle fullscreen with f11 or alt-enter
207
                       love.graphics.toggleFullscreen()
208
                    end
3 by Josh C
basecode main.lua
209
                 end
210
              end,
211
   update = function (self, dt)
212
               the.updateStart = love.timer.getMicroTime()
213
               App.update(self, dt)
214
               if the.updateStart then
215
                  the.updateTook = love.timer.getMicroTime() - the.updateStart
216
               end
217
            end
218
}
48 by Josh C
move fullscreen into love.run so it doesn't keep toggling on ctl-alt-R
219
220
realRun = love.run
221
function love.run()
222
   -- should fail silently if it can't go to fullscreen...
223
   love.graphics.toggleFullscreen()
224
225
   realRun()
226
end