Author Topic: [Avoidance] Making Cherries split without creating an extra object?  (Read 1608 times)

Tamatou

  • Wannabe
  • Posts: 43
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Chrome 49.0.2623.112 Chrome 49.0.2623.112
    • View Profile
  • Playstyle: Gamepad
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)
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:


From Austria with Love <3

Sudnep

  • Global Moderator
  • Spike Dodger
  • Posts: 124
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Chrome 50.0.2661.102 Chrome 50.0.2661.102
    • View Profile
  • Playstyle: Keyboard
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: [Select]
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;
                    }
          } }
}

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: [Select]
with(deliciousFruit) { if (tag == 1) {
            splitObject(<someargumentsgohere>);
} }

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.
« Last Edit: May 24, 2016, 12:20:30 PM by Sudnep »

Tamatou

  • Wannabe
  • Posts: 43
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Chrome 49.0.2623.112 Chrome 49.0.2623.112
    • View Profile
  • Playstyle: Gamepad
Thank you so much for your help  :atkHappy:
However I have a few more questions

My Code
(click to show/hide)

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 ;)
From Austria with Love <3