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.

Dark GDK / I need help trying to shoot for a 2D shooter

Author
Message
Making a game
16
Years of Service
User Offline
Joined: 9th Jul 2008
Location:
Posted: 9th Jul 2008 23:58
I have got a sprite which i can control to move around with collision detecting when it has hit something.

I have been looking around but i cant seem to find a way to shoot from the object.

I can create images on the spot of the player but i cant make it actually shoot the darn thing.

Help would be greatly thank for.
programing maniac
16
Years of Service
User Offline
Joined: 19th Apr 2008
Location: Bawk, Bawkity
Posted: 10th Jul 2008 15:51
You need a piece of code to do that. It should be really simple, make the bullet move forward at the angle it is at.

Also, there was a double post.


www.globalwarfare.tk
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 10th Jul 2008 21:48
xpos+=dbCos(angle)*speed
ypos+=dbSin(angle)*speed

I think that's right. If not, just flip the Cos and Sin parts.

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 10th Jul 2008 22:53
Sorry, wrong! That would give you the same answer every time and that would be the velocity, not the xpos/ypos. Two ways I can think of to determine xpos/ypos.

xpos += xvel;
ypos += yvel;

or, similar to what you're doing

xpos = dbCos (angle) * speed * time + initX;
ypos = dbSin (angle) * speed * time + initY;

The problem with the later one is that you have to reset initX/initY and time every time you change direction.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 11th Jul 2008 01:45
But I'm adding to them...

xpos = xpos + cos(angle) * speed

Why do you need "time"?

Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 11th Jul 2008 01:54
I didn't see the "xpos+" in the post. Did I misread it?

Point of procedure. It would be better to use the velocity approach and recalculate the velocity only when you need to. Calling sin/cos each pass increases your CPU utilization.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Zuka
16
Years of Service
User Offline
Joined: 21st Apr 2008
Location: They locked me in the insane asylum.
Posted: 11th Jul 2008 06:01
Yeah, it's +=.

Login to post a reply

Server time is: 2024-11-17 18:16:58
Your offset time is: 2024-11-17 18:16:58