1
0

There we go, dIntDesJam #2.

This commit is contained in:
Jon Michael Aanes 2016-02-10 15:57:47 +01:00
parent 4c38f4dee3
commit 6692c372f4
4 changed files with 330 additions and 0 deletions

BIN
2/cour.ttf Normal file

Binary file not shown.

143
2/main.lua Normal file
View File

@ -0,0 +1,143 @@
local RESISTENCE = 0.99
local SPEED = 100
local hotspots = {}
function generate_hotspots (nr, mindist)
local mindist = mindist * mindist
while nr>0 do
local x, y = 50+math.random(700), 50+math.random(500)
for _, o_spot in ipairs(hotspots) do
if math.pow(o_spot.x-x, 2) + math.pow(o_spot.y-y, 2) < mindist then
x = 0
end
end
if x ~= 0 then
table.insert(hotspots, {x=x, y=y})
nr = nr - 1
end
end
end
local player = {
x = 400,
y = 300,
dx = 0,
dy = 0,
fisk = 0
}
local hint = {
text = "Move with WASD\nFish with SPACEBAR",
time = 10,
}
function update_player (dt)
local ddy = love.keyboard.isDown("w") and -1 or love.keyboard.isDown("s") and 1 or 0
local ddx = love.keyboard.isDown("a") and -1 or love.keyboard.isDown("d") and 1 or 0
if ddx ~= 0 and ddy ~= 0 then
ddx, ddy = ddx*math.sqrt(2), ddy*math.sqrt(2)
end
player.dx, player.dy = player.dx*RESISTENCE + SPEED*ddx*dt, player.dy*RESISTENCE + SPEED*ddy*dt
player.x, player.y = player.x + player.dx * dt, player.y + player.dy * dt
if player.rocket then
player.rocket = player.rocket - dt * 500
end
end
function draw_player (x,y)
local py = player.rocket and y + math.min(0, player.rocket) or y
local PLAYER_POLY = {
x-30, py+20,
x+20, py+20,
x+30, py,
x+10, py,
x+10, py-20,
x, py-20,
x, py,
x-30, py,
}
love.graphics.polygon('fill', PLAYER_POLY)
if player.rocket then
local ROCKET_POLY = {
x, y+20-30 + player.rocket,
x-10, y+20-10 + player.rocket,
x-20, y+20+40 + player.rocket,
x-5, y+20+20 + player.rocket,
x-2, y+20+30 + player.rocket,
x+2, y+20+37 + player.rocket,
x+5, y+20+20 + player.rocket,
x+20, y+20+40 + player.rocket,
x+10, y+20-10 + player.rocket,
}
love.graphics.polygon('fill', ROCKET_POLY)
end
end
generate_hotspots(5, 100)
love.graphics.setBackgroundColor(100, 100, 200)
function love.update (dt)
update_player(dt)
hint.time = hint.time - dt
if hint.time <= 0 and hint.func then
hint.func()
end
if not hint.active then
for index, spot in ipairs(hotspots) do
if math.pow(spot.x-player.x, 2) + math.pow(spot.y-player.y, 2) < 50 then
hint = {text="Woo, wee! You're close to a FISH!", time=0.1, target = index}
end
end
end
end
local function activate_rocket_3 ()
require "main2"
end
local function activate_rocket_2 ()
hint = {text="", time=5, func=activate_rocket_3}
player.rocket = 500
end
function love.keypressed (key)
if key == "space" and not hint.target and hint.time <= 0 then
hint = {text="You try to FISH, but there's no FISH", time=1}
elseif key == "space" and hint.target and not hint.active then
hint.text = "FISH! FISH!"
hint.active = 10
hint.time = 10
player.dx, player.dy = 0, 0
elseif key == "space" and hint.target and hint.active then
hint.active = hint.active - 1
if hint.active <= 0 then
table.remove(hotspots, hint.target)
hint = {text="Fuck yeah! You've got a FISH!", time=5}
player.fisk = player.fisk + 1
if #hotspots == 0 then
hint = {text="Fucking fuck yeah! You've got ALL of the FISH!\nBut what now? O_o", time=5, func=activate_rocket_2}
end
end
end
end
function love.draw ()
draw_player(player.x, player.y)
love.graphics.print("Fisk: "..player.fisk, 10, 10)
if hint.time > 0 then
love.graphics.printf(hint.text, 300, 100, 200, "center")
end
for _, spot in ipairs(hotspots) do
love.graphics.circle("fill", spot.x, spot.y, 10)
end
end

176
2/main2.lua Normal file
View File

