var win := Window.Open ("graphics:max;max;offscreenonly;nocursor")
const base := 60
const movement := 10
const jump_dis := 25
const gravity := 2
var keyslah : array char of boolean
var tcoins : nat := 0
var jumponly := true
% player position and velocity
var posx := 20
var velx := 0.0
var posy := base
var vely := 0.0
procedure drawbg
drawline (0, base, maxx, base, 64)
locate (2, 4)
put "Coins collected : ", tcoins, "."
locate (3, 4)
put "Time elasped : "
end drawbg
procedure level_tut_1
Draw.ThickLine (25, 180, 100, 180, 2, black)
Draw.ThickLine(200, 220, 315, 220, 2, black)
Draw.ThickLine(450, 240, 575, 240, 2, black)
Draw.ThickLine(660, 260, 785, 260, 2, black)
end level_tut_1
loop
cls
Input.KeyDown (keyslah)
if keyslah ('q') then
exit
end if
% left and right keyt
if keyslah (KEY_LEFT_ARROW) and posx - 10 > 0 then
velx := -movement
elsif keyslah (KEY_RIGHT_ARROW) and posx + 10 < maxx - 10 then
velx := movement
else
velx := 0
end if
%% up key
if keyslah (KEY_UP_ARROW) and jumponly = true then
vely := jump_dis
jumponly := false
end if
% subtract your gravity constant from the velocity
if View.WhatDotColor (posx, posy - 1) not= black then
vely -= gravity
posx += round (velx)
posy += round (vely)
end if
% on the ground ?
if posy < base then
posy := base
vely := 0
jumponly := true
end if
if View.WhatDotColor (posx, posy-1) = black then
vely := 0
vely += gravity
jumponly := true
delay (40)
end if
% change if colors if you can't jump
if jumponly = true then
drawfillbox (posx , posy, posx + 20, posy + 20, green)
else
drawfillbox (posx , posy, posx + 20, posy + 20, 79)
end if
%% just so I know where posx and posy are
drawfilloval (posx, posy, 1, 1, 12)
drawbg
level_tut_1
delay (25)
View.Update
end loop
Window.Close (win)
|