-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardScript.cpp
More file actions
84 lines (67 loc) · 1.92 KB
/
Copy pathCardScript.cpp
File metadata and controls
84 lines (67 loc) · 1.92 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
#include "CardScript.h"
void CardScript::tickScript(float deltaTime) {
ComponentHandle<Transform> transform = entity->get<Transform>();
ComponentHandle<BoxCollider> collider = entity->get<BoxCollider>();
ComponentHandle<Sprite> sprite = entity->get<Sprite>();
if (sprite->visible) {
if (!flipped) {
if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS) {
double mouseX, mouseY;
glfwGetCursorPos(window, &mouseX, &mouseY);
if (mouseX >= transform->position.x - collider->width / 2.0f && mouseX <= transform->position.x + collider->width / 2.0f &&
mouseY >= transform->position.y - collider->height / 2.0f && mouseY <= transform->position.y + collider->height / 2.0f) {
//cout << "Click Card " << (ypos * 4) + xpos << endl;
flipCard();
}
}
}
}
}
void CardScript::assignIdAndPos(int numId, int xpos, int ypos) {
id = numId;
this->xpos = xpos;
this->ypos = ypos;
}
void CardScript::flipCard() {
ComponentHandle<Sprite> sprite = entity->get<Sprite>();
switch (id) {
case 0:
sprite->filepath = "Textures/science_dog.png";
break;
case 1:
sprite->filepath = "Textures/meme_id_1.png";
break;
case 2:
sprite->filepath = "Textures/meme_id_2.png";
break;
case 3:
sprite->filepath = "Textures/meme_id_3.png";
break;
case 4:
sprite->filepath = "Textures/meme_id_4.png";
break;
case 5:
sprite->filepath = "Textures/meme_id_5.png";
break;
case 6:
sprite->filepath = "Textures/meme_id_6.png";
break;
case 7:
sprite->filepath = "Textures/meme_id_7.png";
break;
}
flipped = true;
gameRef->flipCard(this);
}
void CardScript::unflipCard() {
ComponentHandle<Sprite> sprite = entity->get<Sprite>();
sprite->filepath = "Textures/descarga.png";
flipped = false;
}
void CardScript::setGameManagerRef(GameManager* gmr) {
gameRef = gmr;
}
void CardScript::turnVisible(bool vis) {
ComponentHandle<Sprite> sprite = entity->get<Sprite>();
sprite->visible = vis;
}