Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 01-14-2011, 03:49 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Question 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.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #2  
Old 01-14-2011, 05:29 AM
MrOmega MrOmega is offline
One More Time
MrOmega's Avatar
Join Date: Aug 2010
Location: TN, USA
Posts: 631
MrOmega is an unknown quantity at this point
Send a message via AIM to MrOmega Send a message via MSN to MrOmega Send a message via Yahoo to MrOmega
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.
__________________
Time is the fire in which we burn...
Up, Up, Down, Down, Left, Right, Left, Right, B, A, Select, Start! Now I got 99 LIVES!!!

Last edited by MrOmega; 01-14-2011 at 05:39 AM..
Reply With Quote
  #3  
Old 01-14-2011, 05:35 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
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.
Reply With Quote
  #4  
Old 01-14-2011, 06:46 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
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.
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
Reply With Quote
  #5  
Old 01-14-2011, 06:55 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by kingcj View Post
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);

__________________
Quote:

Last edited by fowlplay4; 01-14-2011 at 05:16 PM..
Reply With Quote
  #6  
Old 01-14-2011, 07:16 AM
kingcj kingcj is offline
Registered User
kingcj's Avatar
Join Date: Apr 2006
Location: TN
Posts: 114
kingcj will become famous soon enough
Send a message via MSN to kingcj
Thank you all I believe I understand it now!
__________________
Zie

"It is not necessary to change. Survival is not mandatory." - W. Edwards Deming
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 03:16 PM.


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