Code: Select all
mapa = {}
dolu = 0
nahoru = 0
poloha = 50
function round(num)
return num - (num % 1)
end
function getVyska()
zlomek = poloha % 1
return (mapa[poloha - (poloha % 1)] + (mapa[poloha + 1 - ((poloha + 1) % 1)] - mapa[poloha - (poloha % 1)]) * zlomek)
end
function love.load()
love.graphics.setColorMode("replace")
obrazek_postavy = love.graphics.newImage("postava.png")
love.graphics.draw(nebe, 0, 0, 0, 1, 1, 0, 0)
math.randomseed(os.time())
nahoru = math.random(1, 2)
dolu = math.random (-2, -1)
mapa[0] = math.random(0, 600)
for i = 1, 1000 do
nahoru = nahoru + math.random(-1, 1)
if nahoru < 1 then nahoru = 1 end
dolu = dolu + math.random(-1, 1)
if dolu > -1 then dolu = -1 end
mapa[i] = mapa[i-1] + math.random(dolu, nahoru)
end
end
function love.update(dt)
if love.keyboard.isDown("left") and poloha > 50 then poloha = poloha - 1/math.sqrt(8 + (math.abs(mapa[round(poloha)+1] - mapa[round(poloha-1)+1]))) end
if love.keyboard.isDown("right") and poloha < 950 then poloha = poloha + 1/math.sqrt(8 + (math.abs(mapa[round(poloha)] - mapa[round(poloha+1)]))) end
if love.keyboard.isDown("down") then mapa[round(poloha, 0)] = mapa[round(poloha, 0)] + 1 end
end
function love.draw()
love.graphics.setBackgroundColor(152, 68, 0)
nebe = love.graphics.newImage("nebe.png")
love.graphics.setColor(0, 0, 0)
for i = 1, 1000 do
love.graphics.polygon(
"fill",
(i-1)*8-poloha*8+400,
mapa[i-1]-getVyska()+300,
i*8-poloha*8+400,
mapa[i]-getVyska()+300,
i*8-poloha*8+400,
100000-getVyska()+300,
(i-1)*8-poloha*8+400,
100000-getVyska()+300
)
end
love.graphics.draw(obrazek_postavy, 384, 272, 0, 1, 1, 0, 0)
love.graphics.print(love.timer.getFPS(), 30, 30, 0, 1, 1)
end
NOTE: postava.png is small and negligible 32×32 image
NOTE 2: variable names are in czech.