local SCROLL_SPEED = 100 local RESISTENCE = 1 local SPEED = 100 local FONT = love.graphics.newFont("cour.ttf", 30) love.graphics.setFont(FONT) local COLOR_PLANET = {100/255,200/255,100/255} local COLOR_STARS = {1,1,1} 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(COLOR_STARS) 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(COLOR_STARS) 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, COLOR_PLANET) 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(COLOR_STARS) love.graphics.draw(CANVAS) end math.randomseed(os.time()) generate_stars(30, 100) love.graphics.setBackgroundColor(26/255,26/255,26/255)