summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.vscode/c_cpp_properties.json22
-rw-r--r--.vscode/launch.json15
-rw-r--r--Makefile5
-rw-r--r--build/zombies.exebin0 -> 1650189 bytes
-rw-r--r--include/map.h63
-rw-r--r--include/objects.h38
-rw-r--r--include/players.h29
-rw-r--r--include/zombies.h23
-rw-r--r--libs/SDL2.libbin0 -> 165034 bytes
-rw-r--r--libs/SDL2_mixer.libbin0 -> 17182 bytes
-rw-r--r--libs/libFLAC-8.dllbin0 -> 441344 bytes
-rw-r--r--libs/libmodplug-1.dllbin0 -> 252928 bytes
-rw-r--r--libs/libmpg123-0.dllbin0 -> 337408 bytes
-rw-r--r--libs/libogg-0.dllbin0 -> 52224 bytes
-rw-r--r--libs/libopus-0.dllbin0 -> 124928 bytes
-rw-r--r--libs/libopusfile-0.dllbin0 -> 46592 bytes
-rw-r--r--libs/libvorbis-0.dllbin0 -> 251904 bytes
-rw-r--r--libs/libvorbisfile-3.dllbin0 -> 69632 bytes
-rw-r--r--main.c52
-rw-r--r--map.c241
-rw-r--r--objects.c91
-rw-r--r--players.c173
-rw-r--r--project-base.code-workspace57
-rw-r--r--zombies.c65
24 files changed, 874 insertions, 0 deletions
diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json
new file mode 100644
index 0000000..1fc7b4f
--- /dev/null
+++ b/.vscode/c_cpp_properties.json
@@ -0,0 +1,22 @@
+{
+ "configurations": [
+ {
+ "name": "Win32",
+ "includePath": [
+ "${workspaceFolder}/**",
+ "C:\\mingw\\mingw64\\x86_64-w64-mingw32\\include"
+ ],
+ "defines": [
+ "_DEBUG",
+ "UNICODE",
+ "_UNICODE"
+ ],
+ "windowsSdkVersion": "10.0.19041.0",
+ "compilerPath": "C:\\mingw\\mingw64\\bin\\gcc.exe",
+ "cStandard": "c17",
+ "cppStandard": "c++17",
+ "intelliSenseMode": "windows-gcc-x64"
+ }
+ ],
+ "version": 4
+} \ No newline at end of file
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..570ecaf
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,15 @@
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "type": "by-gdb",
+ "request": "launch",
+ "name": "Launch(gdb)",
+ "program": "build/zombies.exe",
+ "cwd": "${workspaceRoot}"
+ }
+ ]
+} \ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..9f421dc
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,5 @@
+main:
+ rm -rf "build/"
+ mkdir -p "build/"
+ gcc -m64 -g -DMODE_DEBUG main.c -o build/zombies.exe -lprojectbase-debug -Llibs/ -lSDL2 -lSDL2_mixer
+ ./build/zombies.exe
diff --git a/build/zombies.exe b/build/zombies.exe
new file mode 100644
index 0000000..86c8faa
--- /dev/null
+++ b/build/zombies.exe
Binary files differ
diff --git a/include/map.h b/include/map.h
new file mode 100644
index 0000000..0bf1028
--- /dev/null
+++ b/include/map.h
@@ -0,0 +1,63 @@
+#ifndef INCLUDE_MAP
+#define INCLUDE_MAP
+
+#include <projectbase/project_base.h>
+
+#include "players.h"
+#include "objects.h"
+
+typedef struct t_tile {
+ int height;
+
+ // filled in on load.
+ int topleft;
+ int topright;
+ int bottomleft;
+ int bottomright;
+
+ // filled after each frame.
+ vec2f tl;
+ vec2f tr;
+ vec2f bl;
+ vec2f br;
+} tile;
+
+tile map_loaded[10][10];
+
+// data data that is stored on disk
+vec2 spawner_tiles[2] = {
+ {9, 0},
+ {1, 8},
+};
+
+typedef struct t_map_info {
+ int tile_width;
+ int tile_height;
+ int px_raised_per_h;
+ int px_incline;
+} map_info;
+
+// data data that is stored on disk
+int map[10][10] = {
+ {0,0,0,0,0,0,0,0,0,1},
+ {0,0,0,0,0,0,0,0,0,0},
+ {0,0,0,1,1,0,0,0,0,0},
+ {0,0,0,0,0,0,0,0,0,0},
+ {0,0,0,0,0,0,0,0,0,0},
+ {0,0,0,0,0,0,0,0,0,0},
+ {0,0,0,0,0,0,0,0,0,0},
+ {0,0,0,1,1,2,1,0,0,0},
+ {0,0,0,0,0,0,1,0,0,0},
+ {0,0,0,0,0,0,0,0,0,0},
+};
+
+void load_map_from_data();
+tile get_tile_under_coords(platform_window* window, float x, float y);
+float get_height_of_tile_under_coords(platform_window* window, float tocheckx, float tochecky);
+int get_tile_height(platform_window* window);
+int get_tile_width(platform_window* window);
+bool is_in_bounds(platform_window* window, float x, float y);
+void draw_grid(platform_window* window);
+map_info get_map_info(platform_window* window);
+
+#endif \ No newline at end of file
diff --git a/include/objects.h b/include/objects.h
new file mode 100644
index 0000000..c4bb689
--- /dev/null
+++ b/include/objects.h
@@ -0,0 +1,38 @@
+#ifndef INCLUDE_OBJECT
+#define INCLUDE_OBJECT
+
+#include <projectbase/project_base.h>
+
+#include "map.h"
+
+typedef struct t_vec3f {
+ float x,y,z;
+} vec3f;
+
+typedef struct t_object {
+ bool active;
+ vec2f position;
+ vec3f size;
+ float h;
+} object;
+
+typedef struct t_box {
+ vec2f tl_b;
+ vec2f tr_b;
+ vec2f bl_b;
+ vec2f br_b;
+
+ vec2f tl_u;
+ vec2f tr_u;
+ vec2f bl_u;
+ vec2f br_u;
+} box;
+
+object objects[50];
+int max_objects = 50;
+
+void create_objects();
+void draw_objects_at_row(platform_window* window, int row);
+box get_box_of_object(platform_window* window, object o);
+
+#endif \ No newline at end of file
diff --git a/include/players.h b/include/players.h
new file mode 100644
index 0000000..b74ce7e
--- /dev/null
+++ b/include/players.h
@@ -0,0 +1,29 @@
+#ifndef INCLUDE_PLAYER
+#define INCLUDE_PLAYER
+
+#include <projectbase/project_base.h>
+
+#include "map.h"
+#include "objects.h"
+
+typedef struct t_bullet {
+ bool active;
+ float x;
+ float y;
+ float h;
+ float xacceleration;
+ float yacceleration;
+} bullet;
+
+bullet bullets[500] = {0};
+int max_bullets = 500;
+
+float playerx = 3;
+float playery = 3;
+
+void shoot(platform_window* window);
+void draw_player(platform_window* window);
+void draw_bullets(platform_window* window);
+float get_player_size(platform_window* window);
+
+#endif \ No newline at end of file
diff --git a/include/zombies.h b/include/zombies.h
new file mode 100644
index 0000000..c9e22f1
--- /dev/null
+++ b/include/zombies.h
@@ -0,0 +1,23 @@
+#ifndef INCLUDE_ZOMBIES
+#define INCLUDE_ZOMBIES
+
+#include <projectbase/project_base.h>
+
+#include "players.h"
+#include "objects.h"
+
+typedef struct t_zombie {
+ bool alive;
+ float health;
+ vec2f position;
+} zombie;
+
+
+zombie zombies[50] = {0};
+int max_zombies = 50;
+
+void draw_spawners(platform_window* window);
+void draw_zombies_at_tile(platform_window* window, int x, int y);
+void spawn_zombie(int x, int y);
+
+#endif \ No newline at end of file
diff --git a/libs/SDL2.lib b/libs/SDL2.lib
new file mode 100644
index 0000000..ea6fa42
--- /dev/null
+++ b/libs/SDL2.lib
Binary files differ
diff --git a/libs/SDL2_mixer.lib b/libs/SDL2_mixer.lib
new file mode 100644
index 0000000..3b96d7d
--- /dev/null
+++ b/libs/SDL2_mixer.lib
Binary files differ
diff --git a/libs/libFLAC-8.dll b/libs/libFLAC-8.dll
new file mode 100644
index 0000000..71f2e19
--- /dev/null
+++ b/libs/libFLAC-8.dll
Binary files differ
diff --git a/libs/libmodplug-1.dll b/libs/libmodplug-1.dll
new file mode 100644
index 0000000..7c05126
--- /dev/null
+++ b/libs/libmodplug-1.dll
Binary files differ
diff --git a/libs/libmpg123-0.dll b/libs/libmpg123-0.dll
new file mode 100644
index 0000000..c7809b1
--- /dev/null
+++ b/libs/libmpg123-0.dll
Binary files differ
diff --git a/libs/libogg-0.dll b/libs/libogg-0.dll
new file mode 100644
index 0000000..5133481
--- /dev/null
+++ b/libs/libogg-0.dll
Binary files differ
diff --git a/libs/libopus-0.dll b/libs/libopus-0.dll
new file mode 100644
index 0000000..9ba6c38
--- /dev/null
+++ b/libs/libopus-0.dll
Binary files differ
diff --git a/libs/libopusfile-0.dll b/libs/libopusfile-0.dll
new file mode 100644
index 0000000..97a88b6
--- /dev/null
+++ b/libs/libopusfile-0.dll
Binary files differ
diff --git a/libs/libvorbis-0.dll b/libs/libvorbis-0.dll
new file mode 100644
index 0000000..f5ae1bf
--- /dev/null
+++ b/libs/libvorbis-0.dll
Binary files differ
diff --git a/libs/libvorbisfile-3.dll b/libs/libvorbisfile-3.dll
new file mode 100644
index 0000000..d078736
--- /dev/null
+++ b/libs/libvorbisfile-3.dll
Binary files differ
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..0346d3c
--- /dev/null
+++ b/main.c
@@ -0,0 +1,52 @@
+#include <projectbase/project_base.h>
+
+#include "include/players.h"
+#include "include/objects.h"
+#include "include/map.h"
+#include "include/zombies.h"
+
+#include "map.c"
+#include "players.c"
+#include "objects.c"
+#include "zombies.c"
+
+#define CONFIG_DIRECTORY "zombieshooter"
+
+void update_func(platform_window* window) {
+ renderer->render_clear(window, rgb(0,255,0));
+
+ draw_grid(window);
+ draw_spawners(window);
+ draw_bullets(window);
+}
+
+void resize_func(platform_window* window, u32 change_x,u32 change_y) {
+
+}
+
+void close_func(platform_window* window) {
+
+}
+
+int main(int argc, char **argv)
+{
+ platform_init(argc, argv, CONFIG_DIRECTORY);
+
+ platform_window *window = platform_open_window_ex("Zombies!", 700, 700, 1200, 1000, 500, 500, FLAGS_MINIMIZE, update_func, resize_func, close_func, 0, 0);
+ settings_set_number("USE_GPU", 1);
+
+ //fnt = assets_load_font(mono_ttf, mono_ttf+mono_ttf_len, 16);
+ load_map_from_data();
+ create_objects();
+
+ while(platform_keep_running(window)) {
+ platform_handle_events();
+ }
+
+ settings_write_to_file();
+ platform_destroy();
+
+ memory_print_leaks();
+
+ return 0;
+} \ No newline at end of file
diff --git a/map.c b/map.c
new file mode 100644
index 0000000..443255f
--- /dev/null
+++ b/map.c
@@ -0,0 +1,241 @@
+#include "include/map.h"
+
+static int get_height_of_tile_tl(int current_height, int x, int y) {
+ int highest_point = current_height;
+ if (y > 0) {
+ int tile_above = map[y-1][x];
+ if (tile_above > highest_point) {
+ highest_point = tile_above;
+ }
+ }
+ if (y > 0 && x > 0) {
+ int tile_above = map[y-1][x-1];
+ if (tile_above > highest_point) {
+ highest_point = tile_above;
+ }
+ }
+ if (x > 0) {
+ int tile_above = map[y][x-1];
+ if (tile_above > highest_point) {
+ highest_point = tile_above;
+ }
+ }
+ return highest_point;
+}
+
+
+static int get_height_of_tile_br(int current_height, int x, int y) {
+ int highest_point = current_height;
+ if (x < 9) {
+ int tile_right = map[y][x+1];
+ if (tile_right > highest_point) {
+ highest_point = tile_right;
+ }
+ }
+ if (y < 9 && x < 9) {
+ int tile_bottom_right = map[y+1][x+1];
+ if (tile_bottom_right > highest_point) {
+ highest_point = tile_bottom_right;
+ }
+ }
+ if (y < 9) {
+ int tile_bottom = map[y+1][x];
+ if (tile_bottom > highest_point) {
+ highest_point = tile_bottom;
+ }
+ }
+ return highest_point;
+}
+
+static int get_height_of_tile_bl(int current_height, int x, int y) {
+ int highest_point = current_height;
+ if (y > 0 && x > 0) {
+ int tile_left = map[y][x-1];
+ if (tile_left > highest_point) {
+ highest_point = tile_left;
+ }
+ }
+ if (y < 9 && x > 0) {
+ int tile_bottom_left = map[y+1][x-1];
+ if (tile_bottom_left > highest_point) {
+ highest_point = tile_bottom_left;
+ }
+ }
+ if (y < 9) {
+ int tile_bottom = map[y+1][x];
+ if (tile_bottom > highest_point) {
+ highest_point = tile_bottom;
+ }
+ }
+ return highest_point;
+}
+
+static int get_height_of_tile_tr(int current_height, int x, int y) {
+ int highest_point = current_height;
+ if (y > 0) {
+ int tile_above = map[y-1][x];
+ if (tile_above > highest_point) {
+ highest_point = tile_above;
+ }
+ }
+ if (y > 0 && x < 9) {
+ int tile_above_right = map[y-1][x+1];
+ if (tile_above_right > highest_point) {
+ highest_point = tile_above_right;
+ }
+ }
+ if (x < 9) {
+ int tile_right = map[y][x+1];
+ if (tile_right > highest_point) {
+ highest_point = tile_right;
+ }
+ }
+ return highest_point;
+}
+
+// load hardcoded map.
+void load_map_from_data() {
+ for (int y = 0; y < 10; y++) {
+ for (int x = 9; x >= 0; x--) {
+ int h = map[y][x];
+ int highest_point_topleft = get_height_of_tile_tl(h, x, y);
+ int highest_point_topright = get_height_of_tile_tr(h, x, y);
+ int highest_point_bottomright = get_height_of_tile_br(h, x, y);
+ int highest_point_bottomleft = get_height_of_tile_bl(h, x, y);
+ map_loaded[y][x] = (tile){h, highest_point_topleft, highest_point_topright, highest_point_bottomleft, highest_point_bottomright};
+ }
+ }
+}
+
+tile get_tile_under_coords(platform_window* window, float x, float y) {
+ return map_loaded[(int)(y)][(int)(x)];
+}
+
+float get_height_of_tile_under_coords(platform_window* window, float tocheckx, float tochecky) {
+ tile tile_under_coords = get_tile_under_coords(window, tocheckx, tochecky);
+
+ int ty = (int)(tochecky);
+ int tx = (int)(tocheckx);
+
+ float percentage_x = tocheckx - tx;
+ float percentage_y = tochecky - ty;
+
+ float topline_h = min(tile_under_coords.topright, tile_under_coords.topleft);
+ float topline_diff = (tile_under_coords.topright - tile_under_coords.topleft) * percentage_x;
+ if (topline_diff < 0.0f) topline_diff = abs(tile_under_coords.topright - tile_under_coords.topleft) + topline_diff;
+ topline_h += topline_diff;
+
+ float bottomline_h = min(tile_under_coords.bottomright, tile_under_coords.bottomleft);
+ float bottomline_diff = (tile_under_coords.bottomright - tile_under_coords.bottomleft) * percentage_x;
+ if (bottomline_diff < 0.0f) bottomline_diff = abs(tile_under_coords.bottomright - tile_under_coords.bottomleft) + bottomline_diff;
+ bottomline_h += bottomline_diff;
+
+ float playerline = min(topline_h, bottomline_h);
+ float playerline_diff = (bottomline_h - topline_h) * percentage_y;
+ if (bottomline_h < topline_h) {
+ playerline_diff = (topline_h - bottomline_h) * (1 -percentage_y);
+ }
+ playerline += playerline_diff;
+
+ return playerline;
+}
+
+inline int get_tile_width(platform_window* window) {
+ int tile_width = window->height / 14;
+ if (window->width > window->height) tile_width = window->width / 14;
+ return tile_width;
+}
+
+inline int get_tile_height(platform_window* window) {
+ int tile_width = get_tile_width(window);
+ int tile_height = tile_width * 1;
+ return tile_height;
+}
+
+bool is_in_bounds(platform_window* window, float x, float y) {
+ int tile_width = get_tile_width(window);
+ int tile_height = get_tile_height(window);
+ int xdiff_between_bottom_and_top = tile_width/3;
+ return (x >= 0 && x <= 10 && y >= 0 && y < 10);
+}
+
+
+void draw_grid(platform_window* window) {
+ map_info info = get_map_info(window);
+
+ for (int y = 0; y < 10; y++) {
+ for (int x = 9; x >= 0; x--) {
+ tile tile = map_loaded[y][x];
+
+ int xdiff_between_bottom_and_top = info.tile_width/3;
+ int render_x = (info.tile_width * x) + (xdiff_between_bottom_and_top * y);
+ int render_y = info.tile_height * y;
+ render_y -= tile.height*info.px_raised_per_h;
+
+ vec2f topleft;
+ vec2f bottomleft;
+ vec2f bottomright;
+ vec2f topright;
+
+ int highest_point_topleft = tile.topleft;
+ topleft = (vec2f){render_x, info.tile_width * y - highest_point_topleft*info.px_raised_per_h};
+
+ int highest_point_topright = tile.topright;
+ topright = (vec2f){render_x + info.tile_width, info.tile_height * y - highest_point_topright*info.px_raised_per_h};
+
+ int highest_point_bottomright = tile.bottomright;
+ bottomright = (vec2f){render_x + xdiff_between_bottom_and_top+info.tile_width, info.tile_height * y + info.tile_height - highest_point_bottomright*info.px_raised_per_h};
+
+ int highest_point_bottomleft = tile.bottomleft;
+ bottomleft = (vec2f){render_x + xdiff_between_bottom_and_top, info.tile_height * y + info.tile_height - highest_point_bottomleft*info.px_raised_per_h};
+
+ int r = 220;
+ if (highest_point_topleft > highest_point_bottomleft || highest_point_topright > highest_point_bottomright ||
+ highest_point_topleft > highest_point_bottomright || highest_point_topright > highest_point_bottomleft ||
+ highest_point_topright > highest_point_topleft || highest_point_bottomright > highest_point_bottomleft) r = 180;
+ if (highest_point_topleft < highest_point_bottomleft || highest_point_topright < highest_point_bottomright ||
+ highest_point_topleft > highest_point_topright) r = 240;
+
+ renderer->render_quad(
+ topleft.x, topleft.y,
+ bottomleft.x, bottomleft.y,
+ bottomright.x, bottomright.y,
+ topright.x, topright.y,
+ rgb(r,0,0));
+
+ if (highest_point_topleft != highest_point_bottomright && highest_point_bottomleft == highest_point_topright) {
+ if (highest_point_bottomleft < highest_point_topleft || highest_point_bottomleft < highest_point_bottomright) {
+ renderer->render_tri(topleft.x, topleft.y,
+ bottomleft.x, bottomleft.y,
+ bottomright.x, bottomright.y, rgb(180,0,0));
+ }
+ renderer->render_line(topleft.x, topleft.y, bottomright.x, bottomright.y, 1, rgb(0,0,255)); // diag
+ }
+
+ if (highest_point_bottomleft != highest_point_topright && highest_point_topleft == highest_point_bottomright) {
+ renderer->render_line(topright.x, topright.y, bottomleft.x, bottomleft.y, 1, rgb(0,0,255)); // diag
+ }
+
+ renderer->render_line(topleft.x, topleft.y, topright.x, topright.y, 1, rgb(0,0,255)); // top
+ renderer->render_line(topleft.x, topleft.y, bottomleft.x, bottomleft.y, 1, rgb(0,0,255)); // left
+ renderer->render_line(topright.x, topright.y, bottomright.x, bottomright.y, 1, rgb(0,0,255)); // right
+ renderer->render_line(bottomleft.x, bottomleft.y, bottomright.x, bottomright.y, 1, rgb(0,0,255)); // bottom
+
+ map_loaded[y][x].tl = topleft;
+ map_loaded[y][x].tr = topright;
+ map_loaded[y][x].bl = bottomleft;
+ map_loaded[y][x].br = bottomright;
+ }
+
+ draw_objects_at_row(window, y);
+ }
+}
+
+inline map_info get_map_info(platform_window* window) {
+ map_info info;
+ info.tile_width = get_tile_width(window);
+ info.tile_height = get_tile_height(window);
+ info.px_incline = info.tile_width/3;
+ info.px_raised_per_h = info.tile_height/2.5;
+ return info;
+} \ No newline at end of file
diff --git a/objects.c b/objects.c
new file mode 100644
index 0000000..0e1adde
--- /dev/null
+++ b/objects.c
@@ -0,0 +1,91 @@
+#include "include/objects.h"
+
+box get_box_of_object(platform_window* window, object o) {
+ map_info info = get_map_info(window);
+ float render_x = (info.tile_width * o.position.x) + (info.px_incline * o.position.y);
+ vec2f rendertl = (vec2f){render_x, info.tile_width * o.position.y - o.h*info.px_raised_per_h};
+ vec2f rendertr = (vec2f){render_x + info.tile_width, info.tile_height * o.position.y - o.h*info.px_raised_per_h};
+ vec2f renderbr = (vec2f){render_x + info.px_incline+info.tile_width, info.tile_height * o.position.y + info.tile_height - o.h*info.px_raised_per_h};
+ vec2f renderbl = (vec2f){render_x + info.px_incline, info.tile_height * o.position.y + info.tile_height - o.h*info.px_raised_per_h};
+
+ o.h += o.size.z;
+ vec2f rendertl2 = (vec2f){render_x, info.tile_width * o.position.y - o.h*info.px_raised_per_h};
+ vec2f rendertr2 = (vec2f){render_x + info.tile_width, info.tile_height * o.position.y - o.h*info.px_raised_per_h};
+ vec2f renderbr2 = (vec2f){render_x + info.px_incline+info.tile_width, info.tile_height * o.position.y + info.tile_height - o.h*info.px_raised_per_h};
+ vec2f renderbl2 = (vec2f){render_x + info.px_incline, info.tile_height * o.position.y + info.tile_height - o.h*info.px_raised_per_h};
+
+ return (box){rendertl, rendertr, renderbl, renderbr, rendertl2, rendertr2, renderbl2, renderbr2};
+}
+
+void render_quad_with_outline(vec2f tl, vec2f tr, vec2f bl, vec2f br) {
+ renderer->render_quad(
+ tl.x, tl.y,
+ bl.x, bl.y,
+ br.x, br.y,
+ tr.x, tr.y,
+ rgb(200,200,0));
+
+ renderer->render_line(tl.x, tl.y, tr.x, tr.y, 1, rgb(0,0,255)); // top
+ renderer->render_line(tl.x, tl.y, bl.x, bl.y, 1, rgb(0,0,255)); // left
+ renderer->render_line(tr.x, tr.y, br.x, br.y, 1, rgb(0,0,255)); // right
+ renderer->render_line(bl.x, bl.y, br.x, br.y, 1, rgb(0,0,255)); // bottom
+}
+
+object get_object_at_tile(int x, int y) {
+ for (int i = 0; i < max_objects; i++) {
+ object o = objects[i];
+ if (!o.active) continue;
+ if (o.position.x == x && o.position.y == y) return o;
+ }
+ return (object){0};
+}
+
+void draw_objects_at_row(platform_window* window, int row) {
+ map_info info = get_map_info(window);
+
+ bool did_player_draw = false;
+ int x_of_player = playerx;
+ int y_of_player = playery;
+
+ for (int i = 10; i >= 0; i--) {
+ object o = get_object_at_tile(i, row);
+
+ if (row == y_of_player && x_of_player == i) {
+ draw_player(window);
+ }
+
+ draw_zombies_at_tile(window, i, row);
+
+ if (!o.active) continue;
+ box box = get_box_of_object(window, o);
+ render_quad_with_outline(box.tl_b, box.tr_b, box.bl_b, box.br_b);
+ render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u);
+ render_quad_with_outline(box.tl_u, box.tl_b, box.bl_u, box.bl_b);
+ render_quad_with_outline(box.bl_u, box.br_u, box.bl_b, box.br_b);
+ }
+}
+
+void create_box(float x, float y, float h) {
+ for (int i = 0; i < max_objects; i++) {
+ object o = objects[i];
+ if (o.active) continue;
+
+ objects[i].active = true;
+ objects[i].position = (vec2f){x, y};
+ objects[i].h = h;
+ objects[i].size = (vec3f){1,1,2};
+ break;
+ }
+}
+
+void create_objects() {
+ // rechts naar links op map.
+ create_box(4, 0, 0);
+ create_box(1, 0, 0);
+ create_box(0, 0, 0);
+
+ create_box(0, 1, 0);
+ create_box(3, 5, 0);
+
+ spawn_zombie(2, 7);
+} \ No newline at end of file
diff --git a/players.c b/players.c
new file mode 100644
index 0000000..291bd11
--- /dev/null
+++ b/players.c
@@ -0,0 +1,173 @@
+#include "include/players.h"
+
+float get_bullet_size_in_tile(platform_window* window) {
+ return 1 / 8.0f;
+}
+
+float get_bullet_size(platform_window* window) {
+ return get_tile_width(window) * get_bullet_size_in_tile(window);
+}
+
+float get_player_size_in_tile(platform_window* window) {
+ return 0.5;
+}
+
+float get_player_size(platform_window* window) {
+ int player_size = get_tile_width(window) * get_player_size_in_tile(window);
+}
+
+object check_if_player_collided_with_object(platform_window* window) {
+ map_info info = get_map_info(window);
+ float player_size = get_player_size(window);
+
+ for (int i = 0; i < max_objects; i++) {
+ object o = objects[i];
+ if (!o.active) continue;
+
+ box box = get_box_of_object(window, o);
+ float x_to_check = playerx;
+ float y_to_check = playery;
+ float player_size_in_tile_px = player_size / (float)info.tile_width;
+
+ if (x_to_check+player_size_in_tile_px >= o.position.x && x_to_check <= o.position.x+o.size.x
+ && y_to_check >= o.position.y && y_to_check <= o.position.y+o.size.y) {
+ return o;
+ }
+ }
+
+ return (object){0};
+}
+
+void take_player_input(platform_window* window) {
+ float speed = 0.1f;
+ float pad_between_player_and_obj = 0.01f;
+
+ float old_x = playerx;
+ float old_y = playery;
+
+ if (keyboard_is_key_down(KEY_W)) {
+ float newy = playery - speed;
+ if (is_in_bounds(window, playerx, newy)) {
+ playery = newy;
+ object o = check_if_player_collided_with_object(window);
+ if (o.active) playery = o.position.y+o.size.y + pad_between_player_and_obj;
+ }
+ }
+
+ if (keyboard_is_key_down(KEY_S)) {
+ float newy = playery + speed;
+ if (is_in_bounds(window, playerx, newy)) {
+ playery = newy;
+ object o = check_if_player_collided_with_object(window);
+ if (o.active) playery = o.position.y - pad_between_player_and_obj;
+ }
+ }
+
+ if (keyboard_is_key_down(KEY_A)) {
+ float newx = playerx - speed;
+ if (is_in_bounds(window, newx, playery)) {
+ playerx = newx;
+ object o = check_if_player_collided_with_object(window);
+ if (o.active) playerx = o.position.x+o.size.x + pad_between_player_and_obj;
+ }
+ }
+
+ if (keyboard_is_key_down(KEY_D)) {
+ float newx = playerx + speed;
+ if (is_in_bounds(window, newx, playery)) {
+ playerx = newx;
+ object o = check_if_player_collided_with_object(window);
+ if (o.active) playerx = o.position.x-get_player_size_in_tile(window) - pad_between_player_and_obj;
+ }
+ }
+}
+
+void draw_player(platform_window* window) {
+ int size = get_tile_width(window) / 2;
+ map_info info = get_map_info(window);
+ float height = get_height_of_tile_under_coords(window, playerx, playery);
+
+ take_player_input(window);
+
+ if (is_left_down()) {
+ shoot(window);
+ }
+
+ float player_render_x = playerx*info.tile_width + (playery*info.px_incline);
+ float player_render_y = playery*info.tile_height - (height*info.px_raised_per_h);
+ renderer->render_rectangle(player_render_x, player_render_y - size, size, size, rgb(200,150,120));
+
+ _global_camera.x = -(window->width / 2) + player_render_x;
+ _global_camera.y = -(window->height / 2) + player_render_y;
+}
+
+void shoot(platform_window* window) {
+ map_info info = get_map_info(window);
+
+ float hh = get_height_of_tile_under_coords(window, playerx, playery);
+
+ float dirx = (_global_mouse.x - (window->width/2));
+ float diry = (_global_mouse.y - (window->height/2));
+ double length = sqrt(dirx * dirx + diry * diry);
+ dirx /= length;
+ diry /= length;
+
+ for (int i = 0; i < max_bullets; i++) {
+ bullet b = bullets[i];
+ if (b.active) continue;
+
+ bullets[i] = (bullet){true, playerx, playery, hh + 0.5f, dirx, diry};
+ break;
+ }
+}
+
+bool check_if_bullet_collided_with_object(bullet b, platform_window* window) {
+ map_info info = get_map_info(window);
+ float size = get_bullet_size_in_tile(window);
+
+ for (int i = 0; i < max_objects; i++) {
+ object o = objects[i];
+ if (!o.active) continue;
+
+ if (b.x <= o.position.x + o.size.x && b.x + size >= o.position.x && b.y <= o.position.y + o.size.y && b.y >= o.position.y) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+void draw_bullets(platform_window* window) {
+ float bulletspeed = 0.1f;
+ float size = get_bullet_size(window);
+ map_info info = get_map_info(window);
+
+ for (int i = 0; i < max_bullets; i++) {
+ bullet b = bullets[i];
+ if (!b.active) continue;
+
+ bullets[i].x += bullets[i].xacceleration*bulletspeed;
+ bullets[i].y += bullets[i].yacceleration*bulletspeed;
+
+ if (is_in_bounds(window, b.x, b.y)) {
+ tile t = get_tile_under_coords(window, b.x, b.y);
+
+ float h = get_height_of_tile_under_coords(window, bullets[i].x, bullets[i].y);
+ if (h >= b.h) {
+ bullets[i].active = false; // hit the ground.
+ }
+ }
+ else {
+ bullets[i].active = false;
+ }
+
+ if (check_if_bullet_collided_with_object(b, window)) {
+ bullets[i].active = false;
+ }
+ if (!b.active) continue;
+
+ float bullet_render_x = b.x*info.tile_width + (b.y*info.px_incline);
+ float bullet_render_y = b.y*info.tile_height - (b.h*info.px_raised_per_h);
+ renderer->render_rectangle(bullet_render_x - (size/2), bullet_render_y - (size/2), size, size, rgb(0,50,220));
+ }
+} \ No newline at end of file
diff --git a/project-base.code-workspace b/project-base.code-workspace
new file mode 100644
index 0000000..e30453c
--- /dev/null
+++ b/project-base.code-workspace
@@ -0,0 +1,57 @@
+{
+ "folders": [
+ {
+ "path": "../project-base"
+ },
+ {
+ "path": "."
+ }
+ ],
+ "settings": {
+ "files.associations": {
+ "*.ejs": "html",
+ "render_cpu.c": "cpp",
+ "render.c": "cpp",
+ "interface.c": "cpp",
+ "iosfwd": "c",
+ "sdl.h": "c",
+ "*.rc": "c",
+ "cjson.c": "cpp",
+ "cmath": "c",
+ "mono.c": "cpp",
+ "xutility": "c",
+ "initializer_list": "c",
+ "type_traits": "c",
+ "*.rh": "c",
+ "algorithm": "c",
+ "limits": "c",
+ "popup_window.h": "c",
+ "wingdi.h": "c",
+ "info_png.h": "c",
+ "project_base.h": "c",
+ "cstdlib": "c",
+ "array": "cpp",
+ "deque": "cpp",
+ "fstream": "cpp",
+ "iterator": "cpp",
+ "list": "cpp",
+ "memory": "cpp",
+ "sstream": "cpp",
+ "system_error": "cpp",
+ "utility": "cpp",
+ "vector": "cpp",
+ "xhash": "cpp",
+ "xlocale": "cpp",
+ "xlocnum": "cpp",
+ "xmemory": "cpp",
+ "xstring": "cpp",
+ "atomic": "cpp",
+ "*.tcc": "cpp",
+ "string": "cpp",
+ "string_view": "cpp",
+ "objects.h": "c",
+ "map.h": "c",
+ "zombies.h": "c"
+ }
+ }
+} \ No newline at end of file
diff --git a/zombies.c b/zombies.c
new file mode 100644
index 0000000..bad6c17
--- /dev/null
+++ b/zombies.c
@@ -0,0 +1,65 @@
+#include "include/zombies.h"
+
+void spawn_zombie(int x, int y) {
+ for (int i = 0; i < max_zombies; i++) {
+ zombie o = zombies[i];
+ if (o.alive) continue;
+
+ zombies[i].alive = true;
+ zombies[i].health = 100.0f;
+ zombies[i].position = (vec2f){x,y};
+ break;
+ }
+}
+
+void draw_spawners(platform_window* window) {
+ map_info info = get_map_info(window);
+
+ for (int x = 0; x < 2; x++) {
+ vec2 spawner_location = spawner_tiles[x];
+ int render_x = (info.tile_width * spawner_location.x) + (info.px_incline * spawner_location.y);
+ int render_y = info.tile_height * spawner_location.y;
+
+ tile tile = map_loaded[spawner_location.y][spawner_location.x];
+ renderer->render_quad(
+ tile.tl.x, tile.tl.y,
+ tile.bl.x, tile.bl.y,
+ tile.br.x, tile.br.y,
+ tile.tr.x, tile.tr.y,
+ rgb(100, 150, 50));
+
+ renderer->render_line(tile.tl.x, tile.tl.y, tile.tr.x, tile.tr.y, 1, rgb(0,255,255)); // top
+ renderer->render_line(tile.tl.x, tile.tl.y, tile.bl.x, tile.bl.y, 1, rgb(0,255,255)); // left
+ renderer->render_line(tile.tr.x, tile.tr.y, tile.br.x, tile.br.y, 1, rgb(0,255,255)); // right
+ renderer->render_line(tile.bl.x, tile.bl.y, tile.br.x, tile.br.y, 1, rgb(0,255,255)); // bottom
+ }
+
+}
+
+void draw_zombies_at_tile(platform_window* window, int x, int y) {
+ map_info info = get_map_info(window);
+ float zombie_size = get_player_size(window);
+ float speed = 0.05f;
+
+ for (int i = 0; i < max_zombies; i++) {
+ zombie o = zombies[i];
+ if (!o.alive) continue;
+ if ((int)o.position.x != x || (int)o.position.y != y) continue;
+
+ float dirx = (playerx - o.position.x);
+ float diry = (playery - o.position.y);
+ double length = sqrt(dirx * dirx + diry * diry);
+ dirx /= length;
+ diry /= length;
+
+ zombies[i].position.x += dirx*speed;
+ zombies[i].position.y += diry*speed;
+
+ float height = get_height_of_tile_under_coords(window, zombies[i].position.x, zombies[i].position.y);
+ int render_x = (info.tile_width * o.position.x) + (info.px_incline * o.position.y);
+ int render_y = info.tile_height * o.position.y - (height*info.px_raised_per_h);
+
+ renderer->render_rectangle(render_x, render_y - zombie_size, zombie_size, zombie_size, rgb(40,0,255));
+ }
+}
+