forums

TNT Basic Forums > Programming Q&A
360 degree shooting
< Last Thread     Next Thread >
Author
Thread        Post A Reply

07-09-2003 10:26

Posted by:
JAS

Click Here to Email JAS   Find more posts by JAS

What would the code for shooting at 306 degrees look like. I'm trying to figure out how to make a main character shoot like the main character in Abuse (visit http://www.abuse2.com for the full game to download for PC and OS X). The aiming scheme is supposed to follow the mouse's position.

I've figured out how to make him shoot in 8 different directions, but don't know how to make it 360.

07-09-2003 13:22

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

' Not so difficult, but this one works with the keyboard. ( left,tight,space)

graphics mode hardwarwe 800,600
int deg,execution=true,x=100,y=100
int shot=false,shotx,shoty,shotangle

while execution

sprite 1,x,y,0
set sprite rotation 1,deg

if left then deg=deg+2
if right then deg=deg+2


if space and shot=false
shot=true
shotx=x
shoty=y
shotangle=deg
end if

if shot=true
shotx=shotx+cos(shotangle)*2
shoty=shoty+sin(shotangle)*2
if shotx<-50 or shoty<-50 or shotx>825 or shoty>650 then shot=false
end if
wend

07-09-2003 21:41

Posted by:
JAS

Click Here to Email JAS   Find more posts by JAS

Degrees! Of course! Hehe funny how we overlook things like this sometimes. Thanks!

07-10-2003 13:53

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Of course, why not use *degrees* to do a 360 *degrees* shooter! ;)

07-10-2003 21:55

Posted by:
DanLurie

Location:
Earth>USA>New Jersey>Clifton>My Chair

Click Here to Email DanLurie   Find more posts by DanLurie

Why not use radians?

07-10-2003 22:06

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Well, I think it's like using Cm and Inches. They're different but you can get the same result. You'll just need to use an appropriate number.

07-10-2003 22:06

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

But I guess Cos and Sin work with Degrees only.

07-13-2003 21:04

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

There's radian version of all the trig functions, eg RadSin() RadCos() RadTan() RadInvSin() etc.. There's also two functions to convert between the two units, called Degrees() and Radians() although it's a pretty easy conversion!

Cheers,

Mark

11-20-2003 23:06

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

How the heck!?

i'm a bit confused (not very good at math)..
in my game there is a player at the bottom, moved with the arrow keys and there is a target (pointing upwards). now.. how do i code a shot going from the player to the target? how do i calculate the angles??

11-21-2003 00:28

Posted by:
-wyvern

Location:
Bedroom

Find more posts by -wyvern

Use the calculate angle function in tnt basic 1.2 It's in there somewhere... Then, give the shot the resultant angle value for it's direction and supply x,y co-ordinates, then use this rule:

x=x+cos(direction of shot)*bullet speed
y=y+sin(direction of shot)*bullet speed

And there you are. Have fun.

11-21-2003 01:02

Posted by:
fjerkon

Location:
Sweden

Find more posts by fjerkon

Thanks!... but, idont get it...
i did like this..

if mouse button=true
shotx=shotx+cos(shotanglex)*1
shoty=shoty+sin(shotangley)*1
sprite 2,shotanglex,shotangley,2
shot=1
end if

should this move my sprite?

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.