Compare commits
	
		
			4 Commits
		
	
	
		
			08c5c08669
			...
			ec9d0e5007
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| ec9d0e5007 | |||
| 19fcbb4887 | |||
| 3bac02c752 | |||
| 028da65317 | 
							
								
								
									
										20
									
								
								card.c
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								card.c
									
									
									
									
									
								
							@ -44,6 +44,15 @@ void shuffle_hand(Hand *h) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void remove_from_hand(Hand *h, Card *c) {
 | 
				
			||||||
 | 
					  bool card_found = false;
 | 
				
			||||||
 | 
					  for (int i = 0; i < h->count - 1; i++) {
 | 
				
			||||||
 | 
					    if (h->cards[i] == c) card_found = true;
 | 
				
			||||||
 | 
					    h->cards[i] = h->cards[i + 1];
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  h->count--;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void add_to_hand(Hand *h, Card *c) {
 | 
					void add_to_hand(Hand *h, Card *c) {
 | 
				
			||||||
  h->cards[h->count] = c;
 | 
					  h->cards[h->count] = c;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -62,7 +71,7 @@ void add_to_hand(Hand *h, Card *c) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
  c->move.curve = CURVE_EASE_IN_OUT;
 | 
					  c->move.curve = CURVE_EASE_IN_OUT;
 | 
				
			||||||
  c->move.current_time = 0.;
 | 
					  c->move.current_time = 0.;
 | 
				
			||||||
  c->move.end_time = 0.5;
 | 
					  c->move.end_time = 0.1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  h->count++;
 | 
					  h->count++;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -79,3 +88,12 @@ void deal(Hand *from, Hand *to, int count, bool up) {
 | 
				
			|||||||
    from->count--;
 | 
					    from->count--;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Rectangle next_card_position(Hand *h) {
 | 
				
			||||||
 | 
					  return (Rectangle) {
 | 
				
			||||||
 | 
					    h->position.x + ((h->count / 2) * (CARD_WIDTH + 10)),
 | 
				
			||||||
 | 
					    h->position.y + (h->count % 2 * (CARD_HEIGHT + 10)),
 | 
				
			||||||
 | 
					    CARD_WIDTH,
 | 
				
			||||||
 | 
					    CARD_HEIGHT
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								card.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								card.h
									
									
									
									
									
								
							@ -75,5 +75,6 @@ bool point_within_card(Card *c, Vector2 v);
 | 
				
			|||||||
void shuffle_hand(Hand *h);
 | 
					void shuffle_hand(Hand *h);
 | 
				
			||||||
void deal(Hand *from, Hand *to, int count, bool up);
 | 
					void deal(Hand *from, Hand *to, int count, bool up);
 | 
				
			||||||
bool card_done_moving(Card *c);
 | 
					bool card_done_moving(Card *c);
 | 
				
			||||||
 | 
					Rectangle next_card_position(Hand *h);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										111
									
								
								game.c
									
									
									
									
									
								
							
							
						
						
									
										111
									
								
								game.c
									
									
									
									
									
								
							@ -6,6 +6,7 @@
 | 
				
			|||||||
#include "teyaku.h"
 | 
					#include "teyaku.h"
 | 
				
			||||||
#include "dekiyaku.h"
 | 
					#include "dekiyaku.h"
 | 
				
			||||||
#include "field_multiplier.h"
 | 
					#include "field_multiplier.h"
 | 
				
			||||||
 | 
					#include "play.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Vector2 mouse_pos;
 | 
					Vector2 mouse_pos;
 | 
				
			||||||
char teyaku_calculation[400];
 | 
					char teyaku_calculation[400];
 | 
				
			||||||
@ -75,6 +76,15 @@ void initialize_game(Game *g) {
 | 
				
			|||||||
  g->field.count = 0;
 | 
					  g->field.count = 0;
 | 
				
			||||||
  g->field.position = (Vector2) { 400, 300 };
 | 
					  g->field.position = (Vector2) { 400, 300 };
 | 
				
			||||||
  g->field.display_type = HAND_DISPLAY_FIELD;
 | 
					  g->field.display_type = HAND_DISPLAY_FIELD;
 | 
				
			||||||
 | 
					  g->player_scored.count = 0;
 | 
				
			||||||
 | 
					  g->player_scored.position = (Vector2) { 300, 750 };
 | 
				
			||||||
 | 
					  g->player_scored.display_type = HAND_DISPLAY_ROW;
 | 
				
			||||||
 | 
					  g->right_scored.count = 0;
 | 
				
			||||||
 | 
					  g->right_scored.position = (Vector2) { 50, 25 };
 | 
				
			||||||
 | 
					  g->right_scored.display_type = HAND_DISPLAY_ROW;
 | 
				
			||||||
 | 
					  g->left_scored.count = 0;
 | 
				
			||||||
 | 
					  g->left_scored.position = (Vector2) { 750, 25 };
 | 
				
			||||||
 | 
					  g->left_scored.display_type = HAND_DISPLAY_ROW;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  strcpy(teyaku_calculation, "");
 | 
					  strcpy(teyaku_calculation, "");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -92,13 +102,65 @@ void handle_input(Game *g) {
 | 
				
			|||||||
      mouse_pos = GetMousePosition();
 | 
					      mouse_pos = GetMousePosition();
 | 
				
			||||||
      for (int i = 0; i < g->player_hand.count; i++) {
 | 
					      for (int i = 0; i < g->player_hand.count; i++) {
 | 
				
			||||||
	if (point_within_card(g->player_hand.cards[i], mouse_pos)) {
 | 
						if (point_within_card(g->player_hand.cards[i], mouse_pos)) {
 | 
				
			||||||
	  // g->selected_card = g->player_hand.cards[i];
 | 
						  for (int j = 0; j < 48; j++) {
 | 
				
			||||||
 | 
						    g->cards[j].selected = false;
 | 
				
			||||||
 | 
						  }
 | 
				
			||||||
 | 
						  g->player_hand.cards[i]->selected = true;
 | 
				
			||||||
	  break;
 | 
						  break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  case GAME_STATE_PLAYER_CHOOSING_TARGET:
 | 
					  case GAME_STATE_PLAYER_CHOOSING_TARGET:
 | 
				
			||||||
 | 
					    if (IsMouseButtonPressed(0)) {
 | 
				
			||||||
 | 
					      mouse_pos = GetMousePosition();
 | 
				
			||||||
 | 
					      bool clicked_hand_card = false;
 | 
				
			||||||
 | 
					      for (int i = 0; i < g->player_hand.count; i++) {
 | 
				
			||||||
 | 
						if (point_within_card(g->player_hand.cards[i], mouse_pos)) {
 | 
				
			||||||
 | 
						  clicked_hand_card = true;
 | 
				
			||||||
 | 
						  if (g->player_hand.cards[i]->selected) {
 | 
				
			||||||
 | 
						    g->player_hand.cards[i]->selected = false;
 | 
				
			||||||
 | 
						  } else {
 | 
				
			||||||
 | 
						    for (int j = 0; j < g->player_hand.count; j++) {
 | 
				
			||||||
 | 
						      g->player_hand.cards[j]->selected = false;
 | 
				
			||||||
 | 
						    }
 | 
				
			||||||
 | 
						    g->player_hand.cards[i]->selected = true;
 | 
				
			||||||
 | 
						  }
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      Card *selected_card = NULL;
 | 
				
			||||||
 | 
					      for (int i = 0; i < g->player_hand.count; i++) {
 | 
				
			||||||
 | 
						if (g->player_hand.cards[i]->selected) {
 | 
				
			||||||
 | 
						  selected_card = g->player_hand.cards[i];
 | 
				
			||||||
 | 
						  break;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      for (int i = 0; i < g->field.count; i++) {
 | 
				
			||||||
 | 
						if (point_within_card(g->field.cards[i], mouse_pos)) {
 | 
				
			||||||
 | 
						  if (selected_card == NULL) printf("No card selected, whoops");
 | 
				
			||||||
 | 
						  if (valid_play(&g->field, selected_card, g->field.cards[i])) {
 | 
				
			||||||
 | 
						    g->current_play_from_hand = selected_card;
 | 
				
			||||||
 | 
						    g->current_play_target = g->field.cards[i];
 | 
				
			||||||
 | 
						    printf("Valid\n");
 | 
				
			||||||
 | 
						    break;
 | 
				
			||||||
 | 
						  } else {
 | 
				
			||||||
 | 
						    printf("Invalid\n");
 | 
				
			||||||
 | 
						  }
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (CheckCollisionPointRec(mouse_pos, next_card_position(&g->field))) {
 | 
				
			||||||
 | 
						if (valid_play(&g->field, selected_card, NULL)) {
 | 
				
			||||||
 | 
						  g->current_play_from_hand = selected_card;
 | 
				
			||||||
 | 
						  g->current_play_target = NULL;
 | 
				
			||||||
 | 
						  printf("Valid\n");
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
						  printf("Invalid\n");
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  default:
 | 
					  default:
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
@ -134,13 +196,53 @@ void run_frame_calculating_field_multiplier(Game *g) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void run_frame_calculating_teyaku(Game *g) {
 | 
					void run_frame_calculating_teyaku(Game *g) {
 | 
				
			||||||
  calculate_teyaku(g->player_hand, &g->player_teyaku);
 | 
					  calculate_teyaku(g->player_hand, &g->player_teyaku);
 | 
				
			||||||
  // g->selected_card = NULL;
 | 
					  for (int i = 0; i < 48; i++) {
 | 
				
			||||||
 | 
					    g->cards[i].selected = false;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  g->state = GAME_STATE_PLAYER_CHOOSING_FROM_HAND;
 | 
					  g->state = GAME_STATE_PLAYER_CHOOSING_FROM_HAND;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void run_frame_player_choosing_from_hand(Game *g) {
 | 
					void run_frame_player_choosing_from_hand(Game *g) {
 | 
				
			||||||
 | 
					  for (int i = 0; i < g->player_hand.count; i++) {
 | 
				
			||||||
 | 
					    if (g->player_hand.cards[i]->selected) {
 | 
				
			||||||
 | 
					      g->state = GAME_STATE_PLAYER_CHOOSING_TARGET;
 | 
				
			||||||
 | 
					      return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void run_frame_player_choosing_target(Game *g) {
 | 
					void run_frame_player_choosing_target(Game *g) {
 | 
				
			||||||
 | 
					  bool no_cards_selected = true;
 | 
				
			||||||
 | 
					  for (int i = 0; i < g->player_hand.count; i++) {
 | 
				
			||||||
 | 
					    if (g->player_hand.cards[i]->selected) {
 | 
				
			||||||
 | 
					      no_cards_selected = false;
 | 
				
			||||||
 | 
					      break;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (no_cards_selected) {
 | 
				
			||||||
 | 
					    g->state = GAME_STATE_PLAYER_CHOOSING_FROM_HAND;
 | 
				
			||||||
 | 
					    return;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (g->current_play_from_hand) {
 | 
				
			||||||
 | 
					    if (g->current_play_target) {
 | 
				
			||||||
 | 
					      g->current_play_from_hand->selected = false;
 | 
				
			||||||
 | 
					      remove_from_hand(&g->player_hand, g->current_play_from_hand);
 | 
				
			||||||
 | 
					      add_to_hand(&g->player_scored, g->current_play_from_hand);
 | 
				
			||||||
 | 
					      remove_from_hand(&g->field, g->current_play_target);
 | 
				
			||||||
 | 
					      add_to_hand(&g->player_scored, g->current_play_target);
 | 
				
			||||||
 | 
					      g->current_play_from_hand = NULL;
 | 
				
			||||||
 | 
					      g->current_play_target = NULL;
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					      g->current_play_from_hand->selected = false;
 | 
				
			||||||
 | 
					      remove_from_hand(&g->player_hand, g->current_play_from_hand);
 | 
				
			||||||
 | 
					      add_to_hand(&g->field, g->current_play_from_hand);
 | 
				
			||||||
 | 
					      g->current_play_from_hand = NULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    g->state = GAME_STATE_INITIALIZING;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void run_frame(Game *g) {
 | 
					void run_frame(Game *g) {
 | 
				
			||||||
@ -191,10 +293,11 @@ void draw_frame(Game *g) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  switch (g->state) {
 | 
					  switch (g->state) {
 | 
				
			||||||
  case GAME_STATE_PLAYER_CHOOSING_FROM_HAND:
 | 
					  case GAME_STATE_PLAYER_CHOOSING_FROM_HAND:
 | 
				
			||||||
    DrawText("Choose a card to play", 60, 485, 40, BLACK);
 | 
					    DrawText("Choose a card to play", 60, 485, 20, BLACK);
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  case GAME_STATE_PLAYER_CHOOSING_TARGET:
 | 
					  case GAME_STATE_PLAYER_CHOOSING_TARGET:
 | 
				
			||||||
    DrawText("Choose a target on the field", 60, 485, 40, BLACK);
 | 
					    DrawText("Choose a target on the field", 60, 485, 20, BLACK);
 | 
				
			||||||
 | 
					    DrawRectangleRec(next_card_position(&g->field), BLUE);
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
  default:
 | 
					  default:
 | 
				
			||||||
    break;
 | 
					    break;
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										5
									
								
								game.h
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								game.h
									
									
									
									
									
								
							@ -23,9 +23,12 @@ struct Game {
 | 
				
			|||||||
  bool should_close;
 | 
					  bool should_close;
 | 
				
			||||||
  Card cards[48];
 | 
					  Card cards[48];
 | 
				
			||||||
  Texture2D cards_texture;
 | 
					  Texture2D cards_texture;
 | 
				
			||||||
  Hand player_hand, left_hand, right_hand, deck, field;
 | 
					  Hand player_hand, left_hand, right_hand;
 | 
				
			||||||
 | 
					  Hand deck, field;
 | 
				
			||||||
 | 
					  Hand player_scored, left_scored, right_scored;
 | 
				
			||||||
  FieldMultiplier *field_multiplier;
 | 
					  FieldMultiplier *field_multiplier;
 | 
				
			||||||
  Teyaku player_teyaku, left_teyaku, right_teyaku;
 | 
					  Teyaku player_teyaku, left_teyaku, right_teyaku;
 | 
				
			||||||
 | 
					  Card *current_play_from_hand, *current_play_target;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void initialize_game(Game *g);
 | 
					void initialize_game(Game *g);
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								play.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								play.c
									
									
									
									
									
								
							@ -6,7 +6,7 @@ bool valid_play(Hand *field, Card *played, Card *target) {
 | 
				
			|||||||
  if (target == NULL) {
 | 
					  if (target == NULL) {
 | 
				
			||||||
    bool matching_month_in_field = false;
 | 
					    bool matching_month_in_field = false;
 | 
				
			||||||
    for (int i = 0; i < field->count; i++) {
 | 
					    for (int i = 0; i < field->count; i++) {
 | 
				
			||||||
      if (field->cards[i]->month == target->month) {
 | 
					      if (field->cards[i]->month == played->month) {
 | 
				
			||||||
	matching_month_in_field = true;
 | 
						matching_month_in_field = true;
 | 
				
			||||||
	break;
 | 
						break;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user