/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'
7 by Josh C
enemy
25
26
util = {
27
   signOf = function(value)
28
               if value >= 0 then
29
                  return 1
30
               else
31
                  return -1
32
               end
27 by Josh C
try to not spawn rocks where you can see them. not working if screen
33
            end,
7 by Josh C
enemy
34
}
3 by Josh C
basecode main.lua
35
36
GameView = View:extend {
37
   onNew = function (self)
81 by Josh C
load/save (not working yet)
38
              the.storage = Storage:new{filename = 'world.lua'}
34 by Josh C
record high scores
39
              the.storage:load()
64 by Josh C
more old code cleanup
40
              --if not the.storage.data.highScore then
41
              --   print('initializing storage')
42
              --   the.storage.data = {highScore = 0}
43
              --end
34 by Josh C
record high scores
44
29 by Josh C
shoot things!
45
              the.bullets = Group:new()
39 by Josh C
some instructions at game over
46
              the.interface = Group:new()
45 by Josh C
add planet, remove rocks
47
              the.planets = Group:new()
87 by Josh C
show planet labels, get better names
48
              the.planetLabels = Group:new()
47 by Josh C
indicators for where the planets are
49
              the.indicators = Group:new()
69 by Josh C
enemy shields and death
50
              the.enemies = Group:new()
28 by Josh C
prepare a collision box for the rocks
51
81 by Josh C
load/save (not working yet)
52
              -- init bg before build/load since planets need to know bg size
19 by Josh C
move player around looping world
53
              the.bg = Tile:new{
54
                 image = 'data/stars3.png',
75 by Josh C
bigger space, slower movement, maintain enemy density
55
                 width = 27320,
56
                 height = 15360
18 by Josh C
starry background
57
              }
19 by Josh C
move player around looping world
58
              self:add(the.bg)
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
59
81 by Josh C
load/save (not working yet)
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,
86 by Josh C
give planets names
77
                                    goods = planet.goods,
78
                                    name = planet.name
81 by Josh C
load/save (not working yet)
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)
83 by Josh C
last fix for saving
101
102
                 -- reload storage as we've turned it all into objects
103
                 the.storage:load()
81 by Josh C
load/save (not working yet)
104
              end
105
45 by Josh C
add planet, remove rocks
106
              self:add(the.planets)
87 by Josh C
show planet labels, get better names
107
              self:add(the.planetLabels)
45 by Josh C
add planet, remove rocks
108
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
109
              self:add(the.player)
41 by Josh C
thrust indicator
110
              self:add(the.player.thrust)
68 by Josh C
shield
111
              self:add(the.player.shield)
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
112
69 by Josh C
enemy shields and death
113
              self:add(the.enemies)
114
75 by Josh C
bigger space, slower movement, maintain enemy density
115
              for _ = 1, 20 do
72 by Josh C
add enemy state switch
116
                 local e = Enemy:new{x = math.random(the.bg.width),
117
                                     y = math.random(the.bg.height)}
118
                 --local e = Enemy:new{x=the.bg.width / 2, y=the.bg.height / 2}
119
                 the.enemies:add(e)
120
                 self:add(e.thrust) -- why doesn't this work in Enemy.new?
121
                 self:add(e.shield)
122
              end
7 by Josh C
enemy
123
32 by Josh C
stick things into layers
124
              self:add(the.bullets)
47 by Josh C
indicators for where the planets are
125
              self:add(the.indicators)
39 by Josh C
some instructions at game over
126
              self:add(the.interface)
32 by Josh C
stick things into layers
127
14 by Josh C
only fire if cursor is in target area. change cursor to reflect this.
128
              the.cursor = Cursor:new()
129
              self:add(the.cursor)
8 by Josh C
targeting cursor (manual switch to start)
130
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
131
              love.mouse.setGrab(true)
8 by Josh C
targeting cursor (manual switch to start)
132
              love.mouse.setVisible(false)
33 by Josh C
keep score, center mouse on start
133
              love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
3 by Josh C
basecode main.lua
134
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
135
              self.focus = the.player
3 by Josh C
basecode main.lua
136
           end,
26 by Josh C
rocks!
137
   onUpdate = function(self, dt)
78 by Josh C
pause screen
138
                 if the.keys:justPressed('escape') then
139
                    PauseView:new():activate()
140
                 end
