Frame 2
ifFrameLoaded (8) {
gotoAndPlay (4);
}
Frame 3
gotoAndPlay (2);
Frame 7
gotoAndPlay (5);
Frame 8
function getAngle(x1, y1, x2, y2) {
if ((x1 > (x2 - 0.0001)) && (x1 < (x2 + 0.0001))) {
if (y1 > y2) {
angle = 0;
} else {
angle = 180;
}
} else {
angle = (Math.atan((y2 - y1) / (x2 - x1)) * 180) / Math.PI;
if (x2 < x1) {
angle = angle + 180;
}
angle = angle + 90;
}
return(angle);
}
function getLength(x, y) {
return(Math.sqrt((x * x) + (y * y)));
}
function pauseScreen() {
if (pause == "gameStart") {
messageText = "\n\nPress space to start";
if (Key.isDown(32)) {
messageText = "";
pause = "";
}
} else if (pause == "die") {
messageText = "\n\nScore deducted: 100\nPress space to continue";
if (Key.isDown(32)) {
messageText = "";
pause = "";
initBoyBallItem();
}
} else if (pause == "gameOver") {
messageText = "\n\nGame Over\nPress space to continue";
if (Key.isDown(32)) {
i = 0;
while (i < 72) {
var temp = eval ("b" + i);
temp.removeMovieClip();
i++;
}
messageText = "";
pause = "";
initBoyBallItem();
_global.score = score;
gotoAndPlay (9);
}
} else if (pause == "stageClear") {
if (stageNumber == totalStage) {
messageText = "Game finished!";
} else {
messageText = "Stage Clear!";
}
messageText = messageText + (((("\n\nTime Used: " + parseInt(time)) + " secs\nBonus Score: ") + bonus) + "\n\nPress space to continue");
if (Key.isDown(32)) {
if (stageNumber == totalStage) {
gotoAndPlay (9);
} else {
messageText = "";
pause = "";
stageNumber++;
time = 0;
initBoyBallItem();
initMap();
}
}
}
}
function ballBoyInteraction() {
if (boy.action.head.hitTest(ball)) {
headpos = new Vector(boy.action.head._x, boy.action.head._y - 20);
boy.action.localToGlobal(headpos);
normal = new Vector(ball._x - headpos.x, ball._y - headpos.y);
v = new Vector(ball.vx, ball.vy);
if (dot(v, normal) < 0) {
soundHead.start();
projection = new project(v, normal);
ball.vx = (ball.vx - projection.x) - projection.x;
ball.vy = (ball.vy - projection.y) - projection.y;
if (boy.vy < 0) {
ball.vy = ball.vy + (boy.vy / 4);
}
ball.vx = ball.vx + (boy.vx / 4);
ballspeed = getLength(ball.vx, ball.vy);
if (ballspeed > 13) {
ball.vx = ball.vx / 1.2;
ball.vy = ball.vy / 1.2;
}
}
}
}
function ballBrickInteraction() {
var col;
var row;
var brickID;
col = parseInt((ball._x - 20) / 60);
row = parseInt((ball._y - 20) / 20);
brickID = (row * 6) + col;
if (brickID < 72) {
if (brickHP[brickID] > 0) {
if (((ball.vy > 0) && (row > 0)) && (brickHP[brickID - 6] != 0)) {
ball.vx = -ball.vx;
} else if (((ball.vy < 0) && (row < 10)) && (brickHP[brickID + 6] != 0)) {
ball.vx = -ball.vx;
} else {
var Ly;
var Lx;
if (ball.vy > 0) {
Ly = (row * 20) + 20;
} else {
Ly = (row * 20) + 40;
}
Lx = ball._x - ((ball.vx / ball.vy) * (ball._y - Ly));
if ((Lx > ((col * 60) + 10)) && (Lx < ((col * 60) + 90))) {
ball.vy = -ball.vy;
} else {
ball.vx = -ball.vx;
}
}
brickHP[brickID]--;
temp = eval ("b" + brickID);
score = score + 5;
if (brickHP[brickID] <= 0) {
soundBrick.start();
temp._visible = false;
if ((random(5) == 0) && (item.state == 0)) {
item.state = random(2) + 1;
item._x = (col * 60) + 50;
item._y = (row * 20) + 30;
item._visible = true;
item.gotoAndStop(item.state);
}
NumberOfBrick--;
if (NumberOfBrick <= 0) {
bonus = 400 - parseInt(time);
if (bonus < 0) {
bonus = 0;
}
score = score + bonus;
pause = "stageClear";
}
} else {
soundMetal.start();
}
temp.shine.play();
}
}
}
function itemBoyInteraction() {
if (item.state > 0) {
if (boy.hitTest(item)) {
soundItem.start();
if (item.state == 1) {
boy.headSize = boy.headSize + 20;
} else if (item.state == 2) {
boy.walkSpeed = boy.walkSpeed + 2;
}
item.state = 0;
item._visible = false;
}
}
}
function itemRun() {
if (item.state > 0) {
item._y = item._y + 2;
if (item._y > 470) {
item.state = 0;
item._visible = false;
}
}
}
function ballRun() {
if (ball.state == 1) {
if (ball.Hit) {
ball.Hit = false;
return(undefined);
}
ball._x = ball._x + ball.vx;
ball._y = ball._y + ball.vy;
if ((ball._x < 30) && (ball.vx < 0)) {
ball._x = 30;
ball.vx = -ball.vx;
ball.Hit = true;
}
if ((ball._x > 370) && (ball.vx > 0)) {
ball._x = 370;
ball.vx = -ball.vx;
ball.Hit = true;
}
if ((ball._y < 30) && (ball.vy < 0)) {
ball._y = 30;
ball.vy = -ball.vy;
ball.Hit = true;
}
if ((ball._y > 470) && (ball.vy > 0)) {
soundDie.start();
ball._y = 470;
ball.vy = 0;
ball.state = 2;
if (life > 0) {
life--;
score = score - 100;
if (score < 0) {
score = 0;
}
pause = "die";
} else {
pause = "gameOver";
}
}
angle = getAngle(ball.vx, ball.vy);
ball._rotation = angle + 180;
if (ball.Hit == true) {
ball._yscale = 50;
soundWall.start();
} else {
ball._yscale = getLength(ball.vx, ball.vy) * 4;
if (ball._yscale < 50) {
ball._yscale = 50;
}
}
}
if (ball.state == 2) {
ball._rotation = 0;
ball._yscale = 50;
}
ball.gotoAndStop(ball.state);
}
function boyRun() {
boy.gotoAndStop(boy.state);
if (boy._y < landy) {
boy.state = "jump";
boy.vy = boy.vy + 5;
boy._y = boy._y + boy.vy;
boy._x = boy._x + boy.vx;
if (boy._y > landy) {
boy._y = landy;
}
} else if (Key.isDown(38)) {
if (Key.isDown(37)) {
boy.vx = ((-boy.walkSpeed) * 2) / 3;
} else if (Key.isDown(39)) {
boy.vx = (boy.walkSpeed * 2) / 3;
}
boy.vy = -25;
boy._y = boy._y + boy.vy;
} else if (Key.isDown(37)) {
boy.state = "walk";
boy._xscale = -80;
boy.vx = -boy.walkSpeed;
} else if (Key.isDown(39)) {
boy.state = "walk";
boy._xscale = 80;
boy.vx = boy.walkSpeed;
} else {
boy.state = "stand";
boy.vx = 0;
}
boy._x = boy._x + boy.vx;
if (boy._x < 50) {
boy._x = 50;
}
if (boy._x > 350) {
boy._x = 350;
}
boy.action.head._xscale = boy.headSize;
boy.action.head._yscale = boy.headSize;
}
function initBoyBallItem() {
boy._x = 200;
boy._y = 470;
boy.state = "stand";
boy.walkSpeed = initialWalkSpeed;
boy.headSize = initialHeadSize;
boy.gotoAndStop(1);
ball._x = 200;
ball._y = 360;
ball.vx = random(11) - 5;
ball.vy = -10;
ball.Hit = false;
ball.state = 1;
ball.gotoAndStop(1);
landy = 470;
item.state = 0;
item._visible = false;
}
function initMap() {
NumberOfBrick = 0;
var i;
var j;
var ID = 0;
j = 0;
while (j < 12) {
i = 0;
while (i < 6) {
if (brickMap[ID + ((stageNumber - 1) * 72)] > 0) {
var objName = ("b" + ID);
attachMovie("brick", objName, ID);
var temp = eval (objName);
temp._x = (i * 60) + 20;
temp._y = (j * 20) + 20;
temp.gotoAndStop(brickMap[ID + ((stageNumber - 1) * 72)]);
brickHP[ID] = brickMaxHP[brickMap[ID + ((stageNumber - 1) * 72)]];
NumberOfBrick++;
} else {
brickHP[ID] = 0;
}
ID++;
i++;
}
j++;
}
}
function Vector(x, y) {
this.x = x;
this.y = y;
}
function dot(v1, v2) {
return((v1.x * v2.x) + (v1.y * v2.y));
}
function project(v1, v2) {
len = getLength(v2.x, v2.y);
v2.x = v2.x / len;
v2.y = v2.y / len;
d = dot(v1, v2);
this.x = d * v2.x;
this.y = d * v2.y;
}
soundDie = new Sound();
soundBrick = new Sound();
soundHead = new Sound();
soundMetal = new Sound();
soundWall = new Sound();
soundItem = new Sound();
soundDie.attachSound("die.wav");
soundBrick.attachSound("hitBrick.wav");
soundHead.attachSound("hitHead.wav");
soundMetal.attachSound("hitMetal.wav");
soundWall.attachSound("hitWall.wav");
soundItem.attachSound("getItem.mp3");
initialized = false;
totalStage = 5;
stageNumber = 1;
score = 0;
life = 2;
pause = "gameStart";
initialWalkSpeed = 10;
initialHeadSize = 100;
brickHP = new Array(72);
brickMaxHP = [0, 1, 1, 1, 3, 5];
brickMap = [1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4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
function gameRun() {
if (pause == "") {
ballRun();
boyRun();
itemRun();
ballBoyInteraction();
ballBrickInteraction();
itemBoyInteraction();
time = time + 0.04;
} else {
pauseScreen();
}
stageText = "Stage " + stageNumber;
lifeText = "Life: " + life;
scoreText = "Score: " + score;
}
onEnterFrame = function () {
if (initialized != true) {
initialized = true;
time = 0;
initBoyBallItem();
initMap();
} else {
gameRun();
}
};
stop();
Frame 9
onEnterFrame = function () {
};
scoreText = _global.score;
stop();
Frame 10
link = ((("http://www.martiworkshop.com/cuphp/famehall.php?addentry=1&name=" + name) + "&score=") + scoreText) + "&gameid=boy";
loadVariables (link, _root, "POST");
Symbol 13 MovieClip Frame 6
stop();
Symbol 30 Button
on (release) {
gotoAndStop (8);
}
Symbol 42 MovieClip Frame 1
stop();
onEnterFrame = function () {
if (random(20) == 0) {
play();
}
};
Symbol 47 Button
on (release) {
getURL ("http://www.martiwong.com", "_blank");
}
Symbol 66 MovieClip Frame 2
stop();
Symbol 82 Button
on (release) {
play();
}