This repository has been archived by the owner on Jun 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBullet.cpp
122 lines (114 loc) · 4.08 KB
/
Bullet.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "Bullet.hpp"
Bullet::Bullet(int x, int y, int dir, char look, bool from){
this->x = x; //posizione di partenza del proiettile
this->y = y;
if(dir>=0 && dir<=3){ this->dir = dir; } else{ this->dir = 0; }
this->look = look;
this->from = from;
}
int Bullet::move_bul(Map& mappa){
int collision = 0;
char next_char = ' ';
if(this->dir == 0 ){
if(mappa.isEmpty((this->x) + 1, this->y) && !mappa.isMoney((this->x) + 1, this->y)){
this->x+=1;
}
else if((mappa.isMoney((this->x) + 1, this->y) || (mappa.isMonster((this->x) + 1, this->y) && this->from)) && mappa.isEmpty((this->x) + 2, this->y)){
this->x+=2;
}
else if((mappa.isMoney((this->x) + 1, this->y) || (mappa.isMonster((this->x) + 1, this->y) && this->from)) && !mappa.isEmpty((this->x) + 2, this->y)){
next_char = mappa.getMapChar(this->y, (this->x)+2);
}
else {
next_char = mappa.getMapChar(this->y, (this->x)+1);
}
}
else if(this->dir == 1 ){
if(mappa.isEmpty(this->x, (this->y) + 1) && !mappa.isMoney(this->x, (this->y) + 1)){
this->y += 1;
}
else if((mappa.isMoney(this->x, (this->y) + 1) || (mappa.isMonster(this->x, (this->y) + 1) && this->from)) && mappa.isEmpty(this->x, (this->y) + 2)){
this->y += 2;
}
else if((mappa.isMoney(this->x, (this->y) + 1) || (mappa.isMonster(this->x, (this->y) + 1) && this->from)) && !mappa.isEmpty(this->x, (this->y) + 2)){
next_char = mappa.getMapChar((this->y) + 2, this->x);
}
else{
next_char = mappa.getMapChar((this->y) + 1, this->x);
}
}
else if(this->dir == 2 ){
if(mappa.isEmpty((this->x) - 1, this->y) && !mappa.isMoney((this->x) - 1, this->y)){
this->x -= 1;
}
else if((mappa.isMoney((this->x) - 1, this->y) || (mappa.isMonster((this->x) - 1, this->y)) && this->from) && mappa.isEmpty((this->x) - 2, this->y)){
this->x -= 2;
}
else if((mappa.isMoney((this->x) - 1, this->y) || (mappa.isMonster((this->x) - 1, this->y)) && this->from) && !mappa.isEmpty((this->x) - 2, this->y)){
next_char = mappa.getMapChar(this->y, (this->x) - 2);
}
else {
next_char = mappa.getMapChar(this->y, (this->x) - 1);
}
}
else if(this->dir == 3 ){
if(mappa.isEmpty(this->x, (this->y) - 1) && !mappa.isMoney(this->x, (this->y) - 1)){
this->y -= 1;
}
else if((mappa.isMoney(this->x, (this->y)-1) || (mappa.isMonster(this->x, (this->y)-1) && this->from)) && mappa.isEmpty(this->x, (this->y) - 2)){
this->y -= 2;
}
else if((mappa.isMoney(this->x, (this->y) - 1)|| (mappa.isMonster(this->x, (this->y)-1) && this->from)) && !mappa.isEmpty(this->x, (this->y) - 2)){
next_char = mappa.getMapChar((this->y)-2, this->x);
}
else{
next_char = mappa.getMapChar((this->y)-1, this->x);
}
}
if(next_char == '/' || next_char == '[' || next_char == ']')
collision = 1;
else if(next_char >= 'A' && next_char <= 'Z' || next_char >= 'a' && next_char <= 'z'){
if(this->from == 0)
collision = 3;
else
collision = 1;
}
else if(next_char == '1')
collision = 2;
return(collision);
}
int Bullet::getX(){
return this->x;
}
int Bullet::getY(){
return this->y;
}
char Bullet::getLook(){
return this->look;
}
int Bullet::getDir(){
return this->dir;
}
bool Bullet::getFrom(){
return this->from;
}
//codice lista proiettile
pbul new_bullet(pbul lista, Bullet b){
pbul tmp = new blist;
tmp->bul = b;
tmp->next = lista;
lista = tmp;
return lista;
}
pbul search_bullet_by_xy(pbul lista_proiettili, int x, int y){
pbul tmp = lista_proiettili;
bool found = false;
while(!found && tmp != NULL){
if(tmp->bul.getX() == x && tmp->bul.getY() == y){
found = true;
}
else
tmp = tmp->next;
}
return tmp;
}