* * * *

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

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

Inserisci il nome utente, la password e la durata della sessione.

261 Visitatori, 0 Utenti

Autore Topic: ZenGL : Collisioni.  (Letto 5926 volte)

Stilgar

  • Global Moderator
  • Hero Member
  • *****
  • Post: 2382
  • Karma: +10/-0
ZenGL : Collisioni.
« il: Maggio 06, 2012, 03:27:39 pm »
Non mi parte il debugger ... porca paletta :(
Allora il codice incriminato nella finzione "Timer" è questo :
Codice: [Seleziona]

    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 :
Codice: [Seleziona]
  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 ...
Codice: [Seleziona]
            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 :
Codice: [Seleziona]

  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

  • Global Moderator
  • Hero Member
  • *****
  • Post: 2871
  • Karma: +20/-4
Re:ZenGL : Collisioni.
« Risposta #1 il: Maggio 06, 2012, 03:57:32 pm »
col2d_RectInRect... 'ndo' sta? ;)
Imagination is more important than knowledge (A.Einstein)

nomorelogic

  • Global Moderator
  • Hero Member
  • *****
  • Post: 2871
  • Karma: +20/-4
Re:ZenGL : Collisioni.
« Risposta #2 il: Maggio 06, 2012, 04:05:28 pm »
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: [Seleziona]
      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

  • Global Moderator
  • Hero Member
  • *****
  • Post: 2871
  • Karma: +20/-4
Re:ZenGL : Collisioni.
« Risposta #3 il: Maggio 06, 2012, 04:28:11 pm »
io ho dei problemi con Alt+Enter: non mi switcha tra fullscreen e finestra :(

Imagination is more important than knowledge (A.Einstein)

sergio

  • Full Member
  • ***
  • Post: 146
  • Karma: +1/-0
Re:ZenGL : Collisioni.
« Risposta #4 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
Programmo per passione !

Stilgar

  • Global Moderator
  • Hero Member
  • *****
  • Post: 2382
  • Karma: +10/-0
Re:ZenGL : Collisioni.
« Risposta #5 il: Maggio 06, 2012, 08:08:56 pm »
Per le prove ho semplificato all'osso ;)
Codice: [Seleziona]
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
Codice: [Seleziona]
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

  • Global Moderator
  • Hero Member
  • *****
  • Post: 2871
  • Karma: +20/-4
Re:ZenGL : Collisioni.
« Risposta #6 il: Maggio 06, 2012, 10:59:50 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 :)
« Ultima modifica: Maggio 06, 2012, 11:01:22 pm da nomorelogic »
Imagination is more important than knowledge (A.Einstein)

 

Recenti

How To

Utenti
Stats
  • Post in totale: 18784
  • Topic in totale: 2236
  • Online Today: 465
  • Online Ever: 900
  • (Gennaio 21, 2020, 08:17:49 pm)
Utenti Online
Users: 0
Guests: 261
Total: 261

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.