-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoal.cpp
101 lines (90 loc) · 2.63 KB
/
Goal.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
#include "Goal.h"
Goal::Goal(sf::Image* img1, sf::Image* img2, int goalPosition, int column) : ColumnObject(img1, column) {
newSize = size;
hitFrames = 0;
okFrames = 0;
rotateFrames = 0;
altSprite.SetImage(*img2);
size = img2->GetHeight();
altSprite.SetCenter(size / 2, size / 2);
switch (column) {
case 0:
altSprite.SetColor(sf::Color(255, 100, 0, 255));
break;
case 1:
altSprite.SetColor(sf::Color(0, 0, 255, 255));
break;
case 2:
altSprite.SetColor(sf::Color(0, 255, 0, 255));
break;
case 3:
altSprite.SetColor(sf::Color(255, 0, 0, 255));
break;
case 4:
altSprite.SetColor(sf::Color(255, 255, 0, 255));
break;
case 5:
altSprite.SetColor(sf::Color(0, 255, 255, 255));
break;
case 6:
altSprite.SetColor(sf::Color(255, 255, 255, 255));
break;
case 7:
altSprite.SetColor(sf::Color(128, 0, 128, 255));
break;
default:
break;
}
if (column < NUM_COLUMNS_LEFT) {
sprite.SetPosition(vec2((column + 1) * COLUMN_WIDTH, goalPosition));
altSprite.SetPosition(vec2((column + 1) * COLUMN_WIDTH, goalPosition));
} else {
sprite.SetPosition(vec2(1.f * WINDOW_WIDTH - (NUM_COLUMNS - column) * COLUMN_WIDTH, goalPosition));
altSprite.SetPosition(vec2(1.f * WINDOW_WIDTH - (NUM_COLUMNS - column) * COLUMN_WIDTH, goalPosition));
}
}
void Goal::draw(sf::RenderTarget* target) {
// Resize the Goal depending on which frame of the animation it's in.
if (hitFrames > HIT_FRAMES / 2) {
newSize += HIT_RATIO / HIT_FRAMES * size;
hitFrames--;
} else if (hitFrames > 0) {
newSize -= HIT_RATIO / HIT_FRAMES * size;
hitFrames--;
} else if (okFrames > OK_FRAMES/ 2) {
newSize -= OK_RATIO / OK_FRAMES * size;
okFrames--;
} else if (okFrames > 0) {
newSize += OK_RATIO / OK_FRAMES * size;
okFrames--;
}
int rotate = 0;
if (rotateFrames > 0) {
rotate = 90 / ROTATE_FRAMES;
rotateFrames --;
}
if (rotate != 0) {
sprite.Rotate(rotate);
}
if (hitFrames > 0) {
altSprite.Resize(newSize, newSize);
target->Draw(altSprite);
} else {
sprite.Resize(newSize, newSize);
target->Draw(sprite);
}
}
void Goal::goalHit(bool good) {
// This sets the frame limit for the Goal bounce animation.
if (hitFrames == 0 && okFrames == 0) {
if (good)
hitFrames = HIT_FRAMES;
else
okFrames = OK_FRAMES;
}
}
void Goal::goalMiss() {
if (rotateFrames == 0) {
rotateFrames = ROTATE_FRAMES;
}
}