fucking gitignore
This commit is contained in:
parent
096c1dde2b
commit
dc3233343a
5 changed files with 109 additions and 35 deletions
BIN
.DS_Store
vendored
BIN
.DS_Store
vendored
Binary file not shown.
10
.gitignore
vendored
10
.gitignore
vendored
|
|
@ -2,6 +2,16 @@
|
||||||
# Prerequisites
|
# Prerequisites
|
||||||
*.d
|
*.d
|
||||||
|
|
||||||
|
# the game itself
|
||||||
|
game
|
||||||
|
|
||||||
|
# macos bs
|
||||||
|
.DS_Store
|
||||||
|
assets/.DS_Store
|
||||||
|
|
||||||
|
# claude code
|
||||||
|
.claude
|
||||||
|
|
||||||
# Object files
|
# Object files
|
||||||
*.o
|
*.o
|
||||||
*.ko
|
*.ko
|
||||||
|
|
|
||||||
BIN
assets/.DS_Store
vendored
BIN
assets/.DS_Store
vendored
Binary file not shown.
BIN
game
BIN
game
Binary file not shown.
118
src/main.c
118
src/main.c
|
|
@ -31,10 +31,21 @@ typedef struct {
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool is_running; // Controls the main game loop
|
bool is_running; // Controls the main game loop
|
||||||
float escape_timer; // Tracks how long the Escape key has been held (in ms)
|
float escape_timer; // Tracks how long the Escape key has been held (in ms)
|
||||||
int visible_chars; // Number of characters currently revealed in the typewriter text
|
// Message 1: "Hello, human."
|
||||||
uint32_t last_char_time; // Timestamp of the last character revealed
|
const char* message1;
|
||||||
const char* message; // The string to be displayed
|
int visible_chars1; // Number of characters revealed in message1
|
||||||
TTF_Font* font; // Pointer to the loaded TrueType font
|
uint32_t last_char_time1; // Timestamp of last character revealed in message1
|
||||||
|
// Message 2: "It is a known fact that C, is superior to every other programming language."
|
||||||
|
const char* message2;
|
||||||
|
int visible_chars2; // Number of characters revealed in message2
|
||||||
|
uint32_t last_char_time2; // Timestamp of last character revealed in message2
|
||||||
|
int message_stage; // 0: showing message1, 1: showing message2
|
||||||
|
uint32_t message1_finish_time; // Timestamp when message1 finished revealing (0 if not finished)
|
||||||
|
// Fonts
|
||||||
|
TTF_Font* font_large; // Font for message1 (120pt)
|
||||||
|
TTF_Font* font_small; // Font for message2 (24pt)
|
||||||
|
TTF_Font* current_font; // Currently used font (points to either font_large or font_small)
|
||||||
|
// Audio
|
||||||
Mix_Chunk* beep_chunk; // Sound effect for each typed character
|
Mix_Chunk* beep_chunk; // Sound effect for each typed character
|
||||||
// Screen shake effect
|
// Screen shake effect
|
||||||
float shake_timer; // Time remaining for shake effect (ms)
|
float shake_timer; // Time remaining for shake effect (ms)
|
||||||
|
|
@ -66,13 +77,18 @@ bool init_game(Game *game) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the font file from assets. Size is 48 for a cinematic look.
|
// Load the fonts
|
||||||
game->font = TTF_OpenFont("assets/font.ttf", 48);
|
game->font_large = TTF_OpenFont("assets/font.ttf", 120);
|
||||||
if (!game->font) {
|
if (!game->font_large) {
|
||||||
printf("CRITICAL: Failed to load font! TTF_Error: %s\n", TTF_GetError());
|
printf("CRITICAL: Failed to load large font! TTF_Error: %s\n", TTF_GetError());
|
||||||
} else {
|
return false;
|
||||||
printf("SUCCESS: Font loaded successfully!\n");
|
|
||||||
}
|
}
|
||||||
|
game->font_small = TTF_OpenFont("assets/font.ttf", 24);
|
||||||
|
if (!game->font_small) {
|
||||||
|
printf("CRITICAL: Failed to load small font! TTF_Error: %s\n", TTF_GetError());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
game->current_font = game->font_large; // Start with large font for first message
|
||||||
|
|
||||||
// Load the beep sound effect
|
// Load the beep sound effect
|
||||||
game->beep_chunk = Mix_LoadWAV("assets/dialog-beep.wav");
|
game->beep_chunk = Mix_LoadWAV("assets/dialog-beep.wav");
|
||||||
|
|
@ -84,9 +100,14 @@ bool init_game(Game *game) {
|
||||||
// Setup initial state
|
// Setup initial state
|
||||||
game->is_running = true;
|
game->is_running = true;
|
||||||
game->escape_timer = 0.0f;
|
game->escape_timer = 0.0f;
|
||||||
game->visible_chars = 0;
|
game->message1 = "Hello, human.";
|
||||||
game->last_char_time = SDL_GetTicks();
|
game->visible_chars1 = 0;
|
||||||
game->message = "Hello, human.";
|
game->last_char_time1 = SDL_GetTicks();
|
||||||
|
game->message2 = "It is a known fact that C, is superior to every other programming language.";
|
||||||
|
game->visible_chars2 = 0;
|
||||||
|
game->last_char_time2 = 0; // Not used until we switch to message2
|
||||||
|
game->message_stage = 0; // Start with message1
|
||||||
|
game->message1_finish_time = 0; // Not finished yet
|
||||||
// Initialize shake effect
|
// Initialize shake effect
|
||||||
game->shake_timer = 0.0f;
|
game->shake_timer = 0.0f;
|
||||||
game->shake_duration = 300.0f; // 300ms shake duration
|
game->shake_duration = 300.0f; // 300ms shake duration
|
||||||
|
|
@ -148,13 +169,14 @@ void update(Game *game) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TYPEWRITER LOGIC:
|
// TYPEWRITER LOGIC:
|
||||||
// Check if enough time has passed since the last letter appeared.
|
|
||||||
uint32_t current_time = SDL_GetTicks();
|
uint32_t current_time = SDL_GetTicks();
|
||||||
if (current_time - game->last_char_time >= 333) { // Adjusted timing
|
|
||||||
if (game->visible_chars < (int)strlen(game->message)) {
|
if (game->message_stage == 0) {
|
||||||
// Check if the character to be revealed is a space
|
// Handling message1: "Hello, human."
|
||||||
char current_char = game->message[game->visible_chars];
|
if (current_time - game->last_char_time1 >= 333) { // Adjusted timing
|
||||||
game->visible_chars++;
|
if (game->visible_chars1 < (int)strlen(game->message1)) {
|
||||||
|
char current_char = game->message1[game->visible_chars1];
|
||||||
|
game->visible_chars1++;
|
||||||
|
|
||||||
// Play beep for each character except spaces (already lower pitch due to mixer frequency)
|
// Play beep for each character except spaces (already lower pitch due to mixer frequency)
|
||||||
if (game->beep_chunk && current_char != ' ') {
|
if (game->beep_chunk && current_char != ' ') {
|
||||||
|
|
@ -162,7 +184,37 @@ void update(Game *game) {
|
||||||
// Trigger shake effect for non-space characters
|
// Trigger shake effect for non-space characters
|
||||||
game->shake_timer = game->shake_duration;
|
game->shake_timer = game->shake_duration;
|
||||||
}
|
}
|
||||||
game->last_char_time = current_time;
|
game->last_char_time1 = current_time;
|
||||||
|
}
|
||||||
|
// Check if we just finished message1
|
||||||
|
if (game->visible_chars1 == (int)strlen(game->message1)) {
|
||||||
|
game->message1_finish_time = current_time;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if we should switch to message2 (after 3.5 seconds of finishing message1)
|
||||||
|
if (game->message1_finish_time != 0 &&
|
||||||
|
(current_time - game->message1_finish_time >= 3500)) {
|
||||||
|
game->message_stage = 1;
|
||||||
|
game->visible_chars2 = 0;
|
||||||
|
game->last_char_time2 = current_time;
|
||||||
|
game->current_font = game->font_small; // Switch to small font
|
||||||
|
}
|
||||||
|
} else if (game->message_stage == 1) {
|
||||||
|
// Handling message2: "It is a known fact that C, is superior to every other programming language."
|
||||||
|
if (current_time - game->last_char_time2 >= 333) { // Adjusted timing
|
||||||
|
if (game->visible_chars2 < (int)strlen(game->message2)) {
|
||||||
|
char current_char = game->message2[game->visible_chars2];
|
||||||
|
game->visible_chars2++;
|
||||||
|
|
||||||
|
// Play beep for each character except spaces (already lower pitch due to mixer frequency)
|
||||||
|
if (game->beep_chunk && current_char != ' ') {
|
||||||
|
Mix_PlayChannel(-1, game->beep_chunk, 0);
|
||||||
|
// Trigger shake effect for non-space characters
|
||||||
|
game->shake_timer = game->shake_duration;
|
||||||
|
}
|
||||||
|
game->last_char_time2 = current_time;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,15 +235,26 @@ void render(SDL_Renderer *renderer, Game *game) {
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
// 2. Render the revealed portion of the text
|
// 2. Render the revealed portion of the text
|
||||||
if (game->font) {
|
if (game->current_font) {
|
||||||
char buffer[64] = {0};
|
// Determine which message to render based on message_stage
|
||||||
if (game->visible_chars > 0) {
|
const char* message_to_render;
|
||||||
|
int visible_chars_to_render;
|
||||||
|
if (game->message_stage == 0) {
|
||||||
|
message_to_render = game->message1;
|
||||||
|
visible_chars_to_render = game->visible_chars1;
|
||||||
|
} else {
|
||||||
|
message_to_render = game->message2;
|
||||||
|
visible_chars_to_render = game->visible_chars2;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buffer[256] = {0}; // Increased buffer size for safety
|
||||||
|
if (visible_chars_to_render > 0) {
|
||||||
// Copy only the number of characters currently 'revealed'
|
// Copy only the number of characters currently 'revealed'
|
||||||
strncpy(buffer, game->message, game->visible_chars);
|
strncpy(buffer, message_to_render, visible_chars_to_render);
|
||||||
buffer[game->visible_chars] = '\0';
|
buffer[visible_chars_to_render] = '\0';
|
||||||
|
|
||||||
SDL_Color white = {255, 255, 255, 255};
|
SDL_Color white = {255, 255, 255, 255};
|
||||||
SDL_Surface* surface = TTF_RenderText_Blended(game->font, buffer, white);
|
SDL_Surface* surface = TTF_RenderText_Blended(game->current_font, buffer, white);
|
||||||
|
|
||||||
if (surface) {
|
if (surface) {
|
||||||
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
|
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||||
|
|
@ -250,7 +313,8 @@ int main(int argc, char* args[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup memory
|
// Cleanup memory
|
||||||
if (game.font) TTF_CloseFont(game.font);
|
if (game.font_large) TTF_CloseFont(game.font_large);
|
||||||
|
if (game.font_small) TTF_CloseFont(game.font_small);
|
||||||
if (game.beep_chunk) Mix_FreeChunk(game.beep_chunk);
|
if (game.beep_chunk) Mix_FreeChunk(game.beep_chunk);
|
||||||
Mix_CloseAudio();
|
Mix_CloseAudio();
|
||||||
Mix_Quit();
|
Mix_Quit();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue