Computer Science Canada Multiple asteroids. |
Author: | MysticVegeta [ Mon Jun 20, 2005 7:54 am ] | ||
Post subject: | Multiple asteroids. | ||
Hi, I am making a game and its a spaceship game, so i took the code posted before and here it is. The only problem is that how do i make it so there are more rocks at the same time. I tried to make the rocks variable to 20 but they al come at once and then they start flickering, here is the code.
|
Author: | jamonathin [ Mon Jun 20, 2005 8:25 am ] | ||||||
Post subject: | |||||||
You should make your array flexible, and add 1 to it everytime it's necessary. In your procedure asteroids, I changed your for loop to this.
that counts up to the total amount of asteroids by 2, so that we dont have an insane amount. When you get around to your collision checking, use that same for loop, or else your program will be screwy. This code is for when you adda new asteroid. For right now I just make the spacebar adda new asteroid, so you could see for yourself. Just take hat out and put it where its necessary later on.
If you need any more help, juss ask away, or check previous topic on this.
|
Author: | MysticVegeta [ Mon Jun 20, 2005 8:38 am ] |
Post subject: | |
The flexible array will keep on adding the asteroids though, i want something that like shoots mutiple asteroids so that there are like more than 1 at a time on the screen. |
Author: | Cervantes [ Tue Jun 21, 2005 4:22 pm ] |
Post subject: | |
MysticVegeta wrote: The flexible array will keep on adding the asteroids though, i want something that like shoots mutiple asteroids so that there are like more than 1 at a time on the screen.
What? The flexible array does not add asteroids, the new command adds asteroids, combined with the code to initialize their fields. And all this only happens when a certain condition is met: namely the space bar is pressed, as in Jamonathin's code. Are you asking for how to add more than one asteroid at the same time? Well, if that's the case, just use wrap a for loop around that new & initializing code, and you can add however many you want. And Jamonathin, why did you put that by 2 on that for loop? |
Author: | MysticVegeta [ Tue Jun 21, 2005 4:39 pm ] |
Post subject: | |
I meant new from the flexible array. By the ways, you see, the creator created a varible called "rocks" and when i make it more, say i change it to 4, then 2 of them (div 2) come at the same time (thats what i want) but later on, they keep flickering in the end of the screen. Cervantes can you tell me why this is happening. I just need to know because i haven't used records that much and i am not very familiar with them. Thanks alot. |
Author: | Cervantes [ Tue Jun 21, 2005 5:37 pm ] | ||
Post subject: | |||
Check this section out:
I'm not referring to the div 2 in the for loop part, though I still have no idea why you're doing that. |
Author: | MysticVegeta [ Tue Jun 21, 2005 5:53 pm ] |
Post subject: | |
yea me neither so i removed it and made the rocks variable to 1. So well any idea still how i can do it?? |
Author: | Cervantes [ Tue Jun 21, 2005 6:29 pm ] |
Post subject: | |
MysticVegeta wrote: made the rocks variable to 1.
You mean, set rocks to 1? Or set the subscript of the rock array/record to 1? Neither is good... |
Author: | jamonathin [ Tue Jun 21, 2005 9:41 pm ] |
Post subject: | |
Cervantes wrote: And Jamonathin, why did you put that by 2 on that for loop? I think I ment to put that div 2. Oh well, all results to the same thing. It was just there so there weren't an insane amount of asteroids flying. Its an easy method (for me at least) to reduce mass rocks. |
Author: | MysticVegeta [ Wed Jun 22, 2005 6:26 am ] | ||
Post subject: | |||
well thats weird, my collison detection works fine. So to make the asteroid disappear i have to reset the positions of x and y in the array. So i go.
In this code when i change the rock amount to 20 then 10 of them come. The rest flicker, but when i shoot in the flickering, 10 of them come again. How can i implement this code so that when the amount of asteroids x's and y's are over they take random values. I think thats the problem. |
Author: | Cervantes [ Wed Jun 22, 2005 7:05 am ] | ||||
Post subject: | |||||
Okay, if you want to limit the number of asteroids that are coming at you, why would you use that div 2 in the for loop? Just make the rocks variable set to less! Also, if lasercollidesasteroids, then you are resetting ALL of the asteroids. Chances are you only want to reset the one that you hit. You could make a function that takes a parameter (integer) that represents the asteroid ID (element) and returns true or false depnding on whether you shot it. Also, why are you still doing this?
Shouldn't it be
That's what I was mentioning a few posts up. |
Author: | MysticVegeta [ Wed Jun 22, 2005 11:35 am ] |
Post subject: | |
i see, i thought about it, now about lasercollidesasteroids, i was thinking of making one more boolean that will stay false untill the "x" of that lasercollided asteroid comes down to 10 in which case it will be redrawn. Yes i will put it in another function. Thanks Cervantes, Dam , i never thought that changing 2 character would change the flickering -_-'' |
Author: | vagyb [ Thu Jun 23, 2005 8:46 pm ] |
Post subject: | |
wouldn't it be easier to import like 6 astroid pictures (different looking) from bmp file and just change their x value (y too if u like) and make them reset at random locations each time they come |
Author: | jamonathin [ Thu Jun 23, 2005 10:09 pm ] |
Post subject: | |
It wouldn't really make a difference. If he were to use bmp's he would have to change his laserdetection thing, because the oval is drawn in the center, not bottom left (unless he drew his asteroids at [x - Pic.Width(asteroid) div 2]). Now what he could do is use the size of the asteroid, and make the speed of it relevent to its size. So if the size was 14, the speed could be 20 - size, or whatever. Adding .bmp's wouldn't make it much easier. His drawfilloval would turn into Pic.Draw, and his x-values of the asteroid would change and thats it. |
Author: | vagyb [ Fri Jun 24, 2005 6:35 am ] |
Post subject: | |
for my program i just made speeds ranging from like 2 to 6, and multiply each by a variable speed that has a initial value of 1, but later when u pass levels the speed becomes 2, therefor astroid speeds doubling. |
Author: | Cervantes [ Fri Jun 24, 2005 9:01 am ] | ||
Post subject: | |||
Instead of doing something like
you could use the formula for kinetic energy. Ek=1/2*mv^2 Therefore, v = sqrt (2*Ek/m). So, simply decide what you want the kinetic energy of the asteroids to be (this could be somewhat random for each asteroid) and then determine the mass (based on radius and density) and then plug those into the formula and find the appropriate velocity. If you want to make things harder, just increase the kinetic energy. |
Author: | jamonathin [ Fri Jun 24, 2005 10:10 am ] | ||
Post subject: | |||
Yeah, i wish I knew formula's. The only smart class I took this year was calculus. |
Author: | MysticVegeta [ Fri Jun 24, 2005 12:22 pm ] |
Post subject: | |
uh... I think i will go with simplycity... talk about calculus formulas, let me first spend my first day in Grade 10 math in September lol. Those functions and relations just do nothing but confuse me.... |
Author: | Cervantes [ Fri Jun 24, 2005 7:22 pm ] | ||
Post subject: | |||
Simplicity?
Here's a question to ponder. Is it better to make a module that contains an array of asteroids, or to create an asteroid class and create an array of pointers to the class? |
Author: | MysticVegeta [ Sat Jun 25, 2005 8:11 am ] |
Post subject: | |
I dont think you know what i meant from my previous post, I dont know modules, i dont know classes, i dont know pointers (except maybe sometimes i came across pointers in game-hacking) but that was a long time ago. Anyways, all my asteroids will be the same shape, because they really are not asteroids, they are spaceships. I will replace the drawfilloval with Pic.Draw and make necessary changes. So i dont think i will need Kinetic Energy formula. Speed will be random. size/mass will be constant. If i change my mind i might use the module. Cervantes: You love to use flexible array everywhere dont you? Every code i see in your post has array : 1..0 of int/string. lol. |
Author: | Cervantes [ Sat Jun 25, 2005 9:39 am ] |
Post subject: | |
MysticVegeta wrote: Cervantes: You love to use flexible array everywhere dont you? Every code i see in your post has array : 1..0 of int/string. lol.
Whell, this program should, most definately use flexible arrays. Even if you were to use a class, you'd make a flexible array of pointers to the class. |
Author: | jamonathin [ Sat Jun 25, 2005 7:53 pm ] |
Post subject: | |
Yeah because flexible arrays help keep everything organized, and with them you dont need a variable to represent how many asteroids you have. You can simple use upper (fart) |