141
62 by Josh C
clean up some old code, put planet indicators in planet class
142
                 the.bullets:collide(the.planets)
68 by Josh C
shield
143
                 the.bullets:collide(the.player)
69 by Josh C
enemy shields and death
144
                 the.bullets:collide(the.enemies)
26 by Josh C
rocks!
145
              end,
33 by Josh C
keep score, center mouse on start
146
   onEndFrame = function(self)
39 by Josh C
some instructions at game over
147
                   the.interface.translate.x = the.player.x - the.app.width / 2 + the.player.width / 2
148
                   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
149
                end,
3 by Josh C
basecode main.lua
150
   draw = function (self, x, y)
151
             View.draw(self, x, y)
38 by Josh C
remove fps counter
152
             --love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
37 by Josh C
extract updating score. update score again when you calc high score -
153
          end,
3 by Josh C
basecode main.lua
154
}
155
156
MenuScreen = View:extend {
157
   title = Text:new{text = "Press a key to start", font = 48, wordWrap = false},
158
   --title = Tile:new{image = 'data/title.png', x = 0, y = 0},
159
   onNew = function(self)
160
              self:add(self.title)
161
              self.title:centerAround(400, 200)
162
           end,
163
   onUpdate = function(self, elapsed)
164
                 if the.keys:allJustPressed() then
165
                    the.app.view = GameView:new()
166
                 end
167
              end
168
}
169
170
the.app = App:new {
171
   onRun = function (self)
172
              print('Version: ' .. VERSION)
26 by Josh C
rocks!
173
174
              math.randomseed(os.time())
175
3 by Josh C
basecode main.lua
176
              self.view = GameView:new()
43 by Josh C
try to make setting screen resolution more reliable
177
3 by Josh C
basecode main.lua
178
              if DEBUG then
179
                 self.console:watch('VERSION', 'VERSION')
180
                 self.console:watch('updateTook', 'the.updateTook')
19 by Josh C
move player around looping world
181
                 self.console:watch('the.player.x', 'the.player.x')
182
                 self.console:watch('the.player.y', 'the.player.y')
183
                 self.console:watch('the.app.width', 'the.app.width')
184
                 self.console:watch('the.app.height', 'the.app.height')
35 by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets).
185
                 self.console:watch('num mirrors', '#the.mirrors.sprites')
36 by Josh C
don't keep spawning rocks after death.
186
                 self.console:watch('num rocks', '#the.rocks.sprites')
46 by Josh C
bigger area, more planets
187
                 self.console:watch('num planets', '#the.planets.sprites')
80 by Josh C
respawn enemies
188
                 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.
189
                 self.console:watch('onPlanet', 'the.player.onPlanet')
3 by Josh C
basecode main.lua
190
                 --self.console:watch('drawTook', 'the.drawTook')
22 by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored?
191
192
                 -- back off that dark overlay a bit
193
                 self.console.fill.fill[4] = 75
3 by Josh C
basecode main.lua
194
              end
195
           end,
196
   onUpdate = function (self, dt)
46 by Josh C
bigger area, more planets
197
                 if not (DEBUG and the.console.visible) then
78 by Josh C
pause screen
198
                    if the.keys:justPressed('return') and the.keys:pressed('alt') then
199
                       love.graphics.toggleFullscreen()
46 by Josh C
bigger area, more planets
200
                    elseif the.keys:justPressed('f1') then
201
                       local ss = love.graphics.newScreenshot()
202
                       ss:encode('screenshot-' ..love.timer.getTime()..'.png')
203
                    elseif the.keys:justPressed('f11') then
44 by Josh C
toggle fullscreen with f11 or alt-enter
204
                       love.graphics.toggleFullscreen()
205
                    end
3 by Josh C
basecode main.lua
206
                 end
207
              end,
208
   update = function (self, dt)
209
               the.updateStart = love.timer.getMicroTime()
210
               App.update(self, dt)
211
               if the.updateStart then
212
                  the.updateTook = love.timer.getMicroTime() - the.updateStart
213
               end
214
            end
215
}
48 by Josh C
move fullscreen into love.run so it doesn't keep toggling on ctl-alt-R
216
217
realRun = love.run
218
function love.run()
219
   -- should fail silently if it can't go to fullscreen...
220
   love.graphics.toggleFullscreen()
221
222
   realRun()
223
end