-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
157 lines (122 loc) · 3.68 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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
local Flux = require("lib.flux")
local Vector = require("lib.vector")
local Baton = require("lib.baton")
local List = require("lib.list")
local Shine = require("lib.moonshine")
local Wave = require("lib.wave")
local Timer = require("lib.timer")
local Paddle = require("src.paddle")
local Ball = require("src.ball")
local MiddleBeat = require("src.middlebeat")
local hits = require("src.hits")
local Particles = require("src.particles")
local State = require("src.state")
local Sequence = require("src.sequence")
local Logo = require("src.logo")
local cornerMargin = 40
local borderMargin = 8
local length = 120
local width = 20
local totCornerMargin = cornerMargin + length/2
local totBorderMargin = borderMargin + width/2
local Paddles = List()
Paddles:add(Paddle("Top", {
start = Vector( totCornerMargin, totBorderMargin),
finish = Vector(640 - totCornerMargin, totBorderMargin),
size = Vector(length, width),
}))
Paddles:add(Paddle("Left", {
start = Vector(totBorderMargin, totCornerMargin),
finish = Vector(totBorderMargin, 640 - totCornerMargin),
size = Vector(width, length),
}))
Paddles:add(Paddle("Bottom", {
start = Vector(640 - totCornerMargin, 640 - totBorderMargin),
finish = Vector( totCornerMargin, 640 - totBorderMargin),
size = Vector(length, width),
}))
Paddles:add(Paddle("Right", {
start = Vector(640 - totBorderMargin, 640 - totCornerMargin),
finish = Vector(640 - totBorderMargin, totCornerMargin),
size = Vector(width, length),
}))
local ball = Ball({
pos = Vector(360, 360),
vel = Vector(50, -350),
})
local middleBeat = MiddleBeat({
})
local Player = Baton.new({
controls = {
activate = {'key:space', 'button:a', 'mouse:1'},
}
})
local Effect = Shine(Shine.effects.filmgrain)
.chain(Shine.effects.glow)
.chain(Shine.effects.chromasep)
Effect.filmgrain.opacity = 0.1
local Gradient = love.graphics.newImage("assets/gradient.png")
love.graphics.setBackgroundColor(183, 28, 28)
local Track = Wave:newSource("sounds/track.wav", "static")
Track:setIntensity(20)
Track:setBPM(70)
Track:setLooping(true)
Track:onBeat(function()
middleBeat:onBeat()
end)
local Die = love.audio.newSource("sounds/die.wav")
local Shake = Vector(0, 0)
Sequence.init(Paddles:get(1), Paddles:get(2), Paddles:get(3), Paddles:get(4), ball, Track, hits)
Sequence.finish(0)
function love.update(dt)
Player:update()
Shake:set(0, 0)
if State.state == "playing" then
for i = 1, Paddles.size do
local paddle = Paddles:get(i)
paddle:update(dt)
if Player:pressed("activate") then
paddle:activate()
elseif Player:released("activate") then
paddle:deactivate()
end
Shake:add(paddle.shake:get())
end
elseif State.state == "paused" then
if Player:pressed("activate") then
Sequence.start()
end
end
Shake:normalizeInplace()
Shake:mul(4)
Effect.chromasep.angle = math.atan2(Shake.y, Shake.x)
Effect.chromasep.radius = Shake:len() * 2 + 4
local inside = ball:update(dt)
if not inside and State.state == "playing" then
Die:play()
Sequence.finish(1)
end
Particles:update(dt)
Flux.update(dt)
Timer.update(dt)
Track:update(dt)
end
local draw = function ()
love.graphics.draw(Gradient)
love.graphics.push()
love.graphics.translate(Shake.x, Shake.y)
middleBeat:draw()
hits:draw()
love.graphics.setLineWidth(4)
for i = 1, Paddles.size do
Paddles:get(i):draw()
end
ball:draw()
Logo.draw()
Particles:draw()
love.graphics.pop()
end
function love.draw()
love.graphics.setColor(255, 255, 255)
Effect(draw)
end