public GameEngine() { playerOne = new Player(false, true); playerTwo = new Player(true, false); ball = new PongBall(); multiplayer = false; }
public void CheckPlayerCollision(Player player, PongBall ball) { Random rand = new Random(); float[] deflectionSlopes = new float[] { -.8f, -.5f, -.15f, .15f, .5f, .8f }; for (int i = 0; i < 6; i++) { if (collisionCooldown == 0) { if (player.collisionBoxes[i].Intersects(ball.position)) { //player.PlayCollisionSound(); SwitchDirection(); if (player.leftSidePlayer) slope = deflectionSlopes[i]; else slope = -deflectionSlopes[i]; yIntercept = (int)(position.Y - (slope * position.X)); collisionCooldown++; break; } } else { collisionCooldown++; if (collisionCooldown >= 60) collisionCooldown = 0; } } }
public void MovePlayer(Player player, PongBall ball) { int speed = ball.speed/2+3; int playerTopPoint = player.position.Y; int playerBottomPoint = player.position.Y + player.position.Height; if (!((ball.position.Y > playerTopPoint) && (ball.position.Y < playerBottomPoint))) { if (ball.position.Y > playerBottomPoint) player.position.Y += speed; if (ball.position.Y < playerTopPoint) player.position.Y -= speed; } }
public void MovePlayer(Player player, PongBall ball) { int speed = ball.speed / 2 + 3; int playerTopPoint = player.position.Y; int playerBottomPoint = player.position.Y + player.position.Height; if (!((ball.position.Y > playerTopPoint) && (ball.position.Y < playerBottomPoint))) { if (ball.position.Y > playerBottomPoint) { player.position.Y += speed; } if (ball.position.Y < playerTopPoint) { player.position.Y -= speed; } } }
public void Update(PongBall ball) { if (!isAI) { position.Y = Updater.mouse.Y - (position.Height / 2); //Currently will be used for player 1 //MULTPLAYER TODO: Send packet to other player(s) / Server if (!Updater.gameEngine.multiplayer) { if (Updater.kbCurrent.IsKeyDown(Keys.Escape) && Updater.kbOld.IsKeyUp(Keys.Escape)) { Updater.SwitchScreenNoFade(GameScreen.PAUSED); } } } else { computer.MovePlayer(this, ball); } UpdateCollisionBoxes(); }
public void CheckPlayerCollision(Player player, PongBall ball) { Random rand = new Random(); float[] deflectionSlopes = new float[] { -.8f, -.5f, -.15f, .15f, .5f, .8f }; for (int i = 0; i < 6; i++) { if (collisionCooldown == 0) { if (player.collisionBoxes[i].Intersects(ball.position)) { //player.PlayCollisionSound(); SwitchDirection(); if (player.leftSidePlayer) { slope = deflectionSlopes[i]; } else { slope = -deflectionSlopes[i]; } yIntercept = (int)(position.Y - (slope * position.X)); collisionCooldown++; break; } } else { collisionCooldown++; if (collisionCooldown >= 60) { collisionCooldown = 0; } } } }