Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Shooting Bullets/Projectiles Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SAMZ




PostPosted: Mon Apr 14, 2008 9:08 am   Post subject: Shooting Bullets/Projectiles Help

I am trying to create a shooting projectile from a character on a screen. I have already made my character move using the Arrow Keys and in fact have another one using the WASD keys. I am having trouble creating the shooting projectile from the character. I also have a projectile image that I would like to use in place of a ball but if it can't be done, its fine.

I was wondering if anyone can help me with the code?
Sponsor
Sponsor
Sponsor
sponsor
petree08




PostPosted: Mon Apr 14, 2008 9:19 am   Post subject: RE:Shooting Bullets/Projectiles Help

Look at the tutorials,
SAMZ




PostPosted: Mon Apr 14, 2008 4:15 pm   Post subject: Re: RE:Shooting Bullets/Projectiles Help

petree08 @ Mon Apr 14, 2008 9:19 am wrote:
Look at the tutorials,


I tried but couldn't find one that helped me with my problem. Even when I searched. Maybe Im looking under a wrong name.


Care to link me to any tutorials yourself?
isaiahk9




PostPosted: Fri May 09, 2008 3:51 pm   Post subject: Re: Shooting Bullets/Projectiles Help

As long as you are keeping track of where your character is (x, y) then it isn't too bad. In pseudo code :
loop
Variable : bulletx, bullety : int
Bulletx := avatarx + 5
bullety := avatary
Use an if for inputting the key (you said you've done it already before), say space-bar
%this is important. It means after the bullet travels 600 pixels to the right, it will stop. This is not only the size of the screen, but it means that one projectile can be fired at a time
for i : 1..30
When its clicked, Pic.Draw (bulletx, bullety, bulletpic)
bulletx := bulletx + 5
delay (20)
end for
end loop

end of pseudo code
For multiple bullets, use processes (some people dislike them, but I like them and have never run into any problems with them).
This is pseudo code for a bullet moving right. For moving left, you would need to either make a seperate button and subtract 5 instead of adding or you could make a variabel called isplayerleft that is boolean. Set it as false, but when the user clicks the left arrow key, then it is set as true. Make an if saying that
if isplayerleft = true then
draw the projectile flying left (- 5 every time)
else
draw the projectile flying right (+ 5 every time)
end if

Hope that helps. If im being to vague/unclear on this then ask for specifics, but I thinnk you can get the gist of it from this.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: