Oppure

Loading
10/01/10 11:08
davide95
In questo sorgente manca una parentesi graffa, ma non riesco a capire dove.
(il sorgente fa parte di una specie di breakout che sto sviluppando con le librerie allegro)

Inoltre se avete qualche consiglio per far diventare più efficente il programma, ditemelo.

PS: Non siate duri con me :(. è il mio primo programma! (Ed è anche la prima volta che faccio parte di un forum:rotfl:)


// Prima ci sono le varie inizializzazioni delle variabili;
// Se volete le posto
    // Finche non si preme Il tasto "ESC"
	while (!key[KEY_ESC]) { //1
          
       
       /*for (i = 0, numberStone = 0; i<= STONE_NUMBER; i++)
          if (block_exist[i] == 1)
             numberStone++;*/
             
          // Codice di movimento della racchetta         
       raket_vx = (key[KEY_LEFT] - key[KEY_RIGHT])* RAKET_SPEED;
       raket_x += raket_vx;                    
                    //Ferma la racchetta al bordo dello schermo
       if ((raket_x >= 630 - (RAKET_SPEED + 3) - 55)) {//2
          raket_x -= RAKET_SPEED;
          }// !2
       if (raket_x <= RAKET_SPEED + 3 - 10){// 2
          raket_x += RAKET_SPEED;
          }// !2
                       

          
          // Codice di movimento della palla
       ball_x += ball_vx;
       ball_y += ball_vy;
      

          
       // Controlla se la palla collide con un blocco ed esegue le azioni necessarie
       for (i = 0; i <= STONE_NUMBER; i++)
          if ((ball_x >= block_x[i] && ball_x <= block_x[i] +77) && (ball_y >= block_y[i] && ball_y <= block_y[i] + 17)){// 2
             play_sample(stone_collision, 255,128,1000, FALSE);
             if (block_exist[i]){// 3
                  if (ball_y >= block_y[i] + 1 && ball_y <= block_y[i] + 14){// 4
                     ball_vx = -ball_vx;
                     }// !4
                  else{// 4
                     ball_vy = -ball_vy;
                     }// !4
                  if (block_exist[i] == 1) {// 4
                     block_exist[i] = 0;
                     }// !4
                  }// 3
             } // !2
          
              
                  
          
          //Controlla se la palla collide con un muro ed esegue le azioni necessarie
          if (ball_x <= 2||ball_x >= 634){// 2
             ball_vx = -ball_vx; 
             play_sample(wall_collision, 255,128,1000, FALSE);
             }// !2
          
          if (ball_y <= 2) {// 2
             ball_vy = -ball_vy; 
             play_sample(wall_collision, 255,128,1000, FALSE);
             }// !2
             
          // Se la palla finisce sotto...
          else if (ball_y >= 474){// 2
             j = 0; 
             if (life != 0)
             life -= 1;
             ball_vx = 0;
             ball_vy = -4;
             play_sample(dead, 255,128,1000, FALSE);}                               
             ball_x = 320;
             ball_y = 240;
             }// !2
          
          //Controlla se la pallina collide con la racchetta ed esegue le azioni necessarie
          if ((ball_x >= raket_x && ball_x < raket_x+ 75) && (ball_y >= raket_y && ball_y <= raket_y + 15)){// 2
             play_sample(raket_collision, 255,128,1000, FALSE);
             //Da alla racchetta la capacità di direzionare la palla
             if (raket_vx < 0){// 3
                ball_vy = -ball_vy ;
                ball_vx += 1;}// !3
             
             else if (raket_vx > 0){// 3
                ball_vy = -ball_vy;
                ball_vx -= 1;
                }// !3
            
             else ball_vy = -ball_vy ;
             }// !2

          //Codice della gestione della grafica   

          blit(background,buffer,0,0,0,0, 640,480);
          
          
          switch (life){// 2
             case 3:
                textout_ex(buffer, font, "LIFES = 3", 285, 470, 0x000000, TRUE);
                break;
             case 2:
                textout_ex(buffer, font, "LIFES = 2", 285, 470, 0x000000, TRUE);
                break;
             case 1:
                textout_ex(buffer, font, "LIFE = 1", 285, 470, 0x000000, TRUE);
                break;
             default:
                textout_ex(buffer, font, "GAME OVER! PRESS ESC TO EXIT", 210, 470, 0x000000, TRUE);
                }// !2
                           
                    
   if (life){// 2
          // Visualizza blocchi
      for (i = 0; i <= STONE_NUMBER; i++) {// 3
          if (block_exist[i]==1){// 4
             draw_sprite(buffer, stone1, block_x[i], block_y[i]);
             }// !4
          // e quelli indistruttibili
          if (block_exist[i]==2) {// 4
            draw_sprite(buffer, stone2, block_x[i], block_y[i]);
            }// !4
          draw_sprite(buffer, raket, raket_x, raket_y);
          draw_sprite(buffer, ball, ball_x++, ball_y++); 
         }// !3
      }// !2
      
    blit(buffer  ,screen, 0, 0, 0, 0, 640, 480);//Inserisce il buffer nello schermo, cioe' lo visualizza
    vsync();
    clear(buffer);
    }// !1
    
        deinit();

	return 0;
}// 0
END_OF_MAIN()

