-
Notifications
You must be signed in to change notification settings - Fork 2
/
smoke.cpp
43 lines (35 loc) · 1020 Bytes
/
smoke.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
#include "smoke.h"
Smoke::Smoke(int x, int y, RoomPlan *roomPlan): ObjectOnRoomPlan (x, y, roomPlan)
{
isSpread = false;
smokeTime = 0;
}
void Smoke::step()
{
if(!isSpread){
if(smokeTime > 5){
spread();
}
smokeTime++;
}
}
void Smoke::spread()
{
isSpread = true;
int directionRow[4] = {-1, 1, 0 , 0};
int directionCol[4] = {0, 0, 1 , -1};
int** walls = roomPlan->getRoomMatrix();
int r, c;
for (int i = 0; i < 4; i++) {
r = x / roomPlan->getCellWidth() + directionRow[i];
c = y / roomPlan->getCellWidth() + directionCol[i];
if (walls[r][c] == 0) {
if(!roomPlan->isSmokeCoordinate(r * roomPlan->getCellWidth(), c * roomPlan->getCellWidth())){
roomPlan->addSmoke(r * roomPlan->getCellWidth(), c * roomPlan->getCellWidth());
}
}
}
for (int i = 0; i < roomPlan->getWidth(); i++){
delete [] walls[i];
}
}