summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2022-12-20 21:12:07 +0100
committerAldrik Ramaekers <aldrik@amftech.nl>2022-12-20 21:12:07 +0100
commit38d8d7f442a4b5cb66815ada7bb508c734186c6e (patch)
tree17454b271f82719f25d6fdeff7a0be4ad016d573
parent1683c214b37c2bb8f3e43fd9054f3a53f7695f4a (diff)
assets, sprites
-rw-r--r--build/data/imgs/spawner.pngbin0 -> 2474 bytes
-rw-r--r--build/data/imgs/tile_cobblestone.pngbin0 -> 2553 bytes
-rw-r--r--build/data/psd/spawner.psdbin0 -> 84464 bytes
-rw-r--r--build/zombies.exebin1764230 -> 1768159 bytes
-rw-r--r--data/imgs/spawner.pngbin0 -> 2474 bytes
-rw-r--r--data/imgs/tile_cobblestone.pngbin0 -> 2553 bytes
-rw-r--r--data/psd/spawner.psdbin0 -> 84464 bytes
-rw-r--r--include/asset_defs.h4
-rw-r--r--include/sprite.h27
-rw-r--r--include/zombies.h12
-rw-r--r--main.c2
-rw-r--r--project-base.code-workspace3
-rw-r--r--src/asset_defs.c4
-rw-r--r--src/drops.c3
-rw-r--r--src/map.c23
-rw-r--r--src/objects.c9
-rw-r--r--src/sprite.c28
-rw-r--r--src/zombies.c27
18 files changed, 123 insertions, 19 deletions
diff --git a/build/data/imgs/spawner.png b/build/data/imgs/spawner.png
new file mode 100644
index 0000000..eec9f0f
--- /dev/null
+++ b/build/data/imgs/spawner.png
Binary files differ
diff --git a/build/data/imgs/tile_cobblestone.png b/build/data/imgs/tile_cobblestone.png
new file mode 100644
index 0000000..42c6f81
--- /dev/null
+++ b/build/data/imgs/tile_cobblestone.png
Binary files differ
diff --git a/build/data/psd/spawner.psd b/build/data/psd/spawner.psd
new file mode 100644
index 0000000..d05d80a
--- /dev/null
+++ b/build/data/psd/spawner.psd
Binary files differ
diff --git a/build/zombies.exe b/build/zombies.exe
index a776120..49ce0fc 100644
--- a/build/zombies.exe
+++ b/build/zombies.exe
Binary files differ
diff --git a/data/imgs/spawner.png b/data/imgs/spawner.png
new file mode 100644
index 0000000..eec9f0f
--- /dev/null
+++ b/data/imgs/spawner.png
Binary files differ
diff --git a/data/imgs/tile_cobblestone.png b/data/imgs/tile_cobblestone.png
new file mode 100644
index 0000000..42c6f81
--- /dev/null
+++ b/data/imgs/tile_cobblestone.png
Binary files differ
diff --git a/data/psd/spawner.psd b/data/psd/spawner.psd
new file mode 100644
index 0000000..d05d80a
--- /dev/null
+++ b/data/psd/spawner.psd
Binary files differ
diff --git a/include/asset_defs.h b/include/asset_defs.h
index 6dee5d4..d6af444 100644
--- a/include/asset_defs.h
+++ b/include/asset_defs.h
@@ -10,11 +10,15 @@ image* img_icon_bullets;
image* img_icon_nova;
image* img_drop;
+image* img_spawner;
image* img_zombie_chunk_hand;
image* img_zombie_chunk_foot;
image* img_zombie_chunk_blood;
+image* img_tile_cobblestone;
+
+
void load_assets();
#endif \ No newline at end of file
diff --git a/include/sprite.h b/include/sprite.h
new file mode 100644
index 0000000..58ff293
--- /dev/null
+++ b/include/sprite.h
@@ -0,0 +1,27 @@
+#ifndef INCLUDE_SPRITE
+#define INCLUDE_SPRITE
+
+#include <projectbase/project_base.h>
+
+typedef struct t_sprite {
+ image* image;
+ int current_frame;
+ int frame_count;
+ int frame_width;
+ int frame_height;
+ float sec_per_frame;
+ float time;
+} sprite;
+
+typedef struct t_sprite_frame {
+ vec2f tl;
+ vec2f tr;
+ vec2f bl;
+ vec2f br;
+} sprite_frame;
+
+sprite create_sprite(image* img, int frame_count, int fwidth, int fheight, float sec_per_frame);
+void update_sprite(sprite* sprite);
+sprite_frame get_frame(sprite* sprite);
+
+#endif \ No newline at end of file
diff --git a/include/zombies.h b/include/zombies.h
index c99063e..72836ea 100644
--- a/include/zombies.h
+++ b/include/zombies.h
@@ -6,6 +6,7 @@
#include "players.h"
#include "objects.h"
#include "pathfinding.h"
+#include "sprite.h"
typedef struct t_zombie {
bool alive;
@@ -20,21 +21,20 @@ typedef struct t_zombie {
} zombie;
typedef struct t_spawner {
+ bool active;
vec2 position;
float sec_since_last_spawn;
+ sprite sprite;
} spawner;
-#define MAX_SPAWNERS (3)
+#define MAX_SPAWNERS (5)
// data data that is stored on disk
-spawner spawner_tiles[MAX_SPAWNERS] = {
- {15, 5, 999},
- {3, 8, 999},
- {11, 18, 999},
-};
+spawner spawner_tiles[MAX_SPAWNERS] = {0};
#define MAX_ZOMBIES (50)
zombie zombies[MAX_ZOMBIES] = {0};
+void create_spawner(vec2 position);
void draw_spawners(platform_window* window);
void draw_zombies(platform_window* window);
void spawn_zombie(int x, int y);
diff --git a/main.c b/main.c
index 0620f49..32a8668 100644
--- a/main.c
+++ b/main.c
@@ -17,6 +17,7 @@
#include "include/drops.h"
#include "include/wall_item.h"
#include "include/zombie_chunk.h"
+#include "include/sprite.h"
#include "src/map.c"
#include "src/players.c"
@@ -35,6 +36,7 @@
#include "src/drops.c"
#include "src/wall_item.c"
#include "src/zombie_chunk.c"
+#include "src/sprite.c"
#define CONFIG_DIRECTORY "zombieshooter"
diff --git a/project-base.code-workspace b/project-base.code-workspace
index 2045268..de91c68 100644
--- a/project-base.code-workspace
+++ b/project-base.code-workspace
@@ -66,7 +66,8 @@
"bullets.h": "c",
"guns.h": "c",
"iphlpapi.h": "c",
- "asset_defs.h": "c"
+ "asset_defs.h": "c",
+ "sprite.h": "c"
}
}
} \ No newline at end of file
diff --git a/src/asset_defs.c b/src/asset_defs.c
index 337a88f..da8b5f0 100644
--- a/src/asset_defs.c
+++ b/src/asset_defs.c
@@ -12,4 +12,8 @@ void load_assets() {
img_zombie_chunk_hand = assets_load_image_from_file("data/imgs/zombie_chunk_hand.png");
img_zombie_chunk_foot = assets_load_image_from_file("data/imgs/zombie_chunk_foot.png");
img_zombie_chunk_blood = assets_load_image_from_file("data/imgs/zombie_chunk_blood.png");
+
+ img_tile_cobblestone = assets_load_image_from_file("data/imgs/tile_cobblestone.png");
+
+ img_spawner = assets_load_image_from_file("data/imgs/spawner.png");
} \ No newline at end of file
diff --git a/src/drops.c b/src/drops.c
index 18aac1d..9c04509 100644
--- a/src/drops.c
+++ b/src/drops.c
@@ -55,7 +55,6 @@ void draw_drops(platform_window* window) {
b.size.z = 0.0f;
b.position.y += 0.2f;
b.position.x -= 0.07f;
- b.size.x -= 0.1f;
box shadow_box = get_render_box_of_square(window, b.position, b.size);
render_box_with_outline(shadow_box, rgba(0,0,0,alpha * (120.0f/255.0f)));
@@ -63,7 +62,7 @@ void draw_drops(platform_window* window) {
box full_box = get_render_box_of_square(window, b.position, b.size);
//render_box_with_outline(full_box, rgba(218,112,214, alpha));
renderer->render_image_tint(img_drop, full_box.tl_u.x, full_box.tl_u.y,
- full_box.tr_u.x - full_box.tl_d.x, full_box.br_d.y - full_box.tr_u.y, rgba(218,112,214, alpha));
+ full_box.br_d.x - full_box.tl_d.x, full_box.br_d.y - full_box.tr_u.y, rgba(218,112,214, alpha));
int drop_h = full_box.br_d.y - full_box.tr_d.y;
diff --git a/src/map.c b/src/map.c
index a5bc96a..faa447e 100644
--- a/src/map.c
+++ b/src/map.c
@@ -193,29 +193,36 @@ void draw_grid(platform_window* window) {
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};
- color c = rgb(128, 64, 0);
+ color c = rgb(205,205,205);
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) c = rgb(108, 64, 0);
+ highest_point_topright > highest_point_topleft || highest_point_bottomright > highest_point_bottomleft) c = rgb(165,165,165);
if (highest_point_topleft < highest_point_bottomleft || highest_point_topright < highest_point_bottomright ||
- highest_point_topleft > highest_point_topright) c = rgb(148, 64, 0);
+ highest_point_topleft > highest_point_topright) c = rgb(255,255,255);
+ renderer->render_image_quad_tint(img_tile_cobblestone,
+ topleft.x, topleft.y,
+ bottomleft.x, bottomleft.y,
+ bottomright.x, bottomright.y,
+ topright.x, topright.y, c);
+
+ /*
renderer->render_quad(
topleft.x, topleft.y,
bottomleft.x, bottomleft.y,
bottomright.x, bottomright.y,
topright.x, topright.y,
- c);
+ c);*/
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(108, 64, 0));
+ bottomright.x, bottomright.y, rgba(0,0,0,80));
}
- renderer->render_line(topleft.x, topleft.y, bottomright.x, bottomright.y, 1, rgb(0,0,255)); // diag
+ //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
}
@@ -224,7 +231,7 @@ void draw_grid(platform_window* window) {
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;
diff --git a/src/objects.c b/src/objects.c
index 7299aab..7b3b7a0 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -48,10 +48,13 @@ void draw_objects_at_row(platform_window* window, int row) {
if (!o.active) continue;
box box = get_box_of_object(window, o);
+ renderer->render_image(img_drop, box.tl_u.x, box.tl_u.y,
+ box.br_d.x - box.tl_d.x, box.br_d.y - box.tr_u.y);
+ /*
render_quad_with_outline(box.tl_d, box.tr_d, box.bl_d, box.br_d, rgb(200,200,0));
render_quad_with_outline(box.tl_u, box.tr_u, box.bl_u, box.br_u, rgb(200,200,0));
render_quad_with_outline(box.tl_u, box.tl_d, box.bl_u, box.bl_d, rgb(200,200,0));
- render_quad_with_outline(box.bl_u, box.br_u, box.bl_d, box.br_d, rgb(200,200,0));
+ render_quad_with_outline(box.bl_u, box.br_u, box.bl_d, box.br_d, rgb(200,200,0));*/
}
}
@@ -91,5 +94,9 @@ void create_objects() {
create_box(13, 10, 0);
create_box(11, 10, 0);
+ create_spawner((vec2){15, 5});
+ create_spawner((vec2){3, 8});
+ create_spawner((vec2){11, 18});
+
create_wallitem((vec3f){14, 1, 0}, WALLITEM_GUN, (wall_item_data){.gun = GUN_NOVA});
} \ No newline at end of file
diff --git a/src/sprite.c b/src/sprite.c
new file mode 100644
index 0000000..6b35e62
--- /dev/null
+++ b/src/sprite.c
@@ -0,0 +1,28 @@
+#include "../include/sprite.h"
+
+sprite create_sprite(image* img, int frame_count, int fwidth, int fheight, float sec_per_frame) {
+ sprite s;
+ s.current_frame = 0;
+ s.frame_count = frame_count;
+ s.frame_height = fheight;
+ s.frame_width = fwidth;
+ s.image = img;
+ s.sec_per_frame = sec_per_frame;
+ s.time = 0.0f;
+ return s;
+}
+
+void update_sprite(sprite* sprite) {
+ int frame = sprite->time / sprite->sec_per_frame;
+ sprite->current_frame = frame;
+ sprite->time += update_delta;
+}
+
+sprite_frame get_frame(sprite* sprite) {
+ sprite_frame frame;
+ frame.tl = (vec2f){0,0};
+ frame.tr = (vec2f){1,0};
+ frame.bl = (vec2f){0,1};
+ frame.br = (vec2f){1,1};
+ return frame;
+} \ No newline at end of file
diff --git a/src/zombies.c b/src/zombies.c
index a5a9f38..afcfd7f 100644
--- a/src/zombies.c
+++ b/src/zombies.c
@@ -23,6 +23,21 @@ static player get_closest_player_to_tile(int x, int y) {
}
}
+void create_spawner(vec2 position) {
+ spawner s;
+ s.active = true;
+ s.position = position;
+ s.sec_since_last_spawn = 999.0f;
+ s.sprite = create_sprite(img_spawner, 14, 64, 64, 0.3f);
+
+ for (int i = 0; i < MAX_SPAWNERS; i++) {
+ spawner o = spawner_tiles[i];
+ if (o.active) continue;
+ spawner_tiles[i] = s;
+ return;
+ }
+}
+
void spawn_zombie(int x, int y) {
for (int i = 0; i < MAX_ZOMBIES; i++) {
zombie o = zombies[i];
@@ -48,6 +63,7 @@ void spawn_zombie(int x, int y) {
void update_spawners_server() {
for (int x = 0; x < MAX_SPAWNERS; x++) {
spawner spawner = spawner_tiles[x];
+ if (!spawner.active) continue;
spawner_tiles[x].sec_since_last_spawn += SERVER_TICK_RATE;
if (spawner_tiles[x].sec_since_last_spawn >= 2.0f) {
spawn_zombie(spawner.position.x, spawner.position.y);
@@ -61,10 +77,19 @@ void draw_spawners(platform_window* window) {
for (int x = 0; x < MAX_SPAWNERS; x++) {
spawner spawner = spawner_tiles[x];
+ if (!spawner.active) continue;
int render_x = (info.tile_width * spawner.position.x) + (info.px_incline * spawner.position.y);
int render_y = info.tile_height * spawner.position.y;
tile tile = map_loaded[spawner.position.y][spawner.position.x];
+
+ renderer->render_image_quad(spawner.sprite.image,
+ tile.tl.x, tile.tl.y,
+ tile.bl.x, tile.bl.y,
+ tile.br.x, tile.br.y,
+ tile.tr.x, tile.tr.y);
+
+ /*
renderer->render_quad(
tile.tl.x, tile.tl.y,
tile.bl.x, tile.bl.y,
@@ -75,7 +100,7 @@ void draw_spawners(platform_window* window) {
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
+ renderer->render_line(tile.bl.x, tile.bl.y, tile.br.x, tile.br.y, 1, rgb(0,255,255)); // bottom*/
}
}