home *** CD-ROM | disk | FTP | other *** search
- function initGame()
- {
- numBalls = 5;
- currBall = 0;
- score = 0;
- bonus = 0;
- breakOutMode = false;
- soundIndice = 0;
- activeBumperStrength = 2;
- activeLargeBumperStrength = 1.75;
- passiveBumperStrength = 0.75;
- flipperStrength = 15;
- initAllObjects();
- }
- function launchNewBall()
- {
- currBall++;
- display_mc.gotoAndPlay("start");
- mainRamp.gotoAndPlay(2);
- ball.mode = "rampDown";
- score_mc.disp_currBall = currBall;
- playSound(M_launchNewBall_snd);
- }
- function display(mode, str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, str11, str12)
- {
- var displayObj = new Object();
- var i = 1;
- while(i <= 12)
- {
- var str = eval("str" + i);
- displayObj["str" + i] = str;
- trace("DISPLAY: " + str);
- if(str == -1)
- {
- count = i;
- break;
- }
- i++;
- }
- if(mode == 0)
- {
- display_mc.gotoAndPlay("start");
- display_mc.displayObj = displayObj;
- }
- else if(mode == 1)
- {
- this.attachMovie("B_scoreBoard","scoreBoard",5000);
- scoreBoard.displayObj = displayObj;
- scoreBoard._x = 348;
- scoreBoard._y = 307.5;
- }
- else if(mode == 2)
- {
- this.attachMovie("mainScoreBoard","scoreBoard",5000);
- scoreBoard.displayObj = displayObj;
- scoreBoard._x = 357;
- scoreBoard._y = 251;
- }
- return 800 * (count - 1) + 2200;
- }
- function endBall()
- {
- trace("END BALL");
- ball.mode = "stop";
- var dispBonus = score_mc.mainBonus;
- if(score_mc.bonusLevel == 0)
- {
- var dispTotal = score_mc.mainScore + score_mc.mainBonus;
- dispTimer = display(1,"Ball Lost!","Bonus",addSpace(dispBonus),-1);
- }
- else
- {
- var dispMult = score_mc.bonusMult;
- var dispBonusMult = score_mc.mainBonus * score_mc.bonusMult;
- var dispTotal = score_mc.mainScore + dispBonusMult;
- dispTimer = display(1,"Ball Lost!","Bonus",addSpace(dispBonus),"x" + dispMult,addSpace(dispBonusMult),-1);
- }
- score_mc.mainScore = dispTotal;
- timer = setInterval(function()
- {
- score_mc.resetAfterBall();
- launchNewBall();
- clearInterval(timer);
- }
- ,dispTimer);
- }
- function endGame()
- {
- trace("END GAME");
- ball.mode = "stop";
- BG_pepsiTitle.animateLight();
- playSoundLoop(T_musicIntro_snd,100);
- var dispBonus = score_mc.mainBonus;
- if(score_mc.bonusLevel == 0)
- {
- var dispTotal = score_mc.mainScore + score_mc.mainBonus;
- dispTimer = display(1,"Game Over!","Bonus",addSpace(dispBonus),-2,addSpace(dispTotal),-1);
- }
- else
- {
- var dispMult = score_mc.bonusMult;
- var dispBonusMult = score_mc.mainBonus * score_mc.bonusMult;
- var dispTotal = score_mc.mainScore + dispBonusMult;
- dispTimer = display(1,"Game Over!","Bonus",addSpace(dispBonus),"x" + dispMult,addSpace(dispBonusMult),-2,addSpace(dispTotal),-1);
- }
- score_mc.mainScore = dispTotal;
- timer = setInterval(function()
- {
- clearInterval(timer);
- }
- ,dispTimer);
- }
- function submitScore()
- {
- toSend = new LoadVars();
- toSend.gobbledeegook = score_mc.mainScore;
- toSend.send("submitscore.asp","_self","POST");
- }
- function initAllObjects()
- {
- initBonus();
- initBall();
- initWalls();
- initFlippers();
- initBumpers();
- initTargets();
- initMainRamp();
- initLargeBumpers();
- initSwitches();
- initCart();
- }
- function initBonus()
- {
- numBonus = count("bonus");
- var bonusLabel = new Array("x2","x4","x6","x8","x10","hold");
- bonus = new Array();
- i = 0;
- while(i < numBonus)
- {
- var mc = _root["bonus" + i];
- mc.disp_label_mc.text = bonusLabel[i];
- bonus.push(new tBonus(mc));
- i++;
- }
- }
- function initBall()
- {
- radius = 12.5;
- gravity = 0.275;
- bounce = 0.8;
- friction = 0.998;
- maxSpeed = 15;
- toRad = 0.017453292519943295;
- toDeg = 57.29577951308232;
- TOP = 0;
- BOTTOM = 547;
- LEFT = 0;
- RIGHT = 694;
- var mc = ball_mc;
- var pos = new Position(ballLaunch._x,ballLaunch._y);
- var vel = new Position(0,-10);
- ball = new tBall(mc,pos,vel);
- }
- function initWalls()
- {
- numWalls = count("dot");
- numWalls--;
- wall = new Array();
- i = 0;
- while(i < numWalls)
- {
- var mc = attachMovie("wall","wall" + i,1000 + i);
- mc._visible = showWall;
- mc.n = i;
- mc._x = _root["dot" + i]._x;
- mc._y = _root["dot" + i]._y;
- var pos = new Position(mc._x,mc._y);
- var end = new Position(_root["dot" + (i + 1)]._x,_root["dot" + (i + 1)]._y);
- mc._width = dist(pos.x,pos.y,end.x,end.y);
- var angleRad = Math.atan2(end.y - pos.y,end.x - pos.x);
- var angleDeg = mc._rotation = angleRad * toDeg;
- wall.push(new tWall(mc,angleRad,pos));
- i++;
- }
- }
- function initMainRamp()
- {
- numLeftWalls = count("leftDot",_root.mainRamp) - 1;
- numRightWalls = count("rightDot",_root.mainRamp) - 1;
- rampWall = new Array();
- i = 0;
- while(i < numLeftWalls)
- {
- var mc = attachMovie("wall","rampWall" + i,2000 + i);
- mc._visible = showWall;
- mc._x = _root.mainRamp["leftDot" + i]._x + mainRamp._x;
- mc._y = _root.mainRamp["leftDot" + i]._y + mainRamp._y;
- var pos = new Position(mc._x,mc._y);
- var endx = _root.mainRamp["leftDot" + (i + 1)]._x + mainRamp._x;
- var endy = _root.mainRamp["leftDot" + (i + 1)]._y + mainRamp._y;
- var end = new Position(endx,endy);
- mc._width = dist(pos.x,pos.y,end.x,end.y);
- var angleRad = Math.atan2(end.y - pos.y,end.x - pos.x);
- var angleDeg = mc._rotation = angleRad * toDeg;
- rampWall.push(new tWall(mc,angleRad,pos));
- i++;
- }
- i = 0;
- while(i < numRightWalls)
- {
- var indice = i + 100;
- var mc = attachMovie("wall","rampWall" + indice,2000 + indice);
- mc._visible = showWall;
- mc._x = _root.mainRamp["rightDot" + i]._x + mainRamp._x;
- mc._y = _root.mainRamp["rightDot" + i]._y + mainRamp._y;
- var pos = new Position(mc._x,mc._y);
- var endx = _root.mainRamp["rightDot" + (i + 1)]._x + mainRamp._x;
- var endy = _root.mainRamp["rightDot" + (i + 1)]._y + mainRamp._y;
- var end = new Position(endx,endy);
- mc._width = dist(pos.x,pos.y,end.x,end.y);
- var angleRad = Math.atan2(end.y - pos.y,end.x - pos.x);
- var angleDeg = mc._rotation = angleRad * toDeg;
- rampWall.push(new tWall(mc,angleRad,pos));
- i++;
- }
- }
- function initFlippers()
- {
- numFlippers = count("flipper");
- flipper = new Array();
- i = 0;
- while(i < numFlippers)
- {
- var mc = _root["flipper" + i];
- var pos = new Position(mc._x,mc._y);
- var length = mc._width;
- var angle = mc._rotation;
- flipper[i] = new tFlipper(mc,angle,length,pos);
- flipper[i].type = flipper[i].mc.type;
- flipper[i].strength = flipperStrength;
- flipper[i].angleSup = -5.22;
- flipper[i].angleInf = 5.22;
- i++;
- }
- }
- function initBumpers()
- {
- numBumpers = count("bumper");
- bumper = new Array();
- var i = 0;
- while(i < numBumpers)
- {
- var mc = _root["bumper" + i];
- var bRadius = mc._width;
- if(i <= 2)
- {
- var strength = activeBumperStrength;
- }
- else
- {
- var strength = passiveBumperStrength;
- }
- var pos = new Position(mc._x,mc._y);
- var clip = _root["sombrero" + i];
- bumper[i] = new tBumper(mc,bRadius,strength,pos,clip);
- i++;
- }
- }
- function initTargets()
- {
- saloon_mc.setDoorClose();
- numTargetHit = 0;
- numTargets = count("target",_root.allTargets);
- target = new Array();
- var letter = "PEPSISALOON";
- var i = 0;
- while(i < numTargets)
- {
- var mc = _root.allTargets["target" + i];
- mc.gotoAndStop("on");
- var x = mc._x + mc.bumper0._x + allTargets._x;
- var y = mc._y + mc.bumper0._y + allTargets._y;
- mc.disp_letter = letter.charAt(i);
- var pos = new Position(x,y);
- var bRadius = mc.bumper0._width;
- var hitStatus = true;
- target[i] = new tTarget(mc,bRadius,1.5,pos,hitStatus);
- i++;
- }
- }
- function initLargeBumpers()
- {
- var numLargeBumpers = count("largeBumper");
- largeBumper = new Array();
- j = 0;
- while(j < numLargeBumpers)
- {
- largeBumper[j] = new Object();
- largeBumper[j].mc = _root["largeBumper" + j];
- var numSmallBumpers = count("bumper",largeBumper[j].mc);
- largeBumper[j].bumper = new Array();
- i = 0;
- while(i < numSmallBumpers)
- {
- var mc = _root["largeBumper" + j]["bumper" + i];
- var bRadius = mc._width;
- var strength = activeLargeBumperStrength;
- var pos = new Position(mc._x,mc._y);
- pos.x += largeBumper[j].mc._x;
- pos.y += largeBumper[j].mc._y;
- largeBumper[j].bumper[i] = new tBumper(mc,bRadius,strength,pos);
- i++;
- }
- var numWalls = count("dot",largeBumper[j].mc) / 2;
- largeBumper[j].wall = new Array();
- i = 0;
- while(i < numWalls)
- {
- wallDepth++;
- var str = "wall" + wallDepth;
- _root["largeBumper" + j].attachMovie("wall",str,wallDepth);
- var mc = _root["largeBumper" + j][str];
- mc._x = _root["largeBumper" + j]["dot" + i * 2]._x;
- mc._y = _root["largeBumper" + j]["dot" + i * 2]._y;
- var pos = new Position(mc._x,mc._y);
- var endx = _root["largeBumper" + j]["dot" + (i * 2 + 1)]._x;
- var endy = _root["largeBumper" + j]["dot" + (i * 2 + 1)]._y;
- var end = new Position(endx,endy);
- mc._width = dist(pos.x,pos.y,end.x,end.y);
- var angleRad = Math.atan2(end.y - pos.y,end.x - pos.x);
- mc._rotation = angleRad * toDeg;
- pos.x += largeBumper[j].mc._x;
- pos.y += largeBumper[j].mc._y;
- largeBumper[j].wall.push(new tWall(mc,angleRad,pos));
- i++;
- }
- j++;
- }
- largeBumper[0].bumper[0].strength = 0.75;
- largeBumper[0].bumper[5].strength = 0.75;
- }
- function initSwitches()
- {
- gateFlag = new Array(false,false,false);
- numSwitches = count("switch",_root.switch_mc);
- gateSwitch = new Array();
- var i = 0;
- while(i < numSwitches)
- {
- var mc = switch_mc["switch" + i];
- mc.gotoAndStop("off");
- gateSwitch.push(new tSwitch(mc,false));
- i++;
- }
- }
- function initCart()
- {
- cart = new Object();
- cart.mc = eval(_root.cart_mc);
- var numSmallBumpers = count("bumper",cart.mc);
- cart.bumper = new Array();
- i = 0;
- while(i < numSmallBumpers)
- {
- var mc = cart.mc["bumper" + i];
- var bRadius = mc._width / 2;
- var strength = activeLargeBumperStrength;
- var pos = new Position(mc._x,mc._y);
- pos.x += cart.mc._x;
- pos.y += cart.mc._y;
- cart.pos = new Position(pos.x,pos.y);
- cart.bumper[i] = new tBumper(mc,bRadius,strength,pos);
- i++;
- }
- }
- function moveBall()
- {
- ball.oldPos.x = ball.pos.x;
- ball.oldPos.y = ball.pos.y;
- ball.vel.y += gravity;
- ball.vel.x *= friction;
- ball.vel.y *= friction;
- var velocity = new tVector(ball.vel.x,ball.vel.y);
- if(velocity.norm > maxSpeed)
- {
- ball.vel.x = maxSpeed * Math.cos(velocity.phiRad);
- ball.vel.y = maxSpeed * Math.sin(velocity.phiRad);
- }
- ball.pos.x += ball.vel.x;
- ball.pos.y += ball.vel.y;
- ball.mc._x = ball.pos.x;
- ball.mc._y = ball.pos.y;
- }
- function scaleBall()
- {
- var size;
- var minSize = 20;
- var maxSize = 25;
- var minY = 68;
- var maxY = 487;
- var size = (ball.pos.y - minY) / (maxY - minY);
- var size = (maxSize - minSize) * size + minSize;
- var scale = size * 4;
- ball.mc._xscale = scale;
- ball.mc._yscale = scale;
- radius = size / 2;
- }
- function checkOutScreen()
- {
- if(ball.pos.y > BOTTOM || ball.pos.x < LEFT || ball.pos.x > RIGHT || ball.pos.y < TOP)
- {
- if(currBall == numBalls)
- {
- endGame();
- }
- else
- {
- endBall();
- }
- }
- }
- function checkWalls()
- {
- for(i in wall)
- {
- if(wall[i].mc.hitTest(ball.mc))
- {
- doWallCollision(wall[i],ball);
- if(saloonDoorOpen && saloonHitZone.hitTest(ball.pos.x,ball.pos.y,true))
- {
- ball.mode = "saloonEntrance";
- }
- }
- }
- }
- function checkMainRamp()
- {
- for(i in rampWall)
- {
- if(rampWall[i].mc.hitTest(ball.mc))
- {
- doWallCollision(rampWall[i],ball);
- }
- }
- }
- function checkFlippers()
- {
- for(i in flipper)
- {
- if(flipper[i].mc.hitTest(ball.mc))
- {
- if(flipper[i].mc.hitZoneInf.hitTest(ball.pos.x,ball.pos.y,true))
- {
- var angleSurf = flipper[i].angle + flipper[i].angleInf;
- var angleVel = Math.atan2(ball.vel.y,ball.vel.x) * toDeg;
- var normVel = dist(0,0,ball.vel.x,ball.vel.y);
- normVel *= bounce;
- do
- {
- ball.pos.y += 0.25;
- }
- while(flipper[i].mc.hitZoneInf.hitTest(ball.pos.x,ball.pos.y,true));
-
- var newAngleVel = - angleVel + angleSurf;
- if(flipper[i].moving)
- {
- var fl = new tVector();
- var fSpeed = Math.abs(ball.pos.x - flipper[i].pos.x) / 55 * flipper[i].strength;
- fl.x = fSpeed * Math.sin(angleSurf * toRad);
- fl.y = (- fSpeed) * Math.cos(angleSurf * toRad);
- }
- ball.vel.x = normVel * Math.cos(newAngleVel * toRad) + fl.x;
- ball.vel.y = normVel * Math.sin(newAngleVel * toRad) + fl.y;
- }
- if(flipper[i].mc.hitZoneSup.hitTest(ball.pos.x,ball.pos.y,true))
- {
- var angleSurf = flipper[i].angle + flipper[i].angleSup;
- var angleVel = Math.atan2(ball.vel.y,ball.vel.x) * toDeg;
- var normVel = dist(0,0,ball.vel.x,ball.vel.y);
- normVel *= bounce;
- do
- {
- ball.pos.y -= 0.25;
- }
- while(flipper[i].mc.hitZoneSup.hitTest(ball.pos.x,ball.pos.y,true));
-
- var newAngleVel = - angleVel + angleSurf;
- if(flipper[i].moving)
- {
- var fl = new tVector();
- var fSpeed = Math.abs(ball.pos.x - flipper[i].pos.x) / 55 * flipper[i].strength;
- fl.x = fSpeed * Math.sin(angleSurf * toRad);
- fl.y = (- fSpeed) * Math.cos(angleSurf * toRad);
- }
- ball.vel.x = normVel * Math.cos(newAngleVel * toRad) + fl.x;
- ball.vel.y = normVel * Math.sin(newAngleVel * toRad) + fl.y;
- }
- if(flipper[i].mc.endHitZone.hitTest(ball.pos.x,ball.pos.y,true))
- {
- var end = new Position(flipper[i].mc._x,flipper[i].mc._y);
- if(flipper[i].mc.type == "left")
- {
- end.x += 55 * Math.cos(flipper[i].angle * toRad);
- end.y += 55 * Math.sin(flipper[i].angle * toRad);
- }
- else
- {
- end.x += -55 * Math.cos(flipper[i].angle * toRad);
- end.y += -55 * Math.sin(flipper[i].angle * toRad);
- }
- var bv = new tVector(ball.vel.x,ball.vel.y);
- var bm = new tVector(ball.pos.x - end.x,ball.pos.y - end.y);
- bm = normalizeVect(bm);
- bm = new tVector(bm.x * bv.norm * bounce,bm.y * bv.norm * bounce);
- var fl = new tVector();
- var fSpeed = flipper[i].strength;
- fl.x = fSpeed * Math.sin(flipper[i].angle * toRad) * flipper[i].moving;
- fl.y = (- fSpeed) * Math.cos(flipper[i].angle * toRad) * flipper[i].moving;
- var sum = sumVect(bv,bm,fl);
- ball.vel.x = sum.x;
- ball.vel.y = sum.y;
- }
- }
- }
- }
- function checkBumpers()
- {
- for(i in bumper)
- {
- if(bumper[i].mc.hitTest(ball.mc))
- {
- doPointCollision(bumper[i],ball);
- bumper[i].clip.gotoAndPlay("play");
- score_mc.addScore("bumper");
- if(bumper[i].strength == activeBumperStrength)
- {
- playSound(M_bumper_snd);
- }
- }
- }
- }
- function checkTargets()
- {
- if(allTargets.hitTest(ball.mc))
- {
- for(var i in target)
- {
- if(target[i].hitStatus && target[i].mc.bumper0.hitTest(ball.mc))
- {
- doPointCollision(target[i],ball);
- target[i].hitStatus = false;
- target[i].mc.gotoAndStop("off");
- score_mc.addScore("target");
- playSound(M_target_snd);
- numTargetHit++;
- if(numTargetHit >= target.length)
- {
- numTargetHit = 0;
- saloon_mc.setDoorOpen();
- score_mc.addScore("saloonDoor");
- playSound(M_saloonDoor_snd);
- }
- }
- }
- }
- }
- function checkLargeBumpers()
- {
- for(var j in largeBumper)
- {
- if(largeBumper[j].mc.hitTest(ball.mc))
- {
- for(var i in largeBumper[j].bumper)
- {
- if(largeBumper[j].bumper[i].mc.hitTest(ball.mc))
- {
- doPointCollision(largeBumper[j].bumper[i],ball);
- score_mc.addScore("largeBumper");
- var volume = calculateVolume(ball.vel) - 40;
- playSoundVolume(M_barrel_snd,volume);
- }
- }
- }
- }
- }
- function checkSwitches()
- {
- if(switch_mc.hitTest(ball.mc))
- {
- for(var i in gateSwitch)
- {
- if(gateSwitch[i].mc.hitZone.hitTest(ball.pos.x,ball.pos.y,true))
- {
- if(!gateFlag[validatingGate])
- {
- gateSwitch[i].setOn();
- score_mc.addScore("switch");
- if(gateSwitch[0].hitStatus && gateSwitch[1].hitStatus && gateSwitch[2].hitStatus)
- {
- validatingGate = i;
- gateFlag[validatingGate] = true;
- score_mc.bonusUp();
- score_mc.addScore("allSwitch");
- score_mc.addScore("switch");
- playSound(M_ding_mc);
- for(var j in gateSwitch)
- {
- gateSwitch[j].setOff();
- }
- }
- }
- }
- else if(i == validatingGate)
- {
- gateFlag[validatingGate] = false;
- }
- }
- }
- }
- function checkCart()
- {
- if(cart.mc.hitTest(ball.mc))
- {
- var collision = true;
- if(cart.mc.hitZone.hitTest(ball.pos.x,ball.pos.y,true))
- {
- var velocity = new tVector(ball.vel.x,ball.vel.y);
- if(velocity.phiDeg <= -90 && velocity.phiDeg >= -180)
- {
- collision = false;
- ball.mode = "cartEntrance";
- score_mc.addScore("cart");
- stopSound(T_musicIntro_snd);
- playSound(T_musicFinalTheme_snd);
- }
- }
- if(collision)
- {
- for(var i in cart.bumper)
- {
- doPointCollision(cart.bumper[i],ball);
- }
- }
- }
- }
- function checkRightRamp()
- {
- if(rightRampHitZone.hitTest(ball.mc))
- {
- if(rightRampHitZone.hitTest(ball.pos.x,ball.pos.y,true))
- {
- var velocity = new tVector(ball.vel.x,ball.vel.y);
- if(velocity.phiDeg >= -111 && velocity.phiDeg <= 129)
- {
- ball.mode = "rightRamp";
- stopSound(T_musicIntro_snd);
- playSound(T_musicFinalTheme_snd);
- }
- }
- }
- }
- showNormal = false;
- showWall = false;
- showBumper = false;
- showHitZone = false;
- debug = false;
- gotoAndStop(13);
-