Code: Select all
function love.load()
s = ""
--love.graphics.setBackgroundColor(1, 1, 1)
love.physics.setMeter(40)
world = love.physics.newWorld(0, love.physics:getMeter() * 8, true)
moonshine = require 'moonshine'
blur = moonshine(moonshine.effects.gaussianblur)
blur.gaussianblur.sigma = 6
useShader = true
threshold = love.graphics.newShader([[
vec4 effect( vec4 color, Image tex, vec2 tc, vec2 sc )
{
vec4 pixel = Texel(tex, tc);
number avg = (pixel.r + pixel.g + pixel.b) / 3;
if (avg > 0.01) {
return vec4(1.0, 1.0, 1.0, 1.0) * color;
} else {
return pixel;
}
}
]])
balls = {}
count = 500
ballSize = 2
sizeVariation = 2
for i=1, count do
balls[i] = {}
balls[i].body = love.physics.newBody(world, love.graphics.getWidth() / 2 + math.random(), -(ballSize * 2) * i, "dynamic")
balls[i].body:setMass(0.1)
balls[i].size = ballSize + (sizeVariation * math.random())
balls[i].shape = love.physics.newCircleShape(balls[i].size)
balls[i].fixture = love.physics.newFixture(balls[i].body, balls[i].shape, 1)
balls[i].fixture:setRestitution(0.3)
balls[i].fixture:setFriction(0.1)
end
walls = {}
walls[1] = {}
walls[1].body = love.physics.newBody(world, love.graphics.getWidth() / 2, love.graphics.getHeight() - 5, "static")
walls[1].shape = love.physics.newRectangleShape(love.graphics.getWidth(), 10)
walls[1].fixture = love.physics.newFixture(walls[1].body, walls[1].shape, 1)
walls[2] = {}
walls[2].body = love.physics.newBody(world, 0, love.graphics.getHeight() / 2, "static")
walls[2].shape = love.physics.newRectangleShape(10, love.graphics.getWidth())
walls[2].fixture = love.physics.newFixture(walls[2].body, walls[2].shape, 1)
walls[3] = {}
walls[3].body = love.physics.newBody(world, love.graphics.getWidth() - 10, love.graphics.getHeight() / 2, "static")
walls[3].shape = love.physics.newRectangleShape(10, love.graphics.getWidth())
walls[3].fixture = love.physics.newFixture(walls[3].body, walls[3].shape, 1)
walls[4] = {}
walls[4].body = love.physics.newBody(world, love.graphics.getWidth() / 2, love.graphics.getHeight() / 2, "static")
walls[4].shape = love.physics.newRectangleShape(64, 16)
walls[4].fixture = love.physics.newFixture(walls[4].body, walls[4].shape, 1)
walls[5] = {}
walls[5].body = love.physics.newBody(world, love.graphics.getWidth() / 4, love.graphics.getHeight() / 1.5, "static")
walls[5].shape = love.physics.newRectangleShape(0, 0, 100, 8, math.pi / 4)
walls[5].fixture = love.physics.newFixture(walls[5].body, walls[5].shape, 1)
walls[6] = {}
walls[6].body = love.physics.newBody(world, love.graphics.getWidth() - (love.graphics.getWidth() / 4), love.graphics.getHeight() / 1.5, "static")
walls[6].shape = love.physics.newRectangleShape(0, 0, 100, 8, -(math.pi / 4))
walls[6].fixture = love.physics.newFixture(walls[6].body, walls[6].shape, 1)
player = {}
player.body = love.physics.newBody(world, love.graphics.getWidth() / 2, love.graphics.getHeight() / 2, "dynamic")
player.size = ballSize * 16
player.body:setMass(player.size * 8)
player.speed = 1000
player.maxVel = 200
player.jump = 30
player.shape = love.physics.newCircleShape(player.size)
player.fixture = love.physics.newFixture(player.body, player.shape, 1)
player.fixture:setRestitution(0.3 * math.random() + 0.2)
snow = love.graphics.newCanvas()
sprint("'1' to toggle shader")
sprint("'SPACE' to reset")
sprint("'R' to make shit fly")
end
function sprint(t)
s = s..t.."\n"
end
function love.update(dt)
local mx, my = love.mouse.getPosition()
local xVel, yVel = player.body:getLinearVelocity()
local nx, ny = xVel, yVel
if love.keyboard.isDown("d") then
nx = nx + player.speed * dt
if nx > player.maxVel then
nx = player.maxVel
end
elseif love.keyboard.isDown("a") then
nx = nx - player.speed * dt
if nx < -player.maxVel then
nx = -player.maxVel
end
end
player.body:setLinearVelocity(nx, ny)
world:update(dt)
end
function love.draw()
love.graphics.setCanvas(snow)
love.graphics.clear()
if useShader then
blur(function()
love.graphics.setColor(1, 1, 1, 1)
for i,v in ipairs(balls) do
love.graphics.circle("fill", v.body:getX(), v.body:getY(), v.size)
end
end)
else
love.graphics.setColor(1, 1, 1, 1)
for i,v in ipairs(balls) do
love.graphics.circle("fill", v.body:getX(), v.body:getY(), v.size)
end
end
love.graphics.setCanvas()
love.graphics.setColor(0.2, 0.8, 0.4, 1)
if useShader then love.graphics.setShader(threshold) end
love.graphics.draw(snow)
love.graphics.setShader()
love.graphics.setColor(1, 1, 1, 1)
for i,v in ipairs(walls) do
love.graphics.polygon("fill", v.body:getWorldPoints(v.shape:getPoints()))
end
love.graphics.setColor(1, 0.6, 0.4, 1)
love.graphics.circle("fill", player.body:getX(), player.body:getY(), player.size)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.printf(s, 12, 12, love.graphics.getWidth(), "left")
love.graphics.printf(love.timer.getFPS(), 0, 12, love.graphics.getWidth(), "center")
end
function love.keypressed(key)
if key == "escape" then
love.event.push("quit")
elseif key == "space" then
love.load()
elseif key == "1" then
useShader = not useShader
elseif key == "2" then
love.graphics.captureScreenshot(os.time()..".png")
--sprint("Screenshot captured.")
end
if key == "w" then
player.body:applyLinearImpulse(0, -(player.size * 18) )
end
if key == "r" then
for i,v in ipairs(balls) do
v.body:applyLinearImpulse(0, -10 * math.random())
end
end
end