ActiveDen

Ping-Pong game small change

7 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
alisaleh says

Hi there, My email: ali@alisaleh.net

I bought this script: http://activeden.net/item/ping-pong-retro-game/56105

there is one small problem.

the stage height and weight is upon to the stage.

so the ball goes to the end of the page !

I want to give it a specific Height and weight !

and the mouse icon need to be always showing.

See my page: http://alisaleh.net/clients/frontline-ms/

the script is using:

//Setting the variables var xDirection:Number=100; var yDirection:Number = -1; ball_mc.y = Math.random()455;

var targetY:Number = paddle_mc.y; var easing:Number = 7;

var playerScore:Number; var enemyScore:Number; var server:Number = 0;

var winningScore:Number=10; //This variable controls the winning score

var hit:Sound = new Hit(); var hit2:Sound = new Hit2();

//This function will reset the position of the ball when a player has scored. function resetBallPosition():void { if(server == 0) { xDirection = 10; }

else if(server ==1)
{
    xDirection = -10;
}
yDirection = -1;
ball_mc.y = Math.random()455;
ball_mc.x = 316;

}

//This function will check where the ball hits the paddle, and calculate how fast and i wich direction the ball will come back towards the other player function checkHitLocation(paddle:MovieClip):void { var hitPercent:Number; var ballPosition:Number = ball_mc.y – paddle.y; hitPercent = (ballPosition / (paddle.height – ball_mc.height)) – .5; yDirection = hitPercent * 20; xDirection *= 1.05; //This number can be changed to in – or decrease the speed of the ball }

//This function will show who wins the game, and how many points each players has. function showScore():void { if(playerScore >= winningScore) { player_txt.text=”Won”; enemy_txt.text=”Lost”; endGame(); } else if(enemyScore >= winningScore) { enemy_txt.text=”Won”; player_txt.text=”Lost”; endGame(); } else { player_txt.text = ”” + playerScore; enemy_txt.text = ”” + enemyScore; } }

//This function will run in the end of the game, and reset the eventlisteners function endGame():void { paddle_mc.removeEventListener(Event.ENTER_FRAME, movePaddle); enemy_mc.removeEventListener(Event.ENTER_FRAME, moveEnemy); ball_mc.removeEventListener(Event.ENTER_FRAME, moveBall); bg_mc.addEventListener(MouseEvent.CLICK, initializeGame); }

server = 0;
Mouse.show();
start_mc.alpha = 100;

//This function will run automatic when the game starts. function initializeGame(event:MouseEvent):void { playerScore = 0; enemyScore = 0; }

player_txt.text = "" + playerScore;
enemy_txt.text = "" + enemyScore;
paddle_mc.addEventListener(Event.ENTER_FRAME, movePaddle);
enemy_mc.addEventListener(Event.ENTER_FRAME, moveEnemy);
ball_mc.addEventListener(Event.ENTER_FRAME, moveBall);
bg_mc.removeEventListener(MouseEvent.CLICK, initializeGame);
Mouse.hide();
start_mc.alpha = 0;

//This function moves the ball, and change the direction when the ball hits the edge function moveBall(event:Event):void { if(ball_mc.y <= 0) { ball_mc.y = 1; yDirection *= -1; hit2.play(); } else if(ball_mc.y >=stage.stageHeight – ball_mc.height) { ball_mc.y = stage.stageHeight – ball_mc.height -1; yDirection *= -1; hit2.play(); } }

if(ball_mc.hitTestObject(paddle_mc))
{
    xDirection *= -1;
    hit.play();
    checkHitLocation(paddle_mc);
}
if(ball_mc.hitTestObject(enemy_mc))
{
    xDirection *= -1;
    hit.play();
    checkHitLocation(enemy_mc);
}
if(ball_mc.x <= 0)
{
    enemyScore ++;
    server = 1;
    showScore();
    resetBallPosition();
}
else if(ball_mc.x >=stage.stageWidth - ball_mc.width)
{
    playerScore ++;
    server = 0;
    showScore();
    resetBallPosition();
}
ball_mc.y += yDirection;
ball_mc.x += xDirection;

//This function makes the player paddle move function movePaddle(event:Event):void { if(this.mouseY <= paddle_mc.height / 2) { targetY = 0; } else if(this.mouseY >= stage.stageHeight – paddle_mc.height / 2) { targetY = stage.stageHeight – paddle_mc.height; } else { targetY = this.mouseY – paddle_mc.height/2; } }

paddle_mc.y += (targetY - paddle_mc.y) / easing;

//This function creates the intelligent of the computer player function moveEnemy(event:Event):void { var enemyTargetY:Number; enemyTargetY = ball_mc.y – enemy_mc.height/2; }

if(enemyTargetY <= 0)
{
    enemyTargetY = 0;
}
else if(enemyTargetY >= stage.stageHeight - enemy_mc.height)
{
    enemyTargetY = stage.stageHeight - enemy_mc.height;
}
enemy_mc.y += (enemyTargetY - enemy_mc.y) / 3; //The last number in this line can be changed to mage the opponent harder or easier to beat.

//When you click on the background, the game will start bg_mc.addEventListener(MouseEvent.CLICK, initializeGame); ?

2 years ago
260 posts
  • Has been a member for 3-4 years
  • Grew a moustache for the Envato Movember competition
  • Author had a Free File of the Month
  • Exclusive Author
  • Sold between 5 000 and 10 000 dollars
  • Bought between 10 and 49 items
  • United Kingdom
  • Referred between 1 and 9 users
ravenwill says

Hi Ali,

Please don’t post code onto the forums. Please edit this post to remove code.

I can help you with your problem but please email me through my profile page.

Regards

Chris

2 years ago
7 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
alisaleh says

Hi I can’t edit it !

I’m sending ur the email now.

2 years ago
by
by
by
by
by