24
33
GameView = View:extend {
25
34
onNew = function (self)
28
-- self:add(Fill:new{x=x*400, y=y*400,
29
-- width = 32, height = 32,
36
image = 'data/stars2.png',
35
the.storage = Storage:new{filename = 'scores.lua'}
37
--if not the.storage.data.highScore then
38
-- print('initializing storage')
39
-- the.storage.data = {highScore = 0}
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()
49
image = 'data/stars3.png',
44
57
--the.player = CrystalPlayer:new{x=400,y=300}
45
the.player = SpacePlayer:new{x=400,y=300}
58
the.player = SpacePlayer:new{x=the.bg.width / 2, y=the.bg.height / 2}
46
59
self:add(the.player)
48
self:add(Enemy:new{x=400, y=300})
60
self:add(the.player.thrust)
61
self:add(the.player.shield)
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}
70
self:add(e.thrust) -- why doesn't this work in Enemy.new?
75
self:add(the.indicators)
76
self:add(the.interface)
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
86
the.planets:add(planet)
50
89
the.cursor = Cursor:new()
51
90
self:add(the.cursor)
93
y = the.app.height / 2,
94
width = the.app.width,
100
the.interface:add(the.over)
103
the.instructions = Text:new{
104
y = the.app.height / 2 + 32,
105
width = the.app.width,
108
text = "Press Enter to start a new game\nPress Q to quit",
111
the.interface:add(the.instructions)
53
113
love.mouse.setGrab(true)
54
114
love.mouse.setVisible(false)
115
love.mouse.setPosition(the.app.width / 2, the.app.height / 2)
56
--self:loadLayers('data/map.lua')
57
117
self.focus = the.player
58
--self:clampTo(self.map)
119
onUpdate = function(self, dt)
120
the.bullets:collide(the.planets)
121
the.bullets:collide(the.player)
122
the.bullets:collide(the.enemies)
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
60
128
draw = function (self, x, y)
61
129
View.draw(self, x, y)
62
love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
130
--love.graphics.print('FPS:' .. love.timer.getFPS(), 20, 20)
66
134
MenuScreen = View:extend {
80
148
the.app = App:new {
81
149
onRun = function (self)
82
150
print('Version: ' .. VERSION)
152
math.randomseed(os.time())
83
154
self.view = GameView:new()
85
157
self.console:watch('VERSION', 'VERSION')
86
158
self.console:watch('updateTook', 'the.updateTook')
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')
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')
87
166
--self.console:watch('drawTook', 'the.drawTook')
168
-- back off that dark overlay a bit
169
self.console.fill.fill[4] = 75
90
172
onUpdate = function (self, dt)
91
if the.keys:justPressed('escape') then
173
if not (DEBUG and the.console.visible) then
174
if the.keys:justPressed('q') then
176
elseif the.keys:justPressed('return') then
177
if the.keys:pressed('alt') then
178
love.graphics.toggleFullscreen()
180
self.view = GameView:new()
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()
95
190
update = function (self, dt)