Computer Science Canada moving and shooting |
Author: | msimard8 [ Wed Jun 29, 2005 10:32 am ] | ||
Post subject: | moving and shooting | ||
Hello How do you move a object and shoot something out of it ...and have the bullet moving while your moving aswell. ya i know that question may be hard to understand. The code is part of what I have done, and you will see what i mean. I freeze until the bullet stops moving.
|
Author: | Cervantes [ Wed Jun 29, 2005 11:26 am ] |
Post subject: | |
This will require you to learn some new concepts. Turing Walkthrough -> Arrays -> Flexible Arrays In the flexible array tutorial, there is an example of this very thing. It would also be good to know how to use records to keep things organized and to same you some code when you have to remove a bullet. |
Author: | msimard8 [ Thu Jun 30, 2005 2:43 pm ] |
Post subject: | ? |
I dont understand how to incorperate flexible arrays and records to solve this problem thanks |
Author: | Cervantes [ Fri Jul 01, 2005 7:08 am ] | ||||||||||
Post subject: | |||||||||||
Have you read my tutorial and looked at the source code? Make a flexible array of bullets:
When you hit the fire button (via Input.KeyDown), incriment the flexible array.
Notice how I added that 3 + player.velocity. Remember we're not shooting beams of light here. Movement of the bullet is like such:
When you want to delete the bullet (it has collided with something or gone passed its range):
See here we are copying the upper bullet to the position of the one we want to delete and then deleting the original upper bullet. If you want to keep the bullets in "order", you'll need a for loop:
Hope that helps |