//////////////////////////////////////// //updating ball acceleration public void UpdateBall(GameData game) { game.ball.x += game.ball.dx; game.ball.y += game.ball.dy; }
public void PlayerCollisions(GameData game) { //left if (game.ply.player.x >= SwinGame.ScreenWidth() - game.ply.PlayerWidth()) { game.ply.player.dx = -2; SwinGame.PlaySoundEffect("playerWall"); } //right if (game.ply.player.x <= 0) { game.ply.player.dx = +2; SwinGame.PlaySoundEffect("playerWall"); } //up if (game.ply.player.y <= 400) { game.ply.player.dy = +2; SwinGame.PlaySoundEffect("playerWall"); } //down if (game.ply.player.y >= SwinGame.ScreenHeight() - game.ply.PlayerHeight()) { game.ply.player.dy = -2; SwinGame.PlaySoundEffect("playerWall"); } //ball collides with paddle here //if ball is greater than players x pos, stopping ball if left onwards if ((game.ply.player.x <= game.ball.x + game.bl.BallWidth(game.ball)) && (game.ball.x <= game.ply.player.x + game.ply.PlayerWidth())) { //top if (game.ply.player.y <= game.ball.y + game.bl.BallHeight(game.ball)) { //making sure it isn't below the bottom of the player if (game.ply.player.y + game.ply.PlayerHeight() >= game.ball.y + game.bl.BallHeight(game.ball)) { //sends ball up game.ball.dy += -3; SwinGame.PlaySoundEffect("playerBall"); //right side if ((game.ply.PlayerWidth() + game.ply.player.x >= game.ball.x + game.bl.BallWidth(game.ball) / 2) && ((game.ply.player.x + (game.ply.PlayerWidth() * (2 / 3))) <= game.ball.x + game.bl.BallWidth(game.ball) / 2)) { game.ball.dx += 2; } //center if ((game.ply.player.x + 1 / 3 * game.ply.PlayerWidth() <= game.ball.x + game.bl.BallWidth(game.ball) / 2) && (game.ply.player.x + 2 / 3 * game.ply.PlayerWidth() >= game.ball.x + game.bl.BallWidth(game.ball) / 2)) { game.ball.dx = 0; } //left if ((game.ply.player.x <= game.ball.x + game.bl.BallWidth(game.ball) / 2) && (game.ply.player.x + game.ply.PlayerWidth() * 1 / 3 >= game.ball.x + game.bl.BallWidth(game.ball) / 2)) { game.ball.dx -= 2; } } //bottom if (game.ply.player.y + game.ply.PlayerHeight() <= game.ball.y) { //minimum boundary if (game.ply.player.y + game.ply.PlayerHeight() + game.bl.BallHeight(game.ball) / 4 >= game.ball.y) { game.ball.dy += 3; game.ball.dx += 1; SwinGame.PlaySoundEffect("playerBall"); } } } } }