-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.lua
More file actions
58 lines (50 loc) · 1.13 KB
/
main.lua
File metadata and controls
58 lines (50 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'player'
require 'bullets'
require 'asteroids'
require 'world'
--called once when game is started up
function love.load()
world_load()
debugText = "load" .. "\n"
show_debug = false
end
--updates everything
function love.update(dt)
world:update(dt)
player_update(dt)
bullets_update(dt)
asteroids_update(dt)
world_update(dt)
if string.len(debugText) > 600 then
debugText = ""
end
end
--button presses
function love.keypressed(key)
--shoot bullets
if key == (" ") then
bullet_create()
debugText = debugText .. "shoot" .. "\n"
end
--exit the game when escape is pushed
if key == ("escape") then
love.event.push("quit")
end
--debug
if key == ("`") then
show_debug = not show_debug
end
end
--draw everything on the screen;
function love.draw()
love.graphics.setFont(love.graphics.newFont("visitor1.ttf", 15))
player_draw()
bullets_draw()
asteroids_draw()
love.graphics.print("Score: " .. score, width - 100, 10)
--debug
if show_debug then
love.graphics.print("FPS: " .. love.timer.getFPS(), 10, 10)
love.graphics.print(debugText, 10, 25)
end
end