-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
69 lines (59 loc) · 1.92 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
local ShaderScan = require 'shaderscan'
-- Ensure output appears in console as its printed instead of only after
-- program terminates.
io.stdout:setvbuf('no')
local screen = {
x = 500,
y = 500,
half_x = 500/2,
half_y = 500/2,
}
local shaders
local ball = {
pos = {
x = screen.half_x,
y = screen.half_y,
},
size = {
x = 150,
y = 150,
},
}
function love.load(args)
love.window.setMode(screen.x, screen.y)
shaders = ShaderScan()
shaders:load_shader('splitcolor', 'example/splitcolor.glsl')
-- Instead, try extra debug options:
--~ shaders:load_shader('splitcolor', 'example/splitcolor.glsl', {
--~ -- Output shader file when shader compile fails.
--~ dump_file_on_error = true,
--~ -- Omit repeated file name and line text.
--~ terse_error_msg = true,
--~ })
end
function love.update(dt)
shaders:update(dt)
shaders:safe_send('splitcolor', 'iTime', love.timer.getTime())
local x,y = ball.pos.x, ball.pos.y
local speed = 300
if love.keyboard.isDown('d') or love.keyboard.isDown('right') then
x = x + speed * dt
elseif love.keyboard.isDown('a') or love.keyboard.isDown('left') then
x = x - speed * dt
end
if love.keyboard.isDown('w') or love.keyboard.isDown('up') then
y = y - speed * dt
elseif love.keyboard.isDown('s') or love.keyboard.isDown('down') then
y = y + speed * dt
end
ball.pos.x, ball.pos.y = x,y
end
function love.draw()
love.graphics.setShader(shaders.s.splitcolor)
love.graphics.clear(0.1, 0.1, 0.1, 1)
love.graphics.setColor(1, 0, 1, 0.75)
love.graphics.circle('fill', ball.pos.x, ball.pos.y, ball.size.x, ball.size.y)
love.graphics.setShader() -- clear
love.graphics.setColor(1, 1, 1, 1)
love.graphics.print("Modify example/splitcolor.glsl to see these colours change without restarting.")
end