From 371e8623161095b8f74d51d37f3de368b5cd584c Mon Sep 17 00:00:00 2001 From: Magnus Auvinen Date: Sun, 11 Jan 2009 10:26:17 +0000 Subject: fixed so the laser bounces correctly at low angles --- src/game/collision.cpp | 20 +++++++++++++------- src/game/collision.hpp | 2 +- src/game/gamecore.cpp | 2 +- src/game/server/entities/laser.cpp | 6 ++++-- src/game/server/entities/projectile.cpp | 2 +- src/game/server/gamemodes/ctf.cpp | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) (limited to 'src/game') diff --git a/src/game/collision.cpp b/src/game/collision.cpp index 2747b22f..73f4a9c5 100644 --- a/src/game/collision.cpp +++ b/src/game/collision.cpp @@ -60,22 +60,28 @@ int col_is_solid(int x, int y) // TODO: rewrite this smarter! -int col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out) +int col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out_collision, vec2 *out_before_collision) { float d = distance(pos0, pos1); + vec2 last = pos0; for(float f = 0; f < d; f++) { float a = f/d; vec2 pos = mix(pos0, pos1, a); - if(col_is_solid((int)pos.x, (int)pos.y)) + if(col_is_solid(round(pos.x), round(pos.y))) { - if(out) - *out = pos; - return col_get((int)pos.x, (int)pos.y); + if(out_collision) + *out_collision = pos; + if(out_before_collision) + *out_before_collision = last; + return col_get(round(pos.x), round(pos.y)); } + last = pos; } - if(out) - *out = pos1; + if(out_collision) + *out_collision = pos1; + if(out_before_collision) + *out_before_collision = pos1; return 0; } diff --git a/src/game/collision.hpp b/src/game/collision.hpp index 676a477a..0f072daa 100644 --- a/src/game/collision.hpp +++ b/src/game/collision.hpp @@ -16,6 +16,6 @@ int col_is_solid(int x, int y); int col_get(int x, int y); int col_width(); int col_height(); -int col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out); +int col_intersect_line(vec2 pos0, vec2 pos1, vec2 *out_collision, vec2 *out_before_collision); #endif diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index 8d167398..7818fa4b 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -302,7 +302,7 @@ void CHARACTER_CORE::tick(bool use_input) // make sure that the hook doesn't go though the ground bool going_to_hit_ground = false; bool going_to_retract = false; - int hit = col_intersect_line(hook_pos, new_pos, &new_pos); + int hit = col_intersect_line(hook_pos, new_pos, &new_pos, 0); if(hit) { if(hit&COLFLAG_NOHOOK) diff --git a/src/game/server/entities/laser.cpp b/src/game/server/entities/laser.cpp index 20054ed4..2c6fa0ff 100644 --- a/src/game/server/entities/laser.cpp +++ b/src/game/server/entities/laser.cpp @@ -48,14 +48,16 @@ void LASER::do_bounce() } vec2 to = pos + dir*energy; + vec2 org_to = to; - if(col_intersect_line(pos, to, &to)) + if(col_intersect_line(pos, to, 0x0, &to)) { if(!hit_character(pos, to)) { // intersected from = pos; - pos = to - dir*2; + pos = to; + vec2 temp_pos = pos; vec2 temp_dir = dir*4.0f; diff --git a/src/game/server/entities/projectile.cpp b/src/game/server/entities/projectile.cpp index e0b4701a..2a8de766 100644 --- a/src/game/server/entities/projectile.cpp +++ b/src/game/server/entities/projectile.cpp @@ -65,7 +65,7 @@ void PROJECTILE::tick() lifespan--; - int collide = col_intersect_line(prevpos, curpos, &curpos); + int collide = col_intersect_line(prevpos, curpos, &curpos, 0); //int collide = col_check_point((int)curpos.x, (int)curpos.y); CHARACTER *ownerchar = game.get_player_char(owner); CHARACTER *targetchr = game.world.intersect_character(prevpos, curpos, 6.0f, curpos, ownerchar); diff --git a/src/game/server/gamemodes/ctf.cpp b/src/game/server/gamemodes/ctf.cpp index 6e87841f..65058883 100644 --- a/src/game/server/gamemodes/ctf.cpp +++ b/src/game/server/gamemodes/ctf.cpp @@ -122,7 +122,7 @@ void GAMECONTROLLER_CTF::tick() int num = game.world.find_entities(f->pos, 32.0f, (ENTITY**)close_characters, MAX_CLIENTS, NETOBJTYPE_CHARACTER); for(int i = 0; i < num; i++) { - if(!close_characters[i]->alive || close_characters[i]->player->team == -1 || col_intersect_line(f->pos, close_characters[i]->pos, NULL)) + if(!close_characters[i]->alive || close_characters[i]->player->team == -1 || col_intersect_line(f->pos, close_characters[i]->pos, NULL, NULL)) continue; if(close_characters[i]->team == f->team) -- cgit 1.4.1