@ -0,0 +1,176 @@
local SCROLL_SPEED = 100
local RESISTENCE = 1
local SPEED = 100
local FONT = love.graphics.newFont("cour.ttf", 30)
love.graphics.setFont(FONT)
local stars = {}
function generate_stars (nr, mindist)
local mindist = mindist * mindist
while nr>0 do
local x, y = 50+math.random(700), 50+math.random(500)
for _, o_spot in ipairs(stars) do
if math.pow(o_spot[1]-x, 2) + math.pow(o_spot[1]-y, 2) < mindist then
x = 0
end
end
if x ~= 0 then
table.insert(stars, {x, y})
nr = nr - 1
end
end
end
local function shaders ()
hint = {
text = "Dude, there's nothing more, please leave :/",
time = 100,
align = "left"
}
end
local function wait_on_shaders_2 ()
hint = {
text = "",
time = 60,
align = "right",
func = exit
}
end
local function shaders ()
hint = {
text = "Fucking shaders, right?\nTook me way too long a time to create this bad effect :/",
time = 10,
align = "left",
func = wait_on_shaders_2
}
end
local function wait_on_shaders ()
hint = {
text = "",
time = 5,
align = "right",
func = shaders
}
local shader = love.graphics.newShader("stars.glsl")
love.graphics.setShader(shader)
shader:send("stars", unpack(stars))
end
local function love_the_final_frontier()
hint = {
text = "LÖVE, the final frontier...",
time = 0.2,
align = "right",
func = wait_on_shaders
}
end
hint = {
text = "SPACE, the final frontier...",
time = 5,
func = love_the_final_frontier,
align = "right"
}
local player = {
x = 400,
y = 300,
dx = 0,
dy = 0
}
function draw_player (x,y)
love.graphics.setColor(255, 255, 255)
local py = player.rocket and y + math.min(0, player.rocket) or y
local PLAYER_POLY = {
x-30, py+20,
x+20, py+20,
x+30, py,
x+10, py,
x+10, py-20,
x, py-20,
x, py,
x-30, py,
}
local ROCKET_POLY = {
x, y+20-30,
x-10, y+20-10,
x-20, y+20+40,
x-5, y+20+20,
x-2, y+20+30,
x+2, y+20+37,
x+5, y+20+20,
x+20, y+20+40,
x+10, y+20-10,
}
love.graphics.polygon('fill', PLAYER_POLY)
love.graphics.polygon('fill', ROCKET_POLY)
end
function update_player (dt)
local ddy = love.keyboard.isDown("w") and -1 or love.keyboard.isDown("s") and 1 or 0
local ddx = love.keyboard.isDown("a") and -1 or love.keyboard.isDown("d") and 1 or 0
if ddx ~= 0 and ddy ~= 0 then
ddx, ddy = ddx*math.sqrt(2), ddy*math.sqrt(2)
end
player.dx, player.dy = player.dx*RESISTENCE + SPEED*ddx*dt, player.dy*RESISTENCE + SPEED*ddy*dt
player.x, player.y = (player.x + player.dx * dt+800) % 800, (player.y + player.dy * dt+600) % 600
end
function draw_planet (x, y, size, color)
love.graphics.setColor(color)
love.graphics.circle("fill", x, y, size)
end
local scroll = 0
function love.update (dt)
scroll = scroll + dt * SCROLL_SPEED
update_player(dt)
hint.time = hint.time - dt
if hint.time <= 0 and hint.func then
hint.func()
end
end
function draw_stars ()
love.graphics.setColor(255,255,255)
for _, star in ipairs(stars) do
love.graphics.circle("fill", star[1], star[2], 2)
end
end
local CANVAS = love.graphics.newCanvas()
local function draw_canvas()
love.graphics.setCanvas(CANVAS)
love.graphics.clear()
draw_stars()
draw_planet(400, scroll+500, 200, {100, 200, 100})
draw_player(player.x, player.y)
if hint.time > 0 then
love.graphics.printf(hint.text, 100, 100, 600, hint.align or "center")
end
love.graphics.setCanvas()
end
function love.draw ()
draw_canvas()
love.graphics.setColor(255,255,255)
love.graphics.draw(CANVAS)
end
math.randomseed(os.time())
generate_stars(30, 100)
love.graphics.setBackgroundColor(26,26,26)

11
2/stars.glsl Normal file
View File

@ -0,0 +1,11 @@
extern vec2 stars[30];
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords)
{
float dist = 1000;
for (int i = 0; i<30; i++) {
dist = min(dist, pow(stars[i].x - screen_coords.x, 2) + pow(stars[i].y - screen_coords.y, 2));
}
return max(Texel(texture, texture_coords), vec4(1.0,1.0,1.0,1.0)/sqrt(dist));
}