home *** CD-ROM | disk | FTP | other *** search
- function checkForWinner()
- {
- if(homeScore == 5 || awayScore == 5)
- {
- _root.player1Score = homeScore;
- _root.player2Score = awayScore;
- _root.gotoAndPlay("gameOver");
- }
- }
- function author()
- {
- author = "All actionscript by Karl Berseus for NakedPenguinBoy.";
- }
- function runGame()
- {
- playerMove();
- pl2Move();
- var scorer;
- if((scorer = ball.move()) != 0)
- {
- trace(scorer + " scores");
- goal(scorer);
- }
- if(!hitT(1))
- {
- hitT(-1);
- }
- }
- function playerMove()
- {
- if(Key.isDown(38) && pl1._y > -110)
- {
- pl1.move(- plS);
- pl1.ySpeed = 0.7853981633974483;
- }
- else if(Key.isDown(40) && pl1._y < 110)
- {
- pl1.move(plS);
- pl1.ySpeed = -0.7853981633974483;
- }
- else
- {
- pl1.move(0);
- pl1.ySpeed = 0;
- }
- }
- function secondPlayerMove()
- {
- if(Key.isDown(65) && pl2._y > -110)
- {
- pl2.move(- plS);
- pl2.ySpeed = 0.7853981633974483;
- }
- else if(Key.isDown(90) && pl2._y < 110)
- {
- pl2.move(plS);
- pl2.ySpeed = -0.7853981633974483;
- }
- else
- {
- pl2.move(0);
- pl2.ySpeed = 0;
- }
- }
- function aiMove()
- {
- var ball_y = ball.getGlobY();
- var goalie_y = pl2.r1.m0.getGlobY();
- if(ball._x > aiG_l._x || ball._x < aiD_l._x)
- {
- if(ball_y > goalie_y)
- {
- aiSpeed += 1;
- }
- else
- {
- aiSpeed -= 1;
- }
- }
- else
- {
- var attacker_y;
- if(ball_y < ball.og_globY)
- {
- attacker_y = pl2.r2.m0.getGlobY();
- }
- else
- {
- attacker_y = pl2.r2.m1.getGlobY();
- }
- if(ball_y > attacker_y)
- {
- aiSpeed += 1;
- }
- else
- {
- aiSpeed -= 1;
- }
- }
- if(aiSpeed < - aiS)
- {
- aiSpeed = - aiS;
- pl2.ySpeed = 0.7853981633974483;
- }
- else if(aiSpeed > aiS)
- {
- aiSpeed = aiS;
- pl2.ySpeed = -0.7853981633974483;
- }
- if(aiSpeed > 4 || aiSpeed < -4)
- {
- pl2.move(aiSpeed / difConst);
- }
- else
- {
- pl2.move(0);
- pl2.ySpeed = 0;
- }
- }
- function hitT(pl)
- {
- var margin = ball.r + 7;
- var player;
- if(pl == 1)
- {
- player = pl1;
- }
- else
- {
- player = pl2;
- }
- for(var row in player)
- {
- if(ball._x > player[row]._x - margin && ball._x < player[row]._x + margin)
- {
- var r = player[row];
- var ball_y = ball.getGlobY();
- for(var man in r)
- {
- var man_y = r[man].getGlobY();
- if(ball_y > man_y - margin && ball_y < man_y + margin && r[man].gr._currentframe == 1)
- {
- r[man].hit();
- ball.hit(pl);
- return true;
- }
- }
- }
- }
- return false;
- }
- function reset()
- {
- ball.reset();
- efActions.gotoAndStop(2);
- }
- function goal(scorer)
- {
- if(scorer == 1)
- {
- homeScore += 1;
- scoreBoard.homeP = homeScore;
- checkForWinner();
- }
- else
- {
- awayScore += 1;
- scoreBoard.awayP = awayScore;
- checkForWinner();
- }
- ball._visible = false;
- efActions.gotoAndStop(1);
- goalScreen.play();
- pl1.move(0);
- pl2.move(0);
- }
- function ballClose()
- {
- closeSound.play();
- }
- homeScore = 0;
- awayScore = 0;
- aiSpeed = 0;
- plS = 5;
- aiS = 7;
- difConst = _root.diffLevel;
- aiG = 0;
- trace(difConst);
- pl2Move = _root.noOfPlayers;
- if(_root.noOfPlayers == 2)
- {
- pl2Move = secondPlayerMove;
- }
- else
- {
- pl2Move = aiMove;
- }
-