elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Recuerda que debes registrarte en el foro para poder participar (preguntar y responder)


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / Problema identificar teclas preisonadas (Solucionado) en: 27 Octubre 2010, 01:25 am
Hola, estoy aprendiendo a programar en C y queria hacer un jueguito pero tengo un problema con el movimiento que derrepente se hecha  a perder, le meti fflush por todas partes y ni asi se arreglo, xdd, asi que no he seguido avanzando. Por favor si alguien lo puede revisar y hecharme una manito :).

(Como hago un spoiler?? :D?)


Este es el codigo.

Código
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <windows.h>
  4. #include <conio.h>
  5.  
  6.  
  7. struct nave{
  8.       char sprite;
  9.       int x, y;
  10.       };
  11.  
  12. int main(){
  13.    int i, j, b=3;
  14.    char a[20][20];
  15.    char c;
  16.  
  17. start:
  18. struct nave nave1;
  19.       nave1.sprite=1;
  20.       nave1.x=9;
  21.       nave1.y=9;
  22.  
  23. struct nave nave2;
  24.       nave2.sprite=2;
  25.       nave2.x=3;
  26.       nave2.y=3;
  27.  
  28. while(b!=0){
  29.    for(i=0; i<20;i++){
  30.             for(j=0; j<20; j++){
  31.                      if(i==nave1.y && j==nave1.x && i==nave2.y && j==nave2.x){
  32.                           b--;
  33.                           system("cls");
  34.                           goto start;
  35.                           }
  36.                      else if(i==nave1.y && j==nave1.x){
  37.                                    a[i][j]=nave1.sprite;
  38.                                    }
  39.                      else if(i==nave2.y && j==nave2.x){
  40.                                    a[i][j]=nave2.sprite;
  41.                                    }
  42.  
  43.                      else{
  44.                           a[i][j]=' ';
  45.                           }
  46.  
  47.                            printf("%c ", a[i][j]);
  48.                            }
  49.                            printf("\n");
  50.                            }
  51.                            printf("\nVidas: %i\n", b);
  52.  
  53.  
  54.                           system("pause");           //probe con getch() pero agrava el bug
  55.  
  56.                           if(GetKeyState(38))        //37-40 son las flechitas
  57.                           if(nave1.y>0)
  58.                           nave1.y=nave1.y-1;
  59.  
  60.                           if(GetKeyState(40))
  61.                           if(nave1.y<19)
  62.                           nave1.y=nave1.y+1;
  63.  
  64.                           if(GetKeyState(37))
  65.                           if(nave1.x>0)
  66.                           nave1.x=nave1.x-1;
  67.  
  68.                           if(GetKeyState(39))
  69.                           if(nave1.x<19)
  70.                           nave1.x=nave1.x+1;
  71.  
  72.  
  73.                      system("cls");                    
  74. }
  75. printf("\t\t\tGAME OVER!\n\n");
  76.  
  77. system("pause");
  78. return 0;
  79. }
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines