fixed so the laser bounces correctly at low angles

This commit is contained in:
Magnus Auvinen 2009-01-11 10:26:17 +00:00
parent 518db9218f
commit 371e862316
6 changed files with 21 additions and 13 deletions

View file

@ -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;
}

View file

@ -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

View file

@ -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)

View file

@ -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;

View file

@ -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);

View file

@ -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)