Qbasicnews.com
May 26, 2020, 04:45:59 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: attack angles...  (Read 3390 times)
Anonymous
Guest
« on: April 18, 2004, 10:21:21 PM »

hi everybody!

im coding a zelda-like game, and for the most part the engine aint
that hard, but I cant seem to figure out how to do angles. let me
expound.

in zelda (as many know) when you attack something, it sorta flies back in the opposite direction you attacked it from. my ? is how do you calculate angles using just x y coords? any help would be appreciated! Smiley
Logged
Jofers
Been there, done that
*****
Posts: 1040



WWW
« Reply #1 on: April 18, 2004, 10:40:00 PM »

Well, this should be simple.  In Zelda, if you attack something, it moves in the same direction Zelda is, right?  Since there are only 8 directions you can go in Zelda, this shouldn't be much of a challenge.  If you can move Zelda, you can now move this baddie.
Logged
Anonymous
Guest
« Reply #2 on: April 18, 2004, 10:50:03 PM »

heh man am i glad it wasnt that easy Wink

just checked it out. you can actually hit em in any angle.

...

...HELP lol
Logged
Jofers
Been there, done that
*****
Posts: 1040



WWW
« Reply #3 on: April 19, 2004, 12:41:24 AM »

okay then:

where angles is in radians (degrees * pi / 180):
Code:
x = x + cos(angle) * velocity
y = y + sin(angle) * velocity

angle should be the player's angle if the thing is getting thrown back from the player.
Logged
barok
Na_th_an
*****
Posts: 1727


How about a tasty lead sandwich?


« Reply #4 on: April 19, 2004, 12:46:20 AM »

like toonski said, in zelda there are only 8 directions.  when you hit an enemy, they fly back in the opposite direction they are moving.  so if they are moving down, when you hit them they move up.  

hey, if you want help in making it in any way, i'd be glad to help.  i've always wanted to make a zelda clone.
Logged

Jumping Jahoolipers!
Anonymous
Guest
« Reply #5 on: April 19, 2004, 08:52:28 AM »

heh i dont think you guys understand me Tongue


jofers: thats a good method to use... once you know the angles Wink thats what my ? was, to be able to take playerx, playery, enemyx, enemyy, and figure out which angle they are hit at...


barok: dude! no! Tongue you have full 360 degree angles to hit the enemy at. its not just u,ur,r,dr,d,dl,l,ul.... try it.
thanks for th offer Wink we pretty much have it covered, unless you know how to do bionic animation Smiley
Logged
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #6 on: April 19, 2004, 08:59:54 AM »

if you have playerX, playerY, enemyX, enemyY just follow the good ol' formula:

Code:
tangent = (playerY-enemyY)/(playerX-enemyX)
angle = ATN(targent)


ATN is ArcTaNgent, i.e. which angle has the specified tangent.
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Neo
Na_th_an
*****
Posts: 2150



« Reply #7 on: April 19, 2004, 09:34:11 AM »

Hehe, ATN always gets the smallest angle, and will screw up calculations if you don't get angle checks up and running when using ATN.

Code:
E.g.:
     /
    /|
   / |
  /  | y
 /a  |
/----|
   x

Get a by: a = ATN(y / x)

BUT!:

\
|\
| \
|y \
|   \
| x  \a
------X-----

Here get a by a = 180 - ATN(y / x)
Logged
Anonymous
Guest
« Reply #8 on: April 19, 2004, 09:53:37 AM »

thanks a lot guys!!!! Cheesy

i just have a couple of ?'s though.... ;(

first, when i do like PlayX - EnemX do I have to make sure the biggest is the one being subtracted from? or does it not matter?

and secondly. neo, i dont understand. how do you know when to subtract 180? God i shouldve taken maths Tongue
Logged
Jofers
Been there, done that
*****
Posts: 1040



WWW
« Reply #9 on: April 19, 2004, 11:02:10 AM »

it's easier to just post some code, and since i'm a lazy sob, rel wrote it Smiley

Code:
FUNCTION Rel.Angle% (X1, Y1, X2, Y2)
'By RelSoft of Auraflow
'Parameters:
'x1,y1= the starting coord
'x2,y2=the target coord
'Returns=the Angle in degrees between the two coords
'useable with SIN and COS so this is useful for calculating the
'vectors between 2 points.
'This is the Fast BASIC version

'Rad=Deg*PI/180
'Rad*180=Deg*PI
'Rad*180/PI=Deg
'Deg=Rad*180/PI

IF X1 = X2 THEN
IF Y1 < Y2 THEN
Rel.Angle% = 90
EXIT FUNCTION
ELSEIF Y1 > Y2 THEN
Rel.Angle% = 270
EXIT FUNCTION
ELSE
Rel.Angle% = 0
EXIT FUNCTION
END IF
ELSE
DeltaX = X2 - X1
DeltaY = Y2 - Y1
AngleTemp% = ATN(DeltaY / DeltaX) * 180 / 3.141593
AngleTemp% = AngleTemp% + 90
IF X1 > X2 THEN
AngleTemp% = AngleTemp% + 180
END IF
END IF
AngleTemp% = AngleTemp% - 90
IF AngleTemp% < 0 THEN AngleTemp% = AngleTemp% + 360
Rel.Angle% = AngleTemp%


END FUNCTION


...and version 2:
Code:
FUNCTION Rel.Angle2% (X1, Y1, X2, Y2)
'By RelSoft of Auraflow
'Parameters:
'x1,y1= the starting coord
'x2,y2=the target coord
'Returns=the Angle in degrees between the two coords
'useable with SIN and COS so this is useful for calculating the
'vectors between 2 points.
'This is the Readable Version :*)

'Some convertions to help me :*)
'Rad=Deg*PI/180
'Rad*180=Deg*PI
'Rad*180/PI=Deg
'Deg=Rad*180/PI

CONST PI! = 3.141593
CONST Convert! = 180 / PI

DeltaX = X2 - X1
DeltaY = Y2 - Y1

IF DeltaX = 0 THEN
IF DeltaY < 0 THEN
Rel.Angle2% = 270
EXIT FUNCTION
ELSEIF DeltaY > 0 THEN
Rel.Angle2% = 90
EXIT FUNCTION
ELSE
Rel.Angle2% = 0
EXIT FUNCTION
END IF
ELSE
Slope! = DeltaY / DeltaX
Angle! = ATN(Slope!)
AngleTemp% = Angle! * Convert!
AngleTemp% = AngleTemp% + 90 'Error fix
IF X1 > X2 THEN
AngleTemp% = AngleTemp% + 180
END IF
END IF
'Fix the error in the fixer. Riiiight.
AngleTemp% = AngleTemp% - 90
IF AngleTemp% < 0 THEN AngleTemp% = AngleTemp% + 360
Rel.Angle2% = AngleTemp%

END FUNCTION
Logged
Anonymous
Guest
« Reply #10 on: April 19, 2004, 11:30:24 AM »

THANK YOU!!!!!!! ;*)


I love that part, "fix the error in the fixer" bahhahhah

this game would not be possible without you guys, for real Wink
Logged
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #11 on: April 20, 2004, 08:38:41 AM »

Waiting for the Demo. :*)

Hope to hear some Arse kickin' sound clips!!!!
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!