summaryrefslogtreecommitdiff
path: root/src
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 /src
parent1683c214b37c2bb8f3e43fd9054f3a53f7695f4a (diff)
assets, sprites
Diffstat (limited to 'src')
-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
6 files changed, 82 insertions, 12 deletions
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*/
}
}