# Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

### 2D All the way! / directional shooting sprites

Message
Posted: 10th Jul 2003 19:17
Hello

I have a question about the direction of my bullets. I want the bullets to come from the front of my character sprite (naturally) and was wondering how to make that happen. My character rotations are simple. IF UP KEY() THEN ROTATE SPRITE 0: IF DOWNKEY() THEN ROTATE SPRITE 180 : IF LEFTKEY() THEN ROTATE SPRITE 270 : IF RIGHTKEY() THEN ROTATE SPRITE 90. How would I insure that the bullets would fire from the front of my character regardless of what direction it is facing?

My code is not in front of me at the time so I am very sorry for not posting any

Posted: 25th Jul 2003 06:21
Dunno if you found your answer yet but here is how you could do it...

You are basically working on a 2D engine So you have X, and Y.

If Direction = 0(straight up)
X = 10
Y = 0

If Direction = 180(straight down)
X = -10
Y = 0

If Direction = 90(right)
X = 0
Y = 10

If direction = 270(left)
X = 0
Y = -10

Your bullet code could look something like

Xdir = Xdir + X
Ydir = Ydir + Y

Your toon should have its own X, Y coord. You just set Xdir/Ydir to that location(which would probably be in the middle of your toon) so you would have to add/subtract from it first to get the exact start postion correct.

This could both control the direction and speed of your bullet depending on how you code it.

Just the first thing that popped in to my head. just a basic concept of how it could work :p

Posted: 25th Jul 2003 06:26
bulletNumber=sprite of bullet
playerSprite=sprite of player
distance=distance from player to position sprite

rotate sprite bulletNumber,sprite angle(playerSprite)
move sprite bulletNumber,distance

Pneumatic Dryll