set display mode 320,240,16
hide mouse
sync on
sync rate 30
DIM heightmap(319)
`calculate heights
randomize timer()
temp=rnd(360)
for x = 0 to 319
heightmap(x)=120+sin(x+temp)*(sin(temp)*90)
next x
create bitmap 1,320,240
create bitmap 2,320,240
set current bitmap 2
for x=0 to 239
ink rgb(clamp(-1*x+255,0,255),clamp(.013*x^2-3.2*x+255,0,255),clamp(-3*x+255,0,255)),0
line 0,x,319,x
next x
redrawTerrain()
playerx=160
playerxs#=0
playery=heightmap(playerx)-5
playerys#=0
ink 0,0
Do
cls
copy bitmap 1,0
if rightkey() then playerxs#=playerxs#+.25
if leftkey() then playerxs#=playerxs#-.25
playerx=playerx+playerxs#
playerxs#=playerxs#*.95
if playerys#=0
playery=heightmap(playerx)-5
if upkey() then playerys#=-5
else
playery=playery+playerys#
playerys#=playerys#+.51
if playery>heightmap(playerx)-5 then playerys#=0
endif
circle playerx,playery,5
print "FPS: ";screen fps()
sync
Loop
function redrawTerrain()
`draw landscape
set current bitmap 1
cls
copy bitmap 2,1
ink rgb(0,128,255),0
for x = 0 to 319 step 2
line x,heightmap(x),x,0
line x+1,heightmap(x),x+1,0
next x
set current bitmap 0
endfunction
function clamp(a as float,mn as float,mx as float)
if a<mn then a=mn
if a>mx then a=mx
endfunction a
Just realized 'clamp' is from a plugin... added a function for clamp, added character movement (similar to yours+jumping), and made it so terrain is not constantly changing (although it
could. Just remember to call 'redrawTerrain' after changing heightmap).
Thanks BiggAdd!
common people are walking in line.