added some new assets and effects

This commit is contained in:
dvorakmortonxd 2026-08-30 03:21:26 +02:00
commit 096c1dde2b
7 changed files with 68 additions and 10 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

View file

@ -63,4 +63,10 @@ The project includes a `Makefile` to automate the compilation process.
- [ ] Implement transition from Intro Sequence to Active Gameplay. - [ ] Implement transition from Intro Sequence to Active Gameplay.
- [ ] Integrate sprite rendering for the player character. - [ ] Integrate sprite rendering for the player character.
- [ ] Expand game world with interactive objects. - [ ] Expand game world with interactive objects.
- [ ] Add background music and sound effects using `SDL2_mixer`. - [ ] Add background music and sound effects using `SDL2_mixer`.
## 🔊 Audio Credits
- dialog-beep.wav: Sound effect from [freesound.org](https://freesound.org/people/nugsano/sounds/842200/) by nugsano
## 🔤 Font Credits
- font.ttf: Determination Mono Web Font from [FontSpace](https://www.fontspace.com/determination-mono-web-font-f23209)

BIN
assets/.DS_Store vendored Normal file

Binary file not shown.

BIN
assets/dialog-beep.wav Normal file

Binary file not shown.

Binary file not shown.

BIN
game Executable file

Binary file not shown.

View file

@ -3,6 +3,8 @@
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <SDL_ttf.h> #include <SDL_ttf.h>
#include <SDL_mixer.h>
#include <stdlib.h>
/* /*
* Global Constants * Global Constants
@ -22,7 +24,7 @@ typedef struct {
SDL_Color color; SDL_Color color;
} Player; } Player;
/* /*
* Game State Structure * Game State Structure
* This is the 'Brain' of the game, containing everything needed to track the current session. * This is the 'Brain' of the game, containing everything needed to track the current session.
*/ */
@ -33,6 +35,11 @@ typedef struct {
uint32_t last_char_time; // Timestamp of the last character revealed uint32_t last_char_time; // Timestamp of the last character revealed
const char* message; // The string to be displayed const char* message; // The string to be displayed
TTF_Font* font; // Pointer to the loaded TrueType font TTF_Font* font; // Pointer to the loaded TrueType font
Mix_Chunk* beep_chunk; // Sound effect for each typed character
// Screen shake effect
float shake_timer; // Time remaining for shake effect (ms)
float shake_duration; // Total duration of shake effect when triggered (ms)
float shake_intensity; // Current intensity of shake (pixels)
Player player; // The player object Player player; // The player object
} Game; } Game;
@ -53,6 +60,12 @@ bool init_game(Game *game) {
return false; return false;
} }
// Initialize SDL_mixer for audio with lower frequency (22050 Hz) to lower pitch of beep
if (Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 2048) < 0) {
printf("SDL_mixer could not open audio! Mix_Error: %s\n", Mix_GetError());
return false;
}
// Load the font file from assets. Size is 48 for a cinematic look. // Load the font file from assets. Size is 48 for a cinematic look.
game->font = TTF_OpenFont("assets/font.ttf", 48); game->font = TTF_OpenFont("assets/font.ttf", 48);
if (!game->font) { if (!game->font) {
@ -61,14 +74,27 @@ bool init_game(Game *game) {
printf("SUCCESS: Font loaded successfully!\n"); printf("SUCCESS: Font loaded successfully!\n");
} }
// Load the beep sound effect
game->beep_chunk = Mix_LoadWAV("assets/dialog-beep.wav");
if (!game->beep_chunk) {
printf("WARNING: Failed to load beep sound! Mix_Error: %s\n", Mix_GetError());
// Not critical, continue without sound
}
// 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->visible_chars = 0;
game->last_char_time = SDL_GetTicks(); game->last_char_time = SDL_GetTicks();
game->message = "Hello, human."; game->message = "Hello, human.";
// Initialize shake effect
game->shake_timer = 0.0f;
game->shake_duration = 300.0f; // 300ms shake duration
game->shake_intensity = 0.0f;
// Seed random number generator for shake effect
srand((unsigned int)SDL_GetTicks());
game->player = (Player){ .x = 100, .y = 100, .speed = 0.5f, .size = 32, .color = {255, 0, 0, 255} }; game->player = (Player){ .x = 100, .y = 100, .speed = 0.5f, .size = 32, .color = {255, 0, 0, 255} };
return true; return true;
} }
@ -110,12 +136,32 @@ void handle_input(Game *game, float delta_time) {
* Handles the typewriter timing. * Handles the typewriter timing.
*/ */
void update(Game *game) { void update(Game *game) {
// UPDATE SHAKE EFFECT:
// Decrease shake timer and calculate current intensity
if (game->shake_timer > 0.0f) {
game->shake_timer -= 16.67f; // Approximate 60 FPS frame time
if (game->shake_timer < 0.0f) game->shake_timer = 0.0f;
// Calculate intensity based on remaining timer (linear fade out)
game->shake_intensity = (game->shake_timer / game->shake_duration) * 4.0f; // Max 4px shake
} else {
game->shake_intensity = 0.0f;
}
// TYPEWRITER LOGIC: // TYPEWRITER LOGIC:
// Check if enough time has passed since the last letter appeared. // 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 >= 150) { if (current_time - game->last_char_time >= 333) { // Adjusted timing
if (game->visible_chars < (int)strlen(game->message)) { 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++; 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;
}
game->last_char_time = current_time; game->last_char_time = current_time;
} }
} }
@ -150,13 +196,16 @@ void render(SDL_Renderer *renderer, Game *game) {
if (surface) { if (surface) {
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface); SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
// CENTER THE TEXT: // CENTER THE TEXT WITH SHAKE:
// Subtract half the text width/height from center screen coordinates. // Subtract half the text width/height from center screen coordinates.
SDL_Rect text_rect = { // Add shake offset for text jitter effect
(SCREEN_WIDTH - surface->w) / 2, int shake_offset_x = (rand() % (int)(game->shake_intensity * 2 + 1)) - game->shake_intensity;
(SCREEN_HEIGHT - surface->h) / 2, int shake_offset_y = (rand() % (int)(game->shake_intensity * 2 + 1)) - game->shake_intensity;
surface->w, SDL_Rect text_rect = {
surface->h (SCREEN_WIDTH - surface->w) / 2 + shake_offset_x,
(SCREEN_HEIGHT - surface->h) / 2 + shake_offset_y,
surface->w,
surface->h
}; };
SDL_RenderCopy(renderer, texture, NULL, &text_rect); SDL_RenderCopy(renderer, texture, NULL, &text_rect);
@ -202,6 +251,9 @@ int main(int argc, char* args[]) {
// Cleanup memory // Cleanup memory
if (game.font) TTF_CloseFont(game.font); if (game.font) TTF_CloseFont(game.font);
if (game.beep_chunk) Mix_FreeChunk(game.beep_chunk);
Mix_CloseAudio();
Mix_Quit();
SDL_DestroyRenderer(renderer); SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window); SDL_DestroyWindow(window);
TTF_Quit(); TTF_Quit();