Class GameObject
java.lang.Object
core.GameObject
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 -
Constructor Summary
ConstructorsConstructorDescriptionGameObject(double x, double y) Constructs a GameObject at the specified coordinates. -
Method Summary
Modifier and TypeMethodDescriptiondoublegetX()Returns the X-coordinate of the object.doublegetY()Returns the Y-coordinate of the object.abstract voidrender(javafx.scene.canvas.GraphicsContext gc) Renders the object on the screen.voidsetX(double x) Sets the X-coordinate of the object.voidsetY(double y) Sets the Y-coordinate of the object.abstract voidupdate(double dt) Updates the state of the object.
-
Field Details
-
x
protected double xX-coordinate of the object in the game world. -
y
protected double yY-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.
-