Advertisement
arthurassuncao

Animacao em C

Oct 9th, 2011
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio2.h>
  4. //#include <conio.h>
  5. //Poderia melhorar usando varias coisas, uma delas eh a funcao toupper do CTYPE.H
  6.  
  7. #define ENTER 13
  8. #define UM_SEGUNDO 1000000
  9.  
  10. int main()
  11. {
  12.     char tecla='d';
  13.     int x=40;
  14.     int y=10;
  15.     while (tecla!=13)
  16.     {
  17.         gotoxy(x,y); //posiciona o "cursor" nas coordenadas x,y
  18.         printf("@");
  19.         if (kbhit()) //retorna 1 se a pessoa pressionou algo
  20.         {
  21.             tecla=(char)getch();
  22.         }
  23.         switch (tecla)
  24.         {
  25.             case 'd':x++;break;
  26.             case 'a':x--;break;
  27.             case 'w':y--;break;
  28.             case 's':y++;break;
  29.         }
  30.         gotoxy(1,25); //Fim da tela
  31.         usleep(UM_SEGUNDO/10); //gera um atraso
  32.     }
  33.     return 0;
  34. }
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement