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.

76 lines
2.4 KiB

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