diff --git a/.gitignore b/.gitignore index 5cf53d2..b593da5 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ source/*.o source/*.ali xhads sprite/* +song/* diff --git a/source/core.adb b/source/core.adb index 9a87f82..b6e55d9 100644 --- a/source/core.adb +++ b/source/core.adb @@ -133,9 +133,9 @@ package body core is function load_sprite (file_path : in string; frames, states : in integer) return sprite is this : sprite; begin - this.index := import_sprite (c_string (file_path)); - this.width := sprite_width (this.index) / states; - this.height := sprite_height (this.index) / frames; + this.index := import_texture (c_string (file_path)); + this.width := sprite_width (this.index) / states; + this.height := sprite_height (this.index) / frames; this.frames := frames; this.states := states; -- diff --git a/source/core.ads b/source/core.ads index 7439204..2961c51 100644 --- a/source/core.ads +++ b/source/core.ads @@ -88,9 +88,15 @@ package core is procedure render_string (text : in string; x, y, colour, choose : in integer) with import => true, convention => c; procedure render_vector (x1, y1, x2, y2 : in integer) with import => true, convention => c; - function import_sprite (file_path : in string) return integer with import => true, convention => c; - function sprite_width (index : in integer) return integer with import => true, convention => c; - function sprite_height (index : in integer) return integer with import => true, convention => c; + function import_texture (file_path : in string) return integer with import => true, convention => c; + function import_sound (file_path : in string) return integer with import => true, convention => c; + + function sprite_width (index : in integer) return integer with import => true, convention => c; + function sprite_height (index : in integer) return integer with import => true, convention => c; + + procedure play_sound (index : in integer) with import => true, convention => c; + procedure stop_sound (index : in integer) with import => true, convention => c; + procedure loop_sound (index : in integer) with import => true, convention => c; ------------------------------------------------------------------------------------------ diff --git a/source/main.adb b/source/main.adb index 68ed213..ffd0f53 100644 --- a/source/main.adb +++ b/source/main.adb @@ -15,6 +15,8 @@ procedure main is player : chad.information := chad.trait (chad.ognjen); + dummy : integer; + ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ begin @@ -28,6 +30,11 @@ begin core.configure; ui.configure; + + dummy := core.import_sound (core.c_string ("./song/main_menu.wav")); + + core.play_sound (dummy); + attribute.configure; skill.configure; resource.configure; diff --git a/source/raylib.c b/source/raylib.c index 02a9d66..11b11c6 100644 --- a/source/raylib.c +++ b/source/raylib.c @@ -17,8 +17,11 @@ enum { signal_left_control, signal_count }; -static Texture2D * render_texture; -static int render_texture_count = 0; +static int texture_count = 0; +static int sound_count = 0; + +static Texture2D * texture_array; +static Sound * sound_array; static Font font = { 0 }; static Font mono = { 0 }; @@ -34,7 +37,10 @@ static void no_logging (int msgType, const char * text, va_list args) { } static void render_clean_up (void) { - free (render_texture); + free (texture_array); + free (sound_array); + + CloseAudioDevice (); CloseWindow (); } @@ -59,10 +65,16 @@ extern void render_vector (int x1, int y1, int x2, int y2); extern void engine_configure (void); extern void engine_synchronize (void); -extern int import_sprite (char * path); +extern int import_texture (char * path); +extern int import_sound (char * path); + extern int sprite_width (int index); extern int sprite_height (int index); +extern void play_sound (int index); +extern void stop_sound (int index); +extern void loop_sound (int index); + int cursor_x = 0; int cursor_y = 0; int cursor_mode = 0; @@ -88,7 +100,7 @@ void render_sprite (int sprite, int x, int y, int u, int v, int width, int heigh destination.width = (width < 0) ? -width : width; destination.height = (height < 0) ? -height : height; - DrawTexturePro (render_texture [sprite], source, destination, dump, 0.0, tint); + DrawTexturePro (texture_array [sprite], source, destination, dump, 0.0, tint); } void render_string (char * string, int x, int y, int colour, int choose) { @@ -116,6 +128,8 @@ void engine_configure (void) { InitWindow (1800, 900, "Chads of Might & Magic"); SetTargetFPS (60); + InitAudioDevice (); + font = LoadFont ("./sprite/font/gothic.ttf"); mono = LoadFont ("./sprite/font/mono.ttf"); @@ -181,28 +195,50 @@ void engine_synchronize (void) { ClearBackground (background); } -int import_sprite (char * path) { - ++render_texture_count; +int import_texture (char * path) { + ++texture_count; - render_texture = realloc (render_texture, (unsigned long int) render_texture_count * sizeof (* render_texture)); + texture_array = realloc (texture_array, (unsigned long int) texture_count * sizeof (* texture_array)); - render_texture [render_texture_count - 1] = LoadTexture (path); + texture_array [texture_count - 1] = LoadTexture (path); - if ((render_texture [render_texture_count - 1].width == 0) || (render_texture [render_texture_count - 1].height == 0)) { + if ((texture_array [texture_count - 1].width == 0) || (texture_array [texture_count - 1].height == 0)) { printf ("\033[1;31m%3i : '%60s' := %3i, %3i;\033[0m\n", - render_texture_count - 1, + texture_count - 1, path, - render_texture [render_texture_count - 1].width, - render_texture [render_texture_count - 1].height); + texture_array [texture_count - 1].width, + texture_array [texture_count - 1].height); } - return (render_texture_count - 1); + return (texture_count - 1); +} + +int import_sound (char * path) { + ++sound_count; + + sound_array = realloc (sound_array, (unsigned long int) sound_count * sizeof (* sound_array)); + + sound_array [sound_count - 1] = LoadSound (path); + + return (sound_count - 1); } int sprite_width (int index) { - return (render_texture [index].width); + return (texture_array [index].width); } int sprite_height (int index) { - return (render_texture [index].height); + return (texture_array [index].height); +} + +void play_sound (int index) { + PlaySound (sound_array [index]); +} + +void stop_sound (int index) { + StopSound (sound_array [index]); +} + +void loop_sound (int index) { + PlaySound (sound_array [index]); }