/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'
7 by Josh C
enemy
22
23
util = {
24
   signOf = function(value)
25
               if value >= 0 then
26
                  return 1
27
               else
28
                  return -1
29
               end
27 by Josh C
try to not spawn rocks where you can see them. not working if screen
30
            end,
7 by Josh C
enemy
31
}
3 by Josh C
basecode main.lua
32
33
GameView = View:extend {
34
   onNew = function (self)
34 by Josh C
record high scores
35
              the.storage = Storage:new{filename = 'scores.lua'}
36
              the.storage:load()
64 by Josh C
more old code cleanup
37
              --if not the.storage.data.highScore then
38
              --   print('initializing storage')
39
              --   the.storage.data = {highScore = 0}
40
              --end
34 by Josh C
record high scores
41
29 by Josh C
shoot things!
42
              the.bullets = Group:new()
39 by Josh C
some instructions at game over
43
              the.interface = Group:new()
45 by Josh C
add planet, remove rocks
44
              the.planets = Group:new()
47 by Josh C
indicators for where the planets are
45
              the.indicators = Group:new()
69 by Josh C
enemy shields and death
46
              the.enemies = Group:new()
28 by Josh C
prepare a collision box for the rocks
47
19 by Josh C
move player around looping world
48
              the.bg = Tile:new{
49
                 image = 'data/stars3.png',
75 by Josh C
bigger space, slower movement, maintain enemy density
50
                 width = 27320,
51
                 height = 15360
18 by Josh C
starry background
52
              }
19 by Josh C
move player around looping world
53
              self:add(the.bg)
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
54
45 by Josh C
add planet, remove rocks
55
              self:add(the.planets)
56
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
57
              --the.player = CrystalPlayer:new{x=400,y=300}
51 by Josh C
put player in center of map
58
              the.player = SpacePlayer:new{x=the.bg.width / 2, y=the.bg.height / 2}
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
59
              self:add(the.player)
41 by Josh C
thrust indicator
60
              self:add(the.player.thrust)
68 by Josh C
shield
61
              self:add(the.player.shield)
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
62
69 by Josh C
enemy shields and death
63
              self:add(the.enemies)
64
75 by Josh C
bigger space, slower movement, maintain enemy density
65
              for _ = 1, 20 do
72 by Josh C
add enemy state switch
66
                 local e = Enemy:new{x = math.random(the.bg.width),
67
                                     y = math.random(the.bg.height)}
68
                 --local e = Enemy:new{x=the.bg.width / 2, y=the.bg.height / 2}
69
                 the.enemies:add(e)
70
                 self:add(e.thrust) -- why doesn't this work in Enemy.new?
71
                 self:add(e.shield)
72
              end
7 by Josh C
enemy
73
32 by Josh C
stick things into layers
74
              self:add(the.bullets)
47 by Josh C
indicators for where the planets are
75
              self:add(the.indicators)
39 by Josh C
some instructions at game over
76
              self:add(the.interface)
32 by Josh C
stick things into layers
77
73 by Josh C
higher planet floor, recharge shields when you land, stop moving when you land
78
              for _ = 1, math.random(3, 6) do
52 by Josh C
break out planet
79
                 local planet = Planet:new{
46 by Josh C
bigger area, more planets
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
45 by Josh C
add planet, remove rocks
88
14 by Josh C
only fire if cursor is in target area. change cursor to reflect this.
89
              the.cursor = Cursor:new()
90
              self:add(the.cursor)
8 by Josh C
targeting cursor (manual switch to start)
91
70 by Josh C
bring back game over screen
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
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
113
              love.mouse.setGrab(true)
8 by Josh C
targeting cursor (manual switch to start)
114
              love.mouse.setVisible(false)
33 by Josh C
keep score, center mouse on start
115
              love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
3 by Josh C
basecode main.lua
116
4 by Josh C
trying some movement styles. derivatives on crystal quest movement.
117
              self.focus = the.player
3 by Josh C
basecode main.lua
118
           end,
26 by Josh C
rocks!
119
   onUpdate = function(self, dt)
62 by Josh C
clean up some old code, put planet indicators in planet class
120
                 the.bullets:collide(the.planets)
68 by Josh C
shield
121
                 the.bullets:collide(the.player)
69 by Josh C
enemy shields and death
122
                 the.bullets:collide(the.enemies)
26 by Josh C
rocks!
123
              end,
33 by Josh C
keep score, center mouse on start
124
   onEndFrame = function(self)
39 by Josh C
some instructions at game over
125
                   the.interface.translate.x = the.player.x - the.app.width / 2 + the.player.width / 2
126
                   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
127
                end,
3 by Josh C
basecode main.lua
128
   draw = function (self, x, y)
129
             View.draw(self, x, y)
38 by Josh C
remove fps counter
130
             --love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
37 by Josh C
extract updating score. update score again when you calc high score -
131
          end,
3 by Josh C
basecode main.lua
132
}
133
134
MenuScreen = View:extend {
135
   title = Text:new{text = "Press a key to start", font = 48, wordWrap = false},
136
   --title = Tile:new{image = 'data/title.png', x = 0, y = 0},
137
   onNew = function(self)
138
              self:add(self.title)
139
              self.title:centerAround(400, 200)
140
           end,
141
   onUpdate = function(self, elapsed)
142
                 if the.keys:allJustPressed() then
143
                    the.app.view = GameView:new()
144
                 end
145
              end
146
}
147
148
the.app = App:new {
149
   onRun = function (self)
150
              print('Version: ' .. VERSION)
26 by Josh C
rocks!
151
152
              math.randomseed(os.time())
153
3 by Josh C
basecode main.lua
154
              self.view = GameView:new()
43 by Josh C
try to make setting screen resolution more reliable
155
3 by Josh C
basecode main.lua
156
              if DEBUG then
157
                 self.console:watch('VERSION', 'VERSION')
158
                 self.console:watch('updateTook', 'the.updateTook')
19 by Josh C
move player around looping world
159
                 self.console:watch('the.player.x', 'the.player.x')
160
                 self.console:watch('the.player.y', 'the.player.y')
161
                 self.console:watch('the.app.width', 'the.app.width')
162
                 self.console:watch('the.app.height', 'the.app.height')
35 by Josh C
fix double-removing sprites (and subsequent zombie mirror bullets).
163
                 self.console:watch('num mirrors', '#the.mirrors.sprites')
36 by Josh C
don't keep spawning rocks after death.
164
                 self.console:watch('num rocks', '#the.rocks.sprites')
46 by Josh C
bigger area, more planets
165
                 self.console:watch('num planets', '#the.planets.sprites')
3 by Josh C
basecode main.lua
166
                 --self.console:watch('drawTook', 'the.drawTook')
22 by Josh C
mirror (contains a bug where things in the corner aren't getting mirrored?
167
168
                 -- back off that dark overlay a bit
169
                 self.console.fill.fill[4] = 75
3 by Josh C
basecode main.lua
170
              end
171
           end,
172
   onUpdate = function (self, dt)
46 by Josh C
bigger area, more planets
173
                 if not (DEBUG and the.console.visible) then
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
182
                    elseif the.keys:justPressed('f1') then
183
                       local ss = love.graphics.newScreenshot()
184
                       ss:encode('screenshot-' ..love.timer.getTime()..'.png')
185
                    elseif the.keys:justPressed('f11') then
44 by Josh C
toggle fullscreen with f11 or alt-enter
186
                       love.graphics.toggleFullscreen()
187
                    end
3 by Josh C
basecode main.lua
188
                 end
189
              end,
190
   update = function (self, dt)
191
               the.updateStart = love.timer.getMicroTime()
192
               App.update(self, dt)
193
               if the.updateStart then
194
                  the.updateTook = love.timer.getMicroTime() - the.updateStart
195
               end
196
            end
197
}
48 by Josh C
move fullscreen into love.run so it doesn't keep toggling on ctl-alt-R
198
199
realRun = love.run
200
function love.run()
201
   -- should fail silently if it can't go to fullscreen...
202
   love.graphics.toggleFullscreen()
203
204
   realRun()
205
end