-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTarget.cpp
78 lines (67 loc) · 2.18 KB
/
Target.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
#include <stdlib.h>
#include <stdio.h>
#include "Target.h"
Target::Target(sf::Image* img, sf::Image* img2, int speed, int column, int offset, bool special) : ColumnObject(img, column) {
this->speed = speed;
this->special = special;
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, -(size + offset)));
altSprite.SetPosition(vec2((column + 1) * COLUMN_WIDTH, -(size + offset)));
} else {
sprite.SetPosition(vec2(1.f * WINDOW_WIDTH - (NUM_COLUMNS - column) * COLUMN_WIDTH, -(size + offset)));
altSprite.SetPosition(vec2(1.f * WINDOW_WIDTH - (NUM_COLUMNS - column) * COLUMN_WIDTH, -(size + offset)));
}
}
void Target::update(float elapsedTime) {
vec2 pos = getPosition();
altSprite.SetPosition(pos.x, pos.y + elapsedTime * speed);
sprite.SetPosition(pos.x, pos.y + elapsedTime * speed);
}
void Target::draw(sf::RenderTarget* target) {
if (special) {
target->Draw(altSprite);
} else {
target->Draw(sprite);
}
}
float Target::hitCheck(Goal* goal) {
float dist = abs(goal->getPosition().y - getPosition().y);
if(dist <= MAX_HIT_DISTANCE) {
return 100.0 - dist / MAX_HIT_DISTANCE * 100.0;
}
return -1;
}
bool Target::isSpecial() {
return special;
}