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.

74 lines
2.3 KiB

  1. package gameobjects;
  2. import java.awt.Color;
  3. import collider.RectCollider;
  4. import playground.Playground;
  5. import rendering.RectArtist;
  6. /**
  7. * A rectangle object. <br>
  8. * If {@link #generateColliders()} is called, it generates a RectCollider with id-prefix
  9. * "shotcollider_" and registers it for this RectObject.
  10. *
  11. */
  12. public class RectObject extends GameObject {
  13. /** width in pixels of the RectObject (&gt; 0) */
  14. protected double width;
  15. /** height in pixels of the RectObject (&gt; 0) */
  16. protected double height;
  17. /**
  18. * Initializes the RectObject with a suitable RectArtist for drawing the RectObject.
  19. *
  20. * @param id String unique name to be used.
  21. * @param pg {@link Playground} instance this RectObject belongs to (the level it belongs to).
  22. * @param x position in horizontal direction in pixels (zero or positive number).
  23. * @param y position in vertical direction in pixels (zero or positive number).
  24. * @param vx speed/velocity in horizontal direction in pixels (negative, zero or positive number).
  25. * @param vy speed/velocity in vertical direction in pixels (negative, zero or positive number).
  26. * @param width in pixels
  27. * @param height in pixels
  28. * @param color solid color for the whole object, used to initialize an instance of
  29. * {@link rendering.RectArtist} used for this RectObject.
  30. */
  31. public RectObject(String id, Playground pg, double x, double y, double vx, double vy,
  32. double width, double height, Color color) {
  33. super(id, pg, x, y, vx, vy);
  34. this.width = width;
  35. this.height = height;
  36. this.artist = new RectArtist(this, width, height, color);
  37. }
  38. /**
  39. * generates a new {@link RectCollider} with id-prefix "shotcollider_" and registers it for 'this'
  40. * [@link RectObject}. The {@link RectCollider} uses the same dimensions ({@link #width} and {@link #height}) as this RectObject.
  41. *
  42. * @return this RectObject itself
  43. */
  44. public RectObject generateColliders() {
  45. this.scol.add(new RectCollider("shotcollider_" + id, this, this.width, this.height));
  46. return this;
  47. }
  48. /** Getter for the width
  49. *
  50. * @return double width value as set by constructor
  51. */
  52. public double getWidth() {
  53. return this.width;
  54. }
  55. /** Getter for the height
  56. *
  57. * @return double height value as set by constructor
  58. */
  59. public double getHeight() {
  60. return this.height;
  61. }
  62. }