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
|
||||
*.d
|
||||
|
||||
# the game itself
|
||||
game
|
||||
|
||||
# macos bs
|
||||
.DS_Store
|
||||
assets/.DS_Store
|
||||
|
||||
# claude code
|
||||
.claude
|
||||
|
||||
# Object files
|
||||
*.o
|
||||
*.ko
|
||||
|
|
|
|||
BIN
assets/.DS_Store
vendored
BIN
assets/.DS_Store
vendored
Binary file not shown.
BIN
game
BIN
game
Binary file not shown.
132
src/main.c
132
src/main.c
|
|
@ -31,10 +31,21 @@ typedef struct {
|
|||
typedef struct {
|
||||
bool is_running; // Controls the main game loop
|
||||
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
|
||||
uint32_t last_char_time; // Timestamp of the last character revealed
|
||||
const char* message; // The string to be displayed
|
||||
TTF_Font* font; // Pointer to the loaded TrueType font
|
||||
// Message 1: "Hello, human."
|
||||
const char* message1;
|
||||
int visible_chars1; // Number of characters revealed in message1
|
||||
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
|
||||
// Screen shake effect
|
||||
float shake_timer; // Time remaining for shake effect (ms)
|
||||
|
|
@ -66,13 +77,18 @@ bool init_game(Game *game) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Load the font file from assets. Size is 48 for a cinematic look.
|
||||
game->font = TTF_OpenFont("assets/font.ttf", 48);
|
||||
if (!game->font) {
|
||||
printf("CRITICAL: Failed to load font! TTF_Error: %s\n", TTF_GetError());
|
||||
} else {
|
||||
printf("SUCCESS: Font loaded successfully!\n");
|
||||
// Load the fonts
|
||||
game->font_large = TTF_OpenFont("assets/font.ttf", 120);
|
||||
if (!game->font_large) {
|
||||
printf("CRITICAL: Failed to load large font! TTF_Error: %s\n", TTF_GetError());
|
||||
return false;
|
||||
}
|
||||
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
|
||||
game->beep_chunk = Mix_LoadWAV("assets/dialog-beep.wav");
|
||||
|
|
@ -84,9 +100,14 @@ bool init_game(Game *game) {
|
|||
// Setup initial state
|
||||
game->is_running = true;
|
||||
game->escape_timer = 0.0f;
|
||||
game->visible_chars = 0;
|
||||
game->last_char_time = SDL_GetTicks();
|
||||
game->message = "Hello, human.";
|
||||
game->message1 = "Hello, human.";
|
||||
game->visible_chars1 = 0;
|
||||
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
|
||||
game->shake_timer = 0.0f;
|
||||
game->shake_duration = 300.0f; // 300ms shake duration
|
||||
|
|
@ -148,21 +169,52 @@ void update(Game *game) {
|
|||
}
|
||||
|
||||
// TYPEWRITER LOGIC:
|
||||
// Check if enough time has passed since the last letter appeared.
|
||||
uint32_t current_time = SDL_GetTicks();
|
||||
if (current_time - game->last_char_time >= 333) { // Adjusted timing
|
||||
if (game->visible_chars < (int)strlen(game->message)) {
|
||||
// Check if the character to be revealed is a space
|
||||
char current_char = game->message[game->visible_chars];
|
||||
game->visible_chars++;
|
||||
|
||||
// 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;
|
||||
if (game->message_stage == 0) {
|
||||
// Handling message1: "Hello, human."
|
||||
if (current_time - game->last_char_time1 >= 333) { // Adjusted timing
|
||||
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)
|
||||
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_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;
|
||||
}
|
||||
game->last_char_time = current_time;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -183,19 +235,30 @@ void render(SDL_Renderer *renderer, Game *game) {
|
|||
SDL_RenderClear(renderer);
|
||||
|
||||
// 2. Render the revealed portion of the text
|
||||
if (game->font) {
|
||||
char buffer[64] = {0};
|
||||
if (game->visible_chars > 0) {
|
||||
if (game->current_font) {
|
||||
// Determine which message to render based on message_stage
|
||||
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'
|
||||
strncpy(buffer, game->message, game->visible_chars);
|
||||
buffer[game->visible_chars] = '\0';
|
||||
strncpy(buffer, message_to_render, visible_chars_to_render);
|
||||
buffer[visible_chars_to_render] = '\0';
|
||||
|
||||
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) {
|
||||
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
|
||||
|
||||
// CENTER THE TEXT WITH SHAKE:
|
||||
// Subtract half the text width/height from center screen coordinates.
|
||||
// Add shake offset for text jitter effect
|
||||
|
|
@ -250,7 +313,8 @@ int main(int argc, char* args[]) {
|
|||
}
|
||||
|
||||
// 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);
|
||||
Mix_CloseAudio();
|
||||
Mix_Quit();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue