~Hakurei Shrine~ > Rika and Nitori's Garage Experiments
I'm really lost @_@
Naut:
Well, that's because you didn't finish reading the paragraph, sir.
Halca:
--- Quote from: Naut on May 02, 2009, 11:25:46 PM ---Well, that's because you didn't finish reading the paragraph, sir.
--- End quote ---
Sorry... I feel so embarassed now :X
Thank you!
Halca:
My spell is beggining to have the effect I want. How can I make the different types of shots appear at a different rate from eachother?
Naut:
There are a few ways for that effect. I'll explain two of them, the first is extremely easy to understand, but requires making a variable for every section.
If you want to maker things spawn at different rates, then you could make a couple frame variables, like "frame1", "frame2", "frame3", etc., and have them all counting up in your @MainLoop. Then it's just a matter of resetting them everytime you use them. So your @MainLoop could look something like this:
--- Code: ---@MainLoop{
SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 16);
frame1++;
frame2++;
frame3++;
if(frame1==60){
CreateShot01(GetX, GetY, 3, GetAngleToPlayer, RED01, 0);
frame1 = 0;
}
if(frame2==40){
CreateShot01(GetX, GetY, 4, GetAngleToPlayer, BLUE02, 0);
frame2 = 0;
}
if(frame3==16){
CreateShot01(GetX, GetY, 2.4, GetAngleToPlayer, GREEN03, 0);
frame3 = 0;
}
}
--- End code ---
Another way is using a function called modulus (%). When we say frame%15, it returns the remainder of frame if it was divided by 15. So if frame was 45, frame%15 would equal 0, because 15 evenly divides into 45 three times, with no remainder. If frame was 38, frame%15 would equal 8 because 38 divided by 15 equals 2, with a remainder of 8. If frame was 1573, frame%15 would equal 13, etc.
So by using this modulus function, we can have one incrementing frame counter in MainLoop, and still have many bullets spawning at different intervals. Here's an example:
--- Code: ---@MainLoop{
SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 16);
frame++;
if(frame%15==0){
CreateShot01(GetX, GetY, 3, GetAngleToPlayer, RED01, 0);
}
if(frame%20==0){
CreateShot01(GetX, GetY, 2, 90, YELLOW03, 0);
}
if(frame%42==0){
CreateShot01(GetX, GetY, 5, GetAngleToPlayer, GREEN02, 0);
}
}
--- End code ---
In this MainLoop, we have a small red bullet being fired towards the player every 15 frames, a large yellow bullet being fired straight downwards every 20 frames, and a medium green bullet being fired towards the player every 42 frames.
Halca:
It worked beautifully :D
Now to the next spell card! <3
(Thanks Naut :3)