% some constants, tweak this to your liking
const GROUND_HEIGHT := 40
const PLATFORM_HIEGHT := 200
const PLATFORM_HIEGHT2 := 350
const RUN_SPEED := 10
const FAST_SPEED := 13
const JUMP_SPEED := 30
const GRAVITY := 2
var win := Window.Open ("graphics:1200;600,offscreenonly")
var chars : array char of boolean
% player position and velocity
var posx, posy, gx, gx2, rx, lx : int
var velx, vely : real
posx := 200
velx := 0
posy := 400
vely := 0
gx := 10
gx2 := 10000
rx := 500
lx := 400
loop
Input.KeyDown (chars)
if chars ('q') then
exit
end if
% to make the player move
if chars (KEY_LEFT_ARROW) and chars (KEY_CTRL) then
velx := -FAST_SPEED
elsif chars (KEY_RIGHT_ARROW) and chars (KEY_CTRL) then
velx := FAST_SPEED
elsif chars (KEY_LEFT_ARROW) then
velx := -RUN_SPEED
elsif chars (KEY_RIGHT_ARROW) then
velx := RUN_SPEED
else
velx := 0
end if
% remember, in order to jump you MUST be on the ground when pressing UP
if (chars (KEY_UP_ARROW) and posy = GROUND_HEIGHT) or (chars (KEY_UP_ARROW) and posy = PLATFORM_HIEGHT and posx >= gx + 300 and posx <= gx + 400) or (chars (KEY_UP_ARROW) and posy =
PLATFORM_HIEGHT2 and posx >= gx + 500 and posx <= gx + 600) then
vely := JUMP_SPEED
end if
if posx >= rx and chars (KEY_RIGHT_ARROW) and rx < gx2 - (maxx - rx) then
gx -= round (velx)
gx2 -= round (velx)
posx := rx
posx := rx
end if
if posx <= lx and chars (KEY_LEFT_ARROW) and lx > gx + lx - 5 then
gx -= round (velx)
gx2 -= round (velx)
posx := lx
posx := lx
end if
% subtract your "gravity" constant from the velocity EACH frame
vely := vely - GRAVITY
posx := posx + round (velx)
posy := posy + round (vely)
/*if vely < -25 then
vely := -25
end if
*/
% simple "collision" check. just makes sure the player stays above ground
if posy < GROUND_HEIGHT and (posx < gx + 800 or posx > gx + 1000) then
posy := GROUND_HEIGHT
vely := 0
end if
if posy <0 then
posy :=0
end if
if posy <= PLATFORM_HIEGHT and posy >= PLATFORM_HIEGHT - 20 and posx >= gx + 300 and posx <= gx + 400 and vely <= 0 then
posy := PLATFORM_HIEGHT
vely := 0
/*elsif posy <= PLATFORM_HIEGHT and posy >= PLATFORM_HIEGHT - 22 and posx >= gx + 300 and posx <= gx + 400 and vely > 0 then
vely := 1*/
end if
if posy <= PLATFORM_HIEGHT2 and posy >= PLATFORM_HIEGHT2 - 20 and posx >= gx + 500 and posx <= gx + 600 and vely <= 0 then
posy := PLATFORM_HIEGHT2
vely := 0
/*elsif posy <= PLATFORM_HIEGHT2 and posy >= PLATFORM_HIEGHT2 - 22 and posx >= gx + 500 and posx <= gx + 600 and vely > 0 then
vely := 0*/
end if
%makes the square move across the screen when it reaches a certain point
if posx < gx + 10 then
posx := gx + 10
elsif posx > gx2 - 10 then
posx := gx2 - 10
end if
% different colours just to illustrate whether or not you may jump
drawline (gx, GROUND_HEIGHT, gx2, GROUND_HEIGHT, blue)
drawline (gx + 500, PLATFORM_HIEGHT + 150, gx + 600, PLATFORM_HIEGHT + 150, blue)
drawline (gx + 300, PLATFORM_HIEGHT, gx + 400, PLATFORM_HIEGHT, blue)
drawline (gx, GROUND_HEIGHT, gx, maxy - 10, blue)
drawline (gx, maxy - 10, gx2, maxy - 10, blue)
drawline (gx2, maxy - 10, gx2, GROUND_HEIGHT, blue)
drawfill (1, 1, gray, blue)
drawfill (1, maxy - 1, gray, blue)
drawfillbox (gx + 800, 0, gx + 1000, GROUND_HEIGHT, 0)
if posy = GROUND_HEIGHT then
drawfillbox (posx - 10, posy, posx + 10, posy + 20, green)
elsif posy = PLATFORM_HIEGHT and posx >= gx + 300 and posx <= gx + 400 then
drawfillbox (posx - 10, posy, posx + 10, posy + 20, green)
else
drawfillbox (posx - 10, posy, posx + 10, posy + 20, red)
end if
View.Update
exit when posy <=0
delay (25)
cls
end loop
delay (1000)
cls
locatexy (round (maxx/2), round (maxy/2))
put "you lose"
|