#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); } }