public override void gameLogic() { //control left shell if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.W) && Math.Round(leftShell.getVelocityDY()) == 0) { leftShell.setVelocity(leftShell.getVelocityDX(), -191f); } if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.A)) { leftShell.setVelocity(-55, leftShell.getVelocityDY()); } else if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.D)) { leftShell.setVelocity(55, leftShell.getVelocityDY()); } else { leftShell.setVelocity(0, leftShell.getVelocityDY()); } //control right shell if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Up) && Math.Round(rightShell.getVelocityDY()) == 0) { rightShell.setVelocity(rightShell.getVelocityDX(), -191f); } if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Left)) { rightShell.setVelocity(-55, rightShell.getVelocityDY()); } else if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Right)) { rightShell.setVelocity(55, rightShell.getVelocityDY()); } else { rightShell.setVelocity(0, rightShell.getVelocityDY()); } //check ball state if (ball.physicsCollide(sand) && ball.getX() < 200) { //update score rightPoints++; //change score text to reflect this rightScore.changeText(Convert.ToString(rightPoints)); //put ball above winner ball.setPosition(340, 100); //put both shells back at their start position rightShell.setPosition(340, 340); leftShell.setPosition(40, 340); //set ball's velocity to 0 so that it just falls down ball.setVelocity(0, 0); } if (ball.physicsCollide(sand) && ball.getX() > 200) { leftPoints++; leftScore.changeText(Convert.ToString(leftPoints)); ball.setPosition(60, 100); rightShell.setPosition(340, 340); leftShell.setPosition(40, 340); ball.setVelocity(0, 0); } }
public override void gameLogic() { //ball bounces off walls and paddles if (ball.getX() > 390) { ball.setVelocity(-ball.getVelocityDX(), ball.getVelocityDY()); //update score playerPoints++; //reassign text in playersScore text object to reflect this change playerScore.changeText(Convert.ToString(playerPoints)); } if (ball.getX() < 0) { ball.setVelocity(-ball.getVelocityDX(), ball.getVelocityDY()); //update score computerPoints++; //reassign text in computerScore text object to reflect this change computerScore.changeText(Convert.ToString(computerPoints)); } if (ball.getY() > 390) { ball.setVelocity(ball.getVelocityDX(), -ball.getVelocityDY()); } if (ball.getY() < 0) { ball.setVelocity(ball.getVelocityDX(), -ball.getVelocityDY()); } if (ball.pixelCollidesWith(leftPaddle)) { ball.setVelocity(-ball.getVelocityDX(), ball.getVelocityDY()); } //left player moves using Q and A if (ball.pixelCollidesWith(rightPaddle)) { ball.setVelocity(-ball.getVelocityDX(), ball.getVelocityDY()); } if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Q)) { leftPaddle.setVelocity(0, -100); } else if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.A)) { leftPaddle.setVelocity(0, 100); } else { leftPaddle.setVelocity(0, 0); } //autonomouse computer paddle on right paddleM = rightPaddle.getY() + rightPaddle.getHeight() / 2; if (ball.getY() < paddleM && ball.getX() > 150) { rightPaddle.setVelocity(0, -170); } else if (ball.getY() > paddleM && ball.getX() > 150) { rightPaddle.setVelocity(0, 170); } else { rightPaddle.setVelocity(0, 0); } }
public override void gameLogic() { if (stage == 0) { state.changeText("C-Create Session"); state1.changeText("J-Join Session"); if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.C)) { this.net.CreateSession(); //this.net.SignInGamer(); } if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.J)) { //this.net.SignInGamer(); this.net.FindSession(); } netState.changeText(this.net.Message); if (this.net.netState == 1) {//a state of means the player has joined is in play mode stage = 3; } } else if (stage == 3)//game stage { state.changeText(net.Message); //control left shell if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.W) && Math.Round(leftShell.getVelocityDY()) == 0) { leftShell.setVelocity(leftShell.getVelocityDX(), -191f); } if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.A)) { leftShell.setVelocity(-55, leftShell.getVelocityDY()); } else if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.D)) { leftShell.setVelocity(55, leftShell.getVelocityDY()); } else { leftShell.setVelocity(0, leftShell.getVelocityDY()); } //control right shell if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Up) && Math.Round(rightShell.getVelocityDY()) == 0) { rightShell.setVelocity(rightShell.getVelocityDX(), -191f); } if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Left)) { rightShell.setVelocity(-55, rightShell.getVelocityDY()); } else if (this.isKeyPressed(Microsoft.Xna.Framework.Input.Keys.Right)) { rightShell.setVelocity(55, rightShell.getVelocityDY()); } else { rightShell.setVelocity(0, rightShell.getVelocityDY()); } //check ball state if (ball.physicsCollide(sand) && ball.getX() < 200) { //update score rightPoints++; //change score text to reflect this rightScore.changeText(Convert.ToString(rightPoints)); //put ball above winner ball.setPosition(340, 100); //put both shells back at their start position rightShell.setPosition(340, 340); leftShell.setPosition(40, 340); //set ball's velocity to 0 so that it just falls down ball.setVelocity(0, 0); } if (ball.physicsCollide(sand) && ball.getX() > 200) { leftPoints++; leftScore.changeText(Convert.ToString(leftPoints)); ball.setPosition(60, 100); rightShell.setPosition(340, 340); leftShell.setPosition(40, 340); ball.setVelocity(0, 0); } //end of stage 3 } }