82 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			2.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
#include <stdio.h>
 | 
						|
#include <stdlib.h>
 | 
						|
#include "card.h"
 | 
						|
 | 
						|
static Vector2 card_size = (Vector2) { CARD_WIDTH, CARD_HEIGHT };
 | 
						|
static char *month_english_abbr[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
 | 
						|
 | 
						|
void draw_card(Card *c, Texture2D *cards_texture) {
 | 
						|
  int i_vert = c->index % 4;
 | 
						|
  int i_horiz = c->index / 4;
 | 
						|
  int pos_vert = i_vert * CARD_HEIGHT;
 | 
						|
  int pos_horiz = i_horiz * CARD_WIDTH;
 | 
						|
 | 
						|
  if (c->visible) {
 | 
						|
    DrawTexturePro(
 | 
						|
		   *cards_texture,
 | 
						|
		   (Rectangle) { pos_horiz, pos_vert, CARD_WIDTH, CARD_HEIGHT },
 | 
						|
		   (Rectangle) { c->position.x, c->position.y, card_size.x, card_size.y },
 | 
						|
		   (Vector2) { 0, 0 },
 | 
						|
		   0.,
 | 
						|
		   RAYWHITE
 | 
						|
		   );
 | 
						|
  } else {
 | 
						|
    DrawRectangleRec((Rectangle) { c->position.x, c->position.y, card_size.x, card_size.y }, BLACK);
 | 
						|
  }
 | 
						|
 | 
						|
  if (c->selected) {
 | 
						|
    DrawCircle(c->position.x + 10, c->position.y + 10, 10, BLUE);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
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;
 | 
						|
}
 | 
						|
 | 
						|
void shuffle_hand(Hand *h) {
 | 
						|
  Card *swap;
 | 
						|
  for (int i = h->count - 1; i >= 0; i--) {
 | 
						|
    int index = rand() % (i + 1);
 | 
						|
    swap = h->cards[i];
 | 
						|
    h->cards[i] = h->cards[index];
 | 
						|
    h->cards[index] = swap;
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void add_to_hand(Hand *h, Card *c) {
 | 
						|
  h->cards[h->count] = c;
 | 
						|
 | 
						|
  c->move.position = &c->position;
 | 
						|
  c->move.origin.x = c->position.x;
 | 
						|
  c->move.origin.y = c->position.y;
 | 
						|
  switch (h->display_type) {
 | 
						|
  case HAND_DISPLAY_ROW:
 | 
						|
    c->move.destination.x = h->position.x + (h->count * (CARD_WIDTH + 10));
 | 
						|
    c->move.destination.y = h->position.y;
 | 
						|
    break;
 | 
						|
  case HAND_DISPLAY_FIELD:
 | 
						|
    c->move.destination.x = h->position.x + ((h->count / 2) * (CARD_WIDTH + 10));
 | 
						|
    c->move.destination.y = h->position.y + (h->count % 2 * (CARD_HEIGHT + 10));
 | 
						|
    break;
 | 
						|
  }
 | 
						|
  c->move.curve = CURVE_EASE_IN_OUT;
 | 
						|
  c->move.current_time = 0.;
 | 
						|
  c->move.end_time = 0.5;
 | 
						|
 | 
						|
  h->count++;
 | 
						|
}
 | 
						|
 | 
						|
bool card_done_moving(Card *c) {
 | 
						|
  return c->move.current_time > c->move.end_time;
 | 
						|
}
 | 
						|
 | 
						|
void deal(Hand *from, Hand *to, int count, bool up) {
 | 
						|
  for (int i = 0; i < count; i++) {
 | 
						|
    Card *c = from->cards[from->count - 1];
 | 
						|
    c->visible = up;
 | 
						|
    add_to_hand(to, c);
 | 
						|
    from->count--;
 | 
						|
  }
 | 
						|
}
 |