Computer Science Canada Delaying |
Author: | pers2981 [ Thu Dec 01, 2011 9:42 am ] | ||
Post subject: | Delaying | ||
What is it you are trying to achieve? I'm trying to create a wave based "castle defense" game were your job is to survive endless waves of increasing enemies who charge the castle. I managed to spawn the baddies but they are all stacked on top of each other. (Run to see waht I mean) What is the problem you are having? The bad guys spawn on either the left side or the right. Their X/Y cords are all the same so they are "stacked" Describe what you have tried to solve this problem I have tryed adding a delay in the for loop but that didnt really help. I also tryed to subtract a random int from the X but that just glitched it. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) Field.bmp can be found here. Uploaded with ImageShack.us
Please specify what version of Turing you are using 4.1.1[/quote] |
Author: | Raknarg [ Thu Dec 01, 2011 3:06 pm ] | ||||
Post subject: | RE:Delaying | ||||
There are a couple things you should do: 1. Spawn them at different times. What you are doing here is creating 5 enemies with the exact same coordinates. Instead, you should spawn them at different times using something like a counter:
That way they wont be stacked. 2. Give every enemy a random, but constant velocity. Instead of adding Rand.Int (3, 5) to the x coordinate, you can give each enemy a vx (aka a velocity for the x coordinate) when you create them. Just make an array, and when you spawn an enemy, have the vx set to a random number.
|
Author: | pers2981 [ Tue Dec 06, 2011 8:39 am ] | ||||
Post subject: | Re: RE:Delaying | ||||
Raknarg @ Thu Dec 01, 2011 3:06 pm wrote: There are a couple things you should do:
1. Spawn them at different times. What you are doing here is creating 5 enemies with the exact same coordinates. Instead, you should spawn them at different times using something like a counter:
That way they wont be stacked. Spawning the baddies at differant times would be the best option for my project. I have attempted to add a timer but I am having troubles because of the way my game is coded. If I were to do.
Then I would need create_enemy to only create one enemy at a time which would be hard due to the fact that I have it setup to make all of them at once. Any help? |
Author: | programmer1337 [ Tue Dec 06, 2011 10:11 am ] |
Post subject: | Re: Delaying |
tbh i wouldnt spawn them using delaying because that would make the whole form lag, i would count the frames that go by and then depending on the frame just spawn them ^^ |
Author: | Dreadnought [ Tue Dec 06, 2011 3:32 pm ] | ||
Post subject: | Re: Delaying | ||
pers2981 wrote: Then I would need create_enemy to only create one enemy at a time which would be hard due to the fact that I have it setup to make all of them at once. I think you can't do what you want with a procedure that spawns all the enemies at once. Luckily, you can easily change your procedure to spawn only one enemy at a time. Then you can count time (or frames like other posts suggest) to decide when to spawn enemies. Here is an example how one might go about doing this:
Also, setscreen and View.Set are identical in their functionality. So you could also write View.Set ("graphics:640;480,nobuttonbar,offscreenonly,title:Defend Your Castle") |
Author: | mirhagk [ Tue Dec 06, 2011 4:05 pm ] |
Post subject: | RE:Delaying |
Actually you can use your procedure, basically the enemies are at the edges of the screen and move inwards right? So simply have the first one spawn right at the edge, then each one after it spawn just a little beyond. That way it will appear as if they are coming in later. |
Author: | Dreadnought [ Tue Dec 06, 2011 4:41 pm ] |
Post subject: | Re: Delaying |
Ya mirhagk is right you could do that too. My mistake. |