Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Pascal - Movimenti multipli.
Forum - Pascal - Movimenti multipli.

Avatar
gllobal (Normal User)
Rookie


Messaggi: 41
Iscritto: 02/04/2012

Segnala al moderatore
Postato alle 16:46
Venerdì, 01/06/2012
Ciao a tutti, pochi giorni fa ho scaricato pacman da pierotofy e mi è piaciuto moltissimo è stupendo!!!  Io all'inizio dell'anno a scuola ne ho fatto uno ma non è venuto bene quanto questo poichè per far muovere i nemici ho fatto in questo modo:
Repeat
Repeat
{movimento nemici}
until(keypressed);
c:=readkey;
case c of

{movimento del personaggio, destra, sinistra, giù, su.}

end;
until(c='e');

I nemici si muovono però se io mi muovo in continuazione loro aumentanola velocità, come bisogna fare per avere una cosa ben fatta come il pacman di pierotofy???
poi volevo chiedere un'altra cosa per la grafica usando la unit garph, siccome ho fatto una cornice al menu rettangolare il cui interno viene colorato di blu, quando parte il prog. il riquadro si colora non velocemente ma come se stesse invadendo la cornice.
Come faccio a far si che la cornice si colori di scatto?
ciao e grazie a tutti quelli che risponderanno ;).


Program Test;
Uses CRT,Graph;
Var
T:Text;
S1,S2:String;
S:String[20];
Cont,Scheda,Mode,x,op:Integer;
OK:Boolean;
{-------------------------------READLN--PER--GRAPH---------------------------}
Procedure ReadGraph(x,y:Integer; S:String);
Var
c:Char;
Begin
  Repeat
   c:=Readkey;
    If(c<>chr(13))Then
   S:=S+c;
   OutTextXY(x,y,S);
  Until(c=chr(13));
End;
{------------------------------------OPEN--FILE------------------------------}
Procedure Open;
Var
S:String; x:Integer;
Begin
Reset(T);
x:=150;
  While Not EOF(T) DO
   Begin
    Readln(T,S);
    x:=x+15;
    OutTextXY(350,x,S);
   End;
Close(T);
End;
{-----------------------------CONTATORE--DI--CARATTERI-----------------------}
Procedure ContChar(Var Cont:Integer);
Var
c:Char;
Begin
Cont:=0;
Reset(T);
  While Not EOF(T) DO
   Begin
    Read(T,c);
     If(c<>chr(13))AND(c<>chr(10))Then
       INC(Cont);
   End;
Close(T);
End;
{----------------------------CONTATORE--DI--PAROLE---------------------------}
Procedure ContWord(Var Cont:Integer);
Var
SEP:Set OF Char; S:String; I:Integer;
Begin
Cont:=0;
SEP:=[' ','.',';',',',':','?','!','"'];
Reset(T);
  While Not EOF(T) DO
   Begin
    Readln(T,S);
    S:=S+' ';
     For I:=1 to Length(S) DO
      Begin
       If(S[I] in SEP)Then
        If(I<>1)AND Not(S[I-1] in SEP)Then
         INC(Cont);
      End;
   End;
Close(T);
End;
{-----------------------------SOSTITUZIONE--PAROLA---------------------------}
Procedure ClrIns(S1:String; S2:String; Var OK:Boolean);
Var
S,S3:String; SEP:Set OF Char; I,J,m,x:Integer;  V:array[1..100]of string;
Begin
ClrScr;
OK:=false;
SEP:=[' ','.',';',',',':','?','!','"'];
I:=0;
Reset(T);
  While Not EOF(T) DO
   Begin
    Inc(I);
    Readln(T,V[I]);
   End;
  For J:=1 to I DO
   Begin
    S:='';
    S:=V[J]+' ';
     Repeat
      x:=0;
      x:=Pos(S1,S);
       If(x<>0)Then
        Begin
         If(S[x-1] in SEP)AND(S[x+Length(S1)] in SEP)Then
          Begin
           S3:='';
            For m:=1 to x-1 do
             Begin
              S3:=S3+S[m];
             End;
           S3:=S3+S2;
            For m:=x+length(S1) to length(S) do
             S3:=S3+S[m];
           V[J]:='';
           V[J]:=S3;
           S:='';
           S:=S3;
           OK:=true;
          End;
        End;
     Until(x=0);
   End;
Rewrite(T);
  For m:=1 to I do
   Writeln(T,V[m]);
Close(T);
End;
{--------------------------------------ICONE---------------------------------}
Procedure Dis(Ind:Integer; x:Boolean);
Const
Polligono:array[1..6] of PointType = ((X:530; Y:60),(X:600; Y:60),(X:555; Y:90),
             (X:555; Y:160),(X:530; Y:160),(X:530; Y:60));

Porta:array[1..7] of PointType = ((X:520; Y:60),(X:600; Y:60),(X:600; Y:90),
             (X:630; Y:90),(X:630; Y:195),(X:520; Y:195),(X:520; Y:60));

Freccia:Array[1..8] of PointType = ((X:490; Y:120),(X:510; Y:120),(X:510; Y:110),
             (X:519; Y:125),(X:510; Y:140),(X:510; Y:130),(X:490; Y:130),(X:490; Y:120));
Var
I:Integer; S:String;
Begin
  If(x=true)Then
   Begin
    S:=chr(219)+chr(219)+chr(219)+chr(219)+chr(219)+chr(219);
     Case Ind OF
      50:Begin
          I:=50;
          SetColor(7);
           Repeat
            OutTextXY(490,I,S);
            I:=I+20;
           Until(I=210);
          SetColor(16);
          SetFillStyle(1,15);
          FillPoly(7,Porta);
          Line(600,60,630,90);
          SetFillStyle(2,2);
          Bar(525,65,580,95);
          Line(535,95,545,75);
          Line(545,75,555,95);
          Circle(560,75,5);
          I:=105;
           Repeat
            Line(525,I,625,I);
            I:=I+10;
           Until(I=195);
         End;
      90:Begin
          I:=50;
          SetColor(7);
           Repeat
            OutTextXY(490,I,S);
            I:=I+20;
           Until(I=210);
          SetColor(16);
          Line(510,170,510,73);
          SetFillStyle(9,1);
          Bar(515,120,525,160);
          Bar(530,100,540,160);
          Bar(545,85,555,160);
          Bar(560,110,570,160);
          Bar(575,140,585,160);
          Bar(590,135,600,160);
          Line(500,160,610,160);
          Line(507,73,513,73);
          Line(507,73,510,70);
          Line(513,73,510,70);
          Line(610,157,610,163);
          Line(610,157,613,160);
          Line(610,163,613,160);
          Rectangle(578,73,609,90);
          SetFillStyle(1,1);
          Bar(580,75,583,78);
          Line(585,77,595,77);
          SetFillStyle(1,4);
          Line(585,82,599,82);
          Bar(580,80,583,83);
          SetFillStyle(1,16);
          Bar(580,85,583,88);
          Line(585,87,592,87);
         End;
     130:Begin
          I:=50;
          SetColor(7);
           Repeat
            OutTextXY(490,I,S);
            I:=I+20;
           Until(I=210);
          SetColor(2);
          Arc(540,110,90,270,50);
          Arc(540,120,90,270,30);
          Arc(560,150,270,360,50);
          Arc(560,150,0,90,50);
          Arc(560,140,270,360,30);
          Arc(560,140,0,90,30);
          Line(540,160,540,170);
          Line(540,150,540,140);
          Line(540,140,560,156);
          Line(540,170,560,156);
          Line(540,90,540,60);
          Line(560,100,560,90);
          Line(560,110,560,120);
          Line(560,120,540,106);
          Line(560,90,540,106);
          Line(560,170,560,200);
          SetColor(1);
         End;
     170:Begin
          I:=50;
          SetColor(7);
           Repeat
            OutTextXY(490,I,S);
            I:=I+20;
           Until(I=210);
          SetColor(16);
          SetFillStyle(1,8);
          FillPoly(6,Polligono);
          Line(555,160,555,190);
          Line(600,60,600,160);
          Line(600,160,555,190);
          Circle(562,132,2);
          SetFillStyle(9,16);
          FillPoly(8,Freccia);
         End;
     End;
   End;
End;
{----------------------------------STAMPA--FOGLIO----------------------------}
Procedure Foglio;
Var
y,x,c:Integer;
Begin
SetColor(18);
y:=GetMaxY-150;
x:=GetMaxX-400;
Arc(250,150,0,180,70);
Line(320,150,320,y);
Arc(250,y,180,360,70);
Arc(x-70,150,0,90,70);
Line(x,150,x,y);
Arc(x-70,y,270,360,70);
Line(250,80,x-70,80);
Line(250,y+70,x-70,y+70);
Line(180,150,320,150);
Line(180,y,320,y);
SetFillStyle(9,8);
FloodFill(190,140,18);
FloodFill(190,y+2,18);
c:=159;
  Repeat
   c:=c+15;
   Line(345,c,x-20,c);
  Until(c>y-30);
OutTextXY(x div 2,y+10,'Press Enter');
End;
{-----------------------------GESTIONE--CURSORE--MENU------------------------}
Function Curs(Inf,Sup,X:integer; OK:boolean):integer;
Var
op:char; I,Y:Integer;
Begin
Y:=Inf;
  Repeat
   op:=readkey;
    Case op OF
     chr(72):Begin
              SetColor(7);
              OutTextXY(X,Y,'');
              SetColor(16);
               If(Y<>Inf)then
                Y:=Y-40 ;
              OutTextXY(X,Y,'');
             End;
     chr(80):Begin
              SetColor(7);
              OutTextXY(X,Y,'');
              SetColor(16);
               if (Y<>Sup)then
                Y:=Y+40;
              OutTextXY(X,Y,'');
             end;
     chr(75):Begin
              Y:=1;
              op:=chr(13);
             End;
    End;
   Dis(Y,OK);
  Until(op=chr(13));
