void display() { light_position[0] = xluz; light_position[1] = yluz; light_position[2] = zluz; light_position[3] = 0; glLoadIdentity(); glRotatef(rotluz, 1.0, 0.0, 0.0); glLightModelfv( GL_LIGHT_MODEL_AMBIENT, amb_light ); //glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuse ); //glLightfv( GL_LIGHT0, GL_SPECULAR, specular ); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); int k,i,j; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor4f(1,1,1,1.5); reload(); glScaled(boxsize*2,0.5,boxsize*2); drawBox(1, GL_QUADS); // paredes reload(); glTranslatef(boxsize,1,0); glScaled(0.5,2.5,boxsize*2); drawBox(1, GL_QUADS); reload(); glTranslatef(0,1,boxsize); glScaled(boxsize*2,2.5,0.5); drawBox(1, GL_QUADS); reload(); glTranslatef(-boxsize,1,0); glScaled(0.5,2.5,boxsize*2); drawBox(1, GL_QUADS); reload(); glTranslatef(0,1,-boxsize); glScaled(boxsize*2,2.5,0.5); drawBox(1, GL_QUADS); reload(); // DESENHA BOLA glPushMatrix(); colisao(&Bola); glColor4f(1,0,0,1); glTranslatef(Bola.x,Bola.y+Bola.tam,Bola.z); glRotatef(Bola.rot,Bola.rotx,Bola.roty,Bola.rotz); glutSolidSphere(Bola.tam , 10 , 10 ); glPopMatrix(); Sleep(1000/60); glutSwapBuffers(); }
void atirar(){ tiro.vida = 0; // Quando tempo ele ficara na tela? // Posicao do tiro (eixo X) tiro.py = ynave[e]; // Posicao do tiro (eixo Y) int local1 = ((ini * 125) + 15) + 30; // Define a posição inicial da colisão int local2 = (local1 + 125) - 50; // Define a posição final da colisão int i = 0; if (e == 0){ tiro.px = xnave[e] + 90; } else { if (e == 1){ tiro.px = xnave[e] + 150; } else { if (e == 2){ tiro.px = xnave[e] + 60; } } } while (tiro.vida <= 19){ blit(buffer, screen, 0,0,0,0,1280,720); //Limpa a tela clear_bitmap(buffer); //Limpa a tela draw_sprite(buffer, background[back], 0, 0); //Coloca a imagem na tela draw_sprite(screen, nave[e], xnave[e],ynave[e]); //Põe a nave na tela if (tiro.py > yini + 125){ circlefill(buffer, tiro.px, tiro.py, 5, makecol(255, 0, 0)); draw_sprite(screen, inimigo[p], xini, yini); //Põe a nave na tela } tiro.py -= 20; //Velocidade em Y (deslocamento do tiro) tiro.vida += 1; //Contador do "While" if (tiro.py <= 105){ if ((tiro.px >= local1 ) && (tiro.px <= local2 )){ colisao(); tiro.vida = 25; } else{ inimigos(); c += 1; } } if (c == 3){ draw_sprite(screen, inimigo[p], xini,yini); //Põe os inimigos na tela perdeu(); } } blit(buffer, screen, 0,0,0,0,1280,720); //Limpa a tela clear_bitmap(buffer); //Limpa a tela draw_sprite(buffer, background[back], 0, 0); //Coloca a imagem na tela draw_sprite(screen, nave[e], xnave[e],ynave[e]); //Põe a nave na tela }
/** * Main Game Logic */ void jogo() { // Buffer initialization BITMAP * buffer= create_bitmap(3*800,600); // Load background bitmap fundo = load_bitmap("..\\recursos\\fundo.bmp",NULL); // Load character sprite sheet imgpersonagem=load_bitmap("..\\recursos\\stickman.bmp", NULL); // For each frame cut the animation sheet for(int i =0;i<framesPersonagem;i++) { personagem[i] = create_bitmap(80, 140); blit(imgpersonagem, personagem[i], (i*80), 140, 0, 0, 80, 140); } // Load bomb image bomba = load_bitmap("..\\recursos\\bomba.bmp",NULL); // Load heart image coracao = load_bitmap("..\\recursos\\coracao.bmp",NULL); // Init variables int iFrame = 0; char textoPontos[40]; char textoDanos[40]; char textoDebug[40]; bool direita = true; bool pulando = false; // Init random positions xBomba = rand()%800; xCoracao = rand()%800; // Main loop while (!key[KEY_ESC]) { // Buffer clear clear(buffer); // Background blit blit(fundo,buffer,0,0,0,0,800,600); // Update counter sprintf(textoPontos,"Pontos : %d ", pontos ,xBomba,xPersonagem); textout_ex(screen,font,textoPontos,5,5,makecol(255,0,0),-1); sprintf(textoDanos,"Danos : %d ", danos); textout_ex(screen,font,textoDanos,5,20,makecol(255,0,0),-1); // Draw character if(!direita) draw_sprite_h_flip(buffer,personagem[iFrame], xPersonagem, yPersonagem); else draw_sprite(buffer,personagem[iFrame], xPersonagem, yPersonagem); // Draw bomb draw_sprite(buffer,bomba, xBomba, yBomba); if(contadorTempo % 2 ==0) { yBomba++; } if(yBomba >=450) { yBomba = 0; xBomba = rand()%750; } // Draw heart draw_sprite(buffer,coracao, xCoracao, yCoracao); if(contadorTempo % 3 ==0) { yCoracao++; } if(yCoracao >=450) { yCoracao = 0; xCoracao = rand()%750; } // Blit buffer to screen blit(buffer,screen,0,0,0,0,800,600); // Move right if(key[KEY_RIGHT] && (contadorTempo % 3 ==0) && !pulando) { iFrame++; xPersonagem++; xFundo -=1; direita = true; } // Move left if(key[KEY_LEFT] && (contadorTempo % 3 ==0) && !pulando) { iFrame++; xPersonagem--; xFundo +=1; direita = false; } // Jump if(key[KEY_SPACE] && (contadorTempo % 3 ==0) && !pulando) { yPersonagem -= 120; pulando = true; play_sample(sompulo, 255, 128, 1000, 0); } // Check animating frame if(iFrame > 4 || iFrame < 0) iFrame = 0; // Update jump if(pulando && yPersonagem < 360 && (contadorTempo % 2 ==0)) { yPersonagem += 1; } else if(pulando && yPersonagem >= 360) { pulando = false; yPersonagem = 360; } // Check bomb collision if(colisao(xBomba,yBomba,xPersonagem,yPersonagem,xPersonagem+60,yPersonagem+60) && yBomba >= yPersonagem) { play_sample(somdano, 255, 128, 1000, 0); if(pontos>0)pontos--; danos++; yBomba = 0; xBomba = rand()%750; } // Check heart collision if(colisao(xCoracao,yCoracao,xPersonagem,yPersonagem,xPersonagem+60,yPersonagem+60)&& yCoracao >= yPersonagem) { if(pulando) { pontos+=2; } else { play_sample(somponto, 255, 128, 1000, 0); pontos++; } yCoracao = 0; xCoracao = rand()%750; } } }