Fangames > Programming Questions
[Avoidance] Making Cherries split without creating an extra object?
(1/1)
Tamatou:
Hey Guys!
Thanks to the awesome PlasmaNapkin I was able to learn a few thing about "For Statements"
Now I've been experimenting with avoidance patterns a little bit. What I wanna do is to make cherries that fly off from the center of the screen, split intro even more cherries.
My Code looks something like this
(click to show/hide)STEPCOUNTER += 1
if STEPCOUNTER = 150
{
cherry = instance_create(x,y,deliciousFruit);
cherry.radius=100;
cherry.winkel=degtorad(i*36)
}
}
if (STEPCOUNTER >= 150)
{
for(i=0;i<10;i+=1)
{
cherry.x= center_x+cos(cherry.winkel) * cherry.radius
cherry.y= center_y+sin(cherry.winkel) * cherry.radius
cherry.winkel += 0.2;
cherry.radius -=2;
Again thanks to PlasmaNapkin. Also winkel means angle
Now at, lets say Step 180 I want all of the cherries to create new cherries that fly off from their individual origin position.
I was able get one of the cherries to creat new ones. But I want each of them to create a barrage.
Also I could make the first wave of cherries a different object wich then spawns the new cherries. But was wondering if there was a more efficient way of doing this.
Thanks in advance. I hope I explained it right :atkHappy:
Sudnep:
The code you provided is much different from what you had asked. Ignoring that here is an Idea you can use for skipping out on making extra unnecessary objects.
What I generally do is have a variable that I reference to differentiate sets of the same objects through this variable. I call it 'tag'.
With this variable I can set it upon creation of the object(s) and then later reference it like this:
--- Code: ---STEPCOUNTER++;
if (STEPCOUNTER == 1) {
for(var i=0;i<10;i++){
a=instance_create(x,y,deliciousFruit);
a.speed = 10;
a.direction = (360/10)*i;
a.tag = 1;
}
a=instance_create(x,y,deliciousFruit);
a.direction = point_direction(x,y,player.x,player.y);
a.speed = 1;
}
if (STEPCOUNTER == 50) {
with(deliciousFruit) { if (tag == 1) {
repeat(20) {
a=instance_create(x,y,deliciousFruit);
a.direction = random(360);
a.speed = 15;
}
} }
}
--- End code ---
When STEPCOUNTER is 1 it will create 10 deliciousFruit with a tag of 1 in even directions in a circle as well as creates an deliciousFruit that will move towards the players position.
When STEPCOUNTER is 50 it will create 20 deliciousFruit at each deliciousFruit that has a tag equal to 1 in random directions. It also will ignore the deliciousFruit that was moving in the direction of the player, allowing you to reference different sets of deliciousFruit that you had created.
With code like this you can use the built in script in the engine (splitObject?) and reference the cherries like so:
--- Code: ---with(deliciousFruit) { if (tag == 1) {
splitObject(<someargumentsgohere>);
} }
--- End code ---
EDIT:
I also suggest creating a step event code in the deliciousFruit for handling orbiting like you have in the code you presented with a variable to toggle it on or off. It will be easier to control and you won't have to write it every time you want to do it.
Tamatou:
Thank you so much for your help :atkHappy:
However I have a few more questions
My Code
(click to show/hide)STEPCOUNTER += 1;
if (STEPCOUNTER == 1)
{
for( i=0;i<10;i+=1)
{
a=instance_create(x,y,deliciousFruit);
a.speed = 2;
a.direction = (360/10)*i;
a.tag = 1;
}
}
//BAM!!
if (STEPCOUNTER == 50)
{
for(i=0;i<10;i+=1)
{
with(deliciousFruit)
{
if (tag == 1)
{
a=instance_create(x,y,deliciousFruit);
a.speed = 1;
a.direction = (360/10)*i;
a.tag = 2;
}
}
}
}
//Und zurück!
if (STEPCOUNTER == 100)
{
for(i=0;i<10;i+=1)
{
with(deliciousFruit)
{
if (tag == 2)
{
a=instance_create(x,y,deliciousFruit);
a.direction = 90
a.speed = 3;
a.tag = 3;
}
}
}
}
First Question: (Edit: ALSO NOW OBSOLET)
What happens now is, there are 10 Cherries flying off in a circle shape.
Then at Frame 50 I want each of the Cherries to make 10 new cherries fly into 10 different directions (another circle shape) from the current position of the first wave of cherries. What happens now is they just fly to the right. (I guess I'm still missing out on something) EDIT: Yeah I just needed to move the "for Statement" below the "with" and "if" statement. Thank you brain for actually trying to understand what all this code translates to :atkHappy:
Second Question: (Obsolet)
At Frame 100 I want the second wave of cherries to fly into the air.
Now the second wave of cherries creates a new wave of cherries that fly into the air WICH is obvious since I... nevermind I just figured it out. The "a." had to be removed. Thanks brain! :atkHappy:
This post has become unnacessary befor I was even able to post it.
Thanks again. If I come across any more problems. I'll post it ;)
Navigation
[0] Message Index
Go to full version