Class GameObject

java.lang.Object
core.GameObject
Direct Known Subclasses:
Bullet, Character, Laser

public abstract class GameObject extends Object
Abstract base class for all objects in the game world. Each GameObject has a position (x, y) and must be able to update and render itself.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected double
    X-coordinate of the object in the game world.
    protected double
    Y-coordinate of the object in the game world.
  • Constructor Summary

    Constructors
    Constructor
    Description
    GameObject(double x, double y)
    Constructs a GameObject at the specified coordinates.
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    Returns the X-coordinate of the object.
    double
    Returns the Y-coordinate of the object.
    abstract void
    render(javafx.scene.canvas.GraphicsContext gc)
    Renders the object on the screen.
    void
    setX(double x)
    Sets the X-coordinate of the object.
    void
    setY(double y)
    Sets the Y-coordinate of the object.
    abstract void
    update(double dt)
    Updates the state of the object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • x

      protected double x
      X-coordinate of the object in the game world.
    • y

      protected double y
      Y-coordinate of the object in the game world.
  • Constructor Details

    • GameObject

      public GameObject(double x, double y)
      Constructs a GameObject at the specified coordinates. Coordinates are clamped within the game window bounds.
      Parameters:
      x - Initial X-coordinate.
      y - Initial Y-coordinate.
  • Method Details

    • setX

      public void setX(double x)
      Sets the X-coordinate of the object. Clamps the value between 0 and GameApp.WIDTH.
      Parameters:
      x - X-coordinate to set.
    • setY

      public void setY(double y)
      Sets the Y-coordinate of the object. Clamps the value between 0 and GameApp.HEIGHT.
      Parameters:
      y - Y-coordinate to set.
    • getX

      public double getX()
      Returns the X-coordinate of the object.
      Returns:
      Current X-coordinate.
    • getY

      public double getY()
      Returns the Y-coordinate of the object.
      Returns:
      Current Y-coordinate.
    • update

      public abstract void update(double dt)
      Updates the state of the object. This method is called every frame with the time delta.
      Parameters:
      dt - Time elapsed since the last update, in seconds.
    • render

      public abstract void render(javafx.scene.canvas.GraphicsContext gc)
      Renders the object on the screen.
      Parameters:
      gc - GraphicsContext used for drawing.