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