-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
91 lines (75 loc) · 2.52 KB
/
main.lua
File metadata and controls
91 lines (75 loc) · 2.52 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
push = require 'push'
Class = require 'class'
require 'Bomb'
require 'Pipe'
require 'PipePair'
require 'StateMachine'
require 'states/BaseState'
require 'states/PlayState'
require 'states/TitleState'
require 'states/ScoreState'
require 'states/CountdownState'
require 'states/AboutState'
width = 1280
height = 720
virtual_width = 512
virtual_height = 288
local background = love.graphics.newImage('src/images/back.png')
local backgroundScroll = 0
local scroll_speed = 30
local looping_point = 1015
function love.load()
love.graphics.setDefaultFilter('nearest', 'nearest')
math.randomseed(os.time())
love.window.setTitle('Flappy Bomb')
fonts = {
['smallFont'] = love.graphics.newFont('src/font/MultiroundPro.otf', 10),
['mediumFont'] = love.graphics.newFont('src/font/MultiroundPro.otf', 14),
['bigFont'] = love.graphics.newFont('src/font/MultiroundPro.otf', 28),
['countFont'] = love.graphics.newFont('src/font/MultiroundPro.otf', 56)
}
love.graphics.setFont(fonts['bigFont'])
sounds = {
['explosion'] = love.audio.newSource('src/sounds/explosion.wav', 'static'),
['countdown'] = love.audio.newSource('src/sounds/countdown.wav', 'static'),
['score'] = love.audio.newSource('src/sounds/score.wav', 'static'),
['music'] = love.audio.newSource('src/sounds/Little_Big_Lolly_bomb_rock_cover.mp3', 'static')
}
sounds['music']:setLooping(true)
sounds['music']:play()
push:setupScreen(virtual_width, virtual_height, width, height, {
vsync = true,
fullscreen = false,
resizable = false
})
stateMachine = StateMachine {
['title'] = function() return TitleState() end,
['play'] = function() return PlayState() end,
['score'] = function() return ScoreState() end,
['countdown'] = function() return CountdownState() end,
['about'] = function() return AboutState() end
}
stateMachine:change('title')
love.keyboard.keysPressed = {}
end
function love.keypressed(key)
love.keyboard.keysPressed[key] = true
if key == 'escape' then
love.event.quit()
end
end
function love.keyboard.wasPressed(key)
return love.keyboard.keysPressed[key]
end
function love.update(dt)
backgroundScroll = (backgroundScroll + scroll_speed * dt)
% looping_point
stateMachine:update(dt)
love.keyboard.keysPressed = {}
end
function love.draw()
push:start()
love.graphics.draw(background, -backgroundScroll, 0)
stateMachine:render()
push:finish()
end