Sei sulla pagina 1di 47

#ifdef __cplusplus #include <cstdlib> #else #include <stdlib.h> #endif #ifdef __APPLE__ #include <SDL/SDL.h> #else #include <SDL.

h> #endif #include <stdio.h> #include "SDL/SDL.h" #include <SDL_ttf.h> #include <SDL.h> #define TRUE 1 #define FALSE 0 #define SCREEN_W 800 #define SCREEN_H 600 #include <SDL_image.h> #include "SDL/SDL_ttf.h" TTF_Font* my_font; #define FONTSIZE 18 #define PONTOS 10000 int organizador(int arq[],int i) { int pos = 0; int arq_org[11]; int a;

if (arq[i] < arq[0]) { pos += 1; } if (arq[i] < arq[1]) { pos += 1; } if (arq[i] < arq[2]) { pos += 1; } if (arq[i] < arq[3]) {

pos += 1; } if (arq[i] < arq[4]) { pos+= 1; } if (arq[i] < arq[5]) { pos += 1; } if (arq[i] < arq[6]) { pos+= 1; } if (arq[i] < arq[7]) { pos += 1; } if (arq[i] < arq[8]) { pos += 1; } if (arq[i] < arq[9]) { pos += 1; } if (arq[i] < arq[10]) { pos += 1; } return pos; } void score(int*recorde) { FILE *arq; int recorde_org[11]; int i,pos; int recordes[11]; arq = fopen("score.txt","r"); fscanf(arq,"%d",&recordes[i]); while (!feof(arq)) {

i++; fscanf(arq,"%d",&recordes[i]); } recordes[10] = *recorde; for (i=0;i<11;i++) { pos = organizador(recordes,i); recorde_org[pos] = recordes[i]; } fclose(arq); arq = fopen("score.txt","w"); for (i=0;i<10;i++) { fprintf(arq,"%d ",recordes[i]); } fclose(arq); } void desenha_texto(char* texto, SDL_Surface* dst, int x, int y) { SDL_Color cor = {0, 0, 0}; //vermelho SDL_Surface* src = TTF_RenderText_Blended(my_font, texto, cor); SDL_Rect dst_rect = {x, y, 0, 0}; SDL_BlitSurface(src, NULL, dst, &dst_rect); } int colisao(SDL_Rect *quadA, SDL_Rect* quadB) { /* Verifica se h coliso entre dois objetos que se movem na tela. parametros: SDL_Rect *quadA : Retangulo A. SDL_Rect* quadB : Retangulo B. retorno: TRUE: Se ha colisao. FALSE: Se nao ha colisao. */ int leftA, leftB; int rightA, rightB;

int topA, topB; int bottomA, bottomB; leftA = quadA->x; rightA = quadA->x + quadA->w; topA = quadA->y; bottomA = quadA->y + quadA->h; leftB = quadB->x; rightB = quadB->x + quadB->w; topB = quadB->y; bottomB = quadB->y + quadB->h; if (bottomA <= topB) { return FALSE; } if (topA >= bottomB) { return FALSE; } if (rightA <= leftB) { return FALSE; } if (leftA >= rightB) { return FALSE; } return TRUE; } /// As 3 funes da animao da nave inimiga int x_animacao(int x,int c,SDL_Surface* nave) { if (c == 0) { x+= 2; *nave = *(IMG_Load("zeppelin-right.png")); }

else { x+= -2; *nave = *IMG_Load("zeppelin-left.png"); } return x; } int Const_animacao(int x, int c) { if (x >= 800) { c = 1; } if (x<=0) { c = 0; } return c; } int y_animacao(int x, int y) { if (x == 800 ||x == 0) { y += 80; } return y; }

/// Funo da 1 fase int fase1(int recorde_jogador) { int velocidade_morte; int contador_tempo_score = 0; int i = 0; int d2 = 480; int d1 = 200; int temp = 0; int c = 0;

int j = 1; int troca_imagem = 0; int vida_jogador = 1; int voltar = 1; int tiro_a = 0; int c1 = 0; int c2 = 0; int c3 = 0; int c4 = 0; int c5 = 0; int c6 = 0; // Variaveis SDL SDL_Surface* screen; SDL_Rect quad = {0,0,20,20}; // retangulo A nasce na pos(0,0). Tem lados iguais a 64 SDL_Rect quadinimigo1 = {0,0,40,40}; SDL_Rect quadinimigo2 = {100,0,40,40}; SDL_Rect quadinimigo3 = {200,0,40,40}; SDL_Rect quadinimigo4 = {300,0,40,40}; SDL_Rect quadinimigo5 = {400,0,40,40}; SDL_Rect quadinimigo6 = {500,0,40,40};

int passo = 4; int incx = 500; int incy = 570;

// Tamanho do passo do quadrado. // Passo na coordenada x do quad. // Passo na coordenada y do quad.

int prevx,prevy; // Guarda a ultima posicao de um objeto. int flags = 0; int quit = 0; // Variavel que indica a saida do programa.

struct posicao { int x; int y; int c; int vida; } evil_1,evil_2,evil_3,evil_4,evil_5,evil_6; evil_1.x = 0;

evil_1.y = 0; evil_1.c = 0; evil_1.vida = 1; evil_2.x = 100; evil_2.y = 0; evil_2.c = 0; evil_2.vida = 1; evil_3.x = 200; evil_3.y = 0; evil_3.c = 0; evil_3.vida = 1; evil_4.x = 300; evil_4.y = 0; evil_4.c = 0; evil_4.vida = 1; evil_5.x = 400; evil_5.y = 0; evil_5.c = 0; evil_5.vida = 1; evil_6.x = 500; evil_6.y = 0; evil_6.c = 0; evil_6.vida = 1;

struct tiro { int atirou; int tx; int ty; } tiro_nave,tiro_evil1,tiro_evil2,tiro_evil3,tiro_evil4,tiro_evil5,tiro_evil6; tiro_nave.atirou = 0; tiro_nave.tx = 480; tiro_nave.ty = d1; tiro_evil1.atirou = 0; tiro_evil1.tx = quadinimigo1.x; tiro_evil1.ty = 0;

tiro_evil2.atirou = 0; tiro_evil2.tx = quadinimigo2.x; tiro_evil2.ty = 0; tiro_evil3.atirou = 0; tiro_evil3.tx = quadinimigo3.x; tiro_evil3.ty = 0; tiro_evil4.atirou = 0; tiro_evil4.tx = quadinimigo4.x; tiro_evil4.ty = 0; tiro_evil5.atirou = 0; tiro_evil5.tx = quadinimigo5.x; tiro_evil5.ty = 0; tiro_evil6.atirou = 0; tiro_evil6.tx = quadinimigo6.x; tiro_evil6.ty = 0;

SDL_Event event;

// Inicializa SDL video. SDL_Init(SDL_INIT_VIDEO); // Cria janela com reslucao de 640x480. screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 16, SDL_SWSURFACE); // inicializao do programa SDL_Surface *fund; fund = IMG_Load( "mariodrogas.gif" ); SDL_Rect quadFun = {0,0,800,600}; //Blit da inicializao SDL_BlitSurface( fund, &quadFun, screen, NULL ); SDL_Flip(screen); // Temporozador na inicializao. SDL_Delay(3000); // Carrega imagem relativa ao fundo. SDL_Surface *fundo; fundo = IMG_Load ( "bg.png" ); // Diz o tamanho do retngulo da imagem

SDL_Rect quadFundo = {0,0,800,600}; // Inicializa o Audio. SDL_Init(SDL_INIT_AUDIO); SDL_Surface *quadImagem; quadImagem = IMG_Load( "bonecodireita.png" ); // Nome da Janela SDL_WM_SetCaption("Jogo UFRRJ", "Jogo"); SDL_Surface *Tiro; SDL_Surface* nave; nave = IMG_Load("zeppelin-right.png"); SDL_Surface* nave2; nave2 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave3; nave3 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave4; nave4 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave5; nave5 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave6; nave6 = IMG_Load("zeppelin-right.png"); SDL_Surface* nuvem; nuvem = IMG_Load("cloud.png");

// Enquanto o usuario nao fecha a janela. while (!quit) { contador_tempo_score ++; if(contador_tempo_score == 20) { contador_tempo_score = 0; velocidade_morte += 1; } i += 1; if (i == 31) { temp = 1; i = 0; }

SDL_Rect tiro_evil = {tiro_evil1.tx,tiro_evil1.ty,10,10}; SDL_Rect quad_tiro_evil2 = {tiro_evil2.tx,tiro_evil2.ty,10,10}; SDL_Rect quad_tiro_evil3 = {tiro_evil3.tx,tiro_evil3.ty,10,10}; SDL_Rect quad_tiro_evil4 = {tiro_evil4.tx,tiro_evil4.ty,10,10}; SDL_Rect quad_tiro_evil5 = {tiro_evil5.tx,tiro_evil5.ty,10,10}; SDL_Rect quad_tiro_evil6 = {tiro_evil6.tx,tiro_evil6.ty,10,10}; SDL_Rect quadtiro = {tiro_nave.tx,tiro_nave.ty,10,10}; SDL_Rect posnuvem = {0,150,10,10}; Tiro =IMG_Load("Tiro.png");

// "animao" da imagem q devera ser o inimigo quadinimigo1.x = x_animacao(quadinimigo1.x,c1,nave); c1 = Const_animacao(quadinimigo1.x,c1); quadinimigo1.y = y_animacao(quadinimigo1.x,quadinimigo1.y ); quadinimigo2.x = x_animacao(quadinimigo2.x,c2,nave2); c2 = Const_animacao(quadinimigo2.x,c2); quadinimigo2.y = y_animacao(quadinimigo2.x,quadinimigo2.y ); quadinimigo3.x = x_animacao(quadinimigo3.x,c3,nave3); c3 = Const_animacao(quadinimigo3.x,c3); quadinimigo3.y = y_animacao(quadinimigo3.x,quadinimigo3.y ); quadinimigo4.x = x_animacao(quadinimigo4.x,c4,nave4); c4 = Const_animacao(quadinimigo4.x,c4); quadinimigo4.y = y_animacao(quadinimigo4.x,quadinimigo4.y ); quadinimigo5.x = x_animacao(quadinimigo5.x,c5,nave5); c5 = Const_animacao(quadinimigo5.x,c5); quadinimigo5.y = y_animacao(quadinimigo5.x,quadinimigo5.y ); quadinimigo6.x = x_animacao(quadinimigo6.x,c6,nave6); c6 = Const_animacao(quadinimigo6.x,c6); quadinimigo6.y = y_animacao(quadinimigo6.x,quadinimigo6.y ); // Fim da animao dos inimigos // inicio do codigo do tiro if (vida_jogador == 1)

{ if (tiro_nave.atirou == 1) { tiro_nave.ty += -20; if(tiro_nave.ty == 0) { tiro_nave.atirou = 0; tiro_nave.ty = 640; } } } // if criado para no o tiro apos o disparo no seguir a nave if ( tiro_nave.atirou == 0) { tiro_nave.tx = d1; }

if (( temp == 1) || (tiro_evil1.atirou == 1)) { tiro_evil1.atirou = 1; if (tiro_evil1.atirou == 1) { tiro_evil1.ty += 10; if(tiro_evil1.ty == 640) { tiro_evil1.atirou = 0; tiro_evil1.ty = quadinimigo1.y; } } } if ( tiro_evil1.atirou == 0) { tiro_evil1.tx = quadinimigo1.x; }

if (( temp == 1) || (tiro_evil2.atirou == 1))

{ tiro_evil2.atirou = 1; if (tiro_evil2.atirou == 1) { tiro_evil2.ty += 10; if(tiro_evil2.ty == 640) { tiro_evil2.atirou = 0; tiro_evil2.ty = quadinimigo2.y; } } } if ( tiro_evil2.atirou == 0) { tiro_evil2.tx = quadinimigo2.x; }

if (( temp == 1) || (tiro_evil3.atirou == 1)) { tiro_evil3.atirou = 1; if (tiro_evil3.atirou == 1) { tiro_evil3.ty += 10; if(tiro_evil3.ty == 640) { tiro_evil3.atirou = 0; tiro_evil3.ty = quadinimigo3.y; } } } if ( tiro_evil3.atirou == 0) { tiro_evil3.tx = quadinimigo3.x; }

if (( temp == 1) || (tiro_evil4.atirou == 1)) { tiro_evil4.atirou = 1; if (tiro_evil4.atirou == 1)

{ tiro_evil4.ty += 10; if(tiro_evil4.ty == 640) { tiro_evil4.atirou = 0; tiro_evil4.ty = quadinimigo4.x; } } } if ( tiro_evil4.atirou == 0) { tiro_evil4.tx = evil_4.x; } if (( temp == 1) || (tiro_evil5.atirou == 1)) { tiro_evil5.atirou = 1; if (tiro_evil5.atirou == 1) { tiro_evil5.ty += 10; if(tiro_evil5.ty == 640) { tiro_evil5.atirou = 0; tiro_evil5.ty = quadinimigo5.y; } } } if ( tiro_evil5.atirou == 0) { tiro_evil5.tx = quadinimigo5.x; } if (( temp == 1) || (tiro_evil5.atirou == 1)) { tiro_evil6.atirou = 1; if (tiro_evil6.atirou == 1) { tiro_evil6.ty += 10; if(tiro_evil6.ty == 640) { tiro_evil6.atirou = 0; tiro_evil6.ty = quadinimigo6.y;

} } } if ( tiro_evil6.atirou == 0) { tiro_evil6.tx = quadinimigo6.x; } // fim do codigo do tiro // Pega eventos do teclado/mouse. while(SDL_PollEvent(&event)) { // Se fechou a janela. if (event.type == SDL_QUIT) { quit = TRUE; } // Se tecla pressionada. else if( event.type == SDL_KEYDOWN ) { // Verifica tecla pressionada. switch( event.key.keysym.sym ) { case SDLK_SPACE: // Para a esquerda. tiro_nave.atirou = 1; quadImagem = IMG_Load("boneco mao alto direita.png"); break; case SDLK_LEFT: // Para a esquerda. incx = -passo; quadImagem = IMG_Load( "boneco esquerda.png" ); break; case SDLK_RIGHT: // Para a direita. incx = passo; incy = 0; quadImagem = IMG_Load( "bonecodireita.png" ); break; case SDLK_q: // para poder pausar o jogo voltar = 0; while(voltar != 1) { while(SDL_PollEvent(&event)) { if( event.type == SDL_KEYDOWN )

{ // Verifica tecla pressionada. switch( event.key.keysym.sym ) { case SDLK_SPACE: voltar = 1; } } } } break; }

} // Se soltou a tecla nao anda com o objeto. else if( event.type == SDL_KEYUP ) { incx = 0; incy = 0; }

} // if criado para se a bala que no foi disparada esta na mesma pociso da nave. if( event.type == SDL_KEYDOWN ) { d1 = quad.x; } // Se dando um passo, nao passa do limite da esquerda ou direita da janela ento. if ( ((quad.x + quad.w + incx) <= screen->w) && (quad.x + incx >= 0) ) { // Move quadrado na horizontal. quad.x += incx; } // Se dando um passo, nao passa do limite de cima e de baixo da janela ento. if (((quad.y + quad.h + incy) <= screen->h) && (quad.y + incy >= 0)) { // Move quadrado na vertical. quad.y += incy; }

// Inicio do Codigo de Coliso if (colisao(&quadinimigo1, &quadtiro) && ( evil_1.vida == 1)) { evil_1.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo2, &quadtiro) && ( evil_2.vida == 1)) { evil_2.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo3, &quadtiro) && ( evil_3.vida == 1)) { evil_3.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo4, &quadtiro) && ( evil_4.vida == 1)) { evil_4.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo5, &quadtiro) && ( evil_5.vida == 1)) { evil_5.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo6, &quadtiro) && ( evil_6.vida == 1)) { evil_6.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600;

recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quad, &tiro_evil) && ( evil_1.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil2) && ( evil_2.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil3) && ( evil_3.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil4) && ( evil_4.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil5) && ( evil_5.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil6) && ( evil_6.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600;

} // Fim do codigo de coliso

//Blit do Fundo SDL_BlitSurface( fundo, &quadFundo, screen, NULL );

if (vida_jogador == 1) { //Blit da nave do jogador SDL_BlitSurface( quadImagem, NULL, screen, &quad ); if (tiro_nave.atirou == 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quadtiro ); } } if( evil_1.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave, NULL, screen, &quadinimigo1 ); if (tiro_evil1.atirou == 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &tiro_evil ); } } if( evil_2.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave2, NULL, screen, &quadinimigo2 ); if (tiro_evil2.atirou == 1) {

//Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil2 ); } } if( evil_3.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave3, NULL, screen, &quadinimigo3 ); if (tiro_evil3.atirou== 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil3 ); } } if( evil_4.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave4, NULL, screen, &quadinimigo4 ); if (tiro_evil4.atirou== 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil4 ); } } if( evil_5.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave5, NULL, screen, &quadinimigo5 ); if (tiro_evil5.atirou == 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil5 ); } } if( evil_6.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave6, NULL, screen, &quadinimigo6 ); if (tiro_evil6.atirou == 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil6 ); } }

SDL_BlitSurface( nuvem, NULL, screen, &posnuvem ); SDL_Flip(screen); if((evil_6.vida == 0)&&(evil_5.vida == 0)&&(evil_4.vida == 0)&&(evil_3.vida == 0) &&(evil_2.vida == 0)&&(evil_1.vida == 0)||(vida_jogador== 0)) { quit = TRUE; } }

// Fecha a biblioteca. SDL_Quit(); return recorde_jogador; } /// Funo da 2 fase int fase2(int recorde_jogador) { int velocidade_morte; int contador_tempo_score = 0; int tempo = 0; int controle=60; int i = 0; int d2 = 480; int d1 = 200; int temp = 0; int temp2 = 1; int c = 0; int j = 1; int troca_imagem = 0; int vida_jogador = 1; int voltar = 1; int tiro_a = 0; int c1 = 0; int c2 = 0; int c3 = 0;

int c4 = 0; int c5 = 0; int c6 = 0; int c7 = 0; int c8 = 0; int c9 = 0; int c10 = 0; int c11 = 0; int c12 = 0;

/// Variaveis SDL SDL_Surface* screen; SDL_Rect quad = {0,0,20,20}; SDL_Rect quadinimigo1 = {-200,0,40,40}; SDL_Rect quadinimigo2 = {0,0,40,40}; SDL_Rect quadinimigo3 = {100,0,40,40}; SDL_Rect quadinimigo4 = {250,0,40,40}; SDL_Rect quadinimigo5 = {450,0,40,40}; SDL_Rect quadinimigo6 = {550,0,40,40}; SDL_Rect quadinimigo7 = {-150,150,40,40}; SDL_Rect quadinimigo8 = {-50,150,40,40}; SDL_Rect quadinimigo9 = {100,150,40,40}; SDL_Rect quadinimigo10 = {250,150,40,40}; SDL_Rect quadinimigo11 = {400,150,40,40}; SDL_Rect quadinimigo12 = {550,150,40,40};

struct VIDA { int vida; } evil_1,evil_2,evil_3,evil_4,evil_5,evil_6,evil_7,evil_8,evil_9,evil_10,evil_11,evil_12;

evil_1.vida = 1; evil_2.vida = 1; evil_3.vida = 1; evil_4.vida = 1;

evil_5.vida = 1; evil_6.vida = 1; evil_7.vida = 1; evil_8.vida = 1; evil_9.vida = 1; evil_10.vida = 1; evil_11.vida = 1; evil_12.vida = 1;

int passo = 4; int incx = 500; int incy = 570;

// Tamanho do passo do quadrado. // Passo na coordenada x do quad. // Passo na coordenada y do quad.

int prevx,prevy; // Guarda a ultima posicao de um objeto. int flags = 0; int quit = 0; // Variavel que indica a saida do programa. struct tiro { int atirou; int tx; int ty; } tiro_nave,tiro_evil1,tiro_evil2,tiro_evil3,tiro_evil4,tiro_evil5,tiro_evil6,tiro_evil7,tiro_evil8,tiro_evil 9,tiro_evil10,tiro_evil11,tiro_evil12; tiro_nave.atirou = 0; tiro_nave.tx = 480; tiro_nave.ty = d1; tiro_evil1.atirou = 0; tiro_evil1.tx = quadinimigo1.x;

tiro_evil1.ty = 0; tiro_evil2.atirou = 0; tiro_evil2.tx = quadinimigo2.x; tiro_evil2.ty = 0; tiro_evil3.atirou = 0; tiro_evil3.tx = quadinimigo3.x; tiro_evil3.ty = 0; tiro_evil4.atirou = 0; tiro_evil4.tx = quadinimigo4.x; tiro_evil4.ty = 0; tiro_evil5.atirou = 0; tiro_evil5.tx = quadinimigo5.x; tiro_evil5.ty = 0; tiro_evil6.atirou = 0; tiro_evil6.tx = quadinimigo6.x; tiro_evil6.ty = 0; tiro_evil7.atirou = 0; tiro_evil7.tx = quadinimigo7.x; tiro_evil7.ty = 0; tiro_evil8.atirou = 0; tiro_evil8.tx = quadinimigo8.x; tiro_evil8.ty = 0; tiro_evil9.atirou = 0; tiro_evil9.tx = quadinimigo9.x; tiro_evil9.ty = 0; tiro_evil10.atirou = 0; tiro_evil10.tx = quadinimigo10.x; tiro_evil10.ty = 0; tiro_evil11.atirou = 0; tiro_evil11.tx = quadinimigo11.x; tiro_evil11.ty = 0; tiro_evil12.atirou = 0; tiro_evil12.tx = quadinimigo12.x;

tiro_evil12.ty = 0;

SDL_Event event;

// Inicializa SDL video. SDL_Init(SDL_INIT_VIDEO); // Cria janela com reslucao de 640x480. screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 16, SDL_SWSURFACE); // inicializao do programa SDL_Surface *fund; fund = IMG_Load( "mariodrogas.gif" ); SDL_Rect quadFun = {0,0,800,600}; //Blit da inicializao SDL_BlitSurface( fund, &quadFun, screen, NULL ); SDL_Flip(screen); // Temporozador na inicializao. SDL_Delay(3000); // Carrega imagem relativa ao fundo. SDL_Surface *fundo; fundo = IMG_Load ( "bg.png" ); // Diz o tamanho do retngulo da imagem SDL_Rect quadFundo = {0,0,800,600};

SDL_Surface *quadImagem; quadImagem = IMG_Load( "bonecodireita.png" ); // Nome da Janela SDL_WM_SetCaption("Jogo UFRRJ", "Jogo"); SDL_Surface *Tiro;

/// Declarao de SDL_Surface para os inimigos SDL_Surface* nave; nave = IMG_Load("zeppelin-right.png"); SDL_Surface* nave2; nave2 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave3; nave3 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave4;

nave4 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave5; nave5 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave6; nave6 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave7; nave7 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave8; nave8 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave9; nave9 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave10; nave10 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave11; nave11 = IMG_Load("zeppelin-right.png"); SDL_Surface* nave12; nave12 = IMG_Load("zeppelin-right.png"); /// fim da declarao

SDL_Surface* nuvem; nuvem = IMG_Load("cloud.png");

// Enquanto o usuario nao fecha a janela. while (!quit) { contador_tempo_score ++; if(contador_tempo_score == 20) { contador_tempo_score = 0; velocidade_morte += 1; } /// "i" o contador do "temp","temp2" que so temporizadores de tiros da 1 e 2 fileiras de inimigos i += 2; if (i == 20) { temp = 1;

i = 1; } if (i == 21) { temp2 = 1; i = 0; }

/// Declarao do SDL_Rect para todos os enimigos SDL_Rect tiro_evil = {tiro_evil1.tx,tiro_evil1.ty,10,10}; SDL_Rect quad_tiro_evil2 = {tiro_evil2.tx,tiro_evil2.ty,10,10}; SDL_Rect quad_tiro_evil3 = {tiro_evil3.tx,tiro_evil3.ty,10,10}; SDL_Rect quad_tiro_evil4 = {tiro_evil4.tx,tiro_evil4.ty,10,10}; SDL_Rect quad_tiro_evil5 = {tiro_evil5.tx,tiro_evil5.ty,10,10}; SDL_Rect quad_tiro_evil6 = {tiro_evil6.tx,tiro_evil6.ty,10,10}; SDL_Rect quad_tiro_evil7 = {tiro_evil7.tx,tiro_evil7.ty,10,10}; SDL_Rect quad_tiro_evil8 = {tiro_evil8.tx,tiro_evil8.ty,10,10}; SDL_Rect quad_tiro_evil9 = {tiro_evil9.tx,tiro_evil9.ty,10,10}; SDL_Rect quad_tiro_evil10 = {tiro_evil10.tx,tiro_evil10.ty,10,10}; SDL_Rect quad_tiro_evil11 = {tiro_evil11.tx,tiro_evil11.ty,10,10}; SDL_Rect quad_tiro_evil12 = {tiro_evil12.tx,tiro_evil12.ty,10,10}; // Final da declarao do SDL_rect para os inimigos

SDL_Rect quadtiro = {tiro_nave.tx,tiro_nave.ty,10,10}; SDL_Rect posnuvem = {0,150,10,10}; Tiro =IMG_Load("Tiro.png");

/// "animao" da imagem q devera ser o inimigo quadinimigo1.x = x_animacao(quadinimigo1.x,c1,nave); c1 = Const_animacao(quadinimigo1.x,c1); quadinimigo1.y = y_animacao(quadinimigo1.x,quadinimigo1.y ); quadinimigo2.x = x_animacao(quadinimigo2.x,c2,nave2); c2 = Const_animacao(quadinimigo2.x,c2); quadinimigo2.y = y_animacao(quadinimigo2.x,quadinimigo2.y );

quadinimigo3.x = x_animacao(quadinimigo3.x,c3,nave3); c3 = Const_animacao(quadinimigo3.x,c3); quadinimigo3.y = y_animacao(quadinimigo3.x,quadinimigo3.y ); quadinimigo4.x = x_animacao(quadinimigo4.x,c4,nave4); c4 = Const_animacao(quadinimigo4.x,c4); quadinimigo4.y = y_animacao(quadinimigo4.x,quadinimigo4.y ); quadinimigo5.x = x_animacao(quadinimigo5.x,c5,nave5); c5 = Const_animacao(quadinimigo5.x,c5); quadinimigo5.y = y_animacao(quadinimigo5.x,quadinimigo5.y ); quadinimigo6.x = x_animacao(quadinimigo6.x,c6,nave6); c6 = Const_animacao(quadinimigo6.x,c6); quadinimigo6.y = y_animacao(quadinimigo6.x,quadinimigo6.y ); quadinimigo7.x = x_animacao(quadinimigo7.x,c7,nave); c7 = Const_animacao(quadinimigo7.x,c7); quadinimigo7.y = y_animacao(quadinimigo7.x,quadinimigo7.y ); quadinimigo8.x = x_animacao(quadinimigo8.x,c8,nave8); c8 = Const_animacao(quadinimigo8.x,c8); quadinimigo8.y = y_animacao(quadinimigo8.x,quadinimigo8.y ); quadinimigo9.x = x_animacao(quadinimigo9.x,c9,nave9); c9 = Const_animacao(quadinimigo9.x,c9); quadinimigo9.y = y_animacao(quadinimigo9.x,quadinimigo9.y ); quadinimigo10.x = x_animacao(quadinimigo10.x,c10,nave10); c10 = Const_animacao(quadinimigo10.x,c10); quadinimigo10.y = y_animacao(quadinimigo10.x,quadinimigo10.y ); quadinimigo11.x = x_animacao(quadinimigo11.x,c11,nave11); c11 = Const_animacao(quadinimigo11.x,c11); quadinimigo11.y = y_animacao(quadinimigo11.x,quadinimigo11.y ); quadinimigo12.x = x_animacao(quadinimigo12.x,c12,nave12); c12 = Const_animacao(quadinimigo12.x,c12); quadinimigo12.y = y_animacao(quadinimigo12.x,quadinimigo12.y ); // Fim da animao dos inimigos

/// inicio do codigo do tiro if (vida_jogador == 1)

{ if (tiro_nave.atirou == 1) { tiro_nave.ty += -20; if(tiro_nave.ty == 0) { tiro_nave.atirou = 0; tiro_nave.ty = 640; } } } // if criado para no o tiro apos o disparo no seguir a nave if ( tiro_nave.atirou == 0) { tiro_nave.tx = d1; }

if (( temp == 1) || (tiro_evil1.atirou == 1)) { tiro_evil1.atirou = 1; if (tiro_evil1.atirou == 1) { tiro_evil1.ty += 10; if(tiro_evil1.ty == 640) { tiro_evil1.atirou = 0; tiro_evil1.ty = quadinimigo1.y; } } } if ( tiro_evil1.atirou == 0) { tiro_evil1.tx = quadinimigo1.x; } if (( temp == 1) || (tiro_evil2.atirou == 1)) { tiro_evil2.atirou = 1;

if (tiro_evil2.atirou == 1) { tiro_evil2.ty += 10; if(tiro_evil2.ty == 640) { tiro_evil2.atirou = 0; tiro_evil2.ty = quadinimigo2.y; } } } if ( tiro_evil2.atirou == 0) { tiro_evil2.tx = quadinimigo2.x; } if (( temp == 1) || (tiro_evil3.atirou == 1)) { tiro_evil3.atirou = 1; if (tiro_evil3.atirou == 1) { tiro_evil3.ty += 10; if(tiro_evil3.ty == 640) { tiro_evil3.atirou = 0; tiro_evil3.ty = quadinimigo3.y; } } } if ( tiro_evil3.atirou == 0) { tiro_evil3.tx = quadinimigo3.x; } if (( temp == 1) || (tiro_evil4.atirou == 1)) { tiro_evil4.atirou = 1; if (tiro_evil4.atirou == 1) { tiro_evil4.ty += 10; if(tiro_evil4.ty == 640) { tiro_evil4.atirou = 0;

tiro_evil4.ty = quadinimigo4.x; } } } if ( tiro_evil4.atirou == 0) { tiro_evil4.tx = quadinimigo4.x; } if (( temp == 1) || (tiro_evil5.atirou == 1)) { tiro_evil5.atirou = 1; if (tiro_evil5.atirou == 1) { tiro_evil5.ty += 10; if(tiro_evil5.ty == 640) { tiro_evil5.atirou = 0; tiro_evil5.ty = quadinimigo5.y; } } } if ( tiro_evil5.atirou == 0) { tiro_evil5.tx = quadinimigo5.x; } if (( temp == 1) || (tiro_evil5.atirou == 1)) { tiro_evil6.atirou = 1; if (tiro_evil6.atirou == 1) { tiro_evil6.ty += 10; if(tiro_evil6.ty == 640) { tiro_evil6.atirou = 0; tiro_evil6.ty = quadinimigo6.y; } } } if ( tiro_evil6.atirou == 0)

{ tiro_evil6.tx = quadinimigo6.x; } /// Tiros da segunda fileira !!! if (( temp2 == 1) || (tiro_evil7.atirou == 1)) { tiro_evil7.atirou = 1; if (tiro_evil7.atirou == 1) { tiro_evil7.ty += 10; if(tiro_evil7.ty == 640) { tiro_evil7.atirou = 0; tiro_evil7.ty = quadinimigo7.y; } } } if ( tiro_evil7.atirou == 0) { tiro_evil7.tx = quadinimigo7.x; } if (( temp2 == 1) || (tiro_evil8.atirou == 1)) { tiro_evil8.atirou = 1; if (tiro_evil8.atirou == 1) { tiro_evil8.ty += 10; if(tiro_evil8.ty == 640) { tiro_evil8.atirou = 0; tiro_evil8.ty = quadinimigo8.y; } } } if ( tiro_evil9.atirou == 0) { tiro_evil9.tx = quadinimigo9.x; }

if (( temp2 == 1) || (tiro_evil10.atirou == 1)) { tiro_evil10.atirou = 1; if (tiro_evil10.atirou == 1) { tiro_evil10.ty += 10; if(tiro_evil10.ty == 640) { tiro_evil10.atirou = 0; tiro_evil10.ty = quadinimigo10.x; } } } if ( tiro_evil10.atirou == 0) { tiro_evil10.tx = quadinimigo10.x; } if (( temp2 == 1) || (tiro_evil11.atirou == 1)) { tiro_evil11.atirou = 1; if (tiro_evil11.atirou == 1) { tiro_evil11.ty += 10; if(tiro_evil11.ty == 640) { tiro_evil11.atirou = 0; tiro_evil11.ty = quadinimigo11.y; } } } if ( tiro_evil11.atirou == 0) { tiro_evil11.tx = quadinimigo11.x; } if (( temp2 == 1) || (tiro_evil12.atirou == 1)) { tiro_evil12.atirou = 1; if (tiro_evil12.atirou == 1) { tiro_evil12.ty += 10;

if(tiro_evil12.ty == 640) { tiro_evil12.atirou = 0; tiro_evil12.ty = quadinimigo12.y; } } } if ( tiro_evil12.atirou == 0) { tiro_evil12.tx = quadinimigo12.x; }

// fim do codigo do tiro // Pega eventos do teclado/mouse. while(SDL_PollEvent(&event)) { // Se fechou a janela. if (event.type == SDL_QUIT) { quit = TRUE; } // Se tecla pressionada. else if( event.type == SDL_KEYDOWN ) { // Verifica tecla pressionada. switch( event.key.keysym.sym ) { case SDLK_SPACE: // Para a esquerda. tiro_nave.atirou = 1; quadImagem = IMG_Load("boneco mao alto direita.png"); break; case SDLK_LEFT: // Para a esquerda. incx = -passo; quadImagem = IMG_Load( "boneco esquerda.png" ); break; case SDLK_RIGHT: // Para a direita. incx = passo; incy = 0; quadImagem = IMG_Load( "bonecodireita.png" );

break; case SDLK_q: // para poder pausar o jogo voltar = 0; while(voltar != 1) { while(SDL_PollEvent(&event)) { if( event.type == SDL_KEYDOWN ) { // Verifica tecla pressionada. switch( event.key.keysym.sym ) { case SDLK_SPACE: voltar = 1; } } } } break; }

} // Se soltou a tecla nao anda com o objeto. else if( event.type == SDL_KEYUP ) { incx = 0; incy = 0; }

} // if criado para se a bala que no foi disparada esta na mesma pociso da nave. if( event.type == SDL_KEYDOWN ) { d1 = quad.x; } // Se dando um passo, nao passa do limite da esquerda ou direita da janela ento. if ( ((quad.x + quad.w + incx) <= screen->w) && (quad.x + incx >= 0) ) { // Move quadrado na horizontal. quad.x += incx;

} // Se dando um passo, nao passa do limite de cima e de baixo da janela ento. if (((quad.y + quad.h + incy) <= screen->h) && (quad.y + incy >= 0)) { // Move quadrado na vertical. quad.y += incy; }

// Inicio do Codigo de Coliso if (colisao(&quadinimigo1, &quadtiro) && ( evil_1.vida == 1)) { evil_1.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo2, &quadtiro) && ( evil_2.vida == 1)) { evil_2.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo3, &quadtiro) && ( evil_3.vida == 1)) { evil_3.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo4, &quadtiro) && ( evil_4.vida == 1)) { evil_4.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo5, &quadtiro) && ( evil_5.vida == 1))

{ evil_5.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo6, &quadtiro) && ( evil_6.vida == 1)) { evil_6.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo7, &quadtiro) && ( evil_7.vida == 1)) { evil_7.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo8, &quadtiro) && ( evil_8.vida == 1)) { evil_8.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo9, &quadtiro) && ( evil_9.vida == 1)) { evil_9.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo10, &quadtiro) && ( evil_10.vida == 1)) { evil_10.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; }

if (colisao(&quadinimigo11, &quadtiro) && ( evil_11.vida == 1)) { evil_11.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; } if (colisao(&quadinimigo12, &quadtiro) && ( evil_12.vida == 1)) { evil_12.vida = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; recorde_jogador += PONTOS / velocidade_morte; }

if (colisao(&quad, &tiro_evil) && ( evil_1.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil2) && ( evil_2.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil3) && ( evil_3.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil4) && ( evil_4.vida == 1)) { vida_jogador = 0;

tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil5) && ( evil_5.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil6) && ( evil_6.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil7) && ( evil_7.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil8) && ( evil_8.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil9) && ( evil_9.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil10) && ( evil_10.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600;

} if (colisao(&quad, &quad_tiro_evil11) && ( evil_11.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } if (colisao(&quad, &quad_tiro_evil12) && ( evil_12.vida == 1)) { vida_jogador = 0; tiro_nave.atirou = 0; tiro_nave.ty = 600; } // Fim do codigo de coliso

//Blit do Fundo SDL_BlitSurface( fundo, &quadFundo, screen, NULL );

if (vida_jogador == 1) { //Blit da nave do jogador SDL_BlitSurface( quadImagem, NULL, screen, &quad ); if (tiro_nave.atirou == 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quadtiro ); } } if( evil_1.vida == 1) { //Blit da nave inimiga

SDL_BlitSurface( nave, NULL, screen, &quadinimigo1 ); if (tiro_evil1.atirou == 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &tiro_evil ); } } if( evil_2.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave2, NULL, screen, &quadinimigo2 ); if (tiro_evil2.atirou == 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil2 ); } } if( evil_3.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave3, NULL, screen, &quadinimigo3 ); if (tiro_evil3.atirou== 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil3 ); } } if( evil_4.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave4, NULL, screen, &quadinimigo4 ); if (tiro_evil4.atirou== 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil4 ); } } if( evil_5.vida == 1) { //Blit da nave inimiga

SDL_BlitSurface( nave5, NULL, screen, &quadinimigo5 ); if (tiro_evil5.atirou == 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil5 ); } } if( evil_6.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave6, NULL, screen, &quadinimigo6 ); if (tiro_evil6.atirou == 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil6 ); } } if( evil_7.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave7, NULL, screen, &quadinimigo7 ); if (tiro_evil7.atirou == 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil7 ); } } if( evil_8.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave8, NULL, screen, &quadinimigo8 ); if (tiro_evil8.atirou== 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil8 ); } } if( evil_9.vida == 1) { //Blit da nave inimiga

SDL_BlitSurface( nave9, NULL, screen, &quadinimigo9 ); if (tiro_evil9.atirou== 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil9 ); } } if( evil_10.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave10, NULL, screen, &quadinimigo10 ); if (tiro_evil10.atirou == 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil10 ); } } if( evil_11.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave11, NULL, screen, &quadinimigo11 ); if (tiro_evil11.atirou == 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil11 ); } } if( evil_12.vida == 1) { //Blit da nave inimiga SDL_BlitSurface( nave12, NULL, screen, &quadinimigo12 ); if (tiro_evil12.atirou == 1) { //Blit do tiro da nave do jogador SDL_BlitSurface( Tiro, NULL, screen, &quad_tiro_evil12 ); } }

SDL_BlitSurface( nuvem, NULL, screen, &posnuvem );

SDL_Delay(17); SDL_Flip(screen);

if((evil_6.vida == 0)&&(evil_5.vida == 0)&&(evil_4.vida == 0)&&(evil_3.vida == 0) &&(evil_2.vida == 0)&&(evil_1.vida == 0)&&(evil_7.vida == 0)&&(evil_8.vida == 0)&&(evil_9.vida == 0)&&(evil_10.vida == 0)&&(evil_11.vida == 0)&&(evil_12.vida == 0)||(vida_jogador== 0)) { quit = TRUE; } }

// Fecha a biblioteca. SDL_Quit(); return recorde_jogador; }

int menu(int opcao_escolhida) { int voltar = 1; int opcoes_menu = 0; // Variaveis SDL SDL_Surface* screen; SDL_Rect quad = {0,0,20,20}; // retangulo A nasce na pos(0,0). Tem lados iguais a 64 int quit = 0; int ani_pomba = 1; int cons = 0; // Variavel que indica a saida do programa.

SDL_Event event;

// Inicializa SDL video. SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(SCREEN_W, SCREEN_H, 16, SDL_SWSURFACE); if(TTF_Init() == -1) return -1; // Carrega imagem relativa ao fundo. SDL_Surface *fundo; my_font = TTF_OpenFont("aaaa.ttf", FONTSIZE); fundo = IMG_Load ( "bg.png" ); // Diz o tamanho do retngulo da imagem SDL_Rect quadFundo = {0,0,800,600}; SDL_WM_SetCaption("Jogo UFRRJ", "Jogo"); SDL_Surface* opcao1; opcao1 = IMG_Load("Iniciar.png"); SDL_Surface* opcao2; opcao2 = IMG_Load("recordes.png"); SDL_Surface* opcao3; opcao3 = IMG_Load("sair.png"); SDL_Surface* pomba; pomba = IMG_Load ( "balo.png" );

while(!quit) { SDL_Rect quadopcao = {0,150,640,480}; SDL_Rect rcPombaOri , rcPombaDest; //inimigos SDL_SetColorKey ( pomba, SDL_SRCCOLORKEY, 0);

//pomba solitaria rcPombaOri.w = 96; //largura dos quadro rcPombaOri.h = 64; //altura dos quadros rcPombaOri.x = 0 ;//setando para o primeiro quadro rcPombaOri.y = 0; rcPombaDest = rcPombaOri; rcPombaDest.w = rcPombaOri.w; rcPombaDest.h = rcPombaOri.h;

rcPombaDest.y = 220; //animando Pomba rcPombaOri.x = ani_pomba * rcPombaOri.w; ani_pomba++; if (ani_pomba > 31)//contagem de tela na figura original { ani_pomba = 0; }

while(SDL_PollEvent(&event)) { if( event.type == SDL_KEYDOWN ) { // Verifica tecla pressionada. switch( event.key.keysym.sym ) { case SDLK_RETURN: opcao_escolhida = opcoes_menu; quit = TRUE; break; case SDLK_UP: opcoes_menu += -1; break; case SDLK_DOWN: opcoes_menu += 1; break; }

} // Se soltou a tecla nao anda com o objeto.

SDL_BlitSurface( fundo, &quadFundo, screen, NULL ); if(opcoes_menu <= 0) { rcPombaDest.x = 75; opcoes_menu = 0; SDL_BlitSurface(opcao1,NULL,screen,&quadopcao); } if(opcoes_menu == 1) { rcPombaDest.x = 5; SDL_BlitSurface(opcao2,NULL,screen,&quadopcao); } if(opcoes_menu >= 2) { rcPombaDest.x = 75; opcoes_menu = 2; SDL_BlitSurface(opcao3,NULL,screen,&quadopcao); } // mostra na tela SDL_BlitSurface ( pomba, &rcPombaOri, screen, &rcPombaDest ); //desenhando o inimigo na tela desenha_texto("Viva Sociedade Alternativa", screen, 0,465);

SDL_Flip(screen); } // Fecha a biblioteca. SDL_Quit(); return opcao_escolhida; }

int main(int argc, char** argv) { int recorde_jogador = 0; int opcao_escolhida = 0; opcao_escolhida = menu(opcao_escolhida); if (opcao_escolhida == 0) {

recorde_jogador = fase1(recorde_jogador); recorde_jogador = fase2(recorde_jogador);

} printf("%d",recorde_jogador);

return 0; }

Potrebbero piacerti anche