Skip to content

Commit 39544d7

Browse files
committed
Completed "A circle amongst squares"
1 parent 7507d5b commit 39544d7

File tree

9 files changed

+143
-11
lines changed

9 files changed

+143
-11
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,16 @@ It's main focus is generating time-delayed sound and graphics.
1919
**Löve-File:** [thunderstorm.love](bin/thunderstorm.love?raw=true)
2020

2121
**Credits:** [Credits](thunderstorm/credits.md)
22+
23+
## A circle amongst squares
24+
![Circle screenshot](circle-amongst-squares/screenshot.png "A circle amongst squares screenshot")
25+
26+
A little horror "game", in which you are a circle amongst squares.
27+
This one has directional sound in it, so earphones may be a good idea.
28+
I also played around with a pixel shader and am quite pleased with the results. :-)
29+
30+
**How to play:** Move with w, a, s, d or the cursor keys. Press escape to exit.
31+
32+
**Löve-File:** [circle-amongst-squares.love](bin/circle-amongst-squares.love?raw=true)
33+
34+
**Credits:** [Credits](circle-amongst-squares/credits.md)

bin/circle-amongst-squares.love

5.93 MB
Binary file not shown.

circle-amongst-squares/conf.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function love.conf(t)
22
t.window.width = 1280
33
t.window.height = 720
4-
t.window.fullscreen = false
4+
t.window.fullscreen = true
55
t.window.title = "A circle amongst squares"
66
end

circle-amongst-squares/credits.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Credits for *A circle among squares*
2+
3+
Scary Ambient Wind
4+
* Attribution: https://soundcloud.com/alexandr-zhelanov
5+
* Author: Alexandr Zhelanov
6+
* URL: https://opengameart.org/content/scary-ambient-wind
7+
* License: CC-BY 3.0
8+
9+
Paper 03 sound
10+
* Author: rubberduck
11+
* URL: https://opengameart.org/content/100-cc0-sfx
12+
* License: CC0 (Public Domain)
13+
14+
Bump Library
15+
* Author: kikito
16+
* URL: https://github.com/kikito/bump.lua
17+
* License: MIT

circle-amongst-squares/light.glsl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Source of the light in screen coordinates
2+
extern vec2 sourcePos = vec2(0, 0);
3+
4+
number dist(vec2 pos1, vec2 pos2) {
5+
return (pos1.x - pos2.x) * (pos1.x - pos2.x) +
6+
(pos1.y - pos2.y) * (pos1.y - pos2.y);
7+
}
8+
9+
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords){
10+
vec4 pixel = Texel(texture, texture_coords);
11+
number distance = dist(sourcePos, screen_coords);
12+
13+
if (distance > 10000) {
14+
pixel.r = 0;
15+
pixel.g = 0;
16+
pixel.b = 0;
17+
}
18+
// For some reason this doesn't cause problems
19+
// even if distance is 0...
20+
else {
21+
pixel.r *= 1000 / distance;
22+
pixel.g *= 1000 / distance;
23+
pixel.b *= 1000 / distance;
24+
}
25+
return pixel * color;
26+
}

circle-amongst-squares/main.lua

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,89 @@ function newSquare()
2626
return square
2727
end
2828

