/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-06-23 03:10:51 UTC
  • Revision ID: josh@9ix.org-20130623031051-3142chix333jkmqi
pay to fix shield

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'
6
5
vector = require 'vector'
 
6
--inspect = require 'inspect'
7
7
 
8
8
require 'group'
9
9
 
10
10
require 'version'
11
11
require 'wrap_tile'
 
12
require 'mirror'
12
13
require 'player'
13
14
require 'enemy'
14
15
require 'cursor'
15
16
require 'bullet'
16
17
require 'rock'
 
18
require 'boom'
 
19
require 'planet'
 
20
require 'trade_view'
 
21
require 'shield'
17
22
 
18
23
util = {
19
24
   signOf = function(value)
22
27
               else
23
28
                  return -1
24
29
               end
25
 
            end
 
30
            end,
26
31
}
27
32
 
28
33
GameView = View:extend {
29
 
   lastRock = 0,
30
 
   rockInterval = 1,
31
 
   gameStart = 0,
32
34
   onNew = function (self)
33
 
              -- for x = 1,30 do
34
 
              --    for y = 1,30 do
35
 
              --       self:add(Fill:new{x=x*400, y=y*400,
36
 
              --                         width = 32, height = 32,
37
 
              --                         fill = {0,0,255}
38
 
              --                      })
39
 
              --    end
40
 
              -- end
 
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()
41
47
 
42
48
              the.bg = Tile:new{
43
49
                 image = 'data/stars3.png',
44
 
                 -- 1366x768 * 3
45
 
                 width = 4098,
46
 
                 height = 2304
 
50
                 width = 27320,
 
51
                 height = 15360
47
52
              }
48
53
              self:add(the.bg)
49
54
 
 
55
              self:add(the.planets)
 
56
 
50
57
              --the.player = CrystalPlayer:new{x=400,y=300}
51
 
              the.player = SpacePlayer:new{x=1366,y=768}
 
58
              the.player = SpacePlayer:new{x=the.bg.width / 2, y=the.bg.height / 2}
52
59
              self:add(the.player)
53
 
 
54
 
              self:add(Enemy:new{x=400, y=300})
 
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
55
88
 
56
89
              the.cursor = Cursor:new()
57
90
              self:add(the.cursor)
58
91
 
 
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
 
59
113
              love.mouse.setGrab(true)
60
114
              love.mouse.setVisible(false)
 
115
              love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
61
116
 
62
 
              --self:loadLayers('data/map.lua')
63
117
              self.focus = the.player
64
 
              --self:clampTo(self.map)
65
 
 
66
 
              self.gameStart = love.timer.getTime()
67
118
           end,
68
119
   onUpdate = function(self, dt)
69
 
                 if love.timer.getTime() > self.lastRock + self.rockInterval then
70
 
                    local rock = Rock:new{
71
 
                       x = math.random(the.bg.width),
72
 
                       y = math.random(the.bg.height),
73
 
                       velocity = {
74
 
                          x = math.random(-300, 300),
75
 
                          y = math.random(-300, 300),
76
 
                          rotation = math.random(-7, 7)
77
 
                       },
78
 
                       scale = math.random() + 0.5
79
 
                    }
80
 
                    self:add(rock)
81
 
 
82
 
                    self.lastRock = love.timer.getTime()
83
 
                 end
 
120
                 the.bullets:collide(the.planets)
 
121
                 the.bullets:collide(the.player)
 
122
                 the.bullets:collide(the.enemies)
84
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,
85
128
   draw = function (self, x, y)
86
129
             View.draw(self, x, y)
87
 
             love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
88
 
          end
 
130
             --love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
 
131
          end,
89
132
}
90
133
 
91
134
MenuScreen = View:extend {
109
152
              math.randomseed(os.time())
110
153
 
111
154
              self.view = GameView:new()
 
155
 
112
156
              if DEBUG then
113
157
                 self.console:watch('VERSION', 'VERSION')
114
158
                 self.console:watch('updateTook', 'the.updateTook')
116
160
                 self.console:watch('the.player.y', 'the.player.y')
117
161
                 self.console:watch('the.app.width', 'the.app.width')
118
162
                 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')
119
166
                 --self.console:watch('drawTook', 'the.drawTook')
120
167
 
121
168
                 -- back off that dark overlay a bit
123
170
              end
124
171
           end,
125
172
   onUpdate = function (self, dt)
126
 
                 if the.keys:justPressed('escape') then
127
 
                    self.quit()
 
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
128
188
                 end
129
189
              end,
130
190
   update = function (self, dt)
135
195
               end
136
196
            end
137
197
}
 
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'