Privacy Policy

Blog italiano

Clicca qui se vuoi andare al blog italiano su Lazarus e il pascal.

Forum ufficiale

Se non siete riusciti a reperire l'informazione che cercavate nei nostri articoli o sul nostro forum vi consiglio di visitare il
Forum ufficiale di Lazarus in lingua inglese.

Lazarus 1.0

TDD o Test-Driven Development
immagine docker per lavorare con lazarus e free pascal
Indice
Installare lazarus su mac osx sierra
Un dialog per la connessione al database:TfmSimpleDbConnectionDialog
Superclasse form base per programmi gestionali (e non) #4 - wait animation
Superclasse form base per programmi gestionali (e non) #3 - traduzione delle form
Superclasse form base per programmi gestionali (e non) #2 - log, exception call stack, application toolbox
Superclasse form base per programmi gestionali (e non)
Advanced Record Syntax: un esempio pratico
DB concetti fondamentali e TDBEdit, TDBMemo e TDBText
DB concetti fondamentali e DBGrid
Advanced Record Syntax
DB concetti fondamentali e ZeosLib
DB concetti fondamentali e connessioni standard
guida all'installazione di fpc trunk da subversion in linux gentoo
Creare un server multithread
Cifratura: breve guida all'uso dell'algoritmo BlowFish con lazarus e free pascal.
Free Pascal e Lazarus sul Raspberry Pi
fpcup: installazioni parallele di lazarus e fpc
Ubuntu - aggiornare free pascal e lazarus
Come interfacciare periferica twain
Lazarus 1.0
Aspetto retrò (Cmd Line)
Disporre le finestre in un blocco unico (come Delphi)
Zeos ... dietro le quinte (prima parte)
Lavorare con file in formato JSON con Lazarus
Overload di operatori
Dataset virtuale
Linux + Zeos + Firebird
Pascal Script
La gestione degli errori in Lazarus
Indy 10 - Invio email con allegati
Brute force
Le permutazioni
Da DataSource a Excel
StatusBar - aggirare l'errore variabile duplicata
Visualizzare un file Html esterno
Evidenziare voci TreeView
Toolbar
Direttiva $macro
Indy gestiore server FTP lato Client
TImage su Form e Panel
PopUpMenu sotto Pulsante (TSpeedButton)
Conversione numerica
Proprietà
Funzioni a parametri variabili
Overload di funzioni
Liste e puntatori
Conferma di chiusura di un applicazione
Il file: questo sconosciuto
UIB: Unified Interbase
System Tray con Lazarus
Intercettare tasti premuti
LazReport, PDF ed immagini
Lazarus e la crittografia
Ampliare Lazarus
Generare controlli RUN-TIME
TTreeview e Menu
TTreeView
Utilizzare Unità esterne
Lavorare con le directory
Realizzare programmi multilingua
Codice di attivazione
File INI
Esempio lista in pascal
Stabilire il sistema operativo
Recuperare codice HTML da pagina web
Trascinare un file nel programma
Mandare mail con Lazarus
Welcome to Italian community of Lazarus and Free Pascal. Please login or sign up.

Recenti

How To

Utenti
Stats
  • Messaggi totali: 20.582
  • Totale discussioni: 2.471
  • Online today: 310
  • Online ever: 5.949 (Luglio 30, 2026, 09:49:59 PM)
Utenti online
  • Users: 0
  • Guests: 5
  • Total: 5
5 Visitatori, 0 Utenti

ZenGL : Collisioni.

Aperto da Stilgar, Maggio 06, 2012, 03:27:39 PM

Discussione precedente - Discussione successiva

Stilgar

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


    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;       

il record l'ho modificato in questo modo :

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



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

            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 );


Funzione Timer completa :


  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;


(Non sembra rilevare le collisioni delle aree)


Al mondo ci sono 10 tipi di persone ... chi capisce il binario e chi no.

nomorelogic

col2d_RectInRect... 'ndo' sta? ;)
Imagination is more important than knowledge (A.Einstein)

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


      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 );
Imagination is more important than knowledge (A.Einstein)

nomorelogic

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

Imagination is more important than knowledge (A.Einstein)

sergio

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

Stilgar

Per le prove ho semplificato all'osso ;)

procedure Draw;
  var
    i : Integer;
    t : Single;
begin
  batch2d_Begin();
  if time > 255 Then
    begin
      zgl_Disable( COLOR_BUFFER_CLEAR );
      back0_offset:= (time div 10) mod 800;
      back1_offset:= (time div 3) mod 1600;

      ssprite2d_Draw( texBack, -back0_offset, 0, 1600, 600, 0 );
      ssprite2d_Draw( texBack1, -back1_offset, 400, 1600, 200, 0 );

      if back1_offset > 800 then
        ssprite2d_Draw( texBack1, -(back1_offset mod 800-800), 400, 1600, 200, 0 );
      text_Draw( fntMain, 0, 25, 'time: ' + u_IntToStr( time ) );
      text_Draw( fntMain, 0, 50, 'sfondo 0 offset: ' + u_IntToStr( back0_offset ) );
      text_Draw( fntMain, 0, 75, 'sfondo 1 offset: ' + u_IntToStr( back1_offset ) );
      cam2d_Set( @camMain );
      for i := 0 to 20 do
        begin
          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 );
        end;
        asprite2d_Draw( nave.Texture, nave.Pos.X, nave.Pos.Y, 64, 64, 0, nave.Frame div 2 );
    end;

  if time <= 255 Then
    ssprite2d_Draw( texLogo, 400 - 256, 300 - 128, 512, 256, 0, time )
  else
    if time < 510 Then
      begin
        ssprite2d_Draw( texLogo, 400 - 256, 300 - 128, 512, 256, 0, 510 - time );
      end;

  if time > 255 Then
    text_Draw( fntMain, 0, 0, 'FPS: ' + u_IntToStr( zgl_Get( RENDER_FPS ) ) );


  DrawDebugInfo_Joy;

  batch2d_End();
end;   


Al posto di usare tux[20] ho utilizzato nave come reference ;)

ho aggiunto alle uses

zgl_collision_2d


Sospetto che il problema sia proprio l'algoritmo. la funzione controlla se è tutto dentro il rettandolo, mentre noi abbiamo bisogno di sapere se c'è un'intersezione comune ;)


Al mondo ci sono 10 tipi di persone ... chi capisce il binario e chi no.

nomorelogic

#6
Citazione di: sergio il Maggio 06, 2012, 06:13:12 PM
Scusa , ma Castle  non è piu' semplice ? Io non mi trovo molto con ZenGl ! Provo a vedere con castle cosa esce fuori ! Ciao Sergio

Castle renderizza anche in 2D?

Se fai delle prove posta i risultati che sono curioso :)
Imagination is more important than knowledge (A.Einstein)

Disclaimer:

Questo blog non rappresenta una testata giornalistica poiché viene aggiornato senza alcuna periodicità. Non può pertanto considerarsi un prodotto editoriale ai sensi della legge n. 62/2001.