diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/audio_sys.h | 29 | ||||
| -rw-r--r-- | src/controller.h | 28 | ||||
| -rw-r--r-- | src/fmv.h | 5 | ||||
| -rw-r--r-- | src/game/battle.h | 1 | ||||
| -rw-r--r-- | src/game/config.h | 7 | ||||
| -rw-r--r-- | src/game/enemy.c | 107 | ||||
| -rw-r--r-- | src/game/enemy.h | 29 | ||||
| -rw-r--r-- | src/gunner/audio_sys.c (renamed from src/audio_sys.c) | 52 | ||||
| -rw-r--r-- | src/gunner/config.h (renamed from src/config.h) | 1 | ||||
| -rw-r--r-- | src/gunner/controller.c (renamed from src/controller.c) | 4 | ||||
| -rw-r--r-- | src/gunner/fmv.c (renamed from src/fmv.c) | 0 | ||||
| -rw-r--r-- | src/gunner/pl_mpeg.h (renamed from src/pl_mpeg.h) | 0 | ||||
| -rw-r--r-- | src/gunner/rand_sys.c (renamed from src/rand_sys.c) | 12 | ||||
| -rw-r--r-- | src/gunner/rumble.c (renamed from src/rumble.c) | 26 | ||||
| -rw-r--r-- | src/gunner/script_sys.c (renamed from src/script_sys.c) | 16 | ||||
| -rw-r--r-- | src/gunner/shader_sys.c (renamed from src/shader_sys.c) | 8 | ||||
| -rw-r--r-- | src/gunner/text.c | 116 | ||||
| -rw-r--r-- | src/gunner/texture_sys.c (renamed from src/texture_sys.c) | 5 | ||||
| -rw-r--r-- | src/gunner/utils.h (renamed from src/utils.h) | 0 | ||||
| -rw-r--r-- | src/main.c | 38 | ||||
| -rw-r--r-- | src/rand_sys.h | 11 | ||||
| -rw-r--r-- | src/script_sys.h | 7 | ||||
| -rw-r--r-- | src/shader_sys.h | 18 | ||||
| -rw-r--r-- | src/text.c | 64 | ||||
| -rw-r--r-- | src/text.h | 23 | ||||
| -rw-r--r-- | src/texture_sys.h | 16 |
26 files changed, 360 insertions, 263 deletions
diff --git a/src/audio_sys.h b/src/audio_sys.h deleted file mode 100644 index 9607189..0000000 --- a/src/audio_sys.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "config.h" - -// 8 max -i32 load_audio(const char* path); -void play_audio(i32 idx); -void pause_audio(i32 idx); -void resume_audio(i32 idx); - -// Only one at any given time. -// In the future you can load a second one -// It'll be a copy of the one from my Godot games -void load_music(const char* path); -void play_music(void); - -// It would be more convenient if the files had this info -// But it's better to just let you control this for now. -void set_music_loop(b32 loop); -void set_music_loop_point(f32 point); - -void pause_music(void); -void resume_music(void); - -void set_main_vol(f32 vol); - -void update_audio(void); -void unload_active_audio(void); -void unload_current_music(void);
\ No newline at end of file diff --git a/src/controller.h b/src/controller.h deleted file mode 100644 index 3476641..0000000 --- a/src/controller.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include "config.h" - -b32 is_key_pressed(i32 btn); -b32 is_key_held(i32 btn); -b32 is_key_released(i32 btn); - -b32 is_mouse_pressed(i32 btn); -b32 is_mouse_held(i32 btn); -b32 is_mouse_released(i32 btn); - -void set_mouse_scale(f32 x, f32 y); -vec2 get_mouse_pos(void); -fx32 get_wheel_movement(void); - -b32 is_button_pressed(i32 btn); -b32 is_button_held(i32 btn); -b32 is_button_released(i32 btn); - -i32 last_button_press(void); - -vec2 get_dir_input(void); - -// This portion is implemented in rumble.c! // -void set_rumble(f32 duration, f32 strength); -void poll_rumble(f32 dt); -void stop_rumble(void); diff --git a/src/fmv.h b/src/fmv.h deleted file mode 100644 index b9149eb..0000000 --- a/src/fmv.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once - -void fmv_load(const char* path); -void fmv_update(const float dt); -void fmv_unload(void);
\ No newline at end of file diff --git a/src/game/battle.h b/src/game/battle.h new file mode 100644 index 0000000..7b9637e --- /dev/null +++ b/src/game/battle.h @@ -0,0 +1 @@ +#pragma once
\ No newline at end of file diff --git a/src/game/config.h b/src/game/config.h new file mode 100644 index 0000000..7e17f45 --- /dev/null +++ b/src/game/config.h @@ -0,0 +1,7 @@ +#pragma once + +#define GAME_NAME "Conflict deFuse" +#define GAME_WIDTH 320 +#define GAME_HEIGHT 240 +#define DEFAULT_SCALE 2 +#define FRAMERATE 60
\ No newline at end of file diff --git a/src/game/enemy.c b/src/game/enemy.c new file mode 100644 index 0000000..34034ab --- /dev/null +++ b/src/game/enemy.c @@ -0,0 +1,107 @@ +#include "enemy.c" + +static const Enemy enemy_defines[ENEMY_SIZE] = { + { + "Amanita", + ENEMY_AMANITA, + 32, + 20 + }, + { + "Felticia", + ENEMY_FELTICIA, + 40, + 16 + }, + { + "Flatwoods Monster", + ENEMY_FLATWOODS, + 38, + 18 + }, + { + "Time Square", + ENEMY_SQUARE, + 16, + 40 + }, + { + "Robot Gangster", + ENEMY_GANGSTER, + 48, + 12 + }, + { + "Loveland Frog", + ENEMY_FROG, + 28, + 16 + }, + { + "Hanako-san", + ENEMY_HANAKO, + 40, + 40 + }, + { + "Dover Demon", + ENEMY_DOVER, + 38, + 40 + }, + { + "Jersey Devil", + ENEMY_JERSEY, + 50, + 20 + }, + { + "Mothman", + ENEMY_MOTHMAN, + 40, + 10 + }, + { + "Sackman", + ENEMY_SACKMAN, + 48, + 20 + } +}; + +static Enemy stationed[3] = {0}; + +void add_enemy(const EnemyType type) +{ + for(int i = 0; i < 3; ++i){ + if(stationed[i].name == NULL){ + stationed[i] = enemy_defines[type]; + break; + } + } +} + +void damage_enemy(const u8 loc, const i8 dmg) +{ + if(loc > 2) + return; + + if(stationed[i].name == NULL) + return; + + stationed[i].health -= dmg + if(stationed[i].health <= 0) + stationed[i] = {0}; +} + +bool check_active_enemies(void) +{ + bool nice = true; + for(int i = 0; i < 3; ++i){ + if(stationed[i].name != NULL){ + nice = false; + break; + } + + return nice; +}
\ No newline at end of file diff --git a/src/game/enemy.h b/src/game/enemy.h new file mode 100644 index 0000000..4e82e92 --- /dev/null +++ b/src/game/enemy.h @@ -0,0 +1,29 @@ +#pragma once + +#include "../gunner/config.h" + +typedef enum{ + ENEMY_AMANITA = 0, + ENEMY_FELTICIA = 1, + ENEMY_FLATWOODS = 2, + ENEMY_SQUARE = 3, + ENEMY_GANGSTER = 4, + ENEMY_FROG = 5, + ENEMY_HANAKO = 6, + ENEMY_DOVER = 7, + ENEMY_JERSEY = 8, + ENEMY_MOTHMAN = 9, + ENEMY_SACKMAN = 10, + ENEMY_SIZE +}EnemyType; + +typedef struct{ + const char* name; + u8 enemy_type; + i8 health; + i8 mana; +}Enemy; + +void add_enemy(const EnemyType type); +void damage_enemy(const u8 loc, const i8 dmg); +bool check_active_enemies(void);
\ No newline at end of file diff --git a/src/audio_sys.c b/src/gunner/audio_sys.c index f164947..54aba0e 100644 --- a/src/audio_sys.c +++ b/src/gunner/audio_sys.c @@ -1,29 +1,39 @@ -#include "config.h" -#include <raylib.h> - // Defines #define MAX_SOUND 8 -Sound sounds[MAX_SOUND] = {0}; -Music track = {0}; +static Sound sounds[MAX_SOUND] = {0}; +static s8 sound_paths[MAX_SOUND] = {0}; + +static Music track = {0}; +static s8 music_path = {0}; // Audio things i32 load_audio(const char* path) { - i32 idx = -1; + i32 current_idx = BLANK_DEFAULT; + + if(path == NULL) + return current_idx; + + s8 path_str = cstr_to_s8(path); for(int i = 0; i < MAX_SOUND; ++i){ - if(!IsSoundReady(sounds[i])){ - idx = i; + if(equal_s8(path_str, sound_paths[current_idx])){ + free_s8(&path_str); + return i; + } + + if(sounds[i].stream.buffer == NULL){ + current_idx = i; sounds[i] = LoadSound(path); + sound_paths[i] = path_str; break; } } - assert(idx != -1); - return idx; + return current_idx; } void play_audio(i32 idx) @@ -48,6 +58,15 @@ void resume_audio(i32 idx) void load_music(const char* path) { + if(path == NULL) + return; + + s8 path_str = cstr_to_s8(path); + if(equal_s8(path_str, music_path)){ + free_s8(&path_str); + return; + } + track = LoadMusicStream(path); } @@ -91,12 +110,18 @@ void update_audio(void) UpdateMusicStream(track); } +void unload_audio(i32 idx) +{ + StopSound(sounds[idx]); + UnloadSound(sounds[idx]); + free_s8(&sound_paths[idx]); +} + void unload_active_audio(void) { for(int i = 0; i < MAX_SOUND; ++i){ - if(IsSoundReady(sounds[i])){ - StopSound(sounds[i]); //It is probably a good idea to do this... - UnloadSound(sounds[i]); + if(sounds[i].stream.buffer != NULL){ + unload_audio(i); } } } @@ -105,4 +130,5 @@ void unload_current_music(void) { StopMusicStream(track); UnloadMusicStream(track); + free_s8(&music_path); }
\ No newline at end of file diff --git a/src/config.h b/src/gunner/config.h index 81a2a51..dc098e5 100644 --- a/src/config.h +++ b/src/gunner/config.h @@ -43,6 +43,7 @@ typedef i32 fx32; #define TO_FIXED(x) ((fx32)(x) << FIXED_POINT_BITS) #define FROM_FIXED(x) ((x) >> FIXED_POINT_BITS) #define FP_TO_FIXED(x) (fx32)((x) * FIXED_POINT_ONE) +#define FP_FROM_FIXED(x) (f32)((x) * (f32)(1 / FIXED_POINT_ONE)) typedef struct{ fx32 x, y; diff --git a/src/controller.c b/src/gunner/controller.c index 434e3d6..4e56a27 100644 --- a/src/controller.c +++ b/src/gunner/controller.c @@ -1,7 +1,3 @@ -#include "controller.h" - -#include <raylib.h> - // Keyboard things b32 is_key_pressed(i32 btn) diff --git a/src/fmv.c b/src/gunner/fmv.c index 40efa8d..40efa8d 100644 --- a/src/fmv.c +++ b/src/gunner/fmv.c diff --git a/src/pl_mpeg.h b/src/gunner/pl_mpeg.h index 0016211..0016211 100644 --- a/src/pl_mpeg.h +++ b/src/gunner/pl_mpeg.h diff --git a/src/rand_sys.c b/src/gunner/rand_sys.c index 679ac94..ffd2a25 100644 --- a/src/rand_sys.c +++ b/src/gunner/rand_sys.c @@ -1,10 +1,10 @@ -#include "rand_sys.h" +typedef struct _FILETIME { + u32 dwLowDateTime; + u32 dwHighDateTime; +} FILETIME; -#define WIN32_LEAN_AND_MEAN -#define NOSERVICE -#define NOMCX -#define NOIME -#include <windows.h> +#define W32(r) __declspec(dllimport) r __stdcall +W32(void) GetSystemTimeAsFileTime(FILETIME *); static u32 state[2]; diff --git a/src/rumble.c b/src/gunner/rumble.c index b2da191..dca4f08 100644 --- a/src/rumble.c +++ b/src/gunner/rumble.c @@ -1,14 +1,7 @@ /* -I made this a separate source file because Raylib has some quirks -regarding Windows compilation. And I also suppose because it has -some state of its own. - NOTE FOR SPELUNKERS: this requires linking to xinput1_4 AFAIK */ -#include "controller.h" -#include <stdio.h> - // Windows stuff starts // typedef struct _XINPUT_VIBRATION { unsigned wLeftMotorSpeed; @@ -33,6 +26,16 @@ void set_rumble(f32 duration, f32 strength) } } +void stop_rumble(void) +{ + timer = 0; + + XINPUT_VIBRATION state = {}; + state.wLeftMotorSpeed = 0; + state.wRightMotorSpeed = 0; + XInputSetState(0, &state); +} + void poll_rumble(f32 dt) { // Early return @@ -47,12 +50,3 @@ void poll_rumble(f32 dt) } } -void stop_rumble(void) -{ - timer = 0; - - XINPUT_VIBRATION state = {}; - state.wLeftMotorSpeed = 0; - state.wRightMotorSpeed = 0; - XInputSetState(0, &state); -}
\ No newline at end of file diff --git a/src/script_sys.c b/src/gunner/script_sys.c index 4b12e64..12dbac1 100644 --- a/src/script_sys.c +++ b/src/gunner/script_sys.c @@ -3,8 +3,10 @@ #include "shader_sys.h" #include "controller.h" +#include "text.h" #include "rand_sys.h" +#include "audio_sys.h" #include <libtcc.h> #include <stddef.h> @@ -35,6 +37,12 @@ static void restart(void) tcc_add_symbol(new_state, "unload_tex", unload_tex); tcc_add_symbol(new_state, "reset_active_shader", reset_active_shader); + tcc_add_symbol(new_state, "set_blend_mode", BeginBlendMode); + tcc_add_symbol(new_state, "reset_blend_mode", EndBlendMode); + + tcc_add_symbol(new_state, "load_font", load_font); + tcc_add_symbol(new_state, "draw_text_font", draw_text_font); + tcc_add_symbol(new_state, "set_rumble", set_rumble); tcc_add_symbol(new_state, "stop_rumble", stop_rumble); @@ -47,6 +55,14 @@ static void restart(void) tcc_add_symbol(new_state, "get_dir_input", get_dir_input); + tcc_add_symbol(new_state, "load_audio", load_audio); + tcc_add_symbol(new_state, "play_audio", play_audio); + + tcc_add_symbol(new_state, "load_music", load_music); + tcc_add_symbol(new_state, "play_music", play_music); + tcc_add_symbol(new_state, "set_music_loop", set_music_loop); + tcc_add_symbol(new_state, "set_music_loop_point", set_music_loop_point); + if(tcc_add_file(new_state, "assets/src/main.c") == -1){ tcc_delete(new_state); return; diff --git a/src/shader_sys.c b/src/gunner/shader_sys.c index 4d75b6a..d274966 100644 --- a/src/shader_sys.c +++ b/src/gunner/shader_sys.c @@ -1,10 +1,4 @@ -#include "utils.h" -#include "config.h" - -#include "text.h" - -#include <stdlib.h> -#include <stdio.h> +// Defines #define MAX_SHADER_SIZE 8 diff --git a/src/gunner/text.c b/src/gunner/text.c new file mode 100644 index 0000000..0812ff1 --- /dev/null +++ b/src/gunner/text.c @@ -0,0 +1,116 @@ +#define String(s) (s8){(u8*)s, lengthof(s)} +typedef struct { + u8 *buf; + size len; +} s8; + +#define MAX_FONT_SIZE 8 + +size txt_length(const char *text) +{ + size length = 0; + + if(text != NULL){ + while (*text++) length++; + } + + return length; +} + +s8 create_s8(const size sz) +{ + return (s8){(u8*)RL_MALLOC(sz), sz}; +} + +void free_s8(s8* str) +{ + RL_FREE(str->buf); +} + +s8 cstr_to_s8(const char* str) +{ + size sz = txt_length(str) + 1; + s8 final = (s8){(u8*)RL_MALLOC(sz), sz - 1}; + memcpy(final.buf, str, sz); + return final; +} + +b32 equal_s8(const s8 one, const s8 other) +{ + // Get OUTTA here + if(one.len != other.len) + return false; + + for(i32 i = 0; i < one.len; ++i){ + if(one.buf[i] != other.buf[i]) + return false; + } + + return true; +} + +void add_s8(s8 dst, const s8 src, size* pos) +{ + memcpy(dst.buf + *pos, src.buf, src.len); + *pos += src.len; +} + +s8 load_file_text(const s8 path) +{ + char* shr = LoadFileText((const char*)path.buf); + s8 file = cstr_to_s8(shr); + UnloadFileText(shr); + + return file; +} + +// Exposed Functions // + +static Font font_slots[MAX_FONT_SIZE] = {0}; +static s8 font_paths[MAX_FONT_SIZE] = {0}; + +i32 load_font(const char* path) +{ + s8 path_str = cstr_to_s8(path); + + i32 current_idx = BLANK_DEFAULT; + for(i32 i = 0; i < MAX_FONT_SIZE; ++i){ + if(equal_s8(path_str, font_paths[current_idx])){ + free_s8(&path_str); + return i; + } + + if(font_slots[i].texture.id <= 0){ + current_idx = i; + font_slots[current_idx] = LoadFont((const char*)path_str.buf); + font_paths[current_idx] = path_str; + break; + } + } + + //TODO: Handle slots a bit better. + assert(current_idx != BLANK_DEFAULT); + + return current_idx; +} + +void draw_text_font(i32 idx, const char* text, vec2 pos, i32 size, Color col) +{ + Vector2 position = (Vector2){FROM_FIXED(pos.x), FROM_FIXED(pos.y)}; + DrawTextEx(font_slots[idx], text, position, (f32)size, 1.0f, col); +} + +void unload_font(i32 idx) +{ + UnloadFont(font_slots[idx]); + free_s8(&font_paths[idx]); +} + +void unload_all_fonts(void) +{ + for(int i = 0; i < MAX_FONT_SIZE; ++i){ + if(font_slots[i].texture.id > 0) + unload_font(i); + + } +}
\ No newline at end of file diff --git a/src/texture_sys.c b/src/gunner/texture_sys.c index b4c3c4d..2865728 100644 --- a/src/texture_sys.c +++ b/src/gunner/texture_sys.c @@ -1,8 +1,3 @@ -#include "utils.h" -#include "text.h" - -#include <stddef.h> - #define MAX_TEX_SIZE 16 static Texture2D texture_slots[MAX_TEX_SIZE] = {0}; diff --git a/src/utils.h b/src/gunner/utils.h index 2d367d0..2d367d0 100644 --- a/src/utils.h +++ b/src/gunner/utils.h @@ -1,17 +1,30 @@ #include <raylib.h> -#include "texture_sys.h" -#include "shader_sys.h" -#include "script_sys.h" -#include "controller.h" -#include "rand_sys.h" -#include "audio_sys.h" +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "gunner/config.h" +#include "gunner/utils.h" + +#include "gunner/text.c" + +#include "gunner/texture_sys.c" +#include "gunner/shader_sys.c" + +#include "gunner/controller.c" +#include "gunner/rumble.c" +#include "gunner/rand_sys.c" +#include "gunner/audio_sys.c" + +#include "game/config.h" int main() { - InitWindow(640, 480, "Gunner Engine"); + SetTraceLogLevel(LOG_WARNING); + InitWindow(GAME_WIDTH * DEFAULT_SCALE, GAME_HEIGHT * DEFAULT_SCALE, GAME_NAME); - SetTargetFPS(60); + SetTargetFPS(FRAMERATE); InitAudioDevice(); @@ -19,7 +32,8 @@ int main() init_tex_sys(); init_shader_sys(); - init_script_sys(); + + i32 idx = load_font("assets/berry-rotunda.ttf"); while(!WindowShouldClose()){ float dt = GetFrameTime(); @@ -32,14 +46,16 @@ int main() ClearBackground(WHITE); BeginDrawing(); - update_script(); + + draw_text_font(idx, "Uneven Prankster Presents", (vec2){TO_FIXED(4), TO_FIXED(4)}, 16, BLACK); + EndDrawing(); } + unload_all_fonts(); unload_active_audio(); unload_current_music(); - deinit_script_sys(); unload_active_textures(); unload_active_shaders(); diff --git a/src/rand_sys.h b/src/rand_sys.h deleted file mode 100644 index 75198a0..0000000 --- a/src/rand_sys.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "config.h" - -// Based on mattiasgustavsson's rnd.h header - -void rand_seed(void); - -u32 rand_u32(void); - -int rand_range(i32 min, i32 max);
\ No newline at end of file diff --git a/src/script_sys.h b/src/script_sys.h deleted file mode 100644 index 4c2bc6d..0000000 --- a/src/script_sys.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -void init_script_sys(void); - -void update_script(void); - -void deinit_script_sys(void);
\ No newline at end of file diff --git a/src/shader_sys.h b/src/shader_sys.h deleted file mode 100644 index 1e30d7d..0000000 --- a/src/shader_sys.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "utils.h" -#include "config.h" - -void init_shader_sys(void); - -i32 load_new_shader(const char* path); - -void set_active_shader(i32 idx); - -void update_shaders(void); - -void reset_active_shader(void); - -void unload_shader(i32 idx); - -void unload_active_shaders(void);
\ No newline at end of file diff --git a/src/text.c b/src/text.c deleted file mode 100644 index 26c2eab..0000000 --- a/src/text.c +++ /dev/null @@ -1,64 +0,0 @@ -#include "text.h" -#include "utils.h" - -#include <string.h> -#include <stdlib.h> -#include <stdio.h> - -size txt_length(const char *text) -{ - size length = 0; - - if(text != NULL){ - while (*text++) length++; - } - - return length; -} - -s8 create_s8(const size sz) -{ - return (s8){(u8*)RL_MALLOC(sz), sz}; -} - -void free_s8(s8* str) -{ - RL_FREE(str->buf); -} - -s8 cstr_to_s8(const char* str) -{ - size sz = txt_length(str) + 1; - s8 final = (s8){(u8*)RL_MALLOC(sz), sz - 1}; - memcpy(final.buf, str, sz); - return final; -} - -b32 equal_s8(const s8 one, const s8 other) -{ - // Get OUTTA here - if(one.len != other.len) - return false; - - for(i32 i = 0; i < one.len; ++i){ - if(one.buf[i] != other.buf[i]) - return false; - } - - return true; -} - -void add_s8(s8 dst, const s8 src, size* pos) -{ - memcpy(dst.buf + *pos, src.buf, src.len); - *pos += src.len; -} - -s8 load_file_text(const s8 path) -{ - char* shr = LoadFileText((const char*)path.buf); - s8 file = cstr_to_s8(shr); - UnloadFileText(shr); - - return file; -}
\ No newline at end of file diff --git a/src/text.h b/src/text.h deleted file mode 100644 index 9ac01d3..0000000 --- a/src/text.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "config.h" - -#define String(s) (s8){(u8*)s, lengthof(s)} -typedef struct { - u8 *buf; - size len; -} s8; - -size txt_length(const char *text); - -s8 create_s8(const size sz); - -void free_s8(s8* str); - -s8 cstr_to_s8(const char* str); - -b32 equal_s8(const s8 one, const s8 other); - -void add_s8(s8 dst, const s8 src, size* pos); - -s8 load_file_text(const s8 path);
\ No newline at end of file diff --git a/src/texture_sys.h b/src/texture_sys.h deleted file mode 100644 index 50adc3a..0000000 --- a/src/texture_sys.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include "utils.h" -#include "config.h" - -void init_tex_sys(void); - -i32 load_new_tex(const char* path); - -void draw_texture(i32 idx, i32 x, i32 y); - -void update_textures(void); - -void unload_tex(i32 idx); - -void unload_active_textures(void); |
