Forum > Graphics

ZenGL : Collisioni.

(1/2) > >>

Stilgar:
Non mi parte il debugger ... porca paletta :(
Allora il codice incriminato nella finzione "Timer" è questo :

--- Codice: ---

    c1.Y:=tux[20].Pos.Y;
    c1.X:=tux[20].Pos.X;
    c1.W:=64;
    c1.H:=64;
    for i := 0 to 19 do
      begin
        c2.Y:=tux[i].Pos.Y;
        c2.X:=tux[i].Pos.X;
        c2.W:=64;
        c2.H:=64;
        if (col2d_RectInRect(C1,C2)) then
          tux[i].Killed:= true;
      end;
   end;       

--- Termina codice ---
il record l'ho modificato in questo modo :

--- Codice: ---
  TTux = record
    Texture : zglPTexture;
    Frame   : Integer;
    Pos     : zglTPoint2D;
    DeltaX  : single;
    DeltaY  : single;
    Killed  : Boolean;
end;   

--- Termina codice ---


Nella funzione di paint non vengono visualizzati i tux killed ...

--- Codice: ---
            if not tux[ i ].Killed then
            asprite2d_Draw( tux[ i ].Texture, tux[ i ].Pos.X, tux[ i ].Pos.Y, 64, 64, 0, tux[ i ].Frame div 2, 255, FX_BLEND or FX_COLOR );

--- Termina codice ---

Funzione Timer completa :

--- Codice: ---

  procedure Timer;
    var
      i : Integer;
      c1, c2:zglTRect;
  begin
    INC( time, 2 );
    for i := 0 to 20 do
      begin
        INC( tux[ i ].Frame );
        if tux[ i ].Frame > 20 Then
          tux[ i ].Frame := 2;
      end;
    for i := 0 to 9 do
      begin
        tux[ i ].Pos.X := tux[ i ].Pos.X + 1.5;
        if tux[ i ].Pos.X > 864 Then
          tux[ i ].Pos.X := -96;
      end;
    for i := 10 to 19 do
      begin
        tux[ i ].Pos.X := tux[ i ].Pos.X - 1.5;
        if tux[ i ].Pos.X < -96 Then
          tux[ i ].Pos.X := 864;
      end;
    if key_Press( K_ESCAPE ) Then zgl_Exit();
    if key_Down( K_UP ) Then
       tux[ 20 ].Pos.Y := tux[ 20 ].Pos.Y - tux[ 20 ].DeltaY;
    if key_Down( K_DOWN ) Then
       tux[ 20 ].Pos.Y := tux[ 20 ].Pos.Y + tux[ 20 ].DeltaY;
    if key_Down( K_LEFT ) Then
       tux[ 20 ].Pos.X := tux[ 20 ].Pos.X - tux[ 20 ].DeltaX;
    if key_Down( K_RIGHT ) Then
       tux[ 20 ].Pos.X := tux[ 20 ].Pos.X + tux[ 20 ].DeltaX;


    // nomorelogic: joypad movimento "analogico"
    tux[ 20 ].Pos.X := tux[ 20 ].Pos.X + (tux[ 20 ].DeltaX * joy_AxisPos( 0, JOY_AXIS_X ));
    tux[ 20 ].Pos.Y := tux[ 20 ].Pos.Y + (tux[ 20 ].DeltaY * joy_AxisPos( 0, JOY_AXIS_Y ));

    // nomorelogic: joypad movimento "digitale"
    tux[ 20 ].Pos.X := tux[ 20 ].Pos.X + (tux[ 20 ].DeltaX * joy_AxisPos( 0, JOY_POVX ));
    tux[ 20 ].Pos.Y := tux[ 20 ].Pos.Y + (tux[ 20 ].DeltaY * joy_AxisPos( 0, JOY_POVY ));

    key_ClearState();
    joy_ClearState();

    c1.Y:=tux[20].Pos.Y;
    c1.X:=tux[20].Pos.X;
    c1.W:=64;
    c1.H:=64;
    for i := 0 to 19 do
      begin
        c2.Y:=tux[i].Pos.Y;
        c2.X:=tux[i].Pos.X;
        c2.W:=64;
        c2.H:=64;
        if (col2d_RectInRect(C1,C2)) then
          tux[i].Killed:= true;
      end;
   end;

--- Termina codice ---

(Non sembra rilevare le collisioni delle aree)


nomorelogic:
col2d_RectInRect... 'ndo' sta? ;)

nomorelogic:
il test per il disegno va nei 2 cicli (e nei 2 cicli ci sono delle eccezioni):

tieni conto che tux[ 20 ] è lo sprite che governiamo noi


