Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <c2d2\chien2d2.h>
- bool quit;
- int heroi;
- int xHeroi;
- int yHeroi;
- int quadroHeroi;
- int indHeroi;
- int tempo;
- /*
- int heroi2;
- int xHeroi2;
- int yHeroi2;
- int quadroHeroi2;
- int indHeroi2;
- int tempo2;
- */
- #pragma comment(lib, "SDL.lib")
- #pragma comment(lib, "SDLMain.lib")
- #pragma comment(lib, "SDL_image.lib")
- #pragma comment(lib, "SDL_mixer.lib")
- #pragma comment(lib, "opengl32.lib")
- #pragma comment(lib, "glu32.lib")
- #pragma comment(lib, "c2d2.lib")
- #pragma comment(lib, "ca2.lib")
- int animacaoDireita[] = {0, 1, 2, 1};
- int animacaoEsquerda[] = {3, 4, 5, 4 };
- int animacaoCima[] = {6,7,8,6};
- int animacaoBaixo[] = {9,10,11,9};
- int animacaoMorre[] = { 12 };
- /* char 2
- int animacaoDireita2[] = { 9, 10, 11, 9 };
- int animacaoEsquerda2[] = { 6, 7, 8, 6 };
- int animacaoCima2[] = { 3, 4, 5, 3 };
- int animacaoBaixo2[] = { 0, 1, 2, 0 };
- */
- bool inicializar()
- {
- if (!C2D2_Inicia(800, 600, C2D2_JANELA,
- C2D2_DESENHO_OPENGL, "Game"))
- {
- return false;
- }
- heroi = C2D2_CarregaSpriteSet("mundo/imagens/darkphoenix.png", 32, 42);
- xHeroi = 400;
- yHeroi = 300;
- quadroHeroi = 0;
- tempo = 0;
- indHeroi = 0;
- /* heroi2 = C2D2_CarregaSpriteSet("mundo/imagens/atriz.png", 32, 64);
- xHeroi2 = 500;
- yHeroi2 = 300;
- quadroHeroi2 = 0;
- tempo2 = 0;
- indHeroi2 = 0;
- */
- return true;
- }
- //5 pixels a cada quadro.
- //60 quadros por segundo
- //velocidade = 5 * 60 = 300 pixels por segundo
- void atualizar()
- {
- C2D2_Botao* teclas = C2D2_PegaTeclas();
- if (teclas[C2D2_ESC].pressionado ||
- teclas[C2D2_ENCERRA].pressionado)
- {
- quit = true;
- }
- if (teclas[C2D2_DIREITA].ativo)
- {
- tempo++;
- if (tempo > 6)
- {
- tempo = 0;
- indHeroi = (indHeroi+1) % 4;
- }
- xHeroi += 5;
- quadroHeroi = animacaoDireita[indHeroi];
- }
- else if (teclas[C2D2_ESQUERDA].ativo)
- {
- tempo++;
- if (tempo > 6)
- {
- tempo = 0;
- indHeroi = (indHeroi+1) % 4;
- }
- xHeroi -= 5;
- quadroHeroi = animacaoEsquerda[indHeroi];
- }
- if (teclas[C2D2_CIMA].ativo)
- {
- tempo++;
- if (tempo > 6)
- {
- tempo = 0;
- indHeroi = (indHeroi + 1) % 4;
- }
- yHeroi -= 5;
- quadroHeroi = animacaoCima[indHeroi];
- }
- else if (teclas[C2D2_BAIXO].ativo)
- {
- tempo++;
- if (tempo > 6)
- {
- tempo = 0;
- indHeroi = (indHeroi + 1) % 4;
- }
- yHeroi += 5;
- quadroHeroi = animacaoBaixo[indHeroi];
- }
- else if (teclas[C2D2_ESPACO].ativo)
- {
- tempo++;
- if (tempo > 6)
- {
- tempo = 0;
- indHeroi = (indHeroi + 1) % 4;
- }
- quadroHeroi = animacaoMorre[indHeroi];
- }
- // char 2
- /* if (teclas[C2D2_D].ativo)
- {
- tempo2++;
- if (tempo2 > 6)
- {
- tempo2 = 0;
- indHeroi2 = (indHeroi2 + 1) % 4;
- }
- xHeroi2 += 5;
- quadroHeroi2 = animacaoDireita2[indHeroi2];
- }
- else if (teclas[C2D2_A].ativo)
- {
- tempo2++;
- if (tempo2 > 6)
- {
- tempo2 = 0;
- indHeroi2 = (indHeroi2 + 1) % 4;
- }
- xHeroi2 -= 5;
- quadroHeroi2 = animacaoEsquerda2[indHeroi2];
- }
- if (teclas[C2D2_W].ativo)
- {
- tempo2++;
- if (tempo2 > 6)
- {
- tempo2 = 0;
- indHeroi2 = (indHeroi2 + 1) % 4;
- }
- yHeroi2 -= 5;
- quadroHeroi2 = animacaoCima2[indHeroi2];
- }
- else if (teclas[C2D2_S].ativo)
- {
- tempo2++;
- if (tempo2 > 6)
- {
- tempo2 = 0;
- indHeroi2 = (indHeroi2 + 1) % 4;
- }
- yHeroi2 -= -5;
- quadroHeroi2 = animacaoBaixo2[indHeroi2];
- }
- */
- //########### função para char seguir o mouse
- //C2D2_Mouse* mouse = C2D2_PegaMouse();
- //xHeroi = mouse->x;
- //yHeroi = mouse->y;
- }
- void desenhar()
- {
- C2D2_LimpaTela();
- C2D2_DesenhaSprite(heroi, quadroHeroi, xHeroi, yHeroi);
- //C2D2_DesenhaSprite(heroi2, quadroHeroi2, xHeroi2, yHeroi2);
- }
- void finalizar()
- {
- C2D2_Encerra();
- }
- int main(int argc, char* argv[])
- {
- quit = false;
- if (!inicializar())
- {
- return 1;
- }
- do
- {
- atualizar();
- desenhar();
- C2D2_Sincroniza(C2D2_FPS_PADRAO);
- } while (!quit);
- finalizar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement