Hi all, this has been puzzling me for over 4 days and
it has been taking up all of my spare time. Does anyone
knows how to simplify the following
code?
if (exploding == 1) {
location [0] [ random_between_0_and_3 [0] ] -= 2;
location [0] [ random_between_0_and_3 [1] ] += 2;
location [0] [ random_between_0_and_3 [2] ] -= 2;
location [1] [ random_between_0_and_3 [3] ] -= 2;
location [1] [ random_between_0_and_3 [4] ] += 2;
location [1] [ random_between_0_and_3 [5] ] -= 2;.....(etcetera).....
location [8] [ random_between_0_and_3 [24] ] -= 2;
location [8] [ random_between_0_and_3 [25] ] += 2;
location [8] [ random_between_0_and_3 [26] ] -= 2;
}This is not my full program code, only the part i need to simplify
because i have a similar code for rotation when exploding, and for
location and rotation when imploding. This makes my code very long.
To explain a bit about what this small section of my program code
will do, the following
comments are appropriate:
What this code visually will help to do is exploding
my composition that exists of 9 different CUBES. Location [a] [b] will
correspond to the movement of CUBE. [a] will determine the number
of one of the 9 CUBES. [b] will determine wether the movement
of the CUBE occurs parrallel with the x-, the y- or the z- axis.
Everytime an explosion needs to occur, elsewhere in my
code there gets put a random number between 0 and 3
in every element of the array random_between_0_and_3.
So random_between_0_and_3 [c] will determine the [b]
of location [a] [b]. This is done to randomize the explosion
every time an explosion is needed.
Every CUBE gets three random_between_0_and_3 [c]'s
as [b] of location [a] [b]. This is done to make the randomized
explosion not only occur in straight ways.
The -= 2; or += 2; will make the CUBES actually move.
-= 2; will create a negative movement, += 2; will create
a positive movement. I need both positive and negative
movements because otherwise the CUBES will not seem
to explode in all directions. In the small section of my program
code above there are more -= 2;'s than += 2;'s. This should
also get balanced somehow to get a more realistic explosion.If I need to post the full code of my program, please do ask
me to and I will do so. I am really looking for a way to simplify
the explosion-code and would like to thank all of you in advance.
Greets, Vincent Verheyen.