void deinit() {
	clear_keybuf();
	destroy_sample(stone_collision);
    destroy_sample(raket_collision);
   	destroy_sample(wall_collision);
	destroy_sample(dead);
	destroy_bitmap(stone1);
    destroy_bitmap(stone2);
    destroy_bitmap(ball);
    destroy_bitmap(raket);
    destroy_bitmap(background);
    destroy_bitmap(buffer);    	
	allegro_exit();
}


gli errori che mi escono sono:
332 C:\Dev-Cpp\Projects\Arkanoid\main.c previous declaration of 'deinit' was here
350 C:\Dev-Cpp\Projects\Arkanoid\main.c conflicting types for 'deinit'
332 C:\Dev-Cpp\Projects\Arkanoid\main.c previous declaration of 'deinit' was here
C:\Dev-Cpp\Projects\Arkanoid\Makefile.win [Build Error] [main.o] Error 1

Quindi "capta" deinit come la dichiarazione di un'altra funzione, giusto:-?
quindi è stata chiusa una parentesi graffa di troppo:_doubt:
il problema è quale? Purtroppo non sono un maestro del codice leggibile. Chi mi da una mano?

i numeri come // 2 o // !2 sono commenti che segnano le relative aperture /chiusure delle parentesi graffe ( che ho invano inserito per risolvere il problema);
C'é molto altro codice
se volete ve lo posto;
Ultima modifica effettuata da davide95 10/01/10 15:40
aaa
10/01/10 11:27
GuglielmoS
Posta il sorgente completo che è meglio.
Comunque magari è un errore nel prototipo della funzione deinit. Quindi ripeto è meglio se posti il tutto così possiamo verificare bene qual'è il problema.
Ciao GuglielmoS
aaa
10/01/10 11:42
davide95
Potete prenderlo da mediafire qui:
mediafire.com/
è troppo grande per metterlo tutto (circa 7-8 pagine);
aaa
10/01/10 11:49
GuglielmoS
Postato originariamente da davide95:

Potete prenderlo da mediafire qui:
mediafire.com/
è troppo grande per metterlo tutto (circa 7-8 pagine);

Io nel file scaricato ho solo questo:
#include <allegro.h>
#include <alleggl.h>

int main() {
	
	/* Initialize both Allegro and AllegroGL */
	allegro_init();
	install_allegro_gl();
	
	/* Tell Allegro we want to use the keyboard */
	install_keyboard();

	/* Suggest a good screen mode for OpenGL */
	allegro_gl_set(AGL_Z_DEPTH, 8);
	allegro_gl_set(AGL_COLOR_DEPTH, 16);
	allegro_gl_set(AGL_SUGGEST, AGL_Z_DEPTH | AGL_COLOR_DEPTH);

	/* Set the graphics mode */
	set_gfx_mode(GFX_OPENGL_WINDOWED, 640, 480, 0, 0);
	
	/* Clear the screen */
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	/* Set up the view frustum */
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glFrustum(-1.0, 1.0, -1.0, 1.0, 1, 60.0);

	/* Draw a quad using OpenGL */
	glBegin(GL_QUADS);
		glColor3ub(255, 255, 255);
		glVertex3f(-1, -1, -2);
		glVertex3f( 1, -1, -2);
		glVertex3f( 1,  1, -2);
		glVertex3f(-1,  1, -2);
	glEnd();
	
	/* Flip the backbuffer on screen */
	allegro_gl_flip();
	
	/* Wait for the user to press a key */
	readkey();
	
	/* Finished. */
	return 0;
}
END_OF_MAIN();
aaa
10/01/10 14:07
davide95
SCUSATE! mi sono confuso!
non è quello :_doubt: (Quello è il template per la versione in 3D)
Questo è quello giusto

SCUSATE VERAMENTE
mediafire.com/
Ultima modifica effettuata da davide95 10/01/10 14:08
aaa
10/01/10 15:39
davide95
Dopo aver saltato il pranzo per cercarlo, ho trovato l'errore:

alla linea 271 (del secondo codice sorgente)

          else if (ball_y >= 474){// 2
             j = 0; 
             if (life != 0)
             life -= 1;
             ball_vx = 0;
             ball_vy = -4;
             play_sample(dead, 255,128,1000, FALSE);}//Questa è la paretesi di troppo
                                                     // Essa Chiude l'"IF" ma...
             ball_x = 320;
             ball_y = 240;
             }//...dovrebbe farlo questa. Naturalmente chiude anche il 
              //  ciclo in cui è inclusa la generando poi i conseguenti errori;


Il mio programma deve solo essere perfezionato in qualche punto, ma l'ho quasi finito:
:love: Il primo programma non si scorda mai!:rofl::rofl:

Grazie mille per l'aiuto;:hail::hail:
Ultima modifica effettuata da davide95 10/01/10 15:41
aaa