Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Circle polygon maybe? (https://forums.graalonline.com/forums/showthread.php?t=134261669)

kingcj 01-14-2011 03:49 AM

Circle polygon maybe?
 
I've been searching for a way to draw a circle and then from the center of the circle designate different areas (such as Up, Left, Right, Down = 90degrees) from the circle. I don't understand drawpolygon(), and I won't pretend to. I was also wondering if I do get the circle or areas created could they be hidden. I am really not sure how to accomplish this and I can't use an image for the circle.

MrOmega 01-14-2011 05:29 AM

To draw a circle you'll need to use sine and cosine

PHP Code:

temp.circle NULL;

for ( 
temp.0temp.< ( pi); temp.+= ( pi 32);)
{

  
temp.circle.addplayer.costemp.a));
  
temp.circle.addplayer.sintemp.a));

}

showPoly1temp.circle); 

Basically adjust the 32 is the number of sides in the circle. It's not a true circle, but visually it's pretty close, increase it for a smoother edges, but costs for cpu time.

To get a a circle on a quadrant plane you use
X = ORGINX + RADIUS * cos( ANGLE);
Y = ORGINY - RADIUS * sin( ANGLE);

Orgins are the center x/y points of the circle
Radius is the number of tiles for the center point
Angle is the well the angle from the center that we are drawing

As for moving along angles, it involves sine and cosine again.
PHP Code:

temp.angle getanglevecxplayer.dir), vecyplayer.dir));

player.+= costemp.angle) * 0.5;
player.+= -sintemp.angle) * 0.5

Basically getangle() works by getting values and computing its angle
So it gets values in vectors. Grall operates as so, East is 0/360 degrees and north is 90 degress and so forth.

DustyPorViva 01-14-2011 05:35 AM

It'd be better to define how many vertices for the loop.

PHP Code:

temp.vertices 32;
temp.radius 3;
temp.circle = new[0];
temp.= {player.1.5,player.2};
for (
temp.i=0;temp.i<temp.vertices;temp.i++) {
  
temp.= (pi*2)*temp.i;
  
temp.circle.add(temp.O[0] + cos(temp.a)*temp.radius);
  
temp.circle.add(temp.O[1] - sin(temp.a)*temp.radius);
}
showpoly(200,temp.circle); 

At least, that's my opinion. I find it easier to read.

kingcj 01-14-2011 06:46 AM

Ok Thanks, the circle works fine, but I can't seem to getangle() to show the angle of said circle. I am unsure of how to get the angle of the circle.
Sorry I could also use a little help with delta x and delta y (Like if the mouse is in front of the player and the player is following it) I have tried getdir() but it only works for Right and Down.

fowlplay4 01-14-2011 06:55 AM

Quote:

Originally Posted by kingcj (Post 1622660)
Ok Thanks, the circle works fine, but I can't seem to getangle() to show the angle of said circle. I am unsure of how to get the angle of the circle.
Sorry I could also use a little help with delta x and delta y (Like if the mouse is in front of the player and the player is following it) I have tried getdir() but it only works for Right and Down.

getangle and getdir are quite simple after you understand it. You pass it the delta (final position minus the initial position) values between two points and it'll give you the angle/direction towards the final position.

PHP Code:

//#CLIENTSIDE
function onCreated() setTimer(0.05);

function 
onTimeout() {
  
temp.delta_x mousex player.x;
  
temp.delta_y mousey player.y;
  
temp.ang getangle(temp.delta_xtemp.delta_y);
  
temp.ndir getdir(temp.delta_xtemp.delta_y);
  
with (findimg(200)) {
    
player.cos(temp.ang) * 5;
    
player.sin(temp.ang) * 5;
    
image "block.png";
  }
  
with (findimg(201)) {
    
mousex;
    
mousey 0.5;
    
text temp.ang SPC radtodeg(temp.ang);
    
textshadow true;
  }
  
player.dir temp.ndir;
  
setTimer(0.05);



kingcj 01-14-2011 07:16 AM

Thank you all I believe I understand it now!


All times are GMT +2. The time now is 11:57 PM.

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