Team:AUC TURKEY/HumanPractices/FlashGame

From 2013hs.igem.org

Revision as of 07:26, 12 June 2013 by Alihancelikcan (Talk | contribs)



Flash Game

This year's flash game from our last year's flash game maker, Alihan Çelikcan. Graphics were drawn by Fatih Gül.

We will give awards to high scorers in the Jamboree. High scores are stored on your computer so you will have to play the game again in the Jamboree. Train hard and have fun.


Here's the source code of the game if you're interested:
//platform
var platform:MovieClip = _root.createEmptyMovieClip("platform", _root.getNextHighestDepth());
var pID:Number = 20;
var pLeft:Number = 0;
var pRight:Number = pID * 40;
var pFall:Number = 57;
var pInc:Number = 3;
//speed
var speedTimer:Number = 0;
var speedWait:Number = 48;
var speedInc:Number = .2;
var speed:Number = 7;
var minSpeed:Number = 5;
//jump
var fallSpeed:Number = 0;
var jumpSpeed:Number = 10;
var floor:Number = 250;
var jump:Number = 0;
var doubleJump:Boolean = false;
var gravity:Number = .5;
var plat_arr:Array = [pLeft, 250, pRight];
var signal:Boolean = true;
//animation
var animFrame:Number = 0;
igeman_mc.stop();
igeman_mc.run.stop();
//fps
var fps:Number = 48;
var frames:Number = 0;
var startTime:Number = 0;
//fire
var nextFire:Number = random(5) + 20;
//ice
var ices:MovieClip = _root.createEmptyMovieClip("ices", _root.getNextHighestDepth());
var iceUse:Number = 1;
var iceGiven:Number = 1;
var iceReady:Boolean = true;
var iceCooldown:Number = 0;
var iceFloor:Number = 0;
var iceRight:Number = 0;
var iceWait:Number = 120;
//music
var doMute:Boolean = true;
var firstMute:Number = mute_mc.getDepth();
mute_mc.swapDepths(_root.getNextHighestDepth());
if (snd)
{
	mute_mc.gotoAndStop(1);
}
else
{
	mute_mc.gotoAndStop(2);
}
var loop_snd:Sound = new Sound(this);
var pauseTime:Number = 2000;
var pause:Number;
loop_snd.onSoundComplete = processPause;
loop_snd.attachSound("music");
function loopSound()
{
	clearInterval(pause);
	loop_snd.start(0,1);
}
function processPause()
{
	pause = setInterval(loopSound, pauseTime);
}
if (snd)
{
	loopSound();
}
mute_btn.onPress = function()
{
	if (snd)
	{
		pos = loop_snd.position / 1000;
		loop_snd.stop();
		mute_mc.gotoAndStop(2);
	}
	else
	{
		loop_snd.start(pos);
		mute_mc.gotoAndStop(1);
	}
	snd = !snd;
};
//pause
var doPause:Boolean = true;
var firstPause:Number = pause_mc.getDepth();
pause_mc.swapDepths(_root.getNextHighestDepth());
var paused:Boolean = false;
pause_btn.onPress = function()
{
	if (paused)
	{
		pause_mc.gotoAndStop(1);
	}
	else
	{
		pause_mc.gotoAndStop(2);
	}
	paused = !paused;
};

