I know how to make gravity of an object. But how can I make it so that there is a stack of boxes, say 40x40 each, and when you shoot the bottom box they all fall and bouce off each other and scatter over the floor.
Give each object an X & Y velocity variables, as well as more precise X & Y position variables (so at the start of the level, its PosXvar = X(object) * 1000, and such). Then, implement it so that every single frame of gameplay, it follows this algorithm:
(Loop)
>>>PICK RANDOM OBJECT NOT YET PICKED IN LOOP
>>>Set Position X of "Detector" = PosXvar(object) + VelocityX(object)
>>>Set Position Y of "Detector" = PosYvar(object) + VelocityY(object)
IF: Detector isn't colliding with any other objects/backdrops, THEN:
>>>Set PosXvar(object) += VelocityX(object);
>>>Set PosYvar(object) += VelocityY(object);
>>>Set X(object) = PosXvar(object) / 1000;
>>>Set Y(object) = PosYvar(object) / 1000;
ELSE:
>>>Set PosXvar(object) = X(object) * 1000;
>>>Set PosYvar(object) = Y(object) * 1000;
>>>Set VelocityX(object) = 0;
>>>Set VelocityY(object) = 0;
ENDIF:
>>>Set VelocityY(object) += Gravity;
(/Loop)
"Give each object an X & Y velocity variables, as well as more precise X & Y position variables (so at the start of the level, its PosXvar = X(object) * 1000, and such)."
So I've changed 4 of the boxes alterable values to:
VelXvar (for X volocity)
VelYvar (for Y volocity)
PosXvar (for X position)
PosYvar (for Y position)
At start of level > Set AltPosition X (Box) to X Position(Box)*1000
> Set AltPosition Y (Box) to Y Position(Box)*1000
"Then, implement it so that every single frame of gameplay, it follows this algorithm"
How do I do this?
"(Loop)
>>>PICK RANDOM OBJECT NOT YET PICKED IN LOOP"
How do I do this?
">>>Set Position X of "Detector" = PosXvar(object) + VelocityX(object)
>>>Set Position Y of "Detector" = PosYvar(object) + VelocityY(object) "
Are there detectors? How many, because I'm trying to make 50 boxes fall all over each other, does that mean I have to have 50 different active object boxes and 50 different detectors for each?
This seems like a job for the physics object really... But anyway.
"Then, implement it so that every single frame of gameplay, it follows this algorithm" Run it in an always event.
"(Loop) >>>PICK RANDOM OBJECT NOT YET PICKED IN LOOP" You need to spread values through the boxes and run a loop comparing their values to the loop index.
"ENDIF: >>>Set VelocityY(object) += Gravity; (/Loop)" He just means that this happens every loop regardless, += means current value + Gravity.
Yeah, I wrote that in pseudocode; you need to use the pseudocode compiler to run it. I think theres a language add-on for java support
And btw ben; spreading values is not a very efficient way of picking an object during a loop. This means its tough to add in new objects or remove old ones, as well as taking up one of your alterable values (a very big deal in TGF, at least). Instead, you can have a single object picked at random at the beginning of your loop, and turn on a flag for it, then refer to the object by that flag, then kill the flag at the end of the loop.
So like:
ON HITTING THE "SPACE BAR" KEY:
=DO: Set "OBJECT" Flag 0 off;
=DO: Start LOOP TRIGGER "FOO" for #Count("OBJECT") LOOPS;
ON LOOP TRIGGER "FOO":
+OBJECT FLAG 0 IS OFF
=DO: Pick an "OBJECT" at random;
=DO: SET "OBJECT" Flag 0 ON;
=DO: SET "OBJECT" Flag 1 ON;
ON LOOP TRIGGER "FOO":
+OBJECT FLAG 1 IS ON
=DO: (STUFF INSIDE YOUR LOOP)
ON LOOP TRIGGER "FOO":
+OBJECT FLAG 1 IS ON
=DO: SET "OBJECT" Flag 1 OFF;
^that above code for TGF/MMF/MMF2 will iterate through every single object in a random order and only hit each one time. It will specify the object for the inside of the loop.
Loop 10 times{
Add one to X
Set Y to a letter at random from "Waffles"
Add Y and then the 26-letter alphabet equivalent of X to the end of Z
}
If Z is now a really garbled string, make me a sandwich
Otherwise, RETURN Z;