Select cards
This commit is contained in:
parent
ed32f6262d
commit
7b4847e165
7
card.c
7
card.c
@ -1,7 +1,7 @@
|
|||||||
#include "card.h"
|
#include "card.h"
|
||||||
|
|
||||||
void draw_card(Card *c) {
|
void draw_card(Card *c) {
|
||||||
DrawRectangleV(c->position, card_size, RED);
|
DrawRectangleV(c->position, card_size, c->selected ? RED : BLACK);
|
||||||
DrawRectangle(c->position.x + CARD_BORDER, c->position.y + CARD_BORDER, card_size.x - (CARD_BORDER * 2), card_size.y - (CARD_BORDER * 2) , WHITE);
|
DrawRectangle(c->position.x + CARD_BORDER, c->position.y + CARD_BORDER, card_size.x - (CARD_BORDER * 2), card_size.y - (CARD_BORDER * 2) , WHITE);
|
||||||
DrawText(month_english_abbr[c->month], c->position.x + CARD_BORDER + 2, c->position.y + CARD_BORDER + 2, 14, BLACK);
|
DrawText(month_english_abbr[c->month], c->position.x + CARD_BORDER + 2, c->position.y + CARD_BORDER + 2, 14, BLACK);
|
||||||
switch (c->type) {
|
switch (c->type) {
|
||||||
@ -23,3 +23,8 @@ void draw_card(Card *c) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool point_within_card(Card *c, Vector2 point) {
|
||||||
|
return point.x > c->position.x && point.x < c->position.x + card_size.x &&
|
||||||
|
point.y > c->position.y && point.y < c->position.y + card_size.y;
|
||||||
|
}
|
||||||
|
1
card.h
1
card.h
@ -48,6 +48,7 @@ struct Card {
|
|||||||
RibbonType ribbon_type;
|
RibbonType ribbon_type;
|
||||||
Month month;
|
Month month;
|
||||||
Vector2 position;
|
Vector2 position;
|
||||||
|
bool selected;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Hand {
|
struct Hand {
|
||||||
|
12
main.c
12
main.c
@ -65,7 +65,7 @@ int main(int argc, char** argv) {
|
|||||||
case 41:
|
case 41:
|
||||||
t = ANIMAL; break;
|
t = ANIMAL; break;
|
||||||
}
|
}
|
||||||
cards[i] = (Card) { i, t, rt, month, (Vector2) { month * 65, (i % 4) * 110 } };
|
cards[i] = (Card) { i, t, rt, month, (Vector2) { month * 65, (i % 4) * 110 }, false };
|
||||||
}
|
}
|
||||||
|
|
||||||
float delta;
|
float delta;
|
||||||
@ -74,6 +74,16 @@ int main(int argc, char** argv) {
|
|||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
delta = GetFrameTime();
|
delta = GetFrameTime();
|
||||||
|
|
||||||
|
if (IsMouseButtonPressed(0)) {
|
||||||
|
Vector2 mouse_pos = GetMousePosition();
|
||||||
|
for (int i = 0; i < 48; i++) {
|
||||||
|
if (point_within_card(&cards[i], mouse_pos)) {
|
||||||
|
cards[i].selected = !cards[i].selected;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
for (int i = 0; i < 48; i++) {
|
for (int i = 0; i < 48; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user