@@ -151,6 +151,18 @@ package body core is | |||
------------------------------------------------------------------------------------------ | |||
function load_font (file_path : in string; size, pad : in integer) return font is | |||
this : font; | |||
begin | |||
this.index := import_font (c_string (file_path)); | |||
this.size := size; | |||
this.pad := pad; | |||
-- | |||
return this; | |||
end load_font; | |||
------------------------------------------------------------------------------------------ | |||
procedure crop (data : in sprite; x, y, u, v, width, height : in integer) is | |||
begin | |||
render_sprite (data.index, x, y, u, v, width, height); | |||
@@ -207,9 +219,9 @@ package body core is | |||
------------------------------------------------------------------------------------------ | |||
procedure write (text : in string; x, y : in integer; colour : in integer := 16#A37A28#) is | |||
procedure write (text : in string; x, y : in integer; colour : in integer := 16#A37A28#; data : in font := fonts (0)) is | |||
begin | |||
render_string (c_string (text), x, y, colour, 0); | |||
render_string (c_string (text), x, y, colour, data.index, data.size, data.pad); | |||
end write; | |||
------------------------------------------------------------------------------------------ | |||
@@ -40,6 +40,11 @@ package core is | |||
index, width, height, frames, states : integer; | |||
end record; | |||
type font is | |||
record | |||
index, size, pad : integer; | |||
end record; | |||
type vector_2 is | |||
record | |||
x, y : integer; | |||
@@ -81,6 +86,8 @@ package core is | |||
text_box : volatile; | |||
fonts : array (0 .. 3) of font; | |||
------------------------------------------------------------------------------------------ | |||
-- C | |||
@@ -95,12 +102,13 @@ package core is | |||
function window_width return integer with import => true, convention => c; | |||
function window_height return integer with import => true, convention => c; | |||
procedure render_sprite (sprite, x, y, u, v, width, height : in integer) with import => true, convention => c; | |||
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; | |||
procedure render_sprite (sprite, x, y, u, v, width, height : in integer) with import => true, convention => c; | |||
procedure render_string (text : in string; x, y, colour, index, size, pad : in integer) with import => true, convention => c; | |||
procedure render_vector (x1, y1, x2, y2 : in 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 import_font (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; | |||
@@ -137,6 +145,8 @@ package core is | |||
function clip (value, minimum, maximum : in integer) return integer; | |||
function load_sprite (file_path : in string; frames, states : in integer) return sprite; | |||
-- load_song | |||
function load_font (file_path : in string; size, pad : in integer) return font; | |||
procedure crop (data : in sprite; x, y, u, v, width, height : in integer); | |||
procedure view (data : in sprite; x, y, u, v, width, height : in integer); | |||
@@ -145,7 +155,7 @@ package core is | |||
procedure line (origin, offset : in vector_2); | |||
procedure write (text : in string; x, y : in integer; colour : in integer := 16#A37A28#); | |||
procedure write (text : in string; x, y : in integer; colour : in integer := 16#A37A28#; data : in font := fonts (0)); | |||
procedure debug (text : in string); | |||
procedure hexagonal_grid (x, y, width, height : in integer; fill : in boolean); | |||
@@ -29,6 +29,11 @@ begin | |||
core.configure; | |||
ui.configure; | |||
core.fonts (0) := core.load_font ("./font/tenderness.ttf", 22, 2); | |||
core.fonts (1) := core.load_font ("./font/ferrum.ttf", 22, 2); | |||
core.fonts (2) := core.load_font ("./font/gothic.ttf", 22, 2); | |||
core.fonts (3) := core.load_font ("./font/unitblock.ttf", 22, 2); | |||
core.play_sound (core.import_sound (core.c_string ("./song/main_menu.ogg"))); | |||
attribute.configure; | |||
@@ -106,9 +111,15 @@ begin | |||
--~unit.stat (unit.power_lich, 0, 0, true); | |||
-- | |||
magic.menu (0, 0, true); | |||
might.menu (0, 0, true); | |||
--~might.menu (0, 0, true); | |||
-- | |||
ui.draw_text_box (0, core.window_height - 32, core.window_width, 32); | |||
-- | |||
core.write ("Heyo world!", 1600, 700 + 0, 16#CC9966#, core.fonts (0)); | |||
core.write ("Nyaa world!", 1600, 700 + 32, 16#99CC66#, core.fonts (1)); | |||
core.write ("Cyaa world!", 1600, 700 + 64, 16#6699CC#, core.fonts (2)); | |||
core.write ("Neon world!", 1600, 700 + 96, 16#66CC99#, core.fonts (3)); | |||
core.write ("Neon world!", 0, 0, 16#FFFFFF#, core.fonts (0)); | |||
end loop gameplay; | |||
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |||
@@ -19,12 +19,12 @@ enum { | |||
static int texture_count = 0; | |||
static int sound_count = 0; | |||
static int font_count = 0; | |||
static Texture2D * texture_array; | |||
static Sound * sound_array; | |||
static Font * font_array; | |||
static Font font = { 0 }; | |||
static Font mono = { 0 }; | |||
static Color tint = { 255, 255, 255, 255 }; | |||
static Vector2 dump = { 0, 0 }; | |||
@@ -37,8 +37,20 @@ static void no_logging (int msgType, const char * text, va_list args) { | |||
} | |||
static void render_clean_up (void) { | |||
int i; | |||
for (i = 0; i < texture_count; ++i) | |||
UnloadTexture (texture_array [i]); | |||
for (i = 0; i < sound_count; ++i) | |||
UnloadSound (sound_array [i]); | |||
for (i = 0; i < font_count; ++i) | |||
UnloadFont (font_array [i]); | |||
free (texture_array); | |||
free (sound_array); | |||
free (font_array); | |||
CloseAudioDevice (); | |||
@@ -49,17 +61,14 @@ extern int cursor_x; | |||
extern int cursor_y; | |||
extern int cursor_mode; | |||
extern int signal_mode; | |||
extern int engine_active; | |||
extern int framerate; | |||
extern int window_width (void); | |||
extern int window_height (void); | |||
extern void render_sprite (int sprite, int x, int y, int u, int v, int width, int height); | |||
extern void render_string (char * string, int x, int y, int colour, int choose); | |||
extern void render_sprite (int sprite, int x, int y, int u, int v, int width, int height); | |||
extern void render_string (char * string, int x, int y, int colour, int font, int size, int pad); | |||
extern void render_vector (int x1, int y1, int x2, int y2); | |||
extern void engine_configure (void); | |||
@@ -67,6 +76,7 @@ extern void engine_synchronize (void); | |||
extern int import_texture (char * path); | |||
extern int import_sound (char * path); | |||
extern int import_font (char * path); | |||
extern int sprite_width (int index); | |||
extern int sprite_height (int index); | |||
@@ -75,14 +85,12 @@ 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; | |||
int signal_mode = 0; | |||
int cursor_x = 0; | |||
int cursor_y = 0; | |||
int cursor_mode = 0; | |||
int signal_mode = 0; | |||
int engine_active = 0; | |||
int framerate = 0; | |||
int framerate = 0; | |||
int window_width (void) { return (GetScreenWidth ()); } | |||
int window_height (void) { return (GetScreenHeight ()); } | |||
@@ -103,18 +111,19 @@ void render_sprite (int sprite, int x, int y, int u, int v, int width, int heigh | |||
DrawTexturePro (texture_array [sprite], source, destination, dump, 0.0, tint); | |||
} | |||
void render_string (char * string, int x, int y, int colour, int choose) { | |||
Vector2 position = { 4, 4 }; | |||
Color new_tint = { 255, 255, 255, 255 }; | |||
void render_string (char * string, int x, int y, int colour, int font, int size, int pad) { | |||
Color new_tint = { 255, 255, 255, 255 }; | |||
Vector2 position; | |||
position.x += x; | |||
position.y += y; | |||
position.x = pad + x; | |||
position.y = pad + y; | |||
new_tint.r = ((colour & 0XFF0000) >> 16) % 256; | |||
new_tint.g = ((colour & 0X00FF00) >> 8) % 256; | |||
new_tint.b = ((colour & 0X0000FF) >> 0) % 256; | |||
DrawTextPro ((choose != 0) ? mono : font, string, position, dump, 0.0, 18, 3, new_tint); | |||
DrawTextPro (font_array [font], string, position, dump, 0.0, size, 2 * pad, new_tint); | |||
} | |||
void render_vector (int x1, int y1, int x2, int y2) { | |||
@@ -130,9 +139,6 @@ void engine_configure (void) { | |||
InitAudioDevice (); | |||
font = LoadFont ("./sprite/font/gothic.ttf"); | |||
mono = LoadFont ("./sprite/font/mono.ttf"); | |||
atexit (render_clean_up); | |||
} | |||
@@ -223,6 +229,16 @@ int import_sound (char * path) { | |||
return (sound_count - 1); | |||
} | |||
int import_font (char * path) { | |||
++font_count; | |||
font_array = realloc (font_array, (unsigned long int) font_count * sizeof (* font_array)); | |||
font_array [font_count - 1] = LoadFont (path); | |||
return (font_count - 1); | |||
} | |||
int sprite_width (int index) { | |||
return (texture_array [index].width); | |||
} | |||
@@ -118,7 +118,7 @@ package body ui is | |||
------------------------------------------------------------------------------------------ | |||
procedure draw_text_box (x, y, width, height : in integer) is | |||
offset : constant integer := sprite (active, text_middle).width; | |||
offset : constant integer := sprite (active, text_middle).width; | |||
begin | |||
draw_background (text_middle, x + offset, y + offset, width - 2 * offset, height - 2 * offset); | |||
-- | |||
@@ -132,7 +132,7 @@ package body ui is | |||
draw (text_lower_left, x, y + height - offset); | |||
draw (text_lower_right, x + width - offset, y + height - offset); | |||
-- | |||
core.write (core.read_text_box, x + offset, y + offset, 16#999999#); | |||
core.write (core.read_text_box, x, y, 16#999999#); | |||
end draw_text_box; | |||
------------------------------------------------------------------------------------------ | |||