Jump to content

Problemas ao executar a mecânica corretamente do Pulo no Game (bgi) c++


CAIOG94

Postagens Recomendadas

"Estou com um problema na hora de executar a ação do pulo, pois quando eu aperto o botão (seta pra cima) o objeto aparece no limite da altura do pulo e desce. Já pesquisei alguns vídeos ,mas não consegui por isso em prática."

 

#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
#include<math.h>
#include<conio.h>

#define LEFT       75
#define RIGHT      77
#define UP         72
#define DOWN       80
#define ESC        27


#define QntP 3

int main()  { 
 

    int pg = 2;
      int tamC, tamN, tamN2, tamC2;
      int x, y, a=20;
      double passoX, passoY;
      char tecla = 0;
      HWND janela;
      int LarTela, AltTela;
      int LarJogo, AltJogo;
      int xIniJogo, yIniJogo;
      void *Corote[QntP];  // esta variável é um vetor dinâmico que contém o sprite
      void *CoroteM; // esta variável é um vetor dinâmico que contém a máscara
      void *fundo;
      void *fundo2;
    int FPS;
    FPS = 30;
    float CamX=0;
      float CamY=0;
    int CamT=500;
    int CamT2=0;
    int CamV=1;
    float c=0;
    bool anda = false, troca = false, jump = false, chao= false;
    int b = 0;
    int i = 0;
    int itroca = 0;
    unsigned long long gt1, gt2;
    int massa=1;

      
    
    float grav=200;
    
    
      LarTela = 800;
      AltTela = 600;
      

      initwindow(6400, AltTela, "Teste");
      tamN = imagesize(0, 0, 6400, 599);
      fundo = malloc(tamN);
      readimagefile("Mapadomario.bmp", 0, 0, 6400, 599);
      getimage(0, 0, 6400, 599, fundo);
      
      tamN2 = imagesize(0, 0, 800, 599);
      fundo2 = malloc(tamN2);
      readimagefile("Mapadomario.bmp", 0, 0, 6400, 599);
      getimage(5600, 0, 6399, 599, fundo2);
      
      closegraph();
      initwindow(LarTela, AltTela, "Teste");

    tamC2 = imagesize(0, 0, 74, 74);
      for(i = 0; i <= QntP; i++) {
        Corote[i] = malloc(tamC2);
      }
    i = 0;
    

    tamC = imagesize(0, 0, 74, 74);
      CoroteM = malloc(tamC);
  

    
     // Player
      readimagefile("circulo.bmp", 0, 0, 225, 74);
      for(i = 0; i <= QntP; i++) {
        getimage(75*i, 0, 74+75*i, 74, Corote[i]);
     }
      
      // Player
      readimagefile("circulomascara.bmp", 0, 0, 74, 74);
      getimage(0, 0, 74, 74, CoroteM);
      
  
      y = AltTela-200;
      x = 100;
    passoX = 0.5;
      passoY = 0.3;
      
      gt1 = GetTickCount();
      
      
      while(tecla != ESC) {
          
          gt2 = GetTickCount();
          if (gt2 - gt1 > 1000/FPS) { /* este if garante que o programa só desenhará no momento certo */
              gt1 = gt2;
          }    
          
        if (pg == 1) pg = 2; else pg=1;
        setactivepage(pg);
        
        cleardevice();
              
          putimage(CamX, 0, fundo, COPY_PUT);
           putimage(x, y, CoroteM, AND_PUT);
        putimage(x, y, Corote[itroca], OR_PUT);
        
        if (anda == true){
            CamX = 0;
            CamT = 750;
            
            putimage(0, 0, fundo2, COPY_PUT);
            putimage(x, y, CoroteM, AND_PUT);
            putimage(x, y, Corote[itroca], OR_PUT);
            
        }
    
        if (troca == true ){
        itroca ++;
        if (itroca >= QntP){
            itroca = 0;
        }    
    }
        
        //troca = false;
        
        
        if (jump == true){
                
                
                y= -passoY; 
        
            
                
            //    y++;
                //    y -= grav;
                
            //    y= -passoY;
                y+= passoY+y;
            //    x+=passoX+x;
                //delay(1);
                itroca = 2;
            }
            
            jump = false;
            chao = true;
            
            
            if (chao == true)
            {
                if ( y < passoY *2)
                {
                    
                //    y+= grav * massa;
                    jump = false;
                }
            }
                
        
            //    pulo=passoY+y;
        
        
    //    y += grav * massa;
    
        y+= grav;
        
        
    //    y-= grav;
    
        setvisualpage(pg);
        
        
        //define a força da gravidade
        //y += grav;
        
        // definindo colisão com a area direita da tela
         
        // Movimentação da Camera (direita)
            
        if (x > CamT ){  
            x = CamT-1; // = 700
            CamX -= CamV * a; // Movimentação da Camera    (direita)
            b ++;
            if (b == 280){
                anda = true;
            }
            
        }
        
         //definido a colisão com a area esqueda da tela
        if (x < CamT2 ){
            x = CamT2; // = 0
            //CamX += CamV * a;/    // Movimentação da Camera (esquerda)
        }
        
        // definindo a colisão com o chão
        if (y > AltTela-151 ){
            y = AltTela-150;
            
        }

        
        
        //definindo a altura maxima do pulo
        if (y < 200){
            y = 200;
        }
        gt2 = GetTickCount();
        fflush(stdin);
        if(tecla ==LEFT)  {
            x = x - passoX*a;
            
            troca= true;
        //tecla=0;
            
        
        }
        
        //if (tecla==0)
        
    //    troca=false;
            
            
            
        if(GetKeyState(VK_RIGHT)&0x80)  x = x + passoX*a;
        //troca = true;
                
       if (GetKeyState (VK_UP)&0x80&&  y == AltTela-150) {
       
        jump=true;
        
       // if (y==100)
        
        //y-= passoY+y;
        
        //y -= grav;
        
        //delay(5);
}
        
       
        
        // detecta e trata o pressionamento das teclas A, D, W, S
        if(GetKeyState(0x41)&0x80)   x = x - passoX*a;  // A
        if(GetKeyState(0x44)&0x80)   x = x + passoX*a;  // D
        if(GetKeyState(0x57)&0x80)   y = y - passoY*a;  // W
        
        
        if (kbhit()){
            tecla = getch();
            /*if (tecla == UP){
                y = y - passoY*a*a;    
                
                tecla = 0;
            }*/
        }
              
  }
  
 

  closegraph();    
  return 0; 
  

}

Testejogo2semestre.zip

Link to comment
Compartilhe em outros sites

Crie uma conta ou entre para comentar 😀

Você precisa ser um membro para deixar um comentário.

Crie a sua conta

Participe da nossa comunidade, crie sua conta.
É bem rápido!

Criar minha conta agora

Entrar

Você já tem uma conta?
Faça o login agora.

Entrar agora


×
×
  • Create New...