Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-19-2008, 03:24 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by coreys View Post
Whenever I make baddies I just check if a target is in the direction the baddy is facing to do field of view. xP
Now I feel like a chump.
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
__________________
Reply With Quote
  #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
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:52 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.