const GROUND_HEIGHT := 1
const RUN_SPEED := 10
const JUMP_SPEED := 30
const GRAVITY := 3
var win := Window.Open ("graphics:1000;600;offscreenonly")
var chars : array char of boolean
var PLATFORM_HEIGHT : int
var screenPosition : int := 0
var background : int := Pic.FileNew ("back.jpg")
var stepcounter : int := 0
% player position and velocity
var posx, posy : int
var velx, vely : real
var plat : array 1 .. 25, 1 .. 4 of int
var shot : boolean := false
var stand : int := Pic.FileNew ("stand.bmp")
var walk1 : int := Pic.FileNew ("walk1.bmp")
var walk2 : int := Pic.FileNew ("walk2.bmp")
var walk3 : int := Pic.FileNew ("walk3.bmp")
var jump : int := Pic.FileNew ("jump.bmp")
var shoot1 : int := Pic.FileNew ("shoot1.bmp")
var shoot2 : int := Pic.FileNew ("shoot2.bmp")
var shoot3 : int := Pic.FileNew ("shoot3.bmp")
var walkR1 : int := Pic.Mirror (walk1)
var walkR2 : int := Pic.Mirror (walk2)
var walkR3 : int := Pic.Mirror (walk3)
jump := Sprite.New (jump)
stand := Sprite.New (stand)
walk1 := Sprite.New (walk1)
walk2 := Sprite.New (walk2)
walk3 := Sprite.New (walk3)
walkR1 := Sprite.New (walkR1)
walkR2 := Sprite.New (walkR2)
walkR3 := Sprite.New (walkR3)
shoot1 := Sprite.New (shoot1)
shoot2 := Sprite.New (shoot2)
shoot3 := Sprite.New (shoot3)
Sprite.Show (stand)
Sprite.Hide (stand)
% plat (1, 1) := 200
% plat (1, 2) := 200
% plat (1, 3) := 300
% plat (1, 4) := 220
%
% plat (2, 1) := 400
% plat (2, 2) := 320
% plat (2, 3) := 500
% plat (2, 4) := 340
plat (1, 1) := 69
plat (1, 2) := 88
plat (1, 3) := 900
plat (1, 4) := 100
plat (2, 1) := 0
plat (2, 2) := 190
plat (2, 3) := 52
plat (2, 4) := 170
plat (3, 1) := 72
plat (3, 2) := 241
plat (3, 3) := 148
plat (3, 4) := 232
plat (4, 1) := 0
plat (4, 2) := 319
plat (4, 3) := 63
plat (4, 4) := 326
plat (5, 1) := 81
plat (5, 2) := 430
plat (5, 3) := 318
plat (5, 4) := 440
plat (6, 1) := 454
plat (6, 2) := 406
plat (6, 3) := 597
plat (6, 4) := 400
plat (7, 1) := 746
plat (7, 2) := 410
plat (7, 3) := 959
plat (7, 4) := 402
plat (8, 1) := 1990
plat (8, 2) := 0
plat (8, 3) := 2000
plat (8, 4) := 300
plat (9, 1) := 1012
plat (9, 2) := 309
plat (9, 3) := 1112
plat (9, 4) := 316
plat (10, 1) := 1518
plat (10, 2) := 434
plat (10, 3) := 1167
plat (10, 4) := 422
plat (11, 1) := 1182
plat (11, 2) := 600
plat (11, 3) := 1165
plat (11, 4) := 422
plat (12, 1) := 1592
plat (12, 2) := 58
plat (12, 3) := 1223
plat (12, 4) := 48
plat (13, 1) := 1730
plat (13, 2) := 173
plat (13, 3) := 1526
plat (13, 4) := 161
plat (14, 1) := 1534
plat (14, 2) := 234
plat (14, 3) := 1439
plat (14, 4) := 225
plat (15, 1) := 1502
plat (15, 2) := 332
plat (15, 3) := 1722
plat (15, 4) := 319
plat (16, 1) := 1495
plat (16, 2) := 520
plat (16, 3) := 1857
plat (16, 4) := 528
plat (17, 1) := 1877
plat (17, 2) := 528
plat (17, 3) := 1858
plat (17, 4) := 0
plat (18, 1) := 2074
plat (18, 2) := 118
plat (18, 3) := 2810
plat (18, 4) := 106
plat (19, 1) := 2245
plat (19, 2) := 233
plat (19, 3) := 2620
plat (19, 4) := 245
plat (20, 1) := 2334
plat (20, 2) := 385
plat (20, 3) := 2436
plat (20, 4) := 371
plat (21, 1) := 2096
plat (21, 2) := 454
plat (21, 3) := 2362
plat (21, 4) := 436
plat (22, 1) := 2096
plat (22, 2) := 454
plat (22, 3) := 2110
plat (22, 4) := 600
plat (23, 1) := 2480
plat (23, 2) := 515
plat (23, 3) := 2600
plat (23, 4) := 522
plat (24, 1) := 2788
plat (24, 2) := 490
plat (24, 3) := 2682
plat (24, 4) := 476
plat (25, 1) := 2925
plat (25, 2) := 452
plat (25, 3) := 3000
plat (25, 4) := 408
posx := 20
velx := 0
posy := 400
vely := 0
loop
Input.KeyDown (chars)
if chars ('q') then
exit
end if
% to make the player move
if chars (KEY_LEFT_ARROW) then
velx := -RUN_SPEED
stepcounter += RUN_SPEED
Sprite.Hide (stand)
Sprite.Hide (walkR1)
Sprite.Hide (walkR2)
Sprite.Hide (walkR3)
if stepcounter = 10 or stepcounter = 20 or stepcounter = 30 or stepcounter = 40 or stepcounter = 50 then
Sprite.Hide (stand)
Sprite.Hide (walk3)
Sprite.SetPosition (walk1, posx, posy + 20, true)
Sprite.Show (walk1)
Sprite.Hide (walk2)
elsif stepcounter = 60 or stepcounter = 70 or stepcounter = 80 or stepcounter = 90 or stepcounter = 100 then
Sprite.Hide (stand)
Sprite.SetPosition (walk2, posx, posy + 20, true)
Sprite.Show (walk2)
Sprite.Hide (walk1)
elsif stepcounter = 110 or stepcounter = 120 or stepcounter = 130 or stepcounter = 140 or stepcounter = 150 then
Sprite.Hide (stand)
Sprite.SetPosition (walk3, posx, posy + 20, true)
Sprite.Show (walk3)
Sprite.Hide (walk1)
Sprite.Hide (walk2)
end if
if stepcounter = 150 or chars (KEY_LEFT_ARROW) = false then
stepcounter := 0
Sprite.Hide (stand)
end if
if screenPosition <= 0 and posx <= 100 then
screenPosition += 10
velx := 0
plat (1, 1) += 10
plat (1, 3) += 10
plat (2, 1) += 10
plat (2, 3) += 10
plat (3, 1) += 10
plat (3, 3) += 10
plat (4, 1) += 10
plat (4, 3) += 10
plat (5, 1) += 10
plat (5, 3) += 10
plat (6, 1) += 10
plat (6, 3) += 10
plat (7, 1) += 10
plat (7, 3) += 10
plat (8, 1) += 10
plat (8, 3) += 10
plat (9, 1) += 10
plat (9, 3) += 10
plat (10, 1) += 10
plat (10, 3) += 10
plat (11, 1) += 10
plat (11, 3) += 10
plat (12, 1) += 10
plat (12, 3) += 10
plat (13, 1) += 10
plat (13, 3) += 10
plat (14, 1) += 10
plat (14, 3) += 10
plat (15, 1) += 10
plat (15, 3) += 10
plat (16, 1) += 10
plat (16, 3) += 10
plat (17, 1) += 10
plat (17, 3) += 10
plat (18, 1) += 10
plat (18, 3) += 10
plat (19, 1) += 10
plat (19, 3) += 10
plat (20, 1) += 10
plat (20, 3) += 10
plat (21, 1) += 10
plat (21, 3) += 10
plat (22, 1) += 10
plat (22, 3) += 10
plat (23, 1) += 10
plat (23, 3) += 10
plat (24, 1) += 10
plat (24, 3) += 10
plat (25, 1) += 10
plat (25, 3) += 10
elsif posx <= 92 then
end if
elsif chars (KEY_RIGHT_ARROW) then
velx := RUN_SPEED
stepcounter += RUN_SPEED
Sprite.Hide (stand)
Sprite.Hide (walk1)
Sprite.Hide (walk2)
Sprite.Hide (walk3)
if stepcounter = 10 or stepcounter = 20 or stepcounter = 30 or stepcounter = 40 or stepcounter = 50 then
Sprite.Hide (stand)
Sprite.Hide (walkR3)
Sprite.SetPosition (walkR1, posx, posy + 20, true)
Sprite.Show (walkR1)
Sprite.Hide (walkR2)
elsif stepcounter = 60 or stepcounter = 70 or stepcounter = 80 or stepcounter = 90 or stepcounter = 100 then
Sprite.Hide (stand)
Sprite.SetPosition (walkR2, posx, posy + 20, true)
Sprite.Show (walkR2)
Sprite.Hide (walkR1)
elsif stepcounter = 110 or stepcounter = 120 or stepcounter = 130 or stepcounter = 140 or stepcounter = 150 then
Sprite.Hide (stand)
Sprite.SetPosition (walkR3, posx, posy + 20, true)
Sprite.Show (walkR3)
Sprite.Hide (walkR1)
Sprite.Hide (walkR2)
else
Sprite.SetPosition (stand, posx, posy + 20, true)
Sprite.Show (stand)
end if
if stepcounter = 150 or chars (KEY_RIGHT_ARROW) = false then
stepcounter := 0
Sprite.Hide (stand)
end if
if screenPosition >= -2400 and posx >= 500 then
screenPosition -= 10
velx := 0
plat (1, 1) -= 10
plat (1, 3) -= 10
plat (2, 1) -= 10
plat (2, 3) -= 10
plat (3, 1) -= 10
plat (3, 3) -= 10
plat (4, 1) -= 10
plat (4, 3) -= 10
plat (5, 1) -= 10
plat (5, 3) -= 10
plat (6, 1) -= 10
plat (6, 3) -= 10
plat (7, 1) -= 10
plat (7, 3) -= 10
plat (8, 1) -= 10
plat (8, 3) -= 10
plat (9, 1) -= 10
plat (9, 3) -= 10
plat (10, 1) -= 10
plat (10, 3) -= 10
plat (11, 1) -= 10
plat (11, 3) -= 10
plat (12, 1) -= 10
plat (12, 3) -= 10
plat (13, 1) -= 10
plat (13, 3) -= 10
plat (14, 1) -= 10
plat (14, 3) -= 10
plat (15, 1) -= 10
plat (15, 3) -= 10
plat (16, 1) -= 10
plat (16, 3) -= 10
plat (17, 1) -= 10
plat (17, 3) -= 10
plat (18, 1) -= 10
plat (18, 3) -= 10
plat (19, 1) -= 10
plat (19, 3) -= 10
plat (20, 1) -= 10
plat (20, 3) -= 10
plat (21, 1) -= 10
plat (21, 3) -= 10
plat (22, 1) -= 10
plat (22, 3) -= 10
plat (23, 1) -= 10
plat (23, 3) -= 10
plat (24, 1) -= 10
plat (24, 3) -= 10
plat (25, 1) -= 10
plat (25, 3) -= 10
elsif posx >= 632 then
end if
elsif chars (KEY_ENTER) then
Sprite.Hide (stand)
Sprite.Hide (walk1)
Sprite.Hide (walk2)
Sprite.Hide (walk3)
Sprite.Hide (walkR1)
Sprite.Hide (walkR2)
Sprite.Hide (walkR3)
Sprite.SetPosition (shoot1, posx, posy + 20, true)
Sprite.Hide (shoot3)
Sprite.Show (shoot1)
delay (100)
Sprite.SetPosition (shoot2, posx, posy + 20, true)
Sprite.Hide (shoot1)
Sprite.Show (shoot2)
delay (100)
Sprite.SetPosition (shoot3, posx, posy + 20, true)
Sprite.Hide (shoot2)
Sprite.Show (shoot3)
delay (100)
else
velx := 0
end if
Pic.Draw (background, screenPosition, 0, picCopy)
Sprite.Show (stand)
% drawfillbox (plat (1, 1), plat (1, 2), plat (1, 3), plat (1, 4), 3)
% drawfillbox (plat (2, 1), plat (2, 2), plat (2, 3), plat (2, 4), 3)
drawfillbox (plat (1, 1), plat (1, 2), plat (1, 3), plat (1, 4), 3)
drawfillbox (plat (2, 1), plat (2, 2), plat (2, 3), plat (2, 4), 3)
drawfillbox (plat (3, 1), plat (3, 2), plat (3, 3), plat (3, 4), 3)
drawfillbox (plat (4, 1), plat (4, 2), plat (4, 3), plat (4, 4), 3)
drawfillbox (plat (5, 1), plat (5, 2), plat (5, 3), plat (5, 4), 3)
drawfillbox (plat (6, 1), plat (6, 2), plat (6, 3), plat (6, 4), 3)
drawfillbox (plat (7, 1), plat (7, 2), plat (7, 3), plat (7, 4), 3)
drawfillbox (plat (8, 1), plat (8, 2), plat (8, 3), plat (8, 4), 3)
drawfillbox (plat (9, 1), plat (9, 2), plat (9, 3), plat (9, 4), 3)
drawfillbox (plat (10, 1), plat (10, 2), plat (10, 3), plat (10, 4), 3)
drawfillbox (plat (11, 1), plat (11, 2), plat (11, 3), plat (11, 4), 3)
drawfillbox (plat (12, 1), plat (12, 2), plat (12, 3), plat (12, 4), 3)
drawfillbox (plat (13, 1), plat (13, 2), plat (13, 3), plat (13, 4), 3)
drawfillbox (plat (14, 1), plat (14, 2), plat (14, 3), plat (14, 4), 3)
drawfillbox (plat (15, 1), plat (15, 2), plat (15, 3), plat (15, 4), 3)
drawfillbox (plat (16, 1), plat (16, 2), plat (16, 3), plat (16, 4), 3)
drawfillbox (plat (17, 1), plat (17, 2), plat (17, 3), plat (17, 4), 3)
drawfillbox (plat (18, 1), plat (18, 2), plat (18, 3), plat (18, 4), 3)
drawfillbox (plat (19, 1), plat (19, 2), plat (19, 3), plat (19, 4), 3)
drawfillbox (plat (20, 1), plat (20, 2), plat (20, 3), plat (20, 4), 3)
drawfillbox (plat (21, 1), plat (21, 2), plat (21, 3), plat (21, 4), 3)
drawfillbox (plat (22, 1), plat (22, 2), plat (22, 3), plat (22, 4), 3)
drawfillbox (plat (23, 1), plat (23, 2), plat (23, 3), plat (23, 4), 3)
drawfillbox (plat (24, 1), plat (24, 2), plat (24, 3), plat (24, 4), 3)
drawfillbox (plat (25, 1), plat (25, 2), plat (25, 3), plat (25, 4), 3)
drawline (0, GROUND_HEIGHT, maxx, GROUND_HEIGHT, blue)
Sprite.SetPosition (stand, posx, posy, false)
% 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 whatdotcolor (posx, posy) = 3 then
vely := JUMP_SPEED
Sprite.Hide (stand)
end if
% subtract your "gravity" constant from the velocity EACH frame
vely -= GRAVITY
posx += round (velx)
posy += round (vely)
% simple "collision" check. just makes sure the player stays above ground
if posy <= GROUND_HEIGHT then
posy := GROUND_HEIGHT
vely := 0
end if
if posy >= plat (1, 2) and posy <= plat (1, 4) and posx > plat (1, 1) and posx < plat (1, 3) then
posy := plat (1, 4)
vely := 0
elsif posy >= plat (2, 2) and posy <= plat (2, 4) and posx > plat (2, 1) and posx < plat (2, 3) then
posy := plat (2, 4)
vely := 0
elsif posy >= plat (3, 2) and posy <= plat (3, 4) and posx > plat (3, 1) and posx < plat (3, 3) then
posy := plat (3, 4)
vely := 0
elsif posy >= plat (4, 2) and posy <= plat (4, 4) and posx > plat (4, 1) and posx < plat (4, 3) then
posy := plat (4, 4)
vely := 0
elsif posy >= plat (5, 2) and posy <= plat (5, 4) and posx > plat (5, 1) and posx < plat (5, 3) then
posy := plat (5, 4)
vely := 0
elsif posy >= plat (6, 2) and posy <= plat (6, 4) and posx > plat (6, 1) and posx < plat (6, 3) then
posy := plat (6, 4)
vely := 0
elsif posy >= plat (7, 2) and posy <= plat (7, 4) and posx > plat (7, 1) and posx < plat (7, 3) then
posy := plat (7, 4)
vely := 0
elsif posy >= plat (8, 2) and posy <= plat (8, 4) and posx > plat (8, 1) and posx < plat (8, 3) then
posy := plat (8, 4)
vely := 0
elsif posy >= plat (9, 2) and posy <= plat (9, 4) and posx > plat (9, 1) and posx < plat (9, 3) then
posy := plat (9, 4)
vely := 0
elsif posy >= plat (10, 2) and posy <= plat (10, 4) and posx > plat (10, 1) and posx < plat (10, 3) then
posy := plat (10, 4)
vely := 0
elsif posy >= plat (11, 2) and posy <= plat (11, 4) and posx > plat (11, 1) and posx < plat (11, 3) then
posy := plat (11, 4)
vely := 0
elsif posy >= plat (12, 2) and posy <= plat (12, 4) and posx > plat (12, 1) and posx < plat (12, 3) then
posy := plat (12, 4)
vely := 0
elsif posy >= plat (13, 2) and posy <= plat (13, 4) and posx > plat (13, 1) and posx < plat (13, 3) then
posy := plat (13, 4)
vely := 0
elsif posy >= plat (14, 2) and posy <= plat (14, 4) and posx > plat (14, 1) and posx < plat (14, 3) then
posy := plat (14, 4)
vely := 0
elsif posy >= plat (15, 2) and posy <= plat (15, 4) and posx > plat (15, 1) and posx < plat (15, 3) then
posy := plat (15, 4)
vely := 0
elsif posy >= plat (16, 2) and posy <= plat (16, 4) and posx > plat (16, 1) and posx < plat (16, 3) then
posy := plat (16, 4)
vely := 0
elsif posy >= plat (17, 2) and posy <= plat (17, 4) and posx > plat (17, 1) and posx < plat (17, 3) then
posy := plat (17, 4)
vely := 0
elsif posy >= plat (18, 2) and posy <= plat (18, 4) and posx > plat (18, 1) and posx < plat (18, 3) then
posy := plat (18, 4)
vely := 0
elsif posy >= plat (19, 2) and posy <= plat (19, 4) and posx > plat (19, 1) and posx < plat (19, 3) then
posy := plat (19, 4)
vely := 0
elsif posy >= plat (20, 2) and posy <= plat (20, 4) and posx > plat (20, 1) and posx < plat (20, 3) then
posy := plat (20, 4)
vely := 0
elsif posy >= plat (21, 2) and posy <= plat (21, 4) and posx > plat (21, 1) and posx < plat (21, 3) then
posy := plat (21, 4)
vely := 0
elsif posy >= plat (22, 2) and posy <= plat (22, 4) and posx > plat (22, 1) and posx < plat (22, 3) then
posy := plat (22, 4)
vely := 0
elsif posy >= plat (23, 2) and posy <= plat (23, 4) and posx > plat (23, 1) and posx < plat (23, 3) then
posy := plat (23, 4)
vely := 0
elsif posy >= plat (24, 2) and posy <= plat (24, 4) and posx > plat (24, 1) and posx < plat (24, 3) then
posy := plat (24, 4)
vely := 0
elsif posy >= plat (25, 2) and posy <= plat (25, 4) and posx > plat (25, 1) and posx < plat (25, 3) then
posy := plat (25, 4)
vely := 0
end if
put posy
put stepcounter
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
View.Update
delay (25)
cls
end loop
Window.Close (win) |