The title screen is now unusable

This commit is contained in:
Bill Rossi 2025-02-23 21:26:22 -05:00
parent 6b609b3144
commit af3f180fa8
4 changed files with 110 additions and 14 deletions

1
card.c
View File

@ -15,6 +15,7 @@ void draw_card(Card *c, Texture2D *cards_texture, int index) {
Color color = index == 1 ? BLACK : BRICKRED;
if (c->visible) {
printf("draw card %p\n", cards_texture); fflush(stdout);
DrawTexturePro(
*cards_texture,
(Rectangle) { pos_horiz, pos_vert, CARD_WIDTH, CARD_HEIGHT },

36
game.c
View File

@ -23,6 +23,8 @@ void initialize_game(Game *g) {
g->cards_texture_black = LoadTextureFromImage(cards_image_black);
UnloadImage(cards_image_black);
printf("%p %p\n", &g->cards_texture_black, &g->cards_texture_red);
g->deck.count = 0;
g->deck.position = (Vector2) { 500, 300 };
g->deck.display_type = HAND_DISPLAY_DECK;
@ -76,14 +78,18 @@ void initialize_game(Game *g) {
case 41:
t = ANIMAL; break;
}
g->cards[i] = (Card) { i, t, rt, month, { 500, 300 }, false };
g->cards[i] = (Card) { i, t, rt, month, { -500, -300 }, false };
g->cards[i].move.end_time = 0.;
g->cards[i].move.position = &g->cards[i].position;
g->cards[i].move.destination = (Vector2) { 500, 300 };
g->cards[i].move.destination = (Vector2) { -500, -300 };
g->cards[i].order = i;
g->cards[i].selected = false;
g->cards[i].visible = false;
g->deck.count++;
}
printf("DONE CARDS\n");
g->player.points = 100 * g->kan_value;
g->right.points = 100 * g->kan_value;
g->left.points = 100 * g->kan_value;
@ -782,6 +788,7 @@ void run_frame(Game *g) {
if (g->dialog) return;
move_cards(g);
if (g->state == GAME_STATE_TITLE_SCREEN) run_frame_title(g);
if (!done_moving(g)) return;
switch (g->state) {
@ -839,23 +846,24 @@ void run_frame(Game *g) {
case GAME_STATE_NEW_GAME:
run_frame_new_game(g);
break;
case GAME_STATE_OPTIONS:
case GAME_STATE_TITLE_SCREEN:
break;
case GAME_STATE_OPTIONS:
break;
}
}
Texture *cards_texture(Game *g) {
Texture *cards_texture_fun(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], cards_texture_fun(g), 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], cards_texture_fun(g), g->black_card_backs);
}
}
@ -864,11 +872,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], cards_texture_fun(g), 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], cards_texture_fun(g), g->black_card_backs);
}
}
@ -876,16 +884,16 @@ void draw_frame(Game *g) {
BeginDrawing();
ClearBackground(RAYWHITE);
draw_cards(g);
if (g->state == GAME_STATE_OPTIONS) {
options_draw(g);
if (g->state == GAME_STATE_TITLE_SCREEN) {
title_draw(g);
EndDrawing();
return;
}
if (g->state == GAME_STATE_TITLE_SCREEN) {
title_draw(g);
draw_cards(g);
if (g->state == GAME_STATE_OPTIONS) {
options_draw(g);
EndDrawing();
return;
}

86
title.c
View File

@ -1,3 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
#include "title.h"
void initialize_title(Game *g) {
@ -48,10 +50,94 @@ void title_handle_input(Game *g) {
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_fly_card(Game *g, Card *card) {
int x, y;
switch ((int) rand() % 4) {
case 0:
x = (rand() % 1600) - 100;
y = -100;
break;
case 1:
x = (rand() % 1600) - 100;
y = 1000;
break;
case 2:
x = -100;
y = (rand() % 1100) - 100;;
break;
case 3:
x = 1500;
y = (rand() % 1100) - 100;;
break;
}
card->position.x = x;
card->position.y = y;
Move *move = &card->move;
move->position->x = x;
move->position->y = y;
move->origin.x = x;
move->origin.y = y;
switch ((int) rand() % 4) {
case 0:
x = (rand() % 1600) - 100;
y = -100;
break;
case 1:
x = (rand() % 1600) - 100;
y = 1000;
break;
case 2:
x = -100;
y = (rand() % 1100) - 100;;
break;
case 3:
x = 1500;
y = (rand() % 1100) - 100;;
break;
}
move->destination.x = x;
move->destination.y = y;
move->curve = CURVE_LINEAR;
move->current_time = 0.;
move->end_time = (rand() % 5) + 1;
printf("current: %f, end: %f\n", card->move.current_time, card->move.end_time);
}
void run_frame_title(Game *g) {
if (rand() % 20 > 3) return;
Card *card = NULL;
for (int i = 0; i < 48; i++) {
int index = rand() % 48;
if (g->cards[index].move.current_time > g->cards[index].move.end_time) {
card = &g->cards[index];
break;
}
}
if (!card) return;
title_fly_card(g, card);
}
Texture *cards_texture_fun2(Game *g) {
return g->black_card_backs ? &g->cards_texture_black : &g->cards_texture_red;
}
void title_draw(Game *g) {
for (int i = 0; i < 48; i++) {
g->cards[i].visible = true;
draw_card(&g->cards[i], cards_texture_fun2(g), g->black_card_backs);
}
Title *t = g->title;
DrawTextCentered("Hanafuda Hachi-Hachi", 700, 100, 90, BLACK);
DrawTextCentered("Start", 700, 350, 60, t->hover_start ? RED : BLACK);

View File

@ -17,5 +17,6 @@ struct Title {
void title_handle_input(Game *g);
void title_draw(Game *g);
void initialize_title(Game *g);
void run_frame_title(Game *g);
#endif