Compare commits
	
		
			No commits in common. "6b609b3144b4e9a2a8284afd5e34daa12f4f8963" and "941fdcef955b0e09b980c62de9971fb38435d37b" have entirely different histories.
		
	
	
		
			6b609b3144
			...
			941fdcef95
		
	
		
							
								
								
									
										4
									
								
								card.c
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								card.c
									
									
									
									
									
								
							| @ -6,7 +6,7 @@ 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" }; | ||||
| 
 | ||||
| Color BRICKRED = (Color) { 136, 12, 2, 255 }; | ||||
| void draw_card(Card *c, Texture2D *cards_texture, int index) { | ||||
| void draw_card(Card *c, Texture2D **cards_texture, int index) { | ||||
|   int i_vert = c->index % 4; | ||||
|   int i_horiz = c->index / 4; | ||||
|   int pos_vert = i_vert * CARD_HEIGHT; | ||||
| @ -16,7 +16,7 @@ void draw_card(Card *c, Texture2D *cards_texture, int index) { | ||||
| 
 | ||||
|   if (c->visible) { | ||||
|     DrawTexturePro( | ||||
| 		   *cards_texture, | ||||
| 		   *cards_texture[index ? 1 : 0], | ||||
| 		   (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 }, | ||||
|  | ||||
							
								
								
									
										2
									
								
								card.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								card.h
									
									
									
									
									
								
							| @ -73,7 +73,7 @@ struct Hand { | ||||
|   HandDisplayType display_type; | ||||
| }; | ||||
| 
 | ||||
| void draw_card(Card *c, Texture2D *cards_texture, int index); | ||||
| void draw_card(Card *c, Texture2D **cards_texture, int index); | ||||
| bool point_within_card(Card *c, Vector2 v); | ||||
| void shuffle_hand(Hand *h); | ||||
| void deal(Hand *from, Hand *to, int count, bool up, float deal_speed); | ||||
|  | ||||
							
								
								
									
										31
									
								
								game.c
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								game.c
									
									
									
									
									
								
							| @ -15,12 +15,13 @@ Vector2 mouse_pos; | ||||
| char teyaku_calculation[400]; | ||||
| 
 | ||||
| void initialize_game(Game *g) { | ||||
|   g->cards_texture = malloc(2 * sizeof(Texture)); | ||||
|   Image cards_image_red = LoadImage("img/cards_red.png"); | ||||
|   g->cards_texture_red = LoadTextureFromImage(cards_image_red); | ||||
|   g->cards_texture[0] = LoadTextureFromImage(cards_image_red); | ||||
|   UnloadImage(cards_image_red); | ||||
| 
 | ||||
|   Image cards_image_black = LoadImage("img/cards_black.png"); | ||||
|   g->cards_texture_black = LoadTextureFromImage(cards_image_black); | ||||
|   g->cards_texture[1] = LoadTextureFromImage(cards_image_black); | ||||
|   UnloadImage(cards_image_black); | ||||
| 
 | ||||
|   g->deck.count = 0; | ||||
| @ -36,7 +37,6 @@ void initialize_game(Game *g) { | ||||
|   g->black_card_backs = true; | ||||
|   g->deal_speed = 0.2; | ||||
|   g->options = malloc(sizeof(Options)); | ||||
|   initialize_title(g); | ||||
|   load_options_from_game(g); | ||||
| 
 | ||||
|   init_dialogs(g); | ||||
| @ -148,7 +148,7 @@ void initialize_game(Game *g) { | ||||
|   } | ||||
| 
 | ||||
|   g->current_round = 0; | ||||
|   g->state = GAME_STATE_TITLE_SCREEN; | ||||
|   g->state = GAME_STATE_OPTIONS; | ||||
| } | ||||
| 
 | ||||
| Player *current_player(Game *g) { | ||||
| @ -173,10 +173,6 @@ void handle_input(Game *g) { | ||||
|     return options_handle_input(g); | ||||
|   } | ||||
| 
 | ||||
|   if (g->state == GAME_STATE_TITLE_SCREEN) { | ||||
|     return title_handle_input(g); | ||||
|   } | ||||
| 
 | ||||
|   if (g->dialog) { | ||||
|     return dialog_handle_input(g->dialog); | ||||
|   } | ||||
| @ -840,22 +836,17 @@ void run_frame(Game *g) { | ||||
|     run_frame_new_game(g); | ||||
|     break; | ||||
|   case GAME_STATE_OPTIONS: | ||||
|   case GAME_STATE_TITLE_SCREEN: | ||||
|     break; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| Texture *cards_texture(Game *g) { | ||||
|   return g->black_card_backs ? &g->cards_texture_black : &g->cards_texture_red; | ||||
| } | ||||
| 
 | ||||
| void draw_player_cards(Game *g, Player *p) { | ||||
|   for (int i = 0; i < p->hand.count; i++) { | ||||
|     draw_card(p->hand.cards[i], cards_texture(g), g->black_card_backs); | ||||
|     draw_card(p->hand.cards[i], &g->cards_texture, g->black_card_backs); | ||||
|   } | ||||
| 
 | ||||
|   for (int i = 0; i < p->scored.count; i++) { | ||||
|     draw_card(p->scored.cards[i], cards_texture(g), g->black_card_backs); | ||||
|     draw_card(p->scored.cards[i], &g->cards_texture, g->black_card_backs); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| @ -864,11 +855,11 @@ void draw_cards(Game *g) { | ||||
|   draw_player_cards(g, &g->right); | ||||
|   draw_player_cards(g, &g->left); | ||||
|   for (int i = 0; i < g->field.count; i++) { | ||||
|     draw_card(g->field.cards[i], cards_texture(g), g->black_card_backs); | ||||
|     draw_card(g->field.cards[i], &g->cards_texture, g->black_card_backs); | ||||
|   } | ||||
| 
 | ||||
|   for (int i = 0; i < g->deck.count; i++) { | ||||
|     draw_card(g->deck.cards[i], cards_texture(g), g->black_card_backs); | ||||
|     draw_card(g->deck.cards[i], &g->cards_texture, g->black_card_backs); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| @ -884,12 +875,6 @@ void draw_frame(Game *g) { | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (g->state == GAME_STATE_TITLE_SCREEN) { | ||||
|     title_draw(g); | ||||
|     EndDrawing(); | ||||
|     return; | ||||
|   } | ||||
| 
 | ||||
|   if (g->state == GAME_STATE_DEALING) { | ||||
|     DrawText("Dealing....", 60, 385, 40, BLACK); | ||||
|   } else if (g->field_multiplier) { | ||||
|  | ||||
							
								
								
									
										4
									
								
								game.h
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								game.h
									
									
									
									
									
								
							| @ -13,7 +13,6 @@ typedef struct Game Game; | ||||
| #include "player.h" | ||||
| #include "dialog.h" | ||||
| #include "options.h" | ||||
| #include "title.h" | ||||
| 
 | ||||
| typedef enum GameState { | ||||
|   GAME_STATE_INITIALIZING, | ||||
| @ -42,7 +41,7 @@ struct Game { | ||||
|   GameState state; | ||||
|   bool should_close; | ||||
|   Card cards[48]; | ||||
|   Texture2D cards_texture_red, cards_texture_black; | ||||
|   Texture2D *cards_texture; | ||||
|   Hand deck, field; | ||||
|   FieldMultiplier *field_multiplier; | ||||
|   Card *current_play_from_hand, *current_play_target; | ||||
| @ -57,7 +56,6 @@ struct Game { | ||||
|   bool black_card_backs; | ||||
|   float deal_speed; | ||||
|   Options *options; | ||||
|   Title *title; | ||||
| }; | ||||
| 
 | ||||
| void initialize_game(Game *g); | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								img/rules_qr.png
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								img/rules_qr.png
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 406 B | 
							
								
								
									
										3
									
								
								main.c
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								main.c
									
									
									
									
									
								
							| @ -8,6 +8,9 @@ | ||||
| 
 | ||||
| #include "game.h" | ||||
| 
 | ||||
| char *text = "こんにちわ、 世界!"; | ||||
| Texture2D cards_texture; | ||||
| 
 | ||||
| int main(int argc, char** argv) { | ||||
|   srand(time(NULL)); | ||||
|   InitWindow(1400, 900, "Hanafuda Hachi-Hachi"); | ||||
|  | ||||
| @ -29,12 +29,12 @@ void save_options_to_game(Game *g) { | ||||
| 
 | ||||
| void handle_options_save(Game *g) { | ||||
|   save_options_to_game(g); | ||||
|   g->state = GAME_STATE_TITLE_SCREEN; | ||||
|   g->state = GAME_STATE_INITIALIZING; | ||||
| } | ||||
| 
 | ||||
| void handle_options_cancel(Game *g) { | ||||
|   load_options_from_game(g); | ||||
|   g->state = GAME_STATE_TITLE_SCREEN; | ||||
|   g->state = GAME_STATE_INITIALIZING; | ||||
| } | ||||
| 
 | ||||
| void handle_select_kan(Game *g, int index) { | ||||
|  | ||||
							
								
								
									
										77
									
								
								title.c
									
									
									
									
									
								
							
							
						
						
									
										77
									
								
								title.c
									
									
									
									
									
								
							| @ -1,77 +0,0 @@ | ||||
| #include "title.h" | ||||
| 
 | ||||
| void initialize_title(Game *g) { | ||||
|   g->title = malloc(sizeof(Title)); | ||||
|   Image rules_qr_img = LoadImage("img/rules_qr.png"); | ||||
|   g->title->rules_qr = LoadTextureFromImage(rules_qr_img); | ||||
|   UnloadImage(rules_qr_img); | ||||
| } | ||||
| 
 | ||||
| void title_handle_click_start(Game *g) { | ||||
|   g->state = GAME_STATE_INITIALIZING; | ||||
| } | ||||
| 
 | ||||
| void title_handle_click_options(Game *g) { | ||||
|   g->state = GAME_STATE_OPTIONS; | ||||
| } | ||||
| 
 | ||||
| void title_handle_click_quit(Game *g) { | ||||
|   g->should_close = true; | ||||
| } | ||||
| 
 | ||||
| Vector2 tmp; // stands for "title mouse position"
 | ||||
| void title_handle_input(Game *g) { | ||||
|   tmp = GetMousePosition(); | ||||
|   Title *t = g->title; | ||||
|   t->hover_start = false; | ||||
|   t->hover_options = false; | ||||
|   t->hover_quit = false; | ||||
|   t->hover_credits = false; | ||||
|   t->hover_rules = false; | ||||
| 
 | ||||
|   int half_start_width = MeasureText("Start", 60) / 2; | ||||
|   if (tmp.x > 700-half_start_width && tmp.x < 700+half_start_width && tmp.y > 350 && tmp.y < 410) { | ||||
|     t->hover_start = true; | ||||
|     if (IsMouseButtonPressed(0)) title_handle_click_start(g); | ||||
|   } | ||||
|   int half_options_width = MeasureText("Options", 60) / 2; | ||||
|   if (tmp.x > 700-half_options_width && tmp.x < 700+half_options_width && tmp.y > 500 && tmp.y < 560) { | ||||
|     t->hover_options = true; | ||||
|     if (IsMouseButtonPressed(0)) title_handle_click_options(g); | ||||
|   } | ||||
|   int half_quit_width = MeasureText("Quit", 60) / 2; | ||||
|   if (tmp.x > 700-half_quit_width && tmp.x < 700+half_quit_width && tmp.y > 650 && tmp.y < 710) { | ||||
|     t->hover_quit = true; | ||||
|     if (IsMouseButtonPressed(0)) title_handle_click_quit(g); | ||||
|   } | ||||
|   int half_credits_width = MeasureText("Credits", 40) / 2; | ||||
|   if (tmp.x > 1100-half_credits_width && tmp.x < 1100+half_credits_width && tmp.y > 600 && tmp.y < 640) t->hover_credits = true; | ||||
|   int half_rules_width = MeasureText("Rules", 40) / 2; | ||||
|   if (tmp.x > 300-half_rules_width && tmp.x < 300+half_rules_width && tmp.y > 600 && tmp.y < 640) t->hover_rules = true; | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| void title_draw(Game *g) { | ||||
|   Title *t = g->title; | ||||
|   DrawTextCentered("Hanafuda Hachi-Hachi", 700, 100, 90, BLACK); | ||||
|   DrawTextCentered("Start", 700, 350, 60, t->hover_start ? RED : BLACK); | ||||
|   DrawTextCentered("Options", 700, 500, 60, t->hover_options ? RED : BLACK); | ||||
|   DrawTextCentered("Quit", 700, 650, 60, t->hover_quit ? RED : BLACK); | ||||
|   DrawTextCentered("Credits", 1100, 600, 40, BLACK); | ||||
|   DrawTextCentered("Rules", 300, 600, 40, BLACK); | ||||
| 
 | ||||
|   if (t->hover_rules) DrawTextureEx(t->rules_qr, (Vector2) { 135, 250 }, 0., 3., WHITE); | ||||
| 
 | ||||
|   if (t->hover_credits) { | ||||
|     DrawRectangle(870, 200, 460, 380, BLACK); | ||||
|     DrawRectangle(873, 203, 454, 374, WHITE); | ||||
|     DrawTextCentered("Programmed by bassguitarbill", 1100, 210, 25, BLACK); | ||||
|     DrawTextCentered("https://bassguitarbill.rocks", 1100, 240, 25, BLACK); | ||||
|     DrawTextCentered("Running on raylib", 1100, 310, 25, BLACK); | ||||
|     DrawTextCentered("https://www.raylib.com", 1100, 340, 25, BLACK); | ||||
|     DrawTextCentered("Drawn with Aseprite", 1100, 410, 25, BLACK); | ||||
|     DrawTextCentered("https://www.aseprite.org", 1100, 440, 25, BLACK); | ||||
|     DrawTextCentered("Art adapted from Louiemantia", 1100, 510, 25, BLACK); | ||||
|     DrawTextCentered("https://commons.wikimedia.org/wiki/User:Louiemantia", 1100, 540, 18, BLACK); | ||||
|   } | ||||
| } | ||||
							
								
								
									
										21
									
								
								title.h
									
									
									
									
									
								
							
							
						
						
									
										21
									
								
								title.h
									
									
									
									
									
								
							| @ -1,21 +0,0 @@ | ||||
| #ifndef _HF_TITLE_ | ||||
| #define _HF_TITLE_ | ||||
| 
 | ||||
| typedef struct Title Title; | ||||
| 
 | ||||
| #include "game.h" | ||||
| 
 | ||||
| struct Title { | ||||
|   bool hover_start; | ||||
|   bool hover_options; | ||||
|   bool hover_quit; | ||||
|   bool hover_credits; | ||||
|   bool hover_rules; | ||||
|   Texture2D rules_qr; | ||||
| }; | ||||
| 
 | ||||
| void title_handle_input(Game *g); | ||||
| void title_draw(Game *g); | ||||
| void initialize_title(Game *g); | ||||
| 
 | ||||
| #endif | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user