program platformer; var res: resource; {var exitCmd, clicked: command; } {new_gameM,continueM,optionsM,helpM,aboutM,exitM: integer;} exit, play, empty, clicked : command; button: array [1..15] of integer; map: array [0..11,0..9] of char; img: array [97..112] of image; zl:image; //зелен луч logo: image; logoX,logoY: integer; //scr:image; {anim: integer;} animT: array[0..7] of char; animX,animY,animOldX,animOldY,animXX,animYY,animSpeed: array[0..7] of integer; {animY: array[0..7] of integer;} {anim: array [0..9] of image;} {animAI:array[0..1,0..1] of integer;} animAI,animAIAI:array[0..3] of integer;//аним аи -содерж расст от х до аним Х, аиаи - для сравн большменьш h,w: integer; lastSavedTime,sleep:integer; {frame: real;} frame:integer; x,y,oldX,oldY,xx,yy,speed,score,life:integer; timer,timerMS:integer; level:integer; endgame:boolean; startgame:boolean; Sound:boolean; i,j,ii,jj:integer; {x1,y1,x2,y2: integer;} line: string; {sti:integer;} s: string; ch:char; {s1,s2:string;} a,b,c,d: integer; //first:boolean; //чтобы не двиг герой в нач игры {x2sqr, y2sqr, koren:real;//для вычисл столкновений start: boolean;} procedure otladka; begin {s:=s+'a'; drawtext(s,0,0); repaint; delay(1000);} end; procedure getStartParametres; begin w:=getwidth; h:=getheight; // серед для заставк speed:=2; for i:=0 to 7 do animSpeed[i]:=1; for i:=0 to 9 do begin map[0,i]:='a'; map[11,i]:='a'; end; for i:=0 to 11 do begin map[i,0]:='a'; map[i,9]:='a'; end; level:=1; life:=3; startgame:=false; endgame:=false; Sound:=false; //созд кнопк play := createCommand('Выбор', CM_SCREEN, 2); exit := createCommand('Bыход', CM_BACK, 1); {empty:= createCommand(' ', CM_SCREEN, 3); } end; procedure loadingPNG; begin {for ch:='a' to 'l' do begin line:='/'+ch+'.png'; img[ch]:=loadimage(line); end;} zl:=loadImage('/zl.png'); //intro for i:=97 to 112 do begin s:='/'+chr(i)+'.png'; img[i]:=loadImage(s); end; end; procedure getLogoX_LogoY; begin a:=w div 2; c:= getimagewidth(zl) div 2; logoX:=a-c; b:=h div 2; d:= getimageheight(zl) div 2; logoY:=b-d; end; procedure intro; begin // серед для заставк {a:=w div 2; c:= getimagewidth(zl) div 2; a:=a-c; b:=h div 2; d:= getimageheight(zl) div 2; b:=b-d;} {заставка} SetColor(255, 255, 255); FillRect(0, 0, w, h); drawimage(zl,logoX,logoY); zl:=img[105]; // освобожд память repaint; delay(3000); end; procedure mainMenu; begin {exitCmd := CreateCommand('Выход', CM_EXIT, 1); AddCommand(exitCmd); repeat clicked := GetClickedCommand; until clicked <> EmptyCommand; } showMenu('Главное меню', CH_IMPLICIT); {new_game,continue,options,help,about,exit } {new_gameM,continueM,optionsM,helpM,aboutM,exitM} {new_gameM := menuAppendString('Новая игра!'); continueM := menuAppendString('Продолжение'); optionsM := menuAppendString('Опции'); helpM := menuAppendString('Справка'); aboutM := menuAppendString('О программе'); exitM := menuAppendString('Выход');} button[1] := menuAppendString('Новая игра!'); button[2] := menuAppendString('Продолжение'); button[3] := menuAppendString('Сложность'); button[4] := menuAppendString('Звук'); button[5] := menuAppendString('Справка'); button[6] := menuAppendString('О программе'); button[7] := menuAppendString('Выход'); {play := createCommand('Выбор', CM_SCREEN, 2); } addCommand(play); {exit := createCommand('Bыход', CM_BACK, 2); } addCommand(exit); {empty:=createCommand('', CM_SCREEN, 1); } {addCommand(empty);} delay(300); repeat delay(100); clicked := getClickedCommand; if clicked=exit then halt; until clicked = play; end; procedure newGame; begin level:=1; startgame:=true; end; procedure selectLevel; begin {a:=menuAppendString('Первая часть!'); b:=menuAppendString('Вторая часть'); play := createCommand('Выбор', CM_SCREEN, 2); addCommand(play); empty:=createCommand('', CM_SCREEN, 1); addCommand(empty); repeat delay(100); clicked := getClickedCommand; until clicked = play; if menuGetSelectedIndex = a then level:=1; if menuGetSelectedIndex = b then level:=2; } showMenu('Выбор уровня', CH_IMPLICIT); button[8] := menuAppendString('Первая часть!'); button[9] := menuAppendString('Вторая часть'); button[10] := menuAppendString('Третья часть'); addCommand(play); addCommand(exit); delay(300); repeat delay(100); clicked := getClickedCommand; until (clicked = play) or (clicked =exit); if clicked = play then begin startgame:=true; if menuGetSelectedIndex = button[8] then level:=1; if menuGetSelectedIndex = button[9] then level:=2; if menuGetSelectedIndex = button[10] then level:=3; end; end; procedure setLife; begin showMenu('Сложность', CH_IMPLICIT); button[11] := menuAppendString('Легко'); button[12] := menuAppendString('Средне'); button[13] := menuAppendString('Сложно'); addCommand(play); addCommand(exit); delay(300); repeat delay(100); clicked := getClickedCommand; until (clicked = play) or (clicked =exit); if menuGetSelectedIndex = button[11] then life:=5; if menuGetSelectedIndex = button[12] then life:=3; if menuGetSelectedIndex = button[13] then life:=1; end; procedure setSound; begin showMenu('Звук', CH_IMPLICIT); button[14] := menuAppendString('Вкл'); button[15] := menuAppendString('Выкл'); addCommand(play); addCommand(exit); delay(300); repeat delay(100); clicked := getClickedCommand; until (clicked = play) or (clicked =exit); if menuGetSelectedIndex = button[14] then sound:=true; if menuGetSelectedIndex = button[15] then sound:=false; end; {procedure Options; begin showMenu('Настройки', CH_IMPLICIT); button[1] := menuAppendString('Звук'); button[2] := menuAppendString('Сложность'); addCommand(play); addCommand(exit); delay(300); repeat delay(100); clicked := getClickedCommand; until (clicked = play) or (clicked =exit); if clicked = play then begin if menuGetSelectedIndex = button[1] then begin showMenu('Звук', CH_IMPLICIT); button[1] := menuAppendString('Вкл'); button[2] := menuAppendString('Выкл'); addCommand(play); addCommand(exit); delay(300); repeat delay(100); clicked := getClickedCommand; until (clicked = play) or (clicked =exit); if menuGetSelectedIndex = button[1] then sound:=true; if menuGetSelectedIndex = button[2] then sound:=false; end; if menuGetSelectedIndex = button[2] then begin end; end; end;} procedure Help; begin {showMenu('Справка', CH_IMPLICIT); } ClearForm; SetFormTitle('Справка'); a:= formAddString('Вы играете Собирателем. Ваша задача собрать все монеты. Если вас съедает монстр -- вы погибаете. Управление: вверх - 2, вправо – 6, вниз - 8, влево - 4.'); {if i=1 then i := formAddString('Hello world '); if i=2 then i := formAddString('Enter your '); } {FormSetText(1,'AAAAAAAA'); FormSetText(2,'ЧЧЧЧЧЧ'); } {FormSetText(1,'SSS'); FormSetText(2,'DDDD'); } showForm; addCommand(exit); delay(300); repeat delay(100); clicked := getClickedCommand; until clicked =exit; end; procedure About; begin ClearForm; SetFormTitle('О программе'); a:= formAddString('Собиратель 1.0, (с) фирма: Зеленый луч, 2007 год, Все права защищены, автор: Ильин Григорий.'); showForm; addCommand(exit); delay(300); repeat delay(100); clicked := getClickedCommand; until clicked =exit; end; procedure loadingMap; begin s:='/'+IntegerToString(level)+'m'+'.txt'; {res := OpenResource('/111.txt');} res := OpenResource(s); for i:=0 to 9 do begin line:=ReadLine(res); for j:=0 to 7 do begin {map[i,j]:=getchar(line,j);} map[i+1,j+1]:=getchar(line,j); end; end; CloseResource(res); end; procedure loadingAnim; begin s:='/'+IntegerToString(level)+'a'+'.txt'; {res := OpenResource('/111anim.txt');} res := OpenResource(s); for i:=0 to 7 do begin line := ReadLine(res); {if line='0_000_000' then break;} animT[i]:=getchar(line,0); s:=copy(line,2,5); animX[i]:=StringToInteger(s); s:=copy(line,6,9); animY[i]:=StringToInteger(s); {i:=i+1;} end; {anim:=i-1;} CloseResource(res); {s:='aaaa';} end; procedure getX_Y_Timer; begin if level=1 then begin x:=16; y:=16; timer:=99; end; if level=2 then begin x:=0; y:=0; timer:=30; end; if level=3 then begin x:=0; y:=80; timer:=80; end; end; procedure showStartForm; begin ClearForm; SetFormTitle('Игра'); {s:= 'Часть:' +IntegerToString(level)'; a:= formAddString(s); s:='Жизней:' +IntegerToString(life)'; b:= formAddString(s); s:='Очков:' +IntegerToString(score)'; с:= formAddString(s); } s:='Приготовьтесь!'; d:= formAddString(s); {a:= formAddString('Часть: ' +IntegerToString(level)'); b:= formAddString('Жизней: ' +IntegerToString(life)'); с:= formAddString('Очков: ' +IntegerToString(score)'); d:= formAddString('Приготовьтесь!'); } showForm; {addCommand(exit); } {delay(1000); repeat a:=GetKeyClicked; delay(100); until a=KE_KEY5; } end; procedure drawingFon; begin setcolor(255,255,255); fillrect(0,h-15,w,h); setcolor(0,255,0); fillrect(0,0,w,h-16); end; procedure drawingMap; begin for i:=0 to 9 do begin for j:=0 to 7 do begin a:=Ord(map[i+1,j+1]); {if (Ord(map[i,j])>96) and (Ord(map[i,j])<107) then} if (a>96) and (a<107) then drawimage(img[a],j*16,i*16); {begin drawimage(img[map[i,j]],j*16,i*16); end;} end; end; end; procedure getOld; begin oldX:=x; oldY:=y; for i:=0 to 7 do begin if animT[i]<>'0' then begin animOldX[i]:=animX[i]; animOldY[i]:=animY[i]; end; end; end; procedure getMove; begin xx:=0; yy:=0; a:=0; a:=GetKeyPressed; if a=KE_KEY2 then yy:=-1; {if a=KE_KEY3 then begin xx:=1; yy:=-1; end; } if a=KE_KEY6 then xx:=1; {if a=KE_KEY9 then begin xx:=1; yy:=1; end; } if a=KE_KEY8 then yy:=1; {if a=KE_KEY7 then begin xx:=-1; yy:=1; end; } if a=KE_KEY4 then xx:=-1; {if a=KE_KEY1 then begin xx:=-1; yy:=-1; end; } end; procedure getHitStatic; begin a:=y div 16+yy+1; b:=x div 16+xx+1; if map[a,b]<>'0' then begin xx:=0; yy:=0; end; end; procedure movingHero; begin x:=x+xx*speed; y:=y+yy*speed; end; procedure monsterAI; begin a:=animY[i] div 16+1; b:=animX[i] div 16+1; {c:=abs(animY[i]-y); d:=abs(animX[i]-x); c:=abs(c+random(c div 2)-c div 4); d:=abs(d+random(d div 2)-d div 4);} {if (map[a+animYY[i],b+animXX[i]]<>'0') or ((animYY[i]=0) and (animXX[i]=0)) then begin} {animAI[0]:=abs(animX[i]+16-x); animAI[1]:=abs(animX[i]-16-x); animAI[2]:=abs(animY[i]+16-y); animAI[3]:=abs(animY[i]-16-y);} if animT[i]='m' then c:=1 else c:=-1; if map[a,b+1]='0' then animAI[0]:=abs(animX[i]+16-x*c+Random(80)-40) else animAI[0]:=1000; //вправо if map[a,b-1]='0' then animAI[1]:=abs(animX[i]-16-x*c+Random(80)-40) else animAI[1]:=1000; //влево if map[a+1,b]='0' then animAI[2]:=abs(animY[i]+16-y*c+Random(80)-40) else animAI[2]:=1000; //вниз if map[a-1,b]='0' then animAI[3]:=abs(animY[i]-16-y*c+Random(80)-40) else animAI[3]:=1000; //вверх {for j:=0 to 3 do s:=s+' '+IntegerToString(animAI[j]); setcolor(255,255,255); fillrect(0,h-16,w,h); setcolor(0,0,0); drawtext(s,0,h-15); s:=''; repaint; delay(5000);} {if map[a,b+1]='0' then animAI[0]:=d+16 else animAI[0]:=1000; //вправо if map[a,b-1]='0' then animAI[1]:=d-16 else animAI[1]:=1000; //влево if map[a+1,b]='0' then animAI[2]:=c+16 else animAI[2]:=1000; //вниз if map[a-1,b]='0' then animAI[3]:=c-16 else animAI[3]:=1000; //вверх} if (animAI[0]'0' then begin fillrect(animOldX[i],animOldY[i],16,16); end; end; fillrect(oldX,oldY,16,16); //нижнюю часть экр очистить setcolor(255,255,255); fillrect(0,h-16,w,h) { } end; procedure drawingAnim; begin {frame:=frame+0.25;} if frame<5 then frame:=frame+1 else frame:=0; for i:=0 to 7 do begin if animT[i]<>'0' then begin a:=Ord(animT[i])+frame div 3; drawimage(img[a],animX[i],animY[i]); end; end; a:=107+frame div 3; drawimage(img[a],x,y); end; procedure drawingText; begin setcolor(0,0,0); s:='Ж: '+IntegerToString(life)+', '+'Ч: '+IntegerToString(level)+', '+'О: '+IntegerToString(score)+', '+'В: '+IntegerToString(timer); drawtext(s,0,h-15); end; {procedure moveCanvas; begin scr:=ImageFromCanvas(0,0,w,h); DrawImage(scr,0,0); end;} procedure getSleepAndTimer; begin sleep:=50-(GetRelativeTimeMs-lastSavedTime); if sleep>0 then delay(sleep); timerMS:=timerMS+1; if timerMS=19 then begin timerMS:=0; timer:=timer-1; end; {setcolor(255,255,255); fillrect(0,h-16,w,h); setcolor(0,0,0); s:=IntegerToString(sleep); drawtext(s,0,h-15); s:='';} {repaint; delay(5000);} end; procedure money; begin a:=0; score:=score+1; animT[i]:='0'; //проверяем последняя ли монета for j:=0 to 7 do begin if animT[j]='o' then a:=1; end; if a=0 then begin endgame:=true; level:=level+1; end; end; procedure gameover; begin endgame:=true; life:=life-1; {if life=-1 then level:=1;} end; procedure erasingParametres; begin {for i:=0 to 9 do begin for j:=0 to 11 do map[i,j]:=0; end; } endgame:=false; //чтобы дей осн цикл timerMS:=0; {xx:=0; yy:=0;} end; procedure the_end; begin ClearForm; SetFormTitle('Конец'); s:=s+'Вы набрали '+IntegerToString(score)+' очков.'; d:= formAddString(s); //score:=0; delay(4000); end; {procedure win; begin end;} begin repeat {setcolor(0,255,0); for s1:='a' to 'z' do begin j:=ord(s1); s:=IntegerToString(j); drawtext(s,0,0); repaint; delay(1000); end; } otladka; Randomize; otladka; {setcolor(0,255,0);} otladka; getStartParametres; //загрузка otladka; loadingPNG; getLogoX_LogoY; otladka; intro; repeat mainMenu; //результат вывбора в главном меню {if menuGetSelectedIndex = new_gameM then level:=1; if menuGetSelectedIndex = continueM then selectGame; } if menuGetSelectedIndex = button[1] then newGame; if menuGetSelectedIndex = button[2] then selectLevel; if menuGetSelectedIndex = button[3] then setLife; if menuGetSelectedIndex = button[4] then setSound; if menuGetSelectedIndex = button[5] then Help; if menuGetSelectedIndex = button[6] then About; if menuGetSelectedIndex = button[7] then halt; until startgame=true; otladka; {showCanvas; // show canvas and remove menu from the screen } repeat {res := OpenResource('/111.txt');} loadingMap; otladka; loadingAnim; getX_Y_Timer; {CloseResource(res);} otladka; showStartForm; showCanvas; // show canvas and remove menu from the screen otladka; drawingFon; otladka; drawingMap; otladka; //first:=true; repaint; //главный цикл {setcolor(255,255,255); {fillrect(0,h-16,w,h); setcolor(0,0,0); s:=IntegerToString(i); drawtext(s,0,h-15); repaint; delay(2000);} repeat lastSavedTime := GetRelativeTimeMs; getOld; {if first=true then speed:=0 else speed:=2; first:=false;} {begin} if (x mod 16=0) and (y mod 16=0) then begin getMove; getHitStatic; end; {else first:=false; end;} movingHero; for i:=0 to 7 do begin {if Ord(animT[i])>0 then } if animT[i]<>'0' then begin if (animX[i] mod 16=0) and (animY[i] mod 16=0) then monsterAI; movingAnim; end; end; // столкновения getHeroCenter; clearing; for i:=0 to 7 do begin if animT[i]<>'0' then begin c:=animY[i]+8; d:=animX[i]+8; if (abs(a-c)<8) and (abs(b-d)<8) then // a центр по y b центр по x см getHeroCenter; begin if animT[i]='m' then gameover;// отнять жизнь конец игры if animT[i]='o' then money; //прибавить очки и проверить последняя ли монета? end; end; end; if timer=0 then gameover;// отнять жизнь конец игры если законч врем drawingAnim; drawingText; {moveCanvas;} repaint; {start:=false;} getSleepAndTimer; {delay(50);} until endgame=true; repeat a:=GetKeyClicked; delay(100); until a=KE_KEY5; {if life>-1 then showStartForm else gameoverFull;} //showGameover; erasingParametres; {Halt;} until (life<0) or (level>3); // до полной победы или оконч проигр {if life<0 then gameoverFull; if level>2 then win;} if life<0 then s:='Вы проиграли. '; if level>3 then s:='Вы победили! '; the_end; until d=-1000;//просто для цикла знач end.