1
0
dIntDesJam/2016-uge2/main.lua

144 lines
3.4 KiB
Lua

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/256, 100/256, 200/256)
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