245 lines
8.6 KiB
Lua
245 lines
8.6 KiB
Lua
|
|
-- Colors
|
|
local COLOR_WHITE = {1,1,1}
|
|
local COLOR_BG = {26/255,26/255,26/255}
|
|
local COLOR_PLAYER = {0, 1, 0}
|
|
|
|
-- Resources
|
|
|
|
local MUSIC_1 = love.audio.newSource('/All_Star_NoIntro.mp3', 'stream')
|
|
local MUSIC_2 = love.audio.newSource('/All_Reverb.mp3', 'stream')
|
|
|
|
local FONT = love.graphics.newFont('/star_font.ttf', 70)
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
math.randomseed(os.time())
|
|
|
|
love.graphics.setFont(FONT)
|
|
|
|
local plat = require "plat"
|
|
|
|
local system = plat.PlatformSystem.new()
|
|
system:addPlatform(000, 400, 800, 300)
|
|
system:addPlatform(-50, -200000, 50, 400000)
|
|
system:addPlatform(800, -200000, 50, 400000)
|
|
|
|
system:addPlatform(450, 200, 100, 50)
|
|
system:addPlatform(200, 50, 100, 50)
|
|
system:addPlatform(450, -50, 100, 50)
|
|
system:addPlatform(200, -150, 100, 50)
|
|
system:addPlatform(200, -350, 100, 50)
|
|
system:addPlatform(100, -550, 100, 50)
|
|
system:addPlatform(300, -750, 250, 50)
|
|
system:addPlatform(50, -700, 100, 50)
|
|
system:addPlatform(550, -950, 150, 50)
|
|
system:addPlatform(300, -1100, 100, 50)
|
|
system:addPlatform(500, -1300, 100, 50)
|
|
system:addPlatform(150, -1400, 100, 50)
|
|
system:addPlatform(650, -1500, 100, 50)
|
|
system:addPlatform(300, -1550, 100, 50)
|
|
system:addPlatform(500, -1700, 100, 50)
|
|
system:addPlatform(250, -1850, 100, 50)
|
|
system:addPlatform(100, -2050, 50, 250)
|
|
system:addPlatform(400, -2200, 50, 200)
|
|
system:addPlatform(650, -2200, 50, 200)
|
|
system:addPlatform(650, -2500, 50, 200)
|
|
system:addPlatform(700, -2200, 100, 50)
|
|
system:addPlatform(700, -2450, 50, 50)
|
|
system:addPlatform(700, -2450, 50, 50)
|
|
system:addPlatform(600, -2450, 50, 50)
|
|
system:addPlatform(550, -2400, 50, 50)
|
|
system:addPlatform(450, -2700, 150, 50)
|
|
system:addPlatform(350, -2750, 150, 50)
|
|
system:addPlatform(300, -2900, 50, 150)
|
|
system:addPlatform(300, -2950, 100, 50)
|
|
system:addPlatform(650, -3250, 50, 200)
|
|
system:addPlatform(500, -3150, 150, 50)
|
|
system:addPlatform(600, -3400, 150, 50)
|
|
system:addPlatform(250, -3300, 150, 50)
|
|
system:addPlatform(450, -3700, 50, 300)
|
|
system:addPlatform(300, -3550, 150, 50)
|
|
system:addPlatform(100, -3500, 50, 100)
|
|
system:addPlatform(450, -3750, 150, 50)
|
|
system:addPlatform(350, -4100, 50, 250)
|
|
system:addPlatform(400, -4000, 150, 100)
|
|
system:addPlatform(700, -3900, 50, 150)
|
|
system:addPlatform(500, -4250, 300, 50)
|
|
system:addPlatform(0, -4450, 350, 50)
|
|
system:addPlatform(150, -4650, 50, 50)
|
|
system:addPlatform(250, -4850, 50, 50)
|
|
system:addPlatform(400, -4850, 50, 50)
|
|
system:addPlatform(550, -4850, 50, 50)
|
|
system:addPlatform(700, -5050, 50, 50)
|
|
system:addPlatform(450, -5250, 50, 50)
|
|
system:addPlatform(750, -5450, 50, 50)
|
|
system:addPlatform(0, -5500, 50, 50)
|
|
system:addPlatform(0, -5650, 50, 150)
|
|
system:addPlatform(750, -5800, 50, 150)
|
|
system:addPlatform(300, -6100, 200, 50)
|
|
system:addPlatform(250, -6050, 300, 50)
|
|
system:addPlatform(200, -6000, 400, 50)
|
|
system:addPlatform(350, -6150, 100, 50)
|
|
system:addPlatform(550, -6350, 200, 50)
|
|
system:addPlatform(50, -6350, 200, 50)
|
|
system:addPlatform(300, -6550, 200, 50)
|
|
system:addPlatform(350, -6750, 50, 50)
|
|
system:addPlatform(400, -6950, 50, 50)
|
|
system:addPlatform(350, -7150, 50, 50)
|
|
system:addPlatform(400, -7300, 50, 50)
|
|
system:addPlatform(550, -7500, 150, 50)
|
|
system:addPlatform(300, -7500, 150, 50)
|
|
system:addPlatform(350, -7850, 50, 250)
|
|
system:addPlatform(200, -7750, 150, 50)
|
|
system:addPlatform(0, -7650, 100, 50)
|
|
system:addPlatform(500, -8000, 200, 50)
|
|
system:addPlatform(250, -8200, 200, 50)
|
|
system:addPlatform(500, -8400, 50, 50)
|
|
system:addPlatform(200, -8600, 50, 50)
|
|
system:addPlatform(550, -8800, 50, 50)
|
|
system:addPlatform(350, -8950, 50, 50)
|
|
system:addPlatform(300, -9150, 150, 50)
|
|
system:addPlatform(300, -9350, 150, 50)
|
|
system:addPlatform(300, -9550, 150, 50)
|
|
system:addPlatform(150, -9750, 150, 50)
|
|
system:addPlatform(450, -9750, 150, 50)
|
|
system:addPlatform(300, -9950, 150, 50)
|
|
system:addPlatform(400, -10150, 50, 50)
|
|
system:addPlatform(300, -10350, 50, 50)
|
|
system:addPlatform(400, -10550, 50, 50)
|
|
system:addPlatform(450, -10750, 100, 50)
|
|
system:addPlatform(200, -10750, 100, 50)
|
|
system:addPlatform((800-250)/2, -10950, 250, 50)
|
|
|
|
|
|
local BEST_SCORE = math.huge
|
|
local PREVIOUS_SCORE = {}
|
|
local START_OF_GAME, END_OF_GAME = 0, 0
|
|
|
|
local player = system:addPlayer((800-50)/2, 350, 50, 50, {jump = 'up', left = 'left', right = 'right'})
|
|
player.color = COLOR_PLAYER
|
|
|
|
local stars = {}
|
|
for i = 1, 1000 do
|
|
stars[i] = { math.random() * 800, math.random() * 600 * 4 - 1800 }
|
|
end
|
|
|
|
local function set_score (score)
|
|
PREVIOUS_SCORE = score
|
|
local SCORE_L = tostring(math.floor(BEST_SCORE*100)/100)
|
|
PREVIOUS_SCORE[#PREVIOUS_SCORE+1] = ' '
|
|
for i = 1, #SCORE_L do PREVIOUS_SCORE[#PREVIOUS_SCORE+1] = SCORE_L:sub(i,i) end
|
|
for i = 1, #score do
|
|
score[i] = { score[i] }
|
|
score[i].x = math.random() * 10 - 5
|
|
score[i].y = math.random() * 10 - 5
|
|
score[i].r = math.random() * math.pi/2 - math.pi/4
|
|
end
|
|
end
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
local reset_game = nil
|
|
|
|
local goto_highscore = function ()
|
|
local new_score = END_OF_GAME - START_OF_GAME
|
|
local old_draw, text = love.draw, {}
|
|
if new_score < BEST_SCORE then
|
|
BEST_SCORE = new_score
|
|
love.keypressed = function (key)
|
|
if key == 'escape' then
|
|
love.event.quit()
|
|
elseif key == 'return' and #text >= 1 then
|
|
set_score(text)
|
|
reset_game()
|
|
elseif key == 'backspace' then
|
|
text[#text] = nil
|
|
elseif #key == 1 and #text < 3 then
|
|
text[#text+1] = key:upper()
|
|
end
|
|
end
|
|
love.draw = function () old_draw(); love.graphics.printf('New High Score!\nEnter name:\n'..table.concat(text), 0, 200, 800, 'center') end
|
|
else
|
|
love.keypressed = function ()
|
|
if key == 'escape' then
|
|
love.event.quit()
|
|
else
|
|
reset_game()
|
|
end
|
|
end
|
|
love.draw = function () old_draw(); love.graphics.printf(':(', 0, 200, 800, 'center') end
|
|
end
|
|
|
|
love.update = function () end
|
|
player.movable = false
|
|
end
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
local update_game = function (dt)
|
|
system:update(dt)
|
|
|
|
if player.y < -800 and not MUSIC_1:isPlaying() then MUSIC_1:play(); MUSIC_2:play(); START_OF_GAME = love.timer.getTime(); print("start") end
|
|
if player.y < -10950 then player.dy = player.dy - 1000 * dt end
|
|
if player.y < -10950 and not END_OF_GAME then END_OF_GAME = love.timer.getTime() end
|
|
if player.y < -200000 then goto_highscore() end
|
|
|
|
if love.keyboard.isDown('f2') then player.dy = player.dy - 1000 * dt end
|
|
|
|
COLOR_PLAYER[1], COLOR_PLAYER[3] = (player.y+800)/-100000, (player.y+800)/-100000
|
|
MUSIC_1:setVolume((player.y+800)/-12000)
|
|
MUSIC_2:setVolume((1-(player.y+800)/-12000))
|
|
end
|
|
|
|
local draw_previous_score = function (bx, by, inconsitency)
|
|
for i, b in ipairs(PREVIOUS_SCORE) do
|
|
love.graphics.print(b[1], b.x * inconsitency + bx + (i-1) * 80, by + b.y * inconsitency, b.r * inconsitency )
|
|
end
|
|
end
|
|
|
|
local draw_game = function ()
|
|
love.graphics.setBackgroundColor(COLOR_BG)
|
|
|
|
-- Draw score
|
|
love.graphics.setColor(COLOR_WHITE)
|
|
draw_previous_score(100, 200*player.y/-10000 + 200, player.y/-3000)
|
|
|
|
-- Draw Stars
|
|
love.graphics.setColor(COLOR_WHITE)
|
|
if player.y < 10000 then
|
|
for i = 1, #stars do
|
|
love.graphics.points(stars[i][1], - 600 + stars[i][2] - player.y/100)
|
|
end
|
|
end
|
|
|
|
-- Draw System
|
|
system:draw(player.x, player.y - (800-50)/2 - ((player.y < -11000) and (player.y+11000)/400 or 0))
|
|
end
|
|
|
|
function reset_game ( set_score )
|
|
player.x, player.y = (800-50)/2, 250
|
|
--player.x, player.y = (800-50)/2, -10000
|
|
player.dy, player.dx = 0, 0
|
|
player.movable = true
|
|
MUSIC_1:stop(); MUSIC_2:stop()
|
|
|
|
love.update = update_game
|
|
love.draw = draw_game
|
|
love.keypressed = function (key)
|
|
if key == 'escape' then
|
|
love.event.quit()
|
|
elseif key == 'r' then
|
|
reset_game()
|
|
end
|
|
end
|
|
|
|
END_OF_GAME = nil
|
|
end
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
love.load = reset_game
|