So Hundreds was the first game that I programmed and because of that I was pretty skittish about showing anyone my horrible code, because… How would anyone get anything from it? Programmers usually pat me on the head and tell me:
Programmer

Oh that’s cute! You put it all in one file.

Yea real cute. Anyway, I guess my hope is that amateur coders or designers/artists will use it as some sort of stepping stone on the way to demystifying how this whole learning process works. The physics in Hundreds are apparently incredibly simple [as far as physics are concerned] but for me they were a huge challenge to understand. Even now looking at them, I don’t understand what’s going on anymore.

Sometimes it’s tough out here in the wild west but I’ll continue to share as much as I can in hopes that it will help others on their journey through the untamed lands of programming. So, here’s the ugly ass source from Baby Greg’s First Game!

If you put this into a Flash compiler you might be able to run it, but there are a few assets [menu items, intros and etc.] that it’ll probably want.

Here’s a link to a plain text file containing all the code if you don’t want to suffer through copy and pasting: HundredsSourceCode.txt. It’s a little under 1000 lines.

Also, I will say that I’m most proud of the way I figured out how to do the stopwatch [levelTime()]. It was a problem I wasn’t really looking forward to, but when I started trying to find a solution I found it more interesting that I thought I would of. It was really rewarding when I finally thought through it completely and solved it once and for all. :)

