Source Code Snippets: Generate Gibs (Particles For Fatalities) & Shake The Stage

As some may know, the upcoming title for Tetrageddon Arcade is titled Offender 2 (World War B: War on Rabbits).
It’s a delightfully epic violation of the senses taking place in the speculatively not to distant future where aliens (once again) attack Earth for the sake of abducting rabbits.
Much like the original Offender, this version will be a far more rounded, and over-the-top adaptation of the original.
It features gibs, adorable ass kicking rabbits with tons of attitude, and sociopathic aliens.
You play the aforementioned alien, and have to survive abducting the rabbits. Like I said, they have attitude.

It’s coming along beautifully. The engine is now fully completed, and it’s crazy addicting to play.

So, while we wait, here are some source code script bits that may come in handy for your own projects.
I found myself doing these a lot…

Generate Gibs (Particles For Fatalities)
(Click To Test)
[swfobj src=”http://nathalielawhead.com/sourcefiles/Super_Simple_Snippets/gravity_gibs.swf” height=”500″ width=”480″]

Code:

stage.quality = StageQuality.LOW;

var num_yBunny:Number = 400;//(ground level)

function bunnyGibs_move(event:Event):void
{
var clip:MovieClip = MovieClip(event.currentTarget);
//
root[“yVel”+clip.name] += root[“grav”+clip.name];
root[“xPos”+clip.name] += root[“xVel”+clip.name];
root[“yPos”+clip.name] += root[“yVel”+clip.name];
if (root[“yPos”+clip.name]> num_yBunny)
{
root[“yPos”+clip.name] = num_yBunny;
root[“yVel”+clip.name] *= -.10;
root[“xVel”+clip.name] *= .7;
}
//update position with above…
clip.x = root[“xPos”+clip.name];
clip.y = root[“yPos”+clip.name];
//stop it from moving – if it hit the bottom, and stopped bouncing…
if(root[“prevY”+clip.name] == clip.y && Math.ceil(root[“yPos”+clip.name]) == num_yBunny){
clip.removeEventListener(Event.ENTER_FRAME, bunnyGibs_move);
}
//set the previous y position before updating – eventually the above condition returns true…
root[“prevY”+clip.name] = clip.y;
}

function bunnyGibs(){
var num_totalGibs:Number = 10; //total ammount of gibs to spawn
for(var i:Number = 0; iDownload Source: CS5, CS4

—–

Shake The Stage (Or Any Other Graphic / Object)
(Click To Test)
[swfobj src=”http://nathalielawhead.com/sourcefiles/Super_Simple_Snippets/shake_stage.swf” height=”500″ width=”480″]

Code:

stage.quality = StageQuality.LOW;

//Shake the stage, or any other sprite, a given number of times…

function shake(clip:Object, ammount:Number) {
var num_startX:Number = clip.x;
var num_startY:Number = clip.y;
var num_time:Number = 30;
function clip_onEnterFrame(event:Event) {
num_time–;
clip.x = (Math.random()*ammount)-(ammount/2);
clip.y = (Math.random()*ammount)-(ammount/2);
if (num_time< =0) { if (clip == root) { clip.x = 0; clip.y = 0; } else { clip.x = num_startX; clip.y = num_startY; } clip.removeEventListener(Event.ENTER_FRAME, clip_onEnterFrame); } }; clip.addEventListener(Event.ENTER_FRAME, clip_onEnterFrame); } function mouse_down(event:MouseEvent):void { shake(root, 10); } stage.addEventListener(MouseEvent.MOUSE_DOWN,mouse_down); Download Source: CS5, CS4

Visit Tetrageddon Arcade for more, or drop by The Sourcefiles Archive for open sourced code goodness.