Curs:=Y;
End;
{-----------------------------STAMPA--CORNICE--MENU--------------------------}
Procedure Riq;
Begin
Line(70,30,617,30);
Line(65,25,622,25);
Line(70,220,617,220);
Line(65,225,622,225);
Line(30,70,30,180);
Line(25,65,25,185);
Line(657,70,657,180);
Line(662,65,662,185);
Arc(70,70,90,180,40);
Arc(65,65,90,180,40);
Arc(617,70,0,90,40);
Arc(622,65,0,90,40);
Arc(70,180,180,270,40);
Arc(65,185,180,270,40);
Arc(617,180,270,360,40);
Arc(622,185,270,360,40);
End;
{----------------------------------MAIN--PROGRAM-----------------------------}
Begin
Assign(T,'Testo.txt');
Readln;
Scheda:=Detect;
InitGraph(Scheda,Mode,'C:\FPC\2.4.4\units\i386-win32\rtl');
SetBkColor(7);
ClearDevice;
SetTextStyle(2,0,3);
  Repeat
   Dis(50,true);
   SetColor(16);
   Riq;
   OutTextXY(290,50,'');
   OutTextXY(50,50,'Open File');
   OutTextXY(50,90,'Statistic');
   OutTextXY(50,130,'Change  ');
   OutTextXY(50,170,'Exit    ');
   SetFillStyle(1,1);
   FloodFill(80,27,16);
   op:=Curs(50,170,290,true);
    Case op of
      50:Begin
          SetColor(4);
          OutTextXY(50,50,'Open File');
          Delay(150);
          ClearDevice;
          Foglio;
          SetColor(16);
          SetTextStyle(0,0,1);
          Open;
          Readln;
          SetTextStyle(0,0,3);
          ClearDevice;
         End;
      90:Begin
          SetColor(4);
          OutTextXY(50,90,'Statistic');
          Delay(150);
          SetColor(16);
          OutTextXY(470,90,'');
          OutTextXY(350,90,'Char');
          OutTextXY(350,130,'Word');
          op:=Curs(90,130,470,False);
           Case op of
             90:Begin
                 SetColor(4);
                 OutTextXY(350,90,'Char');
                 SetColor(16);
                 Delay(150);
                 ContChar(Cont);
                 S:='';
                 Str(Cont,S);
                 OutTextXY(80,260,'Number of char: ');
                 OutTextXY(500,260,S);
                End;
            130:Begin
                 SetColor(4);
                 OutTextXY(350,130,'Word');
                 SetColor(16);
                 Delay(150);
                 ContWord(Cont);
                 S:='';
                 Str(Cont,S);
                 OutTextXY(100,260,'Number of word: ');
                 OutTextXY(500,260,S);
                End;
           End;
          SetFillStyle(1,1);
           If(op<>1)then
            Begin
             Line(70,240,617,240);
             Line(65,235,622,235);
             Line(70,300,617,300);
             Line(65,305,622,305);
             Line(35,265,35,275);
             Line(652,265,652,275);
             Arc(70,270,90,180,30);
             Arc(65,265,90,180,30);
             Arc(617,270,0,90,30);
             Arc(622,265,0,90,30);
             Arc(70,270,180,270,30);
             Arc(65,275,180,270,30);
             Arc(617,270,270,360,30);
             Arc(622,275,270,360,30);
             FloodFill(37,275,16);
             Readln;
            End;
          ClearDevice;
         End;
     130:Begin
          SetColor(4);
          OutTextXY(50,130,'Change');
          Delay(150);
          SetColor(16);
          SetFillStyle(1,1);
          x:=0;
           Repeat
            Line(70,240+x,617,240+x);
            Line(65,235+x,622,235+x);
            Line(70,300+x,617,300+x);
            Line(65,305+x,622,305+x);
            Line(35,265+x,35,275+x);
            Line(652,265+x,652,275+x);
            Arc(70,270+x,90,180,30);
            Arc(65,265+x,90,180,30);
            Arc(617,270+x,0,90,30);
            Arc(622,265+x,0,90,30);
            Arc(70,270+x,180,270,30);
            Arc(65,275+x,180,270,30);
            Arc(617,270+x,270,360,30);
            Arc(622,275+x,270,360,30);
            FloodFill(37,275+x,16);
            x:=x+80;
           Until(x=240);
          S:='';
          S:=chr(219)+chr(219)+chr(219)+chr(219)+chr(219)+chr(219)+chr(219)+chr(219)+chr(219)+chr(219);
          OutTextXY(80,260,'Old Word: ');
          OutTextXY(80,340,'New Word: ');
          ReadGraph(310,260,S1);
          SetColor(2);
          OutTextXY(595,260,'ok');
          SetColor(16);
          ReadGraph(310,340,S2);
          SetColor(2);
          OutTextXY(595,340,'ok');
          SetColor(16);
          OutTextXY(220,420,'Waiting...');
          ClrIns(S1,S2,ok);
          SetColor(7);
          OutTextXY(220,420,S);
          SetColor(16);
           If(ok<>True)Then
            OutTextXY(130,420,'Exchange not only')
           Else
            OutTextXY(80,420,'Exchanged with success');
          Readln;
          ClearDevice;
         End;
     170:Begin
          SetColor(4);
          OutTextXY(50,170,'Exit');
          Delay(150);
          op:=5;
         End;
    End;
  Until(op=5);
CloseGraph;
End.

Ultima modifica effettuata da gllobal il 01/06/2012 alle 16:51
PM Quote
Avatar
()
Newbie


Messaggi:
Iscritto:

Segnala al moderatore
Postato alle 10:35
Lunedì, 30/07/2012
Il movimento dovrebbe essere indipendente dalla pressione del tasto quindi bisogna usare una funzione che restituisce il tasto premuto senza bloccare il programma (o 0 se non è premuto nessun tasto) e creare un ciclo nel quale si valuta il tempo:

Codice sorgente - presumibilmente Delphi

  1. uses DateUtils;
  2.  
  3. // [...]
  4. var a: TDateTime;
  5. begin
  6.   a := Now;
  7.   repeat
  8.     // Controllo movimento che non blocca il programma
  9.     // Controllo tempo trascorso
  10.     if(MilliSecondSpan(a; Now) > 1000/60)then // Muovi 60 volte al secondo (60 frames per secondo, cambia questo numero per rallentare il movimento)
  11.     begin
  12.       // Movimento Nemici
  13.       a := Now;
  14.     end;
  15.   until running;
  16. // [...]


PM Quote