View Single Post
  #9  
Old 03-05-2002, 12:21 AM
screen_name screen_name is offline
is watching you
Join Date: Mar 2002
Location: The 3rd Dimension
Posts: 2,160
screen_name is on a distinguished road
Send a message via AIM to screen_name Send a message via MSN to screen_name
Quote:
Originally posted by Saga2001
Well I won't go on the assumption that you are not a l33t script0r, so instead I will tell you what I did, your math kind of needs to be strong to do this, and I wish I had a scanner so I could upload me notes, I'll try to overview.
If you think about it, on pong, you have 360 degrees, right? Well you can just cut it in half, to 180 degrees and two modes for x and y, so xmode = (0 || 1); ymode = (0 || 1); and each mode has 180 degrees. So like this, you can, using triginometry (sp?) figure out the direction of any object:
NPC Code:

xincrement = (cos(angle/57.3)*speed)-cos(angle/57.3);
yincrement = (sin(angle/57.3)*speed)-sin(angle/57.3);

Because remember circles are also 360 degrees...
where speed it the amount of space you want it to move each increment.


Than to move the actual object (assuming ox, oy is the object's x and y) you could simply do this:
NPC Code:

if (xmode == 0) ox+=abs(xincrement);
else ox-=abs(xincrement);
if (ymode == 0) oy+=abs(yincrement);
else oy-=abs(yincrement);



Than assuming that mx and my is the max x and y, and lx and ly is the least x and y, we can reverse the mode on hits.
NPC Code:

if (ox>=mx) this.xmode=0;
if (ox<=lx) this.xmode=1;
if (oy>=my) this.ymode=0;
if (oy<=ly) this.ymode=1;


Hope that helps.
are you talking to me??
__________________
[signature]insert here[/signature]
Reply With Quote