Advertisement
GreMendes

C2D2 2 chars anda diagonal

Aug 8th, 2014
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.92 KB | None | 0 0
  1. #include <c2d2\chien2d2.h>
  2.  
  3. bool quit;
  4. int heroi;
  5. int xHeroi;
  6. int yHeroi;
  7. int quadroHeroi;
  8. int indHeroi;
  9. int tempo;
  10.  
  11.  
  12. /*
  13. int heroi2;
  14. int xHeroi2;
  15. int yHeroi2;
  16. int quadroHeroi2;
  17. int indHeroi2;
  18. int tempo2;
  19. */
  20.  
  21.  
  22. #pragma comment(lib, "SDL.lib")
  23. #pragma comment(lib, "SDLMain.lib")
  24. #pragma comment(lib, "SDL_image.lib")
  25. #pragma comment(lib, "SDL_mixer.lib")
  26. #pragma comment(lib, "opengl32.lib")
  27. #pragma comment(lib, "glu32.lib")
  28. #pragma comment(lib, "c2d2.lib")
  29. #pragma comment(lib, "ca2.lib")
  30.  
  31.  
  32. int animacaoDireita[] = {0, 1, 2, 1};
  33. int animacaoEsquerda[] = {3, 4, 5, 4 };
  34. int animacaoCima[] = {6,7,8,6};
  35. int animacaoBaixo[] = {9,10,11,9};
  36. int animacaoMorre[] = { 12 };
  37.  
  38.  
  39. /* char 2
  40.  
  41. int animacaoDireita2[] = { 9, 10, 11, 9 };
  42. int animacaoEsquerda2[] = { 6, 7, 8, 6 };
  43. int animacaoCima2[] = { 3, 4, 5, 3 };
  44. int animacaoBaixo2[] = { 0, 1, 2, 0 };
  45. */
  46.  
  47.  
  48. bool inicializar()
  49. {
  50.     if (!C2D2_Inicia(800, 600, C2D2_JANELA,
  51.         C2D2_DESENHO_OPENGL, "Game"))
  52.     {
  53.         return false;
  54.     }
  55.  
  56.     heroi = C2D2_CarregaSpriteSet("mundo/imagens/darkphoenix.png", 32, 42);
  57.     xHeroi = 400;
  58.     yHeroi = 300;
  59.     quadroHeroi = 0;
  60.     tempo = 0;
  61.     indHeroi = 0;
  62.  
  63. /*  heroi2 = C2D2_CarregaSpriteSet("mundo/imagens/atriz.png", 32, 64);
  64.     xHeroi2 = 500;
  65.     yHeroi2 = 300;
  66.     quadroHeroi2 = 0;
  67.     tempo2 = 0;
  68.     indHeroi2 = 0;
  69.     */
  70.     return true;
  71. }
  72.  
  73. //5 pixels a cada quadro.
  74. //60 quadros por segundo
  75. //velocidade = 5 * 60 = 300 pixels por segundo
  76. void atualizar()
  77. {
  78.     C2D2_Botao* teclas = C2D2_PegaTeclas();
  79.     if (teclas[C2D2_ESC].pressionado ||
  80.         teclas[C2D2_ENCERRA].pressionado)
  81.     {
  82.         quit = true;
  83.     }
  84.  
  85.     if (teclas[C2D2_DIREITA].ativo)
  86.     {
  87.         tempo++;
  88.         if (tempo > 6)
  89.         {
  90.             tempo = 0;
  91.             indHeroi = (indHeroi+1) % 4;
  92.         }
  93.  
  94.        
  95.         xHeroi += 5;
  96.         quadroHeroi = animacaoDireita[indHeroi];
  97.     }
  98.     else if (teclas[C2D2_ESQUERDA].ativo)
  99.     {
  100.         tempo++;
  101.         if (tempo > 6)
  102.         {
  103.             tempo = 0;
  104.             indHeroi = (indHeroi+1) % 4;
  105.         }
  106.  
  107.         xHeroi -= 5;
  108.         quadroHeroi = animacaoEsquerda[indHeroi];
  109.     }
  110.    
  111.    
  112.      if (teclas[C2D2_CIMA].ativo)
  113.     {
  114.         tempo++;
  115.         if (tempo > 6)
  116.         {
  117.             tempo = 0;
  118.             indHeroi = (indHeroi + 1) % 4;
  119.         }
  120.  
  121.         yHeroi -= 5;
  122.         quadroHeroi = animacaoCima[indHeroi];
  123.     }
  124.  
  125.     else if (teclas[C2D2_BAIXO].ativo)
  126.     {
  127.         tempo++;
  128.         if (tempo > 6)
  129.         {
  130.             tempo = 0;
  131.             indHeroi = (indHeroi + 1) % 4;
  132.         }
  133.  
  134.         yHeroi += 5;
  135.         quadroHeroi = animacaoBaixo[indHeroi];
  136.     }
  137.     else if (teclas[C2D2_ESPACO].ativo)
  138.     {
  139.         tempo++;
  140.         if (tempo > 6)
  141.         {
  142.             tempo = 0;
  143.             indHeroi = (indHeroi + 1) % 4;
  144.         }
  145.  
  146.             quadroHeroi = animacaoMorre[indHeroi];
  147.     }
  148.    
  149.  
  150.     //   char 2
  151.  
  152. /*  if (teclas[C2D2_D].ativo)
  153.     {
  154.         tempo2++;
  155.         if (tempo2 > 6)
  156.         {
  157.             tempo2 = 0;
  158.             indHeroi2 = (indHeroi2 + 1) % 4;
  159.         }
  160.  
  161.  
  162.         xHeroi2 += 5;
  163.         quadroHeroi2 = animacaoDireita2[indHeroi2];
  164.     }
  165.     else if (teclas[C2D2_A].ativo)
  166.     {
  167.         tempo2++;
  168.         if (tempo2 > 6)
  169.         {
  170.             tempo2 = 0;
  171.             indHeroi2 = (indHeroi2 + 1) % 4;
  172.         }
  173.  
  174.         xHeroi2 -= 5;
  175.         quadroHeroi2 = animacaoEsquerda2[indHeroi2];
  176.     }
  177.     if (teclas[C2D2_W].ativo)
  178.     {
  179.         tempo2++;
  180.         if (tempo2 > 6)
  181.         {
  182.             tempo2 = 0;
  183.             indHeroi2 = (indHeroi2 + 1) % 4;
  184.         }
  185.  
  186.         yHeroi2 -= 5;
  187.         quadroHeroi2 = animacaoCima2[indHeroi2];
  188.     }
  189.     else if (teclas[C2D2_S].ativo)
  190.     {
  191.         tempo2++;
  192.         if (tempo2 > 6)
  193.         {
  194.             tempo2 = 0;
  195.             indHeroi2 = (indHeroi2 + 1) % 4;
  196.         }
  197.  
  198.         yHeroi2 -= -5;
  199.         quadroHeroi2 = animacaoBaixo2[indHeroi2];
  200.     }
  201.  
  202.  
  203.  
  204.     */
  205.  
  206.     //########### função para char seguir o mouse
  207.     //C2D2_Mouse* mouse = C2D2_PegaMouse();
  208.     //xHeroi = mouse->x;
  209.     //yHeroi = mouse->y;
  210. }
  211.  
  212. void desenhar()
  213. {
  214.     C2D2_LimpaTela();
  215.     C2D2_DesenhaSprite(heroi, quadroHeroi, xHeroi, yHeroi);
  216.     //C2D2_DesenhaSprite(heroi2, quadroHeroi2, xHeroi2, yHeroi2);
  217. }
  218.  
  219. void finalizar()
  220. {
  221.    
  222.     C2D2_Encerra();
  223. }
  224.  
  225. int main(int argc, char* argv[])
  226. {
  227.     quit = false;
  228.     if (!inicializar())
  229.     {
  230.         return 1;
  231.     }
  232.  
  233.     do
  234.     {
  235.         atualizar();
  236.         desenhar();
  237.         C2D2_Sincroniza(C2D2_FPS_PADRAO);
  238.     } while (!quit);
  239.  
  240.     finalizar();
  241.  
  242.     return 0;
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement