You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
5.0 KiB

  1. package playground;
  2. import java.awt.Color;
  3. import collider.RectCollider;
  4. import gameobjects.GameObject;
  5. import gameobjects.RectObject;
  6. public class BreakoutLevel2 extends BreakoutLevelBaseAdvanced {
  7. @Override
  8. protected int calcNrBricksX() {
  9. return 6;
  10. }
  11. @Override
  12. protected int calcNrBricksY() {
  13. return 5;
  14. }
  15. @Override
  16. protected double getBrickSizeX() {
  17. return 60;
  18. }
  19. @Override
  20. protected double getBrickSizeY() {
  21. return 30;
  22. }
  23. @Override
  24. protected double getBrickStartX() {
  25. return 90;
  26. }
  27. @Override
  28. protected double getBrickStartY() {
  29. return 60;
  30. }
  31. @Override
  32. protected void actionIfBallHitsBrick(GameObject ball, GameObject brick) {
  33. for(int i = 0; i < 20; i++) {
  34. //Zuf�llige Geschwindigkeiten
  35. int effectVX = (int)(Math.random() * 480) - 240;
  36. int effectVY = (int)(Math.random() * 480) - 240;
  37. //Fallingstarobject
  38. // gameobjects.FallingStar effect = new gameobjects.FallingStar("effect" + i, this, brick.getX(), brick.getY(), effectVX, effectVY, Color.RED, 3);
  39. // effect.addController(new controller.LimitedTimeController(getGameTime(), 2));
  40. // this.addObject(effect);
  41. double a = Math.random();
  42. if(a <= 0.25) {
  43. gameobjects.FallingStar effect0 = new gameobjects.FallingStar("effect" + i, this, brick.getX(), brick.getY(), effectVX, effectVY, Color.GREEN, 3);
  44. effect0.addController(new controller.LimitedTimeController(getGameTime(), 2));
  45. this.addObject(effect0);
  46. }
  47. if(a > 0.25 && a <= 0.5) {
  48. gameobjects.FallingStar effect1 = new gameobjects.FallingStar("effect" + i, this, brick.getX(), brick.getY(), effectVX, effectVY, Color.BLUE, 3);
  49. effect1.addController(new controller.LimitedTimeController(getGameTime(), 2));
  50. this.addObject(effect1);
  51. }
  52. if(a > 0.5 && a <= 0.75) {
  53. gameobjects.FallingStar effect2 = new gameobjects.FallingStar("effect" + i, this, brick.getX(), brick.getY(), effectVX, effectVY, Color.PINK, 3);
  54. effect2.addController(new controller.LimitedTimeController(getGameTime(), 2));
  55. this.addObject(effect2);
  56. }
  57. if(a > 0.75) {
  58. gameobjects.FallingStar effect3 = new gameobjects.FallingStar("effect" + i, this, brick.getX(), brick.getY(), effectVX, effectVY, Color.YELLOW, 3);
  59. effect3.addController(new controller.LimitedTimeController(getGameTime(), 2));
  60. this.addObject(effect3);
  61. }
  62. }
  63. this.ball.setVY(this.ball.getVY()*-1);
  64. this.deleteObject(brick.getId());
  65. //logger.trace("Collision detected of ball and brick " + brick.getId());
  66. }
  67. @Override
  68. protected void actionIfBallHitsEgo(GameObject ball, GameObject ego) {
  69. if (ball.getX()>= (ego.getX() + 0.45d * 60)) {
  70. this.ball.setVX(this.ball.getVX()*-1);
  71. } else if (ball.getX()<= (ego.getX() - 0.45d * 60)) {
  72. this.ball.setVX(this.ball.getVX()*-1);
  73. }
  74. this.ball.setVY(this.ball.getVY()*-1);
  75. //logger.trace("Collision detected of ball and ego ");
  76. }
  77. @Override
  78. protected GameObject createEgoObject() {
  79. RectObject egoObject_BL1 = new RectObject("egoObject_BL1", this, 350, 550, 0, 0, 60, 10, Color.BLUE);
  80. egoObject_BL1.addController(new controller.EgoController(60, 10));
  81. egoObject_BL1.addCollider(new RectCollider("egoObject_BL1_Col", egoObject_BL1, 60, 10));
  82. //logger.debug("Ego created ");
  83. return egoObject_BL1;
  84. }
  85. @Override
  86. protected GameObject createBall() {
  87. gameobjects.FallingStar BallObject_BL1 = new gameobjects.FallingStar ("BallObject_BL1", this, 350, 350, 130, 130, Color.RED, 5);
  88. BallObject_BL1.addController(new controller.ReboundController());
  89. //logger.debug("Ball created ");
  90. return BallObject_BL1;
  91. }
  92. @Override
  93. protected GameObject createBrick(int row, int column) {
  94. double a = Math.random();
  95. if(a <= 0.25) {
  96. RectObject brick0 = new RectObject("brick" + row + column, this, column * (2 * this.getBrickSizeX()) + this.getBrickStartX(), row * (2 * this.getBrickSizeY()) + this.getBrickStartY(), 0, 0, 60, 30, Color.GREEN);
  97. brick0.addCollider(new RectCollider("brick" + row + column + "Col", brick0, 60, 30));
  98. return brick0;
  99. }
  100. if(a > 0.25 && a <= 0.5) {
  101. RectObject brick1 = new RectObject("brick" + row + column, this, column * (2 * this.getBrickSizeX()) + this.getBrickStartX(), row * (2 * this.getBrickSizeY()) + this.getBrickStartY(), 0, 0, 60, 30, Color.BLUE);
  102. brick1.addCollider(new RectCollider("brick" + row + column + "Col", brick1, 60, 30));
  103. return brick1;
  104. }
  105. if(a > 0.5 && a <= 0.75) {
  106. RectObject brick2 = new RectObject("brick" + row + column, this, column * (2 * this.getBrickSizeX()) + this.getBrickStartX(), row * (2 * this.getBrickSizeY()) + this.getBrickStartY(), 0, 0, 60, 30, Color.PINK);
  107. brick2.addCollider(new RectCollider("brick" + row + column + "Col", brick2, 60, 30));
  108. return brick2;
  109. }
  110. RectObject brick3 = new RectObject("brick" + row + column, this, column * (2 * this.getBrickSizeX()) + this.getBrickStartX(), row * (2 * this.getBrickSizeY()) + this.getBrickStartY(), 0, 0, 60, 30, Color.YELLOW);
  111. brick3.addCollider(new RectCollider("brick" + row + column + "Col", brick3, 60, 30));
  112. return brick3;
  113. //logger.debug("Brick created: " + brick.getId());
  114. }
  115. }