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.

AppGameKit Classic Chat / How to implement bullets

Author
Message
JORGEMAL
14
Years of Service
User Offline
Joined: 2nd Aug 2009
Location:
Posted: 22nd Jan 2012 22:40
I am developing a game in which a spaceship will shoot a kind of "bullet". What is the best way to implement such "bullets"? Is it a good idea to consider each bullet as a sprite?

Respectfully,
Jorge Maldonado
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 22nd Jan 2012 23:06
If it is a physics based game you could create a dynamic sprite and give it velocity then check for collisions each loop.

Another option is to "raycast" and create a sprite to represent the 'shot' after you have fired it...

If you want the 'bullets' to be avoidable then using a sprite with a velocity is better.

LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 27th Jan 2012 00:06
A great first question when learning to write games, and the answer has lots of juicy but simple lessons there-in. I have written the answer in code, and I wrote it all in just a few minutes with only five mistakes before it worked fully. Pretty good huh! Here is your code:



I drink tea, and in my spare time I write software.

Login to post a reply

Server time is: 2024-04-20 13:25:53
Your offset time is: 2024-04-20 13:25:53