/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-05-13 20:41:14 UTC
  • Revision ID: josh@9ix.org-20130513204114-wtg735gs4b38wad4
extract wrapping behavior, wrap bullets

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
DEBUG = true
3
3
 
4
4
require 'zoetrope'
 
5
--__ = require 'underscore'
5
6
vector = require 'vector'
6
 
--inspect = require 'inspect'
7
 
 
8
 
require 'group'
9
7
 
10
8
require 'version'
11
9
require 'wrap_tile'
12
 
require 'mirror'
13
10
require 'player'
14
11
require 'enemy'
15
12
require 'cursor'
16
13
require 'bullet'
17
 
require 'rock'
18
 
require 'boom'
19
 
require 'planet'
20
 
require 'trade_view'
21
 
require 'shield'
22
14
 
23
15
util = {
24
16
   signOf = function(value)
27
19
               else
28
20
                  return -1
29
21
               end
30
 
            end,
 
22
            end
31
23
}
32
24
 
33
25
GameView = View:extend {
34
26
   onNew = function (self)
35
 
              the.storage = Storage:new{filename = 'scores.lua'}
36
 
              the.storage:load()
37
 
              --if not the.storage.data.highScore then
38
 
              --   print('initializing storage')
39
 
              --   the.storage.data = {highScore = 0}
40
 
              --end
41
 
 
42
 
              the.bullets = Group:new()
43
 
              the.interface = Group:new()
44
 
              the.planets = Group:new()
45
 
              the.indicators = Group:new()
46
 
              the.enemies = Group:new()
 
27
              -- for x = 1,30 do
 
28
              --    for y = 1,30 do
 
29
              --       self:add(Fill:new{x=x*400, y=y*400,
 
30
              --                         width = 32, height = 32,
 
31
              --                         fill = {0,0,255}
 
32
              --                      })
 
33
              --    end
 
34
              -- end
47
35
 
48
36
              the.bg = Tile:new{
49
37
                 image = 'data/stars3.png',
50
 
                 width = 27320,
51
 
                 height = 15360
 
38
                 -- 1366x768 * 3
 
39
                 width = 4098,
 
40
                 height = 2304
52
41
              }
53
42
              self:add(the.bg)
54
43
 
55
 
              self:add(the.planets)
56
 
 
57
44
              --the.player = CrystalPlayer:new{x=400,y=300}
58
 
              the.player = SpacePlayer:new{x=the.bg.width / 2, y=the.bg.height / 2}
 
45
              the.player = SpacePlayer:new{x=1366,y=768}
59
46
              self:add(the.player)
60
 
              self:add(the.player.thrust)
61
 
              self:add(the.player.shield)
62
 
 
63
 
              self:add(the.enemies)
64
 
 
65
 
              for _ = 1, 20 do
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
73
 
 
74
 
              self:add(the.bullets)
75
 
              self:add(the.indicators)
76
 
              self:add(the.interface)
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
 
47
 
 
48
              self:add(Enemy:new{x=400, y=300})
88
49
 
89
50
              the.cursor = Cursor:new()
90
51
              self:add(the.cursor)
91
52
 
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
 
 
113
53
              love.mouse.setGrab(true)
114
54
              love.mouse.setVisible(false)
115
 
              love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
116
55
 
 
56
              --self:loadLayers('data/map.lua')
117
57
              self.focus = the.player
 
58
              --self:clampTo(self.map)
118
59
           end,
119
 
   onUpdate = function(self, dt)
120
 
                 the.bullets:collide(the.planets)
121
 
                 the.bullets:collide(the.player)
122
 
                 the.bullets:collide(the.enemies)
123
 
              end,
124
 
   onEndFrame = function(self)
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
127
 
                end,
128
60
   draw = function (self, x, y)
129
61
             View.draw(self, x, y)
130
 
             --love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
131
 
          end,
 
62
             love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
 
63
          end
132
64
}
133
65
 
134
66
MenuScreen = View:extend {
148
80
the.app = App:new {
149
81
   onRun = function (self)
150
82
              print('Version: ' .. VERSION)
151
 
 
152
 
              math.randomseed(os.time())
153
 
 
154
83
              self.view = GameView:new()
155
 
 
156
84
              if DEBUG then
157
85
                 self.console:watch('VERSION', 'VERSION')
158
86
                 self.console:watch('updateTook', 'the.updateTook')
160
88
                 self.console:watch('the.player.y', 'the.player.y')
161
89
                 self.console:watch('the.app.width', 'the.app.width')
162
90
                 self.console:watch('the.app.height', 'the.app.height')
163
 
                 self.console:watch('num mirrors', '#the.mirrors.sprites')
164
 
                 self.console:watch('num rocks', '#the.rocks.sprites')
165
 
                 self.console:watch('num planets', '#the.planets.sprites')
166
91
                 --self.console:watch('drawTook', 'the.drawTook')
167
 
 
168
 
                 -- back off that dark overlay a bit
169
 
                 self.console.fill.fill[4] = 75
170
92
              end
171
93
           end,
172
94
   onUpdate = function (self, dt)
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
186
 
                       love.graphics.toggleFullscreen()
187
 
                    end
 
95
                 if the.keys:justPressed('escape') then
 
96
                    self.quit()
188
97
                 end
189
98
              end,
190
99
   update = function (self, dt)
195
104
               end
196
105
            end
197
106
}
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
 
 
b'\\ No newline at end of file'