-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoin_counter.cpp
81 lines (58 loc) · 1.91 KB
/
coin_counter.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
#include "coin_counter.hpp"
#include <iostream>
// #include "JetpackJoyride.hpp"
using namespace std;
CoinCounter::CoinCounter(SDL_Renderer* rend, SDL_Texture* ast, SDL_Rect mov, int cnt): Unit(rend, ast), mover(mov){
cout<<"coin counter created"<<endl;
src = {682,8, 35, 54}; //constructor, calls the parent class constructor and saves data to its own attributes too
counter=cnt;
}
void CoinCounter::reposition(int x, int y){ //reposition the coin counter to the required x and y
mover.x+=x;
mover.y+=y;
mover.w=50;
mover.h=65;
}
void CoinCounter::draw(){
Unit::draw(src, mover);
if (counter==0){
src = {731,166, 23, 34}; //select the frame in the asset file
}
else if (counter==1){
src = {731,209, 23, 34}; //select the frame in the asset file
}
else if (counter==2){
src = {731,252, 23, 34}; //select the frame in the asset file
}
else if (counter==3){
src = {731,295, 23, 34}; //select the frame in the asset file
}
else if (counter==4){
src = {731,338, 23, 34}; //select the frame in the asset file
}
else if (counter==5){
src = {731,381, 23, 34}; //select the frame in the asset file
}
else if (counter==6){
src = {731,423, 23, 34}; //select the frame in the asset file
}
else if (counter==7){
src = {731,467, 23, 34}; //select the frame in the asset file
}
else if (counter==8){
src = {731,509, 23, 34}; //select the frame in the asset file
}
else if (counter==9){
src = {731,553, 23, 34}; //select the frame in the asset file
}
}
CoinCounter::~CoinCounter(){
cout<<"Coin destroyed"<<endl;
}
void CoinCounter::add(CoinCounter *obj){ //to increase the counter of the other object
obj->counter++;
// counter=0;
}
void CoinCounter::operator ++ ( ){ //overloaded operator
counter++;
}