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.

64 lines
1.7 KiB

  1. package gameobjects;
  2. import java.awt.Color;
  3. import java.util.LinkedList;
  4. import collider.*;
  5. import playground.Playground;
  6. import rendering.*;
  7. /**
  8. * Convenience Class subclassing {@link GameObject}, directly instanciating {@link TextArtist} a
  9. * subclass of {@link Artist} that draws a text. The controller is left undefined, the collider as
  10. * well. However, a single call to the overwritten method {@link #generateColliders} will in fact
  11. * generate a {@link RectCollider} of just the right size for the text.
  12. *
  13. */
  14. public class TextObject extends GameObject {
  15. private String text = null;
  16. protected double rx, ry;
  17. public String getText() {
  18. return this.text;
  19. }
  20. /**
  21. * Constructor.
  22. *
  23. * @param id object name
  24. * @param playground containing {@link Playground} instance
  25. * @param x positionx
  26. * @param y positiony
  27. * @param vx speedx
  28. * @param vy speedy
  29. * @param size font size in Pixel
  30. * @param text String to be displayed
  31. * @param textColor text color, see java.awt.Color
  32. */
  33. public TextObject(String id, Playground playground, double x, double y, double vx, double vy,
  34. String text, int size, Color textColor) {
  35. super(id, playground, x, y, vx, vy);
  36. this.artist = new TextArtist(this, text, size, textColor);
  37. this.setColliders(new LinkedList<Collider>());
  38. }
  39. public void setText(String s) {
  40. this.text = s;
  41. ((TextArtist) this.artist).setText(s);
  42. }
  43. public TextObject generateColliders() {
  44. // we need to Cast to TextArtist as we want to access Width and Height of text
  45. TextArtist kruecke = (TextArtist) (this.artist);
  46. this.scol.clear();
  47. this.scol.add(new RectCollider("rect", this, kruecke.getTextWidth(), kruecke.getTextHeight()));
  48. return this;
  49. }
  50. }