Compare commits
	
		
			No commits in common. "08c5c086690e2cc5ebe4eb1ab2193314c82c370b" and "9701cc9e61cfc60b77518d5ed28f519c1551d4ef" have entirely different histories.
		
	
	
		
			08c5c08669
			...
			9701cc9e61
		
	
		
							
								
								
									
										86
									
								
								game.c
									
									
									
									
									
								
							
							
						
						
									
										86
									
								
								game.c
									
									
									
									
									
								
							| @ -53,10 +53,10 @@ void initialize_game(Game *g) { | |||||||
|     case 41: |     case 41: | ||||||
|       t = ANIMAL; break; |       t = ANIMAL; break; | ||||||
|     } |     } | ||||||
|     g->cards[i] = (Card) { i, t, rt, month, { 800, 100 }, false }; |     g->cards[i] = (Card) { i, t, rt, month, { 800, 100 }, false, false }; | ||||||
|     g->cards[i].move.end_time = 0.; |     g->cards[i].move.end_time = 0.; | ||||||
|     g->cards[i].move.position = &g->cards[i].position; |     g->cards[i].move.position = &g->cards[i].position; | ||||||
|     g->cards[i].move.destination = (Vector2) { 800, 400 }; |     g->cards[i].move.destination = (Vector2) { 800, 300 }; | ||||||
|     g->deck.cards[i] = &g->cards[i]; |     g->deck.cards[i] = &g->cards[i]; | ||||||
|     g->deck.count++; |     g->deck.count++; | ||||||
|   } |   } | ||||||
| @ -64,16 +64,16 @@ void initialize_game(Game *g) { | |||||||
|   shuffle_hand(&g->deck); |   shuffle_hand(&g->deck); | ||||||
| 
 | 
 | ||||||
|   g->player_hand.count = 0; |   g->player_hand.count = 0; | ||||||
|   g->player_hand.position = (Vector2) { 300, 600 }; |   g->player_hand.position = (Vector2) { 300, 550 }; | ||||||
|   g->player_hand.display_type = HAND_DISPLAY_ROW; |   g->player_hand.display_type = HAND_DISPLAY_ROW; | ||||||
|   g->right_hand.count = 0; |   g->right_hand.count = 0; | ||||||
|   g->right_hand.position = (Vector2) { 50, 125 }; |   g->right_hand.position = (Vector2) { 20, 100 }; | ||||||
|   g->right_hand.display_type = HAND_DISPLAY_ROW; |   g->right_hand.display_type = HAND_DISPLAY_ROW; | ||||||
|   g->left_hand.count = 0; |   g->left_hand.count = 0; | ||||||
|   g->left_hand.position = (Vector2) { 750, 125 }; |   g->left_hand.position = (Vector2) { 600, 100 }; | ||||||
|   g->left_hand.display_type = HAND_DISPLAY_ROW; |   g->left_hand.display_type = HAND_DISPLAY_ROW; | ||||||
|   g->field.count = 0; |   g->field.count = 0; | ||||||
|   g->field.position = (Vector2) { 400, 300 }; |   g->field.position = (Vector2) { 400, 250 }; | ||||||
|   g->field.display_type = HAND_DISPLAY_FIELD; |   g->field.display_type = HAND_DISPLAY_FIELD; | ||||||
| 
 | 
 | ||||||
|   strcpy(teyaku_calculation, ""); |   strcpy(teyaku_calculation, ""); | ||||||
| @ -86,22 +86,37 @@ void initialize_game(Game *g) { | |||||||
| 
 | 
 | ||||||
| bool stale_calculation = true; | bool stale_calculation = true; | ||||||
| void handle_input(Game *g) { | void handle_input(Game *g) { | ||||||
|   switch (g->state) { |   if (IsMouseButtonPressed(0)) { | ||||||
|   case GAME_STATE_PLAYER_CHOOSING_FROM_HAND: |     mouse_pos = GetMousePosition(); | ||||||
|     if (IsMouseButtonPressed(0)) { |     for (int i = 0; i < 48; i++) { | ||||||
|       mouse_pos = GetMousePosition(); |       if (point_within_card(&g->cards[i], mouse_pos)) { | ||||||
|       for (int i = 0; i < g->player_hand.count; i++) { | 	g->cards[i].selected = !g->cards[i].selected; | ||||||
| 	if (point_within_card(g->player_hand.cards[i], mouse_pos)) { | 	stale_calculation = true; | ||||||
| 	  // g->selected_card = g->player_hand.cards[i];
 | 	break; | ||||||
| 	  break; |  | ||||||
| 	} |  | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     break; |   } | ||||||
|   case GAME_STATE_PLAYER_CHOOSING_TARGET: | } | ||||||
|     break; | 
 | ||||||
|   default: | void run_calculation(Game *g) { | ||||||
|     break; |   int num_selected = 0; | ||||||
|  |   if (stale_calculation) { | ||||||
|  |     Hand h; | ||||||
|  |     h.count = 0; | ||||||
|  |     for (int i = 0; i < 48; i++) { | ||||||
|  |       num_selected += g->cards[i].selected; | ||||||
|  |       if (g->cards[i].selected) h.cards[h.count++] = &g->cards[i]; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (num_selected == 7) { | ||||||
|  |       Teyaku t; | ||||||
|  |       calculate_teyaku(h, &t); | ||||||
|  |       teyaku_to_string(&t, teyaku_calculation); | ||||||
|  |     } else { | ||||||
|  |       strcpy(teyaku_calculation, ""); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     stale_calculation = false; | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -134,18 +149,10 @@ 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;
 |   g->state = GAME_STATE_INITIALIZING; | ||||||
|   g->state = GAME_STATE_PLAYER_CHOOSING_FROM_HAND; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| void run_frame_player_choosing_from_hand(Game *g) { |  | ||||||
| } |  | ||||||
| void run_frame_player_choosing_target(Game *g) { |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void run_frame(Game *g) { | void run_frame(Game *g) { | ||||||
|   handle_input(g); |  | ||||||
| 
 |  | ||||||
|   float delta = GetFrameTime(); |   float delta = GetFrameTime(); | ||||||
|   bool done_moving = true; |   bool done_moving = true; | ||||||
|   for (int i = 0; i < 48; i++) { |   for (int i = 0; i < 48; i++) { | ||||||
| @ -154,6 +161,8 @@ void run_frame(Game *g) { | |||||||
|   } |   } | ||||||
|   if (!done_moving) return; |   if (!done_moving) return; | ||||||
| 
 | 
 | ||||||
|  |   handle_input(g); | ||||||
|  | 
 | ||||||
|   switch (g->state) { |   switch (g->state) { | ||||||
|   case GAME_STATE_INITIALIZING: |   case GAME_STATE_INITIALIZING: | ||||||
|     return; |     return; | ||||||
| @ -166,13 +175,8 @@ void run_frame(Game *g) { | |||||||
|   case GAME_STATE_CALCULATING_TEYAKU: |   case GAME_STATE_CALCULATING_TEYAKU: | ||||||
|     run_frame_calculating_teyaku(g); |     run_frame_calculating_teyaku(g); | ||||||
|     break; |     break; | ||||||
|   case GAME_STATE_PLAYER_CHOOSING_FROM_HAND: |  | ||||||
|     run_frame_player_choosing_from_hand(g); |  | ||||||
|     break; |  | ||||||
|   case GAME_STATE_PLAYER_CHOOSING_TARGET: |  | ||||||
|     run_frame_player_choosing_target(g); |  | ||||||
|     break; |  | ||||||
|   } |   } | ||||||
|  |   run_calculation(g); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void draw_frame(Game *g) { | void draw_frame(Game *g) { | ||||||
| @ -188,18 +192,6 @@ void draw_frame(Game *g) { | |||||||
|     teyaku_to_string(&g->player_teyaku, s); |     teyaku_to_string(&g->player_teyaku, s); | ||||||
|     DrawText(s, 5, 25, 30, BLACK); |     DrawText(s, 5, 25, 30, BLACK); | ||||||
|   } |   } | ||||||
| 
 |  | ||||||
|   switch (g->state) { |  | ||||||
|   case GAME_STATE_PLAYER_CHOOSING_FROM_HAND: |  | ||||||
|     DrawText("Choose a card to play", 60, 485, 40, BLACK); |  | ||||||
|     break; |  | ||||||
|   case GAME_STATE_PLAYER_CHOOSING_TARGET: |  | ||||||
|     DrawText("Choose a target on the field", 60, 485, 40, BLACK); |  | ||||||
|     break; |  | ||||||
|   default: |  | ||||||
|     break; |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   EndDrawing(); |   EndDrawing(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								game.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								game.h
									
									
									
									
									
								
							| @ -14,8 +14,6 @@ typedef enum GameState { | |||||||
|   GAME_STATE_DEALING, |   GAME_STATE_DEALING, | ||||||
|   GAME_STATE_CALCULATING_FIELD_MULTIPLIER, |   GAME_STATE_CALCULATING_FIELD_MULTIPLIER, | ||||||
|   GAME_STATE_CALCULATING_TEYAKU, |   GAME_STATE_CALCULATING_TEYAKU, | ||||||
|   GAME_STATE_PLAYER_CHOOSING_FROM_HAND, |  | ||||||
|   GAME_STATE_PLAYER_CHOOSING_TARGET, |  | ||||||
| } GameState; | } GameState; | ||||||
| 
 | 
 | ||||||
| struct Game { | struct Game { | ||||||
|  | |||||||
							
								
								
									
										2
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								main.c
									
									
									
									
									
								
							| @ -13,7 +13,7 @@ Texture2D cards_texture; | |||||||
| 
 | 
 | ||||||
| int main(int argc, char** argv) { | int main(int argc, char** argv) { | ||||||
|   srand(time(NULL)); |   srand(time(NULL)); | ||||||
|   InitWindow(1400, 900, "Hanafuda Hachi-Hachi"); |   InitWindow(1200, 700, "Hanafuda Hachi-Hachi"); | ||||||
|   SetTargetFPS(60); |   SetTargetFPS(60); | ||||||
| 
 | 
 | ||||||
|   Game g; |   Game g; | ||||||
|  | |||||||
							
								
								
									
										26
									
								
								play.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								play.c
									
									
									
									
									
								
							| @ -1,26 +0,0 @@ | |||||||
| #include <stddef.h> |  | ||||||
| #include <stdbool.h> |  | ||||||
| #include "play.h" |  | ||||||
| 
 |  | ||||||
| bool valid_play(Hand *field, Card *played, Card *target) { |  | ||||||
|   if (target == NULL) { |  | ||||||
|     bool matching_month_in_field = false; |  | ||||||
|     for (int i = 0; i < field->count; i++) { |  | ||||||
|       if (field->cards[i]->month == target->month) { |  | ||||||
| 	matching_month_in_field = true; |  | ||||||
| 	break; |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     return !matching_month_in_field; |  | ||||||
|   } else { |  | ||||||
|     bool target_in_field = false; |  | ||||||
|     for (int i = 0; i < field->count; i++) { |  | ||||||
|       if (field->cards[i]->index == target->index) { |  | ||||||
| 	target_in_field = true; |  | ||||||
| 	break; |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|     if (!target_in_field) return false; |  | ||||||
|     return played->month == target->month; |  | ||||||
|   } |  | ||||||
| } |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user