Browse Source

Work in progress, semi-stable...

master
Ognjen Milan Robovic 5 months ago
parent
commit
cada5d5340
6 changed files with 145 additions and 37 deletions
  1. +23
    -15
      compile.sh
  2. BIN
      prefab/ashlands.png
  3. +91
    -6
      source/engine.c
  4. +0
    -2
      source/engine.h
  5. +3
    -1
      source/game.h
  6. +28
    -13
      source/main.c

+ 23
- 15
compile.sh View File

@@ -2,22 +2,30 @@

set -xe

clang -g -ansi -Weverything -Werror -Ofast -c -o ./source/engine.o ./source/engine.c
clang -g -ansi -Weverything -Werror -Ofast -c -o ./source/render.o ./source/render.c
clang -g -ansi -Weverything -Werror -Ofast -c -o ./source/game.o ./source/game.c
clang -g -ansi -Weverything -Werror -Ofast -c -o ./source/menu.o ./source/menu.c
#~clang -g -ansi -Weverything -Werror -Ofast -c -o ./source/source.o ./source/source.c
clang -g -ansi -Weverything -Werror -Ofast -c -o ./source/main.o ./source/main.c
#~clang -g -ansi -Weverything -Werror -Ofast -c -o ./source/engine.o ./source/engine.c
#~clang -g -ansi -Weverything -Werror -Ofast -c -o ./source/render.o ./source/render.c
#~clang -g -ansi -Weverything -Werror -Ofast -c -o ./source/game.o ./source/game.c
#~clang -g -ansi -Weverything -Werror -Ofast -c -o ./source/menu.o ./source/menu.c
#~clang -g -ansi -Weverything -Werror -Ofast -c -o ./source/main.o ./source/main.c

gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -Ofast -c -o ./source/engine.o ./source/engine.c
gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -Ofast -c -o ./source/render.o ./source/render.c
gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -Ofast -c -o ./source/game.o ./source/game.c
gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -Ofast -c -o ./source/menu.o ./source/menu.c
#~gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -Ofast -c -o ./source/source.o ./source/source.c
gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -Ofast -c -o ./source/main.o ./source/main.c
#~gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -Ofast -c -o ./source/engine.o ./source/engine.c
#~gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -Ofast -c -o ./source/render.o ./source/render.c
#~gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -Ofast -c -o ./source/game.o ./source/game.c
#~gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -Ofast -c -o ./source/menu.o ./source/menu.c
#~gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -Ofast -c -o ./source/main.o ./source/main.c

#~gcc -o umorna ./source/main.o ./source/source.o ./source/menu.o ./source/game.o ./source/engine.o -lraylib
gcc -o umorna ./source/main.o ./source/game.o ./source/engine.o ./source/menu.o ./source/render.o -lraylib
#~gcc -o umorna ./source/main.o ./source/game.o ./source/engine.o -lraylib
clang -g -ansi -Weverything -Werror -c -o ./source/engine.o ./source/engine.c
clang -g -ansi -Weverything -Werror -c -o ./source/render.o ./source/render.c
clang -g -ansi -Weverything -Werror -c -o ./source/game.o ./source/game.c
clang -g -ansi -Weverything -Werror -c -o ./source/menu.o ./source/menu.c
clang -g -ansi -Weverything -Werror -c -o ./source/main.o ./source/main.c

gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -c -o ./source/engine.o ./source/engine.c
gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -c -o ./source/render.o ./source/render.c
gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -c -o ./source/game.o ./source/game.c
gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -c -o ./source/menu.o ./source/menu.c
gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -c -o ./source/main.o ./source/main.c

gcc -o umorna ./source/main.o ./source/game.o ./source/engine.o ./source/menu.o ./source/render.o -lraylib -lpng

exit

BIN
prefab/ashlands.png View File

Before After
Width: 1024  |  Height: 1024  |  Size: 48KB

+ 91
- 6
source/engine.c View File

@@ -1,7 +1,12 @@
#include "engine.h"

int camera_x = 30;
int camera_y = 30;
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <png.h>

int camera_x = 0;
int camera_y = 0;

