-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPacman.cpp
104 lines (81 loc) · 2.37 KB
/
Pacman.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_image.h>
#include <allegro5/keyboard.h>
#include "Pacman.h"
#include <stdio.h>
#include <iostream>
using namespace std;
Pacman::Pacman(){
//posicao inicial pacman
pos_x = (LARGURA_TABULEIRO/2-(LARGURA_PACMAN/2));
pos_y = ((ALTURA_TABULEIRO/2-(ALTURA_PACMAN/2))+ALTURA_PACMAN);
DESLOCAMENTO = 5;
direcao = PARADO;
intencao = SEM_INTENCAO;
nome_imagem = "./imagenstrab/sprites2.png";
}
int Pacman::coleta_pilula(Labirinto *lab)
{
int indiceX = (pos_x + (LARGURA_PACMAN / 2)) / LARGURA_PACMAN;
int indiceY = (pos_y + (ALTURA_PACMAN / 2)) / ALTURA_PACMAN;
if (lab->matriz_colisao[indiceY][indiceX] == PILULA)
{
lab->matriz_colisao[indiceY][indiceX] = CELULA_VAZIA;
return 1;
}
return 0;
}
void Pacman::exibe_pacman(){
sprite_personagem = al_load_bitmap(nome_imagem);
al_draw_bitmap_region(sprite_personagem, LARGURA_PACMAN*(int)frame, current_frame_y, LARGURA_PACMAN, ALTURA_PACMAN, pos_x ,pos_y,0);
altera_frame_pacman();
}
void Pacman::move_pacman(Labirinto lab){
if(intencao == SEM_INTENCAO && direcao == PARADO){
return;
}
if(intencao == DIREITA && colidiu_direita_tijolo(lab)){
direcao = intencao;
}
if(intencao == ESQUERDA && colidiu_esquerda_tijolo(lab)){
direcao = intencao;
}
if(intencao == CIMA && colidiu_cima_tijolo(lab)){
direcao = intencao;
}
if(intencao == BAIXO && colidiu_baixo_tijolo(lab)){
direcao = intencao;
}
if(direcao == DIREITA){
direcao = colidiu_direita_tijolo(lab);
if(direcao != PARADO){
current_frame_y = 0;
pos_x+=DESLOCAMENTO;
}
}else if(direcao == ESQUERDA){
direcao =colidiu_esquerda_tijolo(lab);
if(direcao != PARADO){
current_frame_y = ALTURA_PACMAN;
pos_x-= DESLOCAMENTO;
}
}else if(direcao == BAIXO){
direcao =colidiu_baixo_tijolo(lab);
if(direcao != PARADO){
current_frame_y = ALTURA_PACMAN*3;
pos_y+=DESLOCAMENTO;
}
}else if(direcao == CIMA){
direcao = colidiu_cima_tijolo(lab);
if(direcao != PARADO) {
current_frame_y = ALTURA_PACMAN*2;
pos_y-= DESLOCAMENTO;
}
}
}
void Pacman::altera_frame_pacman(){
frame += 0.2f;
if(frame > 2){
frame -= 2;
}
}