-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.cpp
More file actions
146 lines (123 loc) · 2.88 KB
/
Copy pathCard.cpp
File metadata and controls
146 lines (123 loc) · 2.88 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include "Card.h"
#include "RectMaths.h"
#include <string>
Card::Card(SDL_Renderer* renderer, SDL_Rect rect, SDL_Color color, int value, bool facingPlayer, bool interactable)
{
AddTexture(renderer, "textures/unoCard.png");
cardBack = IMG_LoadTexture(renderer, "textures/unoCardBack.png");
reverseIcon = IMG_LoadTexture(renderer, "textures/unoIconReverse.png");
colourWheelIcon = IMG_LoadTexture(renderer, "textures/unoIconColourWheel.png");
location = rect;
SDL_QueryTexture(texture, NULL, NULL, &location.w, &location.h);
location.w = 100;
location.h = 150;
this->color = color;
this->value = value;
this->facingPlayer = facingPlayer;
this->interactable = interactable;
std::string cardVal = std::to_string(value).c_str();
switch (value)
{
case 10:
cardVal = "+2";
break;
case 11:
cardVal = "+4";
break;
}
if (value == 13)
{
this->color = {0, 0, 0, 255};
}
text = new Text(renderer, cardVal.c_str(), 50, location, {255, 255, 255, 255});
text->CenterTexture(location);
}
Card::~Card()
{
delete text;
}
void Card::RenderCall(SDL_Renderer* renderer)
{
SDL_Rect location = this->location;
MousePos mousePos;
SDL_GetMouseState(&mousePos.x, &mousePos.y);
if (interactable && CheckMouseOver(mousePos))
{
location.y -= 30;
zOrder = 10;
}
else if (CheckMouseOver(mousePos) && zOrder == 10)
{
zOrder = 0;
}
if (!facingPlayer)
{
SDL_RenderCopy(renderer, cardBack, NULL, &location);
return;
}
// I think this is fine to hardcode
SDL_Rect colorBacking = location;
colorBacking.w -= 6;
colorBacking.h -= 6;
colorBacking.x += 3;
colorBacking.y += 3;
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, color.a);
SDL_RenderFillRect(renderer, &colorBacking);
if (SDL_RenderCopy(renderer, texture, NULL, &location) != 0)
{
SDL_LogError(0, "Failed to Render");
}
if (value == 12)
{
SDL_Rect iconLocation = {
location.x + location.w / 8,
location.y + location.h / 4,
location.h / 2,
location.h / 2
};
SDL_RenderCopy(renderer, reverseIcon, NULL, &iconLocation);
}
else if (value == 13)
{
SDL_Rect iconLocation = {
location.x + location.w / 8,
location.y + location.h / 4,
location.h / 2,
location.h / 2
};
SDL_RenderCopy(renderer, colourWheelIcon, NULL, &iconLocation);
}
else
{
// set text location incase card has been moved
text->CenterTexture(location);
text->RenderCall(renderer);
}
}
void Card::FlipCard()
{
facingPlayer = !facingPlayer;
}
bool Card::HasLinkWith(Card* card)
{
bool colorMatch = card->color.r == color.r &&
card->color.g == color.g&&
card->color.b == color.b&&
card->color.a == color.a;
bool valueMatch = card->value == value;
if (card->value == 13 || this->value == 13)
valueMatch = true;
return colorMatch || valueMatch;
}
int Card::GetValue()
{
return value;
}
void Card::OverrideColour(SDL_Color color)
{
this->color = color;
}
SDL_Color Card::GetColour()
{
return color;
}