added some new assets and effects
This commit is contained in:
parent
6d77491228
commit
096c1dde2b
7 changed files with 68 additions and 10 deletions
BIN
.DS_Store
vendored
Normal file
BIN
.DS_Store
vendored
Normal file
Binary file not shown.
|
|
@ -64,3 +64,9 @@ The project includes a `Makefile` to automate the compilation process.
|
||||||
- [ ] 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
BIN
assets/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
assets/dialog-beep.wav
Normal file
BIN
assets/dialog-beep.wav
Normal file
Binary file not shown.
BIN
assets/font.ttf
BIN
assets/font.ttf
Binary file not shown.
BIN
game
Executable file
BIN
game
Executable file
Binary file not shown.
60
src/main.c
60
src/main.c
|
|
@ -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
|
||||||
|
|
@ -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,12 +74,25 @@ 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,11 +196,14 @@ 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.
|
||||||
|
// Add shake offset for text jitter effect
|
||||||
|
int shake_offset_x = (rand() % (int)(game->shake_intensity * 2 + 1)) - game->shake_intensity;
|
||||||
|
int shake_offset_y = (rand() % (int)(game->shake_intensity * 2 + 1)) - game->shake_intensity;
|
||||||
SDL_Rect text_rect = {
|
SDL_Rect text_rect = {
|
||||||
(SCREEN_WIDTH - surface->w) / 2,
|
(SCREEN_WIDTH - surface->w) / 2 + shake_offset_x,
|
||||||
(SCREEN_HEIGHT - surface->h) / 2,
|
(SCREEN_HEIGHT - surface->h) / 2 + shake_offset_y,
|
||||||
surface->w,
|
surface->w,
|
||||||
surface->h
|
surface->h
|
||||||
};
|
};
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue