umorna/source/render.c

109 lines
3.4 KiB
C

#include "render.h"
#include "engine.h"
#include <stdlib.h>
#include <raylib.h>
float render_zoom = 2.0;
static Texture2D render_texture [render_texture_count];
static Font font = { 0 };
static Color tint = { 255, 255, 255, 255 };
static Vector2 dump = { 0, 0 };
static void render_clean_up (void) {
CloseWindow ();
}
int render_width (void) { return (GetScreenWidth ()); }
int render_height (void) { return (GetScreenHeight ()); }
static void limit (int * pointer, int minimum, int maximum) {
if (* pointer < minimum) { * pointer = minimum; }
if (* pointer > maximum) { * pointer = maximum; }
}
void render_sprite (int sprite, int x, int y, int u, int v, int width, int height) {
Rectangle source, destination;
source.x = u;
source.y = v;
source.width = width;
source.height = height;
destination.x = x;
destination.y = y;
destination.width = width * ((sprite <= overui) ? 1 : render_zoom);
destination.height = height * ((sprite <= overui) ? 1 : render_zoom);
DrawTexturePro (render_texture [sprite], source, destination, dump, 0.0, tint);
}
void render_string (char * string, int x, int y) {
Vector2 position = { 4, 4 };
position.x += x;
position.y += y;
DrawTextPro (font, string, position, dump, 0.0, FONT_SIZE, 4, tint);
}
int render_active = 0;
static void render_exit (void) {
render_active = 0;
}
static void (* render_action [80]) (void);
void render_configure (void) {
render_active = 1;
InitWindow (1800, 900, "EAX");
SetTargetFPS (60);
font = LoadFont ("sprite/gothic.ttf");
atexit (render_clean_up);
render_action [0] = render_exit;
render_texture [neonui] = LoadTexture ("sprite/neonui.png");
render_texture [ui] = LoadTexture ("sprite/ui.png");
render_texture [overui] = LoadTexture ("sprite/hack.png");
SetTextureFilter (render_texture [neonui], TEXTURE_FILTER_POINT);
SetTextureFilter (render_texture [ui], TEXTURE_FILTER_POINT);
SetTextureFilter (render_texture [overui], TEXTURE_FILTER_POINT);
render_texture [orcs] = LoadTexture ("sprite/orcs.png"); /* TODO */
render_texture [humans] = LoadTexture ("sprite/humans.png");
render_texture [elves] = LoadTexture ("sprite/elves.png");
render_texture [ashlands] = LoadTexture ("sprite/ashlands.png");
}
void render_synchronize (void) {
Color background = { 0, 0, 0, 0 };
if (IsKeyPressed (KEY_RIGHT)) { camera_x++; limit (& camera_x, 0, world_width - (render_width () / (int) (BASE_SIZE * render_zoom))); }
if (IsKeyPressed (KEY_LEFT)) { camera_x--; limit (& camera_x, 0, world_width - (render_width () / (int) (BASE_SIZE * render_zoom))); }
if (IsKeyPressed (KEY_DOWN)) { camera_y++; limit (& camera_y, 0, world_height - (render_height () / (int) (BASE_SIZE * render_zoom))); }
if (IsKeyPressed (KEY_UP)) { camera_y--; limit (& camera_y, 0, world_height - (render_height () / (int) (BASE_SIZE * render_zoom))); }
if (IsKeyPressed (KEY_T)) { menu_show [menu_traits] = menu_show [menu_traits] ? 0 : 1; }
if (IsKeyPressed (KEY_S)) { menu_show [menu_skills] = menu_show [menu_skills] ? 0 : 1; }
if (IsKeyPressed (KEY_V)) { menu_show [menu_values] = menu_show [menu_values] ? 0 : 1; }
if (IsKeyPressed (KEY_R)) { menu_show [menu_resources] = menu_show [menu_resources] ? 0 : 1; }
if (WindowShouldClose ()) { render_active = 0; }
/*if (IsKeyPressed (KEY_P)) { dump_world_screenshot (); }*/
EndDrawing ();
BeginDrawing ();
ClearBackground (background);
}