-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
58 lines (51 loc) · 1.19 KB
/
main.lua
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("ball")
require("ai")
require("background")
function love.load()
Player:load()
Ball:load()
AI:load()
Background:load()
Score = {
player = 0,
ai = 0
}
font = love.graphics.newFont(30)
sound = love.audio.newSource("assets/sounds/pong.ogg", "static")
music = love.audio.newSource("assets/sounds/background.mp3", "stream")
love.audio.setVolume(0.1)
music:play()
end
function love.update(dt)
Player:update(dt)
Ball:update(dt)
print(Ball.speed)
AI:update(dt)
Background:update(dt)
end
function love.draw()
Background:draw()
Player:draw()
Ball:draw()
AI:draw()
drawScore()
end
function drawScore()
love.graphics.setFont(font)
love.graphics.print("Player: " .. Score.player, 50, 50)
love.graphics.print("AI: " .. Score.ai, 1000, 50)
end
function checkCollision(a, b)
if a.x + a.width > b.x and a.x < b.x + b.width and a.y + a.height > b.y and a.y < b.y + b.height then
love.audio.play(sound)
Ball.speed = Ball.speed + 2
return true
end
return false
end
function love.keypressed(key)
if key == "escape" then
love.event.quit()
end
end