-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ghost.cpp
149 lines (137 loc) · 3.14 KB
/
Ghost.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//Group Names: ABDELRAHMAN SAID, MOSTAFA IBRAHIM, MOHAMED FAKHERLDIN
#include "Ghost.h"
Ghost::Ghost(int row, int col, int xIndex, int yIndex)
{
ghostTexture.loadFromFile("Ghost spritesheet.png");
currentRow = row;
currentColumn = col;
width = 28 / 2;
height = 280 / 20;
x = xIndex;
y = yIndex;
isFrightMode = false;
enemy.setTexture(ghostTexture);
enemy.setTextureRect(IntRect(width * x, height * y, width, height));
enemy.setScale(3.0f, 3.0f);
enemy.setPosition(20 + 48 * currentColumn, 20 + 48 * currentRow);
}
void Ghost::move(char direction, int yIndex, bool standable) //direction is a random number from 1 to 4, 1:up, 2:down, 3:right, 4:left
{
if (direction == 'U' || direction == 'u')
{
if (standable)
{
currentRow--;
enemy.move(0, -48);
if (isFrightMode == false)
{
x++;
x = x % 2;
enemy.setTextureRect(IntRect(width * x, height * yIndex, width, height));
}
else
enemy.setTextureRect(IntRect(width * 0, height * 18, width, height));
}
}
else if (direction == 'D' || direction == 'd')
{
if (standable)
{
currentRow++;
enemy.move(0, 48);
//Animation Handeling.
if (isFrightMode == false)
{
x++;
x = x % 2;
enemy.setTextureRect(IntRect(width * x, height * yIndex, width, height));
}
else
enemy.setTextureRect(IntRect(width * 0, height * 18, width, height));
}
}
else if (direction == 'R' || direction == 'r')
{
if (currentRow == 10 && currentColumn >= 16)
{
enemy.setPosition(20 + 48 * 0, 20 + 48 * 10); //10 is the index of the other portal
currentColumn = 0;
return;
}
if (standable)
{
currentColumn++;
enemy.move(48, 0);
//Animation Handeling
if (isFrightMode == false)
{
x++;
x = x % 2;
enemy.setTextureRect(IntRect(width * x, height * yIndex, width, height));
}
else
enemy.setTextureRect(IntRect(width * 0, height * 18, width, height));
}
}
else if (direction == 'L' || direction == 'l')
{
if (currentRow == 10 && currentColumn == 0)
{
enemy.setPosition(20 + 48 * 16, 20 + 48 * 10); //10 is the index of the other portal
currentColumn = 16;
return;
}
if (standable)
{
currentColumn--;
enemy.move(-48, 0);
//Animation Handeling
if (isFrightMode == false)
{
x++;
x = x % 2;
enemy.setTextureRect(IntRect(width * x, height * yIndex, width, height));
}
else
enemy.setTextureRect(IntRect(width * 0, height * 18, width, height));
}
}
}
Sprite Ghost::getEnemy() const
{
return enemy;
}
int Ghost::getCurrentRow() const
{
return currentRow;
}
int Ghost::getCurrentColumn() const
{
return currentColumn;
}
void Ghost::resetPosition()
{
currentRow = currentColumn = 8;
enemy.setPosition(20 + 48 * currentColumn, 20 + 48 * currentRow);
}
void Ghost::drawOnBoard(RenderWindow& window)
{
window.draw(enemy);
}
void Ghost::frightModeOn()
{
//cout << "fright mode called" << endl;
enemy.setTextureRect(IntRect(width * 0, height * 18, width, height));
}
void Ghost::frightModeOff()
{
enemy.setTextureRect(IntRect(width * x, height * y, width, height));
}
void Ghost::setFrightMode(bool flag)
{
isFrightMode = flag;
}
bool Ghost::getFrightMode() const
{
return isFrightMode;
}