View Single Post
  #2  
Old 03-19-2008, 06:29 PM
DrakilorP2P DrakilorP2P is offline
Registered User
DrakilorP2P's Avatar
Join Date: Apr 2006
Posts: 755
DrakilorP2P is just really niceDrakilorP2P is just really nice
Quote:
Originally Posted by Chompy View Post
They aren't for checking distances tho

it's to draw pretty lights

But, the only thing I mislike in those scripts is that you edit variables with the same name as the function params Only that, other then that they are very nice
Only small adjustments are required in order to check if a particular baddy have a clear line of sight to the intended target.
PHP Code:
function lineOfSight(x0y0x1y1)
{
  
// Things can screw up if we don't use integers.
  
x0 int(x0); y0 int(y0); x1 int(x1); y1 int(y1);
  
  
dx abs(x1 x0) << 1;
  
dy abs(y1 y0) << 1;
  
  if (
x1 x0ix 1;
  else 
ix = -1;
  if (
y1 y0iy 1;
  else 
iy = -1;
  
  if (
onwall(x0y0)) return false;
  
  if (
dx >= dy) {
    
error dy - (dx >> 1);
    
    while (
x0 != x1) {
      if (
error >= 0) {
        if (
error != || (ix 0)) {
          
y0 += iy;
          
error -= dx;
        }
      }
      
      
x0 += ix;
      
error += dy;
      
      if (
onwall(x0y0)) return false;
    }
  }
  else {
    
error dx - (dy >> 1);
    
    while (
y0 != y1) {
      if (
error >= 0) {
        if (
error != || iy 0) {
          
x0 += ix;
          
error -= dy;
        }
      }
      
      
y0 += iy;
      
error += dx;
      
      if (
onwall(x0y0)) return false;
    }
  }
  
  
// Success
  
return true;

If you want distance with that, add a counter or employ trigonometry in a separate function.
Reply With Quote