-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathred_lights.cpp
67 lines (51 loc) · 1.62 KB
/
red_lights.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
#include "red_lights.hpp"
#include <iostream>
// #include "JetpackJoyride.hpp"
using namespace std;
RedLights::RedLights(SDL_Renderer* rend, SDL_Texture* ast, SDL_Rect mov): Unit(rend, ast), mover(mov){
// cout<<"light created"<<endl;
src = {996,18, 40, 71};
}
void RedLights::draw(){ //draw the RedLightss
Unit::draw(src, mover); //draw the object
mover.x -=4; //move the RedLights to the left at a speed of 3 pixels
animation(); //animate the RedLights
frame++; //increment the frame
// cout<<"Red light drawn"<<endl;
}
RedLights::~RedLights(){ //destructor
// cout<<"Light destroyed"<<endl;
}
void RedLights::animation(){ //make the RedLights walk
if (frame==1*frame_speed){
src={1210,-8, 102, 102}; //selecting the image from asset file
}
else if (frame==2*frame_speed){
src = {1368,-8, 102, 102}; //selecting the image from asset file
// frame=0;
}
else if (frame==3*frame_speed){
src = {1527,-8, 102, 102}; //selecting the image from asset file
// frame=0;
}
else if (frame==4*frame_speed){
src = {1210,140, 102, 102}; //selecting the image from asset file
// frame=0;
}
else if (frame==5*frame_speed){
src = {1368,140, 102, 102}; //selecting the image from asset file
// frame=0;
}
else if (frame==6*frame_speed){
src = {1527,140, 102, 102}; //selecting the image from asset file
frame=0;
}
}
bool RedLights::delete_item(){ //to delete the lights
if (mover.x<-150){
return true;
}
else{
return false;
}
}