//game over
var over:Boolean = false;
var score:Number = 0;
var minTemp:Number = Infinity;
//the Code
for (var i:Number = 0; i < pID; i++)
{
	var newPlat:MovieClip = platform.attachMovie("platform", "platform_" + i + "_mc",
platform.getNextHighestDepth());
	newPlat._x = i * 40;
	newPlat._y = 250;
	if (--nextFire == 0)
	{
		var newFire:MovieClip = platform.attachMovie("fire", "fire_" + pID + "_mc",
platform.getNextHighestDepth());
		nextFire = random(12) + 3;
		newFire._x = newPlat._x + 20;
		newFire._y = newPlat._y + 10;
		newFire.onEnterFrame = function()
		{
			if (paused)
			{
				return;
			}
			if (igeman_mc.hitTest(this._x + platform._x, this._y - 50, true))
			{
				speed -= .4;
			}
			if (platform._x < -this._x - 80)
			{
				this.removeMovieClip();
			}
		};
	}
	newPlat.onEnterFrame = function()
	{
		if (paused)
		{
			return;
		}
		this.gotoAndStop(Math.max(1, (200 - (int(speed * 8)))));
		if (platform._x < -this._x - 80)
		{
			this.removeMovieClip();
		}
	};
}
onEnterFrame = function ()
{
	//mute 
	if (Key.isDown(77))
	{
		if (doMute)
		{
			mute_btn.onPress();
			doMute = false;
		}
	}
	else
	{
		doMute = true;
	}
	//pause
	if (Key.isDown(80))
	{
		if (doPause)
		{
			pause_btn.onPress();
			doPause = false;
		}
	}
	else
	{
		doPause = true;
	}
	if (paused)
	{
		return;
	}
	var currentTime:Number = (getTimer() - startTime) / 1000;
	frames++;
	if (currentTime > 1)
	{
		fps = Math.floor((frames / currentTime) * 10.0) / 10.0;
		startTime = getTimer();
		frames = 0;
	}
	if (signal && igeman_mc._x - platform._x + 20 > plat_arr[0])
	{
		floor = plat_arr[1];
		plat_arr = plat_arr.slice(2);
		signal = !signal;
		realFloor = floor;
	}
	if (!signal && igeman_mc._x - platform._x - 20 > plat_arr[0])
	{
		floor = 800;
		plat_arr = plat_arr.slice(1);
		signal = !signal;
		realFloor = floor;
	}
	if (igeman_mc._x - platform._x - 10 < iceRight)
	{
		floor = Math.min(realFloor, iceFloor);
		if (floor == iceFloor && !jump)
		{
			speedInc = 1.2;
		}
		else
		{
			speedInc = .2;
		}
	}
	else
	{
		speedInc = .2;
		floor = realFloor;
	}
	if (!over)
	{
		if (platform._x <= -pLeft + 550)
		{
			addPlatform();
			pFall += pInc;
		}
		if (++speedTimer >= speedWait)
		{
			speedTimer = 0;
			speed += speedInc;
		}
		if (speed < minSpeed)
		{
			speed = minSpeed;
		}
		platform._x -= speed * 12 / 25;
		ices._x -= speed * 12 / 25;
		animFrame = (animFrame + speed * 25 / 120) % igeman_mc.run._totalframes;
		igeman_mc.run.gotoAndStop(int(animFrame));
		if (!jump && floor > igeman_mc._y + 95 / 2)
		{
			fallSpeed = 0;
			jump = 1;
		}
		if (Key.isDown(Key.UP))
		{
			if (jump == 0)
			{
				fallSpeed = -jumpSpeed;
				jump++;
			}
			if (doubleJump == true)
			{
				fallSpeed = -jumpSpeed;
				jump++;
				doubleJump = false;
			}
		}
		else if (jump == 1)
		{
			doubleJump = true;
		}
		if (floor + 1 < igeman_mc._y + 95 / 2)
		{
			over = true;
			ices.removeMovieClip();
		}
	}
	if (jump || over)
	{
		igeman_mc._y += fallSpeed += gravity;
		if (igeman_mc._y > floor - 95 / 2 && !over)
		{
			jump = 0;
			doubleJump = false;
			igeman_mc._y = floor - 95 / 2;
		}
	}
	if (jump)
	{
		igeman_mc.gotoAndStop(2);
		animFrame = 25;
	}
	else
	{
		igeman_mc.gotoAndStop(1);
	}
	var dist:Number = Math.floor((-platform._x) / 50);
	//ice
	if (dist >= iceGiven * iceWait)
	{
		iceGiven++;
		iceUse++;
	}
	if (iceCooldown > 0)
	{
		iceCooldown--;
	}
	if (Key.isDown(Key.SPACE))
	{
		if (iceReady && iceUse && !iceCooldown)
		{
			iceCooldown = 24;
			iceReady = false;
			iceUse--;
			iceRight = -platform._x + igeman_mc._x + 300;
			var newIce:MovieClip = ices.attachMovie("ice", "ice", ices.getNextHighestDepth());
			newIce._x = -platform._x + igeman_mc._x;
			newIce._y = igeman_mc._y + 95 / 2;
			iceFloor = newIce._y;
			newIce.onEnterFrame = function()
			{
				if (paused)
				{
					return;
				}
				if (this._x < -300 - ices._x)
				{
					this.removeMovieClip();
				}
			};
		}
	}
	else
	{
		iceReady = true;
	}
	//ui
	//fps_txt.text = (Math.round(fps * 10) / 10);
	speed_txt.text = (Math.round(speed * 10) / 10);
	dist_txt.text = dist;
	special_txt.text = iceUse;
	special_mc._xscale = 100 - (iceGiven * iceWait - dist) / iceWait * 100;
	//temp_txt.text = (200 - (int(speed * 8)));
	var temp:Number = (200 - (int(speed * 8)));
	minTemp = Math.min(minTemp, temp);
	thermometer_mc.gotoAndStop(Math.max(1, temp));
	bg_mc.gotoAndStop(Math.max(1, temp));
	if (igeman_mc._y > 400)
	{
		over = true;
		loop_snd.stop();
		platform.removeMovieClip();
		ices.removeMovieClip();
		score = dist * 25 + Math.pow(Math.min(Math.max(0, 144 - minTemp), 144), 2);
		mute_mc.swapDepths(firstMute);
		pause_mc.swapDepths(firstPause);
		nextFrame();
		delete onEnterFrame;
	}
};
function addPlatform()
{
	var h:Number = random(150) + 200;
	var len:Number = random(10) + 1;
	var moving:Boolean = false;
	pLeft = pRight + pFall;
	pRight = pLeft + len * 40;
	plat_arr.push(pLeft);
	plat_arr.push(h);
	plat_arr.push(pRight);
	if (len > 4 && !(random(5)))
	{
		moving = true;
	}
	for (var i:Number = 0; i < len; i++)
	{
		var newPlat:MovieClip = platform.attachMovie("platform", "platform_" + pID + "_mc",
platform.getNextHighestDepth());
		newPlat._x = i * 40 + pLeft;
		newPlat._y = h;
		if (!moving && --nextFire == 0)
		{
			var newFire:MovieClip = platform.attachMovie("fire", "fire_" + pID + "_mc",
platform.getNextHighestDepth());
			nextFire = random(12) + 3;
			newFire._x = newPlat._x + 20;
			newFire._y = newPlat._y + 10;
			newFire.onEnterFrame = function()
			{
				if (paused)
				{
					return;
				}
				if (this.hitTest(ices))
				{
					this.removeMovieClip();
				}
				if (igeman_mc.hitTest(this._x + platform._x, this._y - 50, true))
				{
					speed -= .4;
				}
				if (platform._x < -this._x - 80)
				{
					this.removeMovieClip();
				}
			};
			pID++;
		}
		newPlat.onEnterFrame = function()
		{
			if (paused)
			{
				return;
			}
			this.gotoAndStop(Math.max(1, (200 - (int(speed * 8)))));
			if (platform._x < -this._x - 80)
			{
				this.removeMovieClip();
			}
		};
	}
	if (moving)
	{
		var newFire:MovieClip = platform.attachMovie("fire", "fire_" + pID + "_mc",
platform.getNextHighestDepth());
		newFire._x = pLeft + random(len) * 40 + 20;
		newFire._y = h + 10;
		newFire.left = pLeft + 20;
		newFire.right = pRight - 20;
		newFire.speed = 2;
		newFire.onEnterFrame = function()
		{
			if (paused)
			{
				return;
			}
			if (this.hitTest(ices))
			{
				this.removeMovieClip();
			}
			if (this._x < this.left || this._x > this.right)
			{
				this.speed *= -1;
			}
			this._x += this.speed;
			if (igeman_mc.hitTest(this._x + platform._x, this._y - 50, true))
			{
				speed -= .4;
			}
			if (platform._x < -this._x - pRight + pLeft - 80)
			{
				this.removeMovieClip();
			}
		};
	}
}

<forum_subtle/>