package src
{
	package src
{
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.text.*;
	import flash.media.*;
	import flash.net.*;
	import flash.utils.getTimer;
	import flash.net.SharedObject;

	import SWFStats.*;

	public class BPop extends Sprite
	{

		//GAME OBJECTS
		private var color:uint = 0xCCCCCC;
		private var circle:MovieClip;
		private var circleBlur:Shape;
		private var circlePack:Array = [];
		private var colorPack:Array = [];
		private var velocityPack:Array = [];
		private var blurPack:Array = [];

		private var velocity:Point;
		private var mouseDist:Point;
		private var crossDist:Point;
		private var killDist:Point;
		private var bounceDist:Point;
		private var circleDist:Point;

		private var mouseOffStage:Boolean = false;

		private var GROW_RATE:Number = 5;
		private var START_SIZE:Number = 10;
		private var START_RADIUS:Number = 42;
		private var SPEED:Number = 7;
		private var STEP:Number = 3;
		private var colored:Boolean = false;
		private var touched:Boolean = false;
		private var circleShrunk:Boolean = false;
		private var blurCount:Number = 0;

		//HUD ELEMENTS
		private var circleSize:TextField;
		private var circleFormat:TextFormat;
		private var thePause:Boolean = false;
		private var uiPause:Boolean = false;
		private var counter:Number = 0;
		private var circleDeath:MovieClip;
		private var crossDistKill:Point;
		private var bounceKill:Boolean = false;

		private var minCounter:Number = 30;

		//SOUND
		private var circleHit:Sound;
		private var circleKill:Sound;

		//MENU
		private var bg:Shape;
		private var bgHack:Shape;
		private var level:Number = 3;
		private var levelAdjust:Number = 2;
		private var levelStop:Boolean = false;
		private var gameOver:Boolean = false;
		private var gameWin:Boolean = false;
		private var uiGameOver:MovieClip;
		private var uiGameWin:MovieClip;
		private var uiGameLock:MovieClip;
		private var uiTitleScreen:MovieClip;
		private var uiScore:MovieClip;
		private var score:Number = 0;

		private var gameStarted:Boolean = false;
		private var siteLocked:Boolean = true;

		private var timeFormat:TextFormat;
		private var scoreFormat:TextFormat;
		private var levelFormat:TextFormat;

		private var days:Number = 0;
		private var daysString:String = "";
		private var hours:Number = 0;
		private var hoursString:String = "";
		private var minutes:Number = 0;
		private var minutesString:String = "";
		private var seconds:Number = 0;
		private var secondsString:String = "";
		private var mSeconds:Number = 0;
		private var mSecondsString:String = "";

		private var levelStartTime:Number = 0;
		private var levelEndTime:Number = 0;

		private var virginHack:Boolean = true;

		private var iconCircle:SimpleButton;
		private var iconPack:Array = [];

		//SAVING
		private var sharedObj:SharedObject;
		private var saveData:Object;
		private var maxLevels:Number = 1;

		public function BPop():void
		{
			//LOAD SWF STATS
			SWFStats.Log.View(513, "6feb47a0-aa7c-4b86-b7b0-72c0261a7fd6", root.loaderInfo.loaderURL);

			blurPack = new Array();

			//LOAD SOUNDS
			circleHit = new sfx_circleHit();
			circleKill = new sfx_circleKill();

			addEventListener(Event.ENTER_FRAME, tick);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, shiftPress);
			stage.addEventListener(Event.MOUSE_LEAVE, offStage);
			stage.addEventListener(MouseEvent.MOUSE_MOVE, onStage);

			loadLocalData();
			titleScreen();
			stage.focus = stage;

			function tick(e:Event):void
			{
				physics();
				collisionCheck();
				uiLogic();
			}
		}

		private function offStage(e:Event):void
		{
			mouseOffStage = true;
		}

		private function onStage(e:Event):void
		{
			mouseOffStage = false;
		}

		private function shiftPress(e:KeyboardEvent):void
		{
			if (bg != null && e.keyCode == 32) //SPACEBAR RESTART
			{
				runRestart();
			}
		}

		private function runRestart():void
		{
			if(iconCircle != null)
			{
				stage.addEventListener(MouseEvent.CLICK, iconClick);
			}

			if(gameOver == true)
			{
				removeChild(bg);
				removeChild(uiScore);
				removeChild(uiGameOver);

				if(iconCircle != null)
				{
					for(var i = 0; i < iconPack.length; i++)
					{
						removeChild(iconPack[i]);
					}
				}

				iconPack = new Array();
			}

			if(gameWin == true)
			{

				removeChild(bg);
				removeChild(uiScore);
				removeChild(uiGameWin);

				if(iconCircle != null)
				{
					for(var p = 0; p  999)
			{
				seconds++;
				mSeconds -= 1000
			}
			if(mSeconds  59)
			{
				minutes++;
				seconds -= 60;
			}
			if(seconds  59)
			{
				hours++;
				minutes -= 60;
			}
			if(minutes  23)
			{
				days++;
				hours -= 24;
			}
			if(hours <= 9)
			{
				hoursString = hoursString.concat("0");
			}
			hoursString = hoursString.concat(hours); //HOURS

			if(days < 9)
			{
				daysString = daysString.concat("0");
			}
				else
				{
					daysString = daysString.concat(days);
				}

			return daysString + ":" + hoursString + ":" + minutesString + ":" + secondsString + ":" + mSecondsString;
		}

		private function levelSelect():void
		{
			for(var i = 0; i = 0 && i = 10 && i = 20 && i = 30 && i = 40 && i = 50 && i = 60 && i = 70 && i = 80 && i = 90 && i < 100)
				{
					iconCircle.x = 456 + ((i - 90) * 32);
					iconCircle.y = 325;
				}
			}
		}

		private function populate():void
		{
			uiScore = new ui_score();
			addChild(uiScore);

			levelFormat = new TextFormat();
			levelFormat.letterSpacing = -16;

			uiScore.txt_level.defaultTextFormat = levelFormat;
			uiScore.txt_level.setTextFormat(levelFormat);

			trace("score added");
			trace("level =" + (level - 2));

			uiScore.txt_level.text = level - 2;			

			if(levelStop == false)
			{
				for(var i = 1; i < level + levelAdjust; i++)
				{
					circles(Math.random()*(stage.stageWidth - (START_RADIUS * 2)) + START_RADIUS, Math.random()*(stage.stageHeight - (START_RADIUS * 2)) + START_RADIUS, START_RADIUS);

					velocity = new Point(Math.random() * SPEED, Math.random() * SPEED);
					velocityPack.push(velocity);

					if(i == ((level + levelAdjust) - 1))
					{
						levelStop = true;
						trace("done");
					}
				}
			}

			for(var p = 0; p  circlePack[p].x + circlePack[p].width/2 && mouseX  circlePack[p].y + circlePack[p].height/2 && mouseY < circlePack[p].y - circlePack[p].height/2)
				   {
						circlePack[p].y += circlePack[p].height;
				   }
				}
			}

			//START A FRESH STOPWATCH
			levelStartTime = getTimer();

			days = 0;
			daysString = "";
			hours = 0;
			hoursString = "";
			minutes = 0;
			minutesString = "";
			seconds = 0;
			secondsString = "";
			mSeconds = 0;
			mSecondsString = "";
		}

		private function physics():void
		{
			if(thePause == false)
			{
				for(var t = 0; t < STEP; t++)
				{
					for(var i = 0; i < circlePack.length; i++)
					{
						circlePack[i].x += velocityPack[i].x / STEP; //SPEED VECTORS DIVIDED BY STEP ITERATIONS (t)
						circlePack[i].y += velocityPack[i].y / STEP;

						for(var p = i + 1; p < circlePack.length; p++) //CIRCLE TO CIRCLE BOUNCE
						{
							crossDist = new Point(circlePack[p].x - circlePack[i].x, circlePack[p].y - circlePack[i].y);

							if(crossDist.length - (circlePack[i].width/2 + circlePack[p].width/2) <= 0)
							{
								if(circlePack[i].circleColored == false || circlePack[p].circleColored == false)
								{
									bounceKill = true;

									crossDist.normalize((circlePack[i].width/2) + (circlePack[p].width/2));

									var centerPoint = new Point(circlePack[i].x + (crossDist.x / 2), circlePack[i].y + (crossDist.y / 2));

									var circlePoint_p:Point = new Point(centerPoint.x + (crossDist.x / 2), centerPoint.y + (crossDist.y / 2));
									var circlePoint_i:Point = new Point(centerPoint.x - (crossDist.x / 2), centerPoint.y - (crossDist.y / 2));

									circlePack[p].x = circlePoint_p.x;
									circlePack[p].y = circlePoint_p.y;
									circlePack[i].x = circlePoint_i.x;
									circlePack[i].y = circlePoint_i.y;

									//BOUNCE
									crossDist.normalize(1);

									var dotProdVelocity_p:Number = (crossDist.x * velocityPack[p].x) + (crossDist.y * velocityPack[p].y);
									var wallNormalProduct_p:Point = new Point((dotProdVelocity_p * crossDist.x) * 2, (dotProdVelocity_p * crossDist.y) * 2);
									var newVelocity_p:Point = new Point(velocityPack[p].x - wallNormalProduct_p.x, velocityPack[p].y - wallNormalProduct_p.y);

									var dotProdVelocity_i:Number = (crossDist.x * velocityPack[i].x) + (crossDist.y * velocityPack[i].y);
									var wallNormalProduct_i:Point = new Point((dotProdVelocity_i * crossDist.x) * 2, (dotProdVelocity_i * crossDist.y) * 2);
									var newVelocity_i:Point = new Point(velocityPack[i].x - wallNormalProduct_i.x, velocityPack[i].y - wallNormalProduct_i.y);

									var dotProd:Number = (velocityPack[i].x * velocityPack[p].x) + (velocityPack[i].y * velocityPack[p].y);

									if(dotProd = stage.stageWidth)
					{
						velocityPack[i].x = -velocityPack[i].x;

						if(circlePack[i].x + circlePack[i].width/2 > stage.stageWidth) //JITTER CHECK
						{
							circlePack[i].x = (stage.stageWidth - 1) - (circlePack[i].width/2);
						}
					}
					//LEFT BOUND BOUNCE
					if(circlePack[i].x - circlePack[i].width/2 <= 0)
					{
						velocityPack[i].x = -velocityPack[i].x;

						if(circlePack[i].x - circlePack[i].width/2 < 0) //JITTER CHECK
						{
							circlePack[i].x = ((circlePack[i].width/2) + 1);
						}
					}
					//BOTTOM BOUND BOUNCE
					if(circlePack[i].y = stage.stageHeight) //JITTER CHECK
						{
							velocityPack[i].y = -velocityPack[i].y;

							if(circlePack[i].y + circlePack[i].height/2 > stage.stageHeight) //CAN'T GROW PAST SCREEN HEIGHT
							{
								circlePack[i].y = (stage.stageHeight - 1) - (circlePack[i].height/2);
							}
						}
					}
						else
						{
							velocityPack[i].y = 0;
						}
					//TOP BOUND BOUNCE
					if(circlePack[i].y < stage.stageHeight)
					{
						if(circlePack[i].y - circlePack[i].height/2 <= 0)
						{
							velocityPack[i].y = -velocityPack[i].y;

							if(circlePack[i].y - circlePack[i].height/2 < 0) //JITTER CHECK
							{
								circlePack[i].y = ((circlePack[i].height/2) + 1);
							}
						}
					}
						else
						{
							velocityPack[i].y = 0;
						}
					}
				}
			}
				else
				{
					if (bg == null && uiPause == false)
					{
						levelKill();
					}
				}
		}

		private function collisionCheck():void
		{
			if(thePause == false)
			{
				for(var i = 0; i < circlePack.length; i++)
				{
					mouseDist = new Point(circlePack[i].x - mouseX, circlePack[i].y - mouseY);

					if (mouseDist.length <= circlePack[i].width/2 && mouseOffStage == false)
					{
						circlePack[i].circleColored = true;

						circleHit.play();

						if(circlePack[i].height <= stage.stageHeight)
						{
							circlePack[i].width += GROW_RATE;
							circlePack[i].height += GROW_RATE;

							//CIRCLE SPECIFIC SIZE TEXT
							circlePack[i].circleSize.text = (parseInt(circlePack[i].circleSize.text) + 1).toString();

							//COLOR SWITCH
							circlePack[i].graphics.clear();
							circlePack[i].graphics.beginFill(0xff0000, 1);
							circlePack[i].graphics.drawCircle(0, 0, START_SIZE);
							circlePack[i].graphics.endFill();

							score++;
						}
					}
						else
						{
							circlePack[i].circleColored = false;
						}

					if(circlePack[i].circleColored == false)
					{
						circlePack[i].graphics.clear();
						circlePack[i].graphics.beginFill(colorPack[i], 1);
						circlePack[i].graphics.drawCircle(0, 0, START_SIZE);
						circlePack[i].graphics.endFill();
					}
				}
			}
				else
				{
					return;
				}
		}

		private function levelWin():void
		{
			if(gameWin == false)
			{
				trace("win counter: " + counter);
				if(counter <= 30)
				{
					for(var i = 0; i < circlePack.length; i++)
					{
						circlePack[i].graphics.clear();
						circlePack[i].graphics.beginFill(0xDEDEDE, minCounter/30);
						circlePack[i].graphics.drawCircle(0, 0, START_SIZE);
						circlePack[i].graphics.endFill();

						uiScore.alpha = minCounter/30;
					}
				}
					else
					{
						trace("draw me the sky!");
						gameWin = true;
						uiPause = false;
						thePause = false;
						minCounter = 30;
						counter = 0;
					}

				minCounter--;
				counter++;
			}
		}

		private function levelKill():void
		{
			if(gameOver == false)
			{
				trace("lose counter: " + counter);

				if(counter == 1)
				{
					for(var i = 0; i  1 && counter  99 && bg == null)
					{
						trace("win game")
						levelEndTime = getTimer();
						uiPause = true;
						thePause = true;

						if(level - 2 < saveData.maxLevels)
						{
							trace("not added to levels");
						}
							else
							{
								saveData.maxLevels++;
								Log.LevelCounterMetric("Max Level", maxLevels);
							}

						updateSave();
					}

					if(gameOver == true && bg == null)
					{
						//Log.LevelCounterMetric("Max Level", maxLevels);

						bg = new Shape();
						bg.graphics.clear();
						bg.graphics.beginFill(0xFF0000, 1);
						bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
						bg.graphics.endFill();
						addChild(bg);

						stage.focus = stage;

						uiGameOver = new ui_gameOver();

						levelFormat = new TextFormat();
						levelFormat.letterSpacing = -9;
						scoreFormat = new TextFormat();
						scoreFormat.letterSpacing = -4;
						timeFormat = new TextFormat();
						timeFormat.letterSpacing = -4;

						uiGameOver.txt_level.defaultTextFormat = levelFormat;
						uiGameOver.txt_level.setTextFormat(levelFormat);
						uiGameOver.txt_score.defaultTextFormat = scoreFormat;
						uiGameOver.txt_score.setTextFormat(scoreFormat);
						uiGameOver.txt_time.defaultTextFormat = timeFormat;
						uiGameOver.txt_time.setTextFormat(timeFormat);

						addChild(uiGameOver);

						uiGameOver.txt_level.text = level - 2; //LEVEL
						uiGameOver.txt_score.text = score; //SCORE
						uiGameOver.txt_time.text = levelTime(); //TIME

						levelSelect();

						for(var i = 0; i < circlePack.length; i++)
						{
							removeChild(circlePack[i]);
						}

						circlePack = new Array();
					}

					if(gameWin == true && bg == null)
					{
						//Log.LevelCounterMetric("Max Level", maxLevels);

						bg = new Shape();
						bg.graphics.clear();
						bg.graphics.beginFill(0xFFFFFF, 1);
						bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
						bg.graphics.endFill();
						addChild(bg);

						stage.focus = stage;

						uiGameWin = new ui_gameWin();

						levelFormat = new TextFormat();
						levelFormat.letterSpacing = -9;
						timeFormat = new TextFormat();
						timeFormat.letterSpacing = -4;

						uiGameWin.txt_level.defaultTextFormat = levelFormat;
						uiGameWin.txt_level.setTextFormat(levelFormat);
						uiGameWin.txt_time.defaultTextFormat = timeFormat;
						uiGameWin.txt_time.setTextFormat(timeFormat);

						addChild(uiGameWin);

						//NEXT BUTTON
						uiGameWin.btn_next.addEventListener(MouseEvent.CLICK, nextClick);
						uiGameWin.btn_next.useHandCursor = true;

						uiGameWin.txt_level.text = level - 2; //LEVEL
						uiGameWin.txt_time.text = levelTime(); //TIME

						for(var p = 0; p < circlePack.length; p++)
						{
							removeChild(circlePack[p]);
						}

						level++;

						circlePack = new Array();
					}
				}
			}
				else
				{
					levelWin();
				}
		}

		private function titleScreen():void
		{
			bg = new Shape();
			bg.graphics.clear();
			bg.graphics.beginFill(0xFF0000, 1);
			bg.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
			bg.graphics.endFill();
			addChild(bg);

			stage.focus = stage;

			uiTitleScreen = new ui_titleScreen();
			uiTitleScreen.btn_intro.addEventListener(MouseEvent.CLICK, introClick);
			uiTitleScreen.btn_start.addEventListener(MouseEvent.CLICK, startClick);
			uiTitleScreen.btn_start.useHandCursor = true;

			addChild(uiTitleScreen);

			circlePack = new Array();
			trace("ADDDDDDDD");
		}
	}
}

In case you missed the link to the plain text file, here it is: HundredsSourceCode.txt