Bradandez wrote:Whoa! Way better than mine! Care to explain how to make it?
Sure! It's all simple Physics; all parts get a random velocity in a random direction (between two values of say 5 pixels per 'step' (the game's time is in 'steps' as opposed to seconds - 30 steps a second in this case - Game Maker's inner workings) and 8 pixels per 'step') and are affected by gravity. I tweaked how much each part is affected by considering how large the part is and how heavy it is. Each also gets a momentum spin affected by how fast it's travelling and some parts are also mirrored as they fly in different directions, but that's purely aesthetical and completely non-sensical in real life.
Here's the code for a single piece - if you (
read: anyone who reads this) don't understand what it says, I'll elaborate more.
Code: Select all
--CREATE EVENT--
//Basically, this 'event' - all code is driven by 'events' in Game Maker - initialises all variables so that they can be used within the object's code
flyoffdir = random(360); //Choose a random value between 0 and 360 (the degrees of the angle in which this particular piece will fly off in)
flyoffspeed = 25-random(5); //The velocity at which this piece will fly off in. Maximum is 25 pixels per step, minimum is 20 (in this particular piece of gib).
hspeed = (cos(flyoffdir) * flyoffspeed); // '*' is this code's way of writing 'is multiplied by'
vspeed = (sin(flyoffdir) * flyoffspeed);
grav = 0.08; //Gravity
t = 0; //A 'time' variable
vy = 0; //y-velocity
Code: Select all
--STEP EVENT--
//Every 'step' of the game (1/30th of a second in this game), this code is run:
t += 1; // '+= 1' means 'add one relatively'; if the value is '1', for example, the value becomes '2'. The next time the code is run, it becomes '3'.
vy += grav*t;
y += vy;
x += hspeed;
image_angle += hspeed; //The displayed rotation of the object.
image_xscale = sign(hspeed); //The image's scaling in x-direction is equal to the sign (+1 or -1) of the horizontal speed.
image_yscale = sign(hspeed); //Idem but in y-direction
if image_xscale = 0 {image_xscale = 1;}
if image_yscale = 0 {image_yscale = 1;}
Code: Select all
--DRAW EVENT--
//This event draws the object on the screen. Don't worry about this big function described below - it's just interesting to people who are into Game Maker.
draw_sprite_ext(sprite_index,image_index,x,y,image_xscale,image_yscale,image_angle,image_blend,image_alpha);
Some variables are not initialised, such as 'hspeed', because these are variables that Game Maker treats as variables inherent to the object. It's all a bit of programmer jibber-jabber, actually.
And that's basically the same code repeated for all the different pieces - about 13 in total I believe. Then there's a bit of fancy 'appearing' bloodspatter, but you can probably figure out how that works in Flash yourself (but I'll give you the code too if you're interested).