-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPoliceCar.cpp
81 lines (70 loc) · 1.43 KB
/
PoliceCar.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
#include "PoliceCar.hpp"
#include <iostream>
#include <SDL.h>
//draw police car
void PoliceCar::Draw()
{
SDL_RenderCopy(Drawing::gRenderer, Drawing::assets, &srcRect, &moverRect);
};
//Initialize police car values
PoliceCar::PoliceCar()
{
setmoverRect(500,50, 100, 120);
setRect(1136,27, 139,256);
direction = 1;
};
//drive police car
void PoliceCar::DriveCar()
{
//moving car left and right
if(direction ==1)
{
moverRect.x +=30;
}
else
{
moverRect.x-=30;
}
//change direction if touching boundary
if(moverRect.x<=300 || moverRect.x>=1100)
{
direction *=-1;
}
//shoot fire
fram++;
if(fram== 10)
{
Fire* f =new Fire(moverRect.x,moverRect.y);
fires.push_back(f);
fram = 0;
}
};
//return direction of police car movement
int PoliceCar::getDirection()
{
return direction;
}
//draw bullets of police car
void PoliceCar::DrawBullets(car* h)
{
for(int i=0;i<fires.size();i++)
{
fires[i]->Draw(); //draw fire
fires[i]->ShootFire(); //movement of fire
fires[i]->Mask(h); //collision with hero car
//delete fire if missed
if(fires[i]->firegone==true)
{
fires.erase(i+fires.begin());
}
}
}
//destructor of police car
PoliceCar::~PoliceCar()
{
for(int i=0;i<fires.size();i++)
{
delete fires[i];
}
fires.clear();
}