void view_unit (int race, int unit, int x, int y) {
int u, v, width, height;
@@ -104,14 +109,27 @@ void view_neon_menu (int menu, int align, int x, int y) {
}

void view_map (int offset_x, int offset_y) {
int x, y;
int x, y, index;

for (x = 0; x < (render_width () - SIDE_SIZE) / (BASE_SIZE * render_zoom); ++x) {
for (y = 0; y < render_height () / (BASE_SIZE * render_zoom); ++y) {
for (x = 0; (x < (render_width () - SIDE_SIZE) / (BASE_SIZE * render_zoom)) && (x < CHAD_WORLD_WIDTH); ++x) {
for (y = 0; (y < render_height () / (BASE_SIZE * render_zoom)) && (y < CHAD_WORLD_HEIGHT); ++y) {
render_sprite (ashlands, (int) (x * BASE_SIZE * render_zoom), (int) (y * BASE_SIZE * render_zoom), 0,
chad_world [0] [offset_x + x] [offset_y + y] * BASE_SIZE, BASE_SIZE, BASE_SIZE);
chad_world [0] [(offset_x + x) * CHAD_WORLD_HEIGHT + offset_y + y] * BASE_SIZE, BASE_SIZE, BASE_SIZE);
}
}

for (index = 0; index < CHAD_WORLD_MODEL; ++index) {
if (chad_world_model_x [0] [index] < offset_x) continue;
if (chad_world_model_y [0] [index] < offset_y) continue;

if (chad_world_model_x [0] [index] > (render_width () - SIDE_SIZE) / (BASE_SIZE * render_zoom)) continue;
if (chad_world_model_y [0] [index] > render_height () / (BASE_SIZE * render_zoom)) continue;

x = (int) ((chad_world_model_x [0] [index] - offset_x) * BASE_SIZE * render_zoom);
y = (int) ((chad_world_model_y [0] [index] - offset_y) * BASE_SIZE * render_zoom);

render_sprite (model_1_1, x, y, 0, chad_world_model [0] [index] * BASE_SIZE, BASE_SIZE, BASE_SIZE);
}
}

void view_base_1 (int index, int x, int y) {
@@ -125,3 +143,70 @@ void view_base_2 (int index, int x, int y) {
void view_side_hud (void) {
return;
}

/*static void dump_block (unsigned int * * * pixels, unsigned int * source, int index, int x, int y) {
int i, j;

for (i = 0; i < BASE_SIZE; ++i) {
for (j = 0; j < BASE_SIZE; ++j) {
pixels [x] [y] [i * BASE_SIZE + j] = source [index * BASE_SIZE * BASE_SIZE + i * BASE_SIZE + j];
}
}
}

static void dump_world_screenshot (void) {
unsigned int * * * screenshot;
unsigned int * a;

unsigned int map [28 * BASE_SIZE * 12 * BASE_SIZE];

int i, j, k;

png_image input = { 0 };
png_image output = { 0 };

input.version = PNG_IMAGE_VERSION;

png_image_begin_read_from_file (& input, "sprite/ashlands.png");

input.format = PNG_FORMAT_RGBA;

png_image_finish_read (& input, NULL, map, 0, NULL);

png_image_free (& input);

a = calloc (CHAD_WORLD_SIZE * CHAD_WORLD_SIZE * BASE_SIZE * BASE_SIZE, sizeof (* a));
screenshot = calloc (CHAD_WORLD_SIZE, sizeof (* screenshot));
for (i = 0; i < CHAD_WORLD_SIZE; ++i) {
screenshot [i] = calloc (CHAD_WORLD_SIZE, sizeof (* * screenshot));
for (j = 0; j < CHAD_WORLD_SIZE; ++j) {
screenshot [i] [j] = calloc (BASE_SIZE * BASE_SIZE, sizeof (* * * screenshot));
}
}

for (i = 0; i < CHAD_WORLD_SIZE; ++i) {
for (j = 0; j < CHAD_WORLD_SIZE; ++j) {
dump_block (screenshot, map, chad_world [0] [i] [j], i, j);
}
}

for (i = 0; i < CHAD_WORLD_SIZE; ++i) {
for (j = 0; j < CHAD_WORLD_SIZE; ++j) {
for (k = 0; k < BASE_SIZE * BASE_SIZE; ++k) {
a [(i * CHAD_WORLD_SIZE + j) * BASE_SIZE * BASE_SIZE + k] = screenshot [i] [j] [k];
}
}
}

output.version = PNG_IMAGE_VERSION;
output.format = PNG_FORMAT_RGBA;
output.width = (unsigned int) (CHAD_WORLD_SIZE * BASE_SIZE);
output.height = (unsigned int) (CHAD_WORLD_SIZE * BASE_SIZE);

if (png_image_write_to_file (& output, "a.png", 0, a, 0, NULL) == 0) write (1, "\033[1;31mFailed to export render as PNG image!\033[0m\n", 49);

png_image_free (& output);

free (screenshot);
free (a);
}*/

+ 0
- 2
source/engine.h View File

@@ -5,8 +5,6 @@
#include "menu.h"
#include "render.h"

#include <string.h>

extern int camera_x;
extern int camera_y;



+ 3
- 1
source/game.h View File

@@ -17,7 +17,9 @@

#define CHAD_WORLD_MODEL (120)
#define CHAD_WORLD_WIDTH (120)
#define CHAD_WORLD_HEIGHT ( 60)
#define CHAD_WORLD_HEIGHT (100)

#define CHAD_WORLD_SIZE (CHAD_WORLD_WIDTH * CHAD_WORLD_HEIGHT)

#include <xolatile/chads.h>



+ 28
- 13
source/main.c View File

@@ -4,11 +4,11 @@
#include "menu.h"

#include <stdio.h>
#include <raylib.h>

extern int snprintf (char *, unsigned long, const char *, ...);

static void limit (int * pointer, int minimum, int maximum) {
if ((* pointer >= minimum) && (* pointer <= maximum)) { return; }
if (* pointer < minimum) { * pointer = minimum; }
if (* pointer > maximum) { * pointer = maximum; }
}
@@ -26,37 +26,52 @@ int main (void) {

menu_configure ();

chad_world_model [0] [0] = 44;
chad_world_model_x [0] [0] = 2;
chad_world_model_y [0] [0] = 2;
chad_world_model [0] [1] = 44;
chad_world_model_x [0] [1] = 3;
chad_world_model_y [0] [1] = 3;
chad_world_model [0] [2] = 44;
chad_world_model_x [0] [2] = 3;
chad_world_model_y [0] [2] = 2;
chad_world_model [0] [3] = 44;
chad_world_model_x [0] [3] = 2;
chad_world_model_y [0] [3] = 3;

while (! WindowShouldClose ()) {
Color tint = { 0, 0, 0, 0 };

if (IsKeyPressed (KEY_RIGHT)) { camera_x++; limit (& camera_x, 0, CHAD_WORLD_WIDTH - (render_width () / (int) (BASE_SIZE * render_zoom))); }
if (IsKeyPressed (KEY_LEFT)) { camera_x--; limit (& camera_x, 0, CHAD_WORLD_WIDTH - (render_width () / (int) (BASE_SIZE * render_zoom))); }
if (IsKeyPressed (KEY_DOWN)) { camera_y++; limit (& camera_y, 0, CHAD_WORLD_HEIGHT - (render_height () / (int) (BASE_SIZE * render_zoom))); }
if (IsKeyPressed (KEY_UP)) { camera_y--; limit (& camera_y, 0, CHAD_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 (IsKeyPressed (KEY_P)) { dump_world_screenshot (); }*/

BeginDrawing ();

ClearBackground (tint);

view_map (camera_x, camera_y);

/*
view_base_1 (0, 32, 128);
view_base_1 (1, 32, 512);

view_base_2 (0, 1024, 128);
view_base_2 (1, 1024, 512);
/*
for (int i = 0; i < 18; ++i) {
view_unit (orc, i, 900 + 32 * i, 32);
view_unit (human, i, 900 + 32 * i, 64);
view_unit (elf, i, 900 + 32 * i, 96);
}
*/
if (IsKeyPressed (KEY_RIGHT)) { camera_x++; limit (& camera_x, 0, CHAD_WORLD_WIDTH * BASE_SIZE - render_width ()); }
if (IsKeyPressed (KEY_LEFT)) { camera_x--; limit (& camera_x, 0, CHAD_WORLD_WIDTH * BASE_SIZE - render_width ()); }
if (IsKeyPressed (KEY_DOWN)) { camera_y++; limit (& camera_y, 0, CHAD_WORLD_HEIGHT * BASE_SIZE - render_height ()); }
if (IsKeyPressed (KEY_UP)) { camera_y--; limit (& camera_y, 0, CHAD_WORLD_HEIGHT * BASE_SIZE - render_height ()); }

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; }

view_hud (0, SIDE_SIZE, render_height (), render_width () - SIDE_SIZE, 0);
view_hud (1, render_width () - SIDE_SIZE, render_height (), 0, 0);
debug ();


Loading…
Cancel
Save