summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-10-29 16:53:33 +0100
committerAldrik Ramaekers <aldrik@amftech.nl>2023-10-29 16:53:33 +0100
commit04024078984bbaf84f34352061da2a224ecdb0b0 (patch)
treee576cdd0451e06d96c71131c551b1bc32d633f0d
parent61c5fb1e253f31d2faa3a0fc970ce4e18f32b205 (diff)
fix throwable collision
-rw-r--r--build/zombies.exebin1989137 -> 1990195 bytes
-rw-r--r--include/audio.h1
-rw-r--r--include/guns.h4
-rw-r--r--include/throwables.h1
-rw-r--r--src/audio.c1
-rw-r--r--src/bullets.c4
-rw-r--r--src/map.c2
-rw-r--r--src/math_helper.c6
-rw-r--r--src/objects.c5
-rw-r--r--src/throwables.c48
10 files changed, 52 insertions, 20 deletions
diff --git a/build/zombies.exe b/build/zombies.exe
index ea5f8fd..b93778d 100644
--- a/build/zombies.exe
+++ b/build/zombies.exe
Binary files differ
diff --git a/include/audio.h b/include/audio.h
index 4354e6e..22e0a99 100644
--- a/include/audio.h
+++ b/include/audio.h
@@ -11,6 +11,7 @@
#define CHANNEL_IMPACT 2
#define CHANNEL_RELOAD 3
#define CHANNEL_EXPLODE 4
+#define CHANNEL_COLLECT 5
typedef enum t_audio_event_type {
EVENT_SHOOT,
diff --git a/include/guns.h b/include/guns.h
index 2ea0d1e..52f4a10 100644
--- a/include/guns.h
+++ b/include/guns.h
@@ -23,8 +23,8 @@ typedef struct t_gun {
gun guns[GUN_ALL] = {
{GUN_DESERTEAGLE, "Desert Eagle", 8, 64, 0.0f, 1, 4.0f, 350, 1.0f},
- {GUN_MP5, "MP5", 30, 120, 0.1f, 1, 10.0f, 150, 1.0f},
- {GUN_NOVA, "Nova", 12, 80, 0.2f, 3, 1.2f, 600, 1.0f},
+ {GUN_MP5, "MP5", 30, 120, 0.05f, 1, 10.0f, 150, 1.0f},
+ {GUN_NOVA, "Nova", 12, 80, 0.1f, 3, 1.2f, 600, 1.0f},
};
image* get_image_of_gun(gun_type type);
diff --git a/include/throwables.h b/include/throwables.h
index 0d227d9..714e66b 100644
--- a/include/throwables.h
+++ b/include/throwables.h
@@ -31,6 +31,7 @@ typedef struct t_throwable {
int bounces;
sprite sprite;
int damage;
+ float rotation;
} throwable;
vec3f grenade_explosion_size = (vec3f){2.0f, 2.0f, 2.0f};
diff --git a/src/audio.c b/src/audio.c
index db424f3..1f15a66 100644
--- a/src/audio.c
+++ b/src/audio.c
@@ -39,6 +39,7 @@ static int get_channel_from_audio_event_type(audio_event_type event) {
case EVENT_RELOAD: return CHANNEL_RELOAD;
case EVENT_IMPACT: return CHANNEL_IMPACT;
case EVENT_EXPLODE_THROWABLE: return CHANNEL_EXPLODE;
+ case EVENT_COLLECT: return CHANNEL_COLLECT;
default: return 0;
}
diff --git a/src/bullets.c b/src/bullets.c
index a3a876e..ed7ca58 100644
--- a/src/bullets.c
+++ b/src/bullets.c
@@ -21,7 +21,9 @@ void shoot(platform_window* window, u32 id, float dirx, float diry) {
if (bullets_to_shoot > p->ammo_in_mag) bullets_to_shoot = p->ammo_in_mag;
p->ammo_in_mag -= bullets_to_shoot;
- add_audio_event_to_queue(EVENT_SHOOT, p->id, (vec3f){.x = p->playerx, .y = p->playery, .z = p->height});
+ if (bullets_to_shoot > 0) {
+ add_audio_event_to_queue(EVENT_SHOOT, p->id, (vec3f){.x = p->playerx, .y = p->playery, .z = p->height});
+ }
for (int i = 0; i < bullets_to_shoot; i++)
{
diff --git a/src/map.c b/src/map.c
index 8d5e26b..1eddf90 100644
--- a/src/map.c
+++ b/src/map.c
@@ -398,6 +398,6 @@ inline map_info get_map_info(platform_window* window) {
info.tile_width = get_tile_width(window);
info.tile_height = get_tile_height(window);
info.px_incline = 0.0f; //info.tile_width/3; // info.tile_width/3; // offset*info.tile_width;
- info.px_raised_per_h = info.tile_height/2.5;
+ info.px_raised_per_h = info.tile_height/5.0f;
return info;
} \ No newline at end of file
diff --git a/src/math_helper.c b/src/math_helper.c
index b795fe2..51db867 100644
--- a/src/math_helper.c
+++ b/src/math_helper.c
@@ -30,11 +30,11 @@ vec2f get_dir_of_line(vec2f p1, vec2f p2) {
}
bool neg2(float p1, float p2) {
- return p1 < 0.0f && p2 < 0.0f || abs(p1-p2) < 1.0f;
+ return p1 < 0.0f && p2 < 0.0f || abs(p1-p2) < 1.5f;
}
bool pos2(float p1, float p2) {
- return (p1 >= 0.0f && p2 >= 0.0f) || abs(p1-p2) < 1.0f;
+ return (p1 >= 0.0f && p2 >= 0.0f) || abs(p1-p2) < 1.5f;
}
vec3f get_center_of_square(vec3f position, vec3f size) {
@@ -68,7 +68,7 @@ bool lines_intersect(vec2f p1, vec2f q1, vec2f p2, vec2f q2)
// p2, q2 and q1 are collinear and q1 lies on segment p2q2
if (o4 == 0 && onSegment(p2, q1, q2)) return true;
-
+
return false; // Doesn't fall in any of the above cases
}
diff --git a/src/objects.c b/src/objects.c
index 17123f9..4ba9961 100644
--- a/src/objects.c
+++ b/src/objects.c
@@ -61,16 +61,17 @@ void draw_objects_at_row(platform_window* window, int row) {
if (!o.active) continue;
box box = get_box_of_object(window, o);
+ /*
image* img = get_image_from_objecttype(o.type);
if (img) {
renderer->render_image(img, 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));
}
}
diff --git a/src/throwables.c b/src/throwables.c
index cd8f8af..86a9734 100644
--- a/src/throwables.c
+++ b/src/throwables.c
@@ -33,27 +33,45 @@ bool check_if_throwable_collided_with_object(throwable* b, vec3f oldpos, vec3f n
if (b->position.z <= o.h + o.size.z && b->position.z >= o.h) {
box obj_box = get_box_of_square((vec3f){o.position.x, o.position.y, o.h}, o.size);
+ if (o.type == OBJECT_PLANTBOX1 && oldpos.x < o.position.x && newpos.x > o.position.x) {
+ log_infox("intersect {%.2f %.2f}{%.2f %.2f} {%.2f %.2f}{%.2f %.2f}",
+ oldpos.x, oldpos.y, newpos.x, newpos.y, o.position.x, o.position.y, o.position.x, o.position.y + o.size.y);
+
+ //if (lines_intersect((vec2f){15.99, 8.58}, (vec2f){16.05, 8.58}, (vec2f){16.00, 8.00}, (vec2f){16.00, 9.00})) {
+ // log_info("POOOp");
+ //}
+ }
+
+ // top
if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
(vec2f){.x = o.position.x, .y = o.position.y}, (vec2f){.x = o.position.x + o.size.x, .y = o.position.y})) {
- result = true;
+ result = true;
+ direction->y = -direction->y;
}
- if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
+
+ // bottom
+ else if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
(vec2f){.x = o.position.x, .y = o.position.y + o.size.y}, (vec2f){.x = o.position.x + o.size.x, .y = o.position.y + o.size.y})) {
- result = true;
+ result = true;
+ direction->y = -direction->y;
}
- if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
+
+ // left
+ else if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
(vec2f){.x = o.position.x, .y = o.position.y}, (vec2f){.x = o.position.x, .y = o.position.y + o.size.y})) {
- result = true;
+ result = true;
+ direction->x = -direction->x;
}
- if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
- (vec2f){.x = o.position.x + o.size.x, .y = o.position.y}, (vec2f){.x = o.position.x + o.size.x, .y = o.position.y + o.position.y})) {
- result = true;
+
+ // right
+ else if (lines_intersect((vec2f){.x = oldpos.x, .y = oldpos.y}, (vec2f){.x = newpos.x, .y = newpos.y},
+ (vec2f){.x = o.position.x + o.size.x, .y = o.position.y}, (vec2f){.x = o.position.x + o.size.x, .y = o.position.y + o.size.y})) {
+ result = true;
+ direction->x = -direction->x;
}
if (result) {
- b->position = oldpos;
- direction->x = -direction->x;
- direction->y = -direction->y;
+ b->position = oldpos;
return true;
}
}
@@ -91,6 +109,9 @@ void update_throwables_server() {
throwable b = throwables[i];
if (!b.active) continue;
+ throwables[i].rotation += SERVER_TICK_RATE*3.0f*throwables[i].bounces;
+
+
throwables[i].alive_time += SERVER_TICK_RATE;
if (throwables[i].alive_time >= 2.0f) {
@@ -164,6 +185,7 @@ void draw_throwables(platform_window* window) {
box box = get_render_box_of_square(window, explode_location, grenade_explosion_size);
sprite_frame frame = sprite_get_frame(&throwables[i].sprite);
+
renderer->render_image_quad_partial(img_grenade_explode,
box.tl_u.x, box.tl_u.y,
box.bl_d.x, box.bl_d.y,
@@ -172,9 +194,13 @@ void draw_throwables(platform_window* window) {
frame.tl, frame.tr, frame.bl, frame.br);
}
else if (t.state == THROWABLE_FLYING) {
+ renderer->render_set_rotation(t.rotation);
+
box full_box = get_render_box_of_square(window, t.position, (vec3f){0.2, 0.2, 0.2});
renderer->render_image(img_grenade, full_box.tl_u.x, full_box.tl_u.y,
full_box.br_d.x - full_box.tl_d.x, full_box.br_d.y - full_box.tr_u.y);
+
+ renderer->render_set_rotation(0.0f);
}
}
} \ No newline at end of file