--- Codice: ---
      for i := 0 to 9 do
        if i = 2 Then
          begin
            // EN: Render the text in frame over penguins.
            t := text_GetWidth( fntMain, 'I''m so red...' ) * 0.75 + 4;
            pr2d_Rect( tux[ i ].Pos.X - 2, tux[ i ].Pos.Y - fntMain.MaxHeight + 4, t, fntMain.MaxHeight, $000000, 200, PR2D_FILL );
            pr2d_Rect( tux[ i ].Pos.X - 2, tux[ i ].Pos.Y - fntMain.MaxHeight + 4, t, fntMain.MaxHeight, $FFFFFF );
            text_DrawEx( fntMain, tux[ i ].Pos.X, tux[ i ].Pos.Y - fntMain.MaxHeight + 8, 0.75, 0, 'I''m so red...' );
            // EN: Render red penguin using fx2d-function and flag FX_COLOR.
            fx2d_SetColor( $FF0000 );
            if not tux[ i ].Killed then
               asprite2d_Draw( tux[ i ].Texture, tux[ i ].Pos.X, tux[ i ].Pos.Y, 64, 64, 0, tux[ i ].Frame div 2, 255, FX_BLEND or FX_COLOR );
          end else
            if i = 7 Then
              begin
                t := text_GetWidth( fntMain, '???' ) * 0.75 + 4;
                pr2d_Rect( tux[ i ].Pos.X + 32 - t / 2, tux[ i ].Pos.Y - fntMain.MaxHeight + 4, t, fntMain.MaxHeight, $000000, 200, PR2D_FILL );
                pr2d_Rect( tux[ i ].Pos.X + 32 - t / 2, tux[ i ].Pos.Y - fntMain.MaxHeight + 4, t, fntMain.MaxHeight, $FFFFFF );
                text_DrawEx( fntMain, tux[ i ].Pos.X + 32, tux[ i ].Pos.Y - fntMain.MaxHeight + 8, 0.75, 0, '???', 255, $FFFFFF, TEXT_HALIGN_CENTER );
                // EN: Render penguin ghost using flag FX_COLOR and mode FX_COLOR_SET :)
                fx_SetColorMode( FX_COLOR_SET );
                fx2d_SetColor( $FFFFFF );
                if not tux[ i ].Killed then
                   asprite2d_Draw( tux[ i ].Texture, tux[ i ].Pos.X, tux[ i ].Pos.Y, 64, 64, 0, tux[ i ].Frame div 2, 155, FX_BLEND or FX_COLOR );
                // EN: Return default mode.
                fx_SetColorMode( FX_COLOR_MIX );
              end else
                 if not tux[ i ].Killed then
                   asprite2d_Draw( tux[ i ].Texture, tux[ i ].Pos.X, tux[ i ].Pos.Y, 64, 64, 0, tux[ i ].Frame div 2 );

      // EN: Render penguins, that go another way using special flag for flipping texture - FX2D_FLIPX.
      for i := 10 to 19 do
        if i = 13 Then
          begin
            t := text_GetWidth( fntMain, 'I''m so big...' ) * 0.75 + 4;
            pr2d_Rect( tux[ i ].Pos.X - 2, tux[ i ].Pos.Y - fntMain.MaxHeight - 10, t, fntMain.MaxHeight, $000000, 200, PR2D_FILL );
            pr2d_Rect( tux[ i ].Pos.X - 2, tux[ i ].Pos.Y - fntMain.MaxHeight - 10, t, fntMain.MaxHeight, $FFFFFF );
            text_DrawEx( fntMain, tux[ i ].Pos.X, tux[ i ].Pos.Y - fntMain.MaxHeight - 4, 0.75, 0, 'I''m so big...' );
            // EN: Render "big" penguin. It must be shifted up, because FX2D_SCALE scale sprite relative to the center.
            fx2d_SetScale( 1.25, 1.25 );
            if not tux[ i ].Killed then
               asprite2d_Draw( tux[ i ].Texture, tux[ i ].Pos.X, tux[ i ].Pos.Y - 8, 64, 64, 0, tux[ i ].Frame div 2, 255, FX_BLEND or FX2D_FLIPX or FX2D_SCALE );
          end else
            if i = 17 Then
              begin
                // EN: Render "tall" penguin using flag FX2D_VCHANGE instead of FX2D_SCALE, and function fx2d_SetVertexes for
                // shifting upper vertexes of sprite.
                fx2d_SetVertexes( 0, -16, 0, -16, 0, 0, 0, 0 );
                if not tux[ i ].Killed then
                   asprite2d_Draw( tux[ i ].Texture, tux[ i ].Pos.X, tux[ i ].Pos.Y, 64, 64, 0, tux[ i ].Frame div 2, 255, FX_BLEND or FX2D_FLIPX or FX2D_VCHANGE );
              end else
                 if not tux[ i ].Killed then
                   asprite2d_Draw( tux[ i ].Texture, tux[ i ].Pos.X, tux[ i ].Pos.Y, 64, 64, 0, tux[ i ].Frame div 2, 255, FX_BLEND or FX2D_FLIPX );

--- Termina codice ---

nomorelogic:
io ho dei problemi con Alt+Enter: non mi switcha tra fullscreen e finestra :(

sergio:
Scusa , ma Castle  non è piu' semplice ? Io non mi trovo molto con ZenGl ! Provo a vedere con castle cosa esce fuori ! Ciao Sergio

Navigazione

[0] Indice dei post

[#] Pagina successiva

Vai alla versione completa