29+
function sign(x)
30+
if x > 0 then
31+
return 1
32+
elseif x < 0 then
33+
return -1
34+
else
35+
return 0
36+
end
37+
end
38+
39+
function move_something()
40+
-- Find a rect very close to the edge
41+
-- of visible objects and move it.
42+
x = circle.x + circle.r
43+
y = circle.y + circle.r
44+
45+
for _, sq in pairs(squares) do
46+
local dx = sq.x + sq.width / 2 - x
47+
local dy = sq.y + sq.height / 2 - y
48+
distance = dx * dx + dy * dy
49+
50+
if 5000 < distance and distance < 8000 then
51+
local sq_dx = love.math.random(-10, 10)
52+
local sq_dy = love.math.random(-10, 10)
53+
sq.x, sq.y = world:move(sq, sq.x + sq_dx, sq.y + sq_dy)
54+
movesound:setPosition(sign(dx), sign(dy))
55+
movesound:play()
56+
return true
57+
end
58+
end
59+
60+
return false
61+
end
62+
63+
--------------------
64+
-- love callbacks --
65+
--------------------
2966
function love.load()
67+
-- hide mouse cursor
68+
love.mouse.setVisible(false)
69+
70+
ambient = love.audio.newSource("res/scary.ogg", "stream")
71+
ambient:setLooping(true)
72+
ambient:setVolume(0.1)
73+
ambient:play()
74+
75+
movesound = love.audio.newSource("res/movement.ogg", "static")
76+
next_move_in = love.math.random(10, 20)
77+
78+
light = love.graphics.newShader("light.glsl")
3079
world = bump.newWorld()
3180
squares = {}
32-
circle = {x=0, y=0, dx=0, dy=0, speed=100, r=10, color={1, 0, 1, 1}}
81+
circle = {x=0, y=0, dx=0, dy=0, speed=100, r=10, color={1, 1, 1, 1}}
3382
world:add(circle, circle.x, circle.y, circle.r * 2, circle.r * 2)
3483

3584
for i = 1, 100 do
3685
local square = newSquare()
3786
table.insert(squares, square)
3887
world:add(square, square.x, square.y, square.width, square.height)
3988
end
89+
90+
light:send("sourcePos", {circle.x + circle.r, circle.y + circle.r})
4091
end
4192

4293
function love.draw()
94+
love.graphics.setShader(light)
95+
4396
for _, sq in pairs(squares) do
44-
with_color(sq.color, love.graphics.rectangle,
45-
"fill", sq.x, sq.y, sq.width, sq.height)
97+
love.graphics.setColor(sq.color)
98+
love.graphics.rectangle("fill", sq.x, sq.y, sq.width, sq.height)
4699
end
47100

48101
-- draw the circle to the right/bottom of x, y,
49-
-- since bump uses these coordinates for collision
50-
-- checks
51-
with_color(circle.color, love.graphics.arc, "fill",
52-
circle.x + circle.r, circle.y + circle.r, circle.r, 0, math.pi*2)
102+
-- since bump uses these coordinates for collision checks
103+
love.graphics.setColor(circle.color)
104+
local x, y = circle.x + circle.r, circle.y + circle.r
105+
love.graphics.arc("fill", x, y, circle.r, 0, math.pi*2)
106+
107+
love.graphics.setShader()
53108
end
54109

55110
function love.update(dt)
56-
-- handle keyboard input
111+
-- handle circle movement
57112
if love.keyboard.isDown("a", "left") then
58113
circle.dx = - circle.speed
59114
elseif love.keyboard.isDown("d", "right") then
@@ -72,6 +127,27 @@ function love.update(dt)
72127

73128
local x = circle.x + circle.dx * dt
74129
local y = circle.y + circle.dy * dt
75-
-- circle.x, circle.y = world:move(circle, x - circle.r, y - circle.r)
76-
circle.x, circle.y = world:move(circle, x, y)
130+
131+
if x ~= circle.x or y ~= circle.y then
132+
circle.x, circle.y = world:move(circle, x, y)
133+
-- update the light shader source position
134+
light:send("sourcePos", {circle.x + circle.r, circle.y + circle.r})
135+
end
136+
137+
-- handle randomly moving squares
138+
next_move_in = next_move_in - dt
139+
if next_move_in <= 0 then
140+
if move_something() then
141+
next_move_in = love.math.random(10, 20)
142+
else
143+
next_move_in = 0
144+
end
145+
end
146+
end
147+
148+
function love.keypressed(key, scancode, isrepeat)
149+
-- exit on Escape
150+
if key == "escape" then
151+
love.event.quit()
152+
end
77153
end
9.52 KB
Binary file not shown.
5.93 MB
Binary file not shown.
3.92 KB
Loading

0 commit comments

Comments
 (0)