diff options
Diffstat (limited to 'pacman/model/src/main')
3 files changed, 142 insertions, 5 deletions
diff --git a/pacman/model/src/main/java/com/gr15/pacman/model/entities/Entity.java b/pacman/model/src/main/java/com/gr15/pacman/model/entities/Entity.java index 0792219..8d2a176 100644 --- a/pacman/model/src/main/java/com/gr15/pacman/model/entities/Entity.java +++ b/pacman/model/src/main/java/com/gr15/pacman/model/entities/Entity.java @@ -4,7 +4,26 @@ import com.gr15.pacman.model.Board; import com.gr15.pacman.model.Position; /** - * Entity + * Represents an abstract entity with a position + * and collision radius on a game board. + * + * <p> + * This class stores both tile-based {@link Position} + * and fine-grained sub-tile coordinates + * to allow smooth movement within and across grid tiles. + * </p> + * + * <p> + * The full world coordinates are computed by combining + * the integer {@code Position} with + * {@code subTileX} and {@code subTileY}, allowing sub-tile precision + * useful for animation or collision detection. + * </p> + * + * <p> + * Subclasses must implement the {@code move} method + * to define entity-specific behavior over time. + * </p> */ public abstract class Entity { @@ -16,23 +35,101 @@ public abstract class Entity { public enum Direction { UP, DOWN, LEFT, RIGHT, NONE }; + /** + * Constructs an Entity with the specified starting position and radius. + * + * @param startPos The initial tile-based position of the entity. + * @param radius The collision radius of the entity. + * @throws IllegalArgumentException if any parameter is invalid: + * - startPos is null + * - radius is less than or equal to zero + */ public Entity(Position startPos, double radius) { + if (startPos == null) { throw new IllegalArgumentException("startPos cannot be null"); } + if (radius <= 0) { throw new IllegalArgumentException("radius must be positive"); } this.radius = radius; this.position = startPos; } + /** + * Updates the entity's position based on game logic and elapsed time. + * + * @param board The board the entity is moving on. + * @param deltaSeconds The time elapsed since the last update, in seconds. + */ public abstract void move(Board board, double deltaSeconds); - /* Getters and setters */ + + /* Getters */ + /** + * Gets the tile-based position of the entity. + * + * @return The current tile position. + */ public Position getPosition() { return this.position; } + + /** + * Gets the entity's sub-tile X offset. + * + * @return The sub-tile X coordinate. + */ public float getSubTileX() { return this.subTileX; } + + /** + * Gets the entity's sub-tile Y offset. + * + * @return The sub-tile Y coordinate. + */ public float getSubTileY() { return this.subTileY; } + + /** + * Gets the radius of the entity. + * + * @return The collision radius. + */ public double getRadius() { return this.radius; } + + /** + * Gets the full X coordinate, including sub-tile offset. + * + * @return The entity's X position as a double. + */ public double getPositionX() { return position.x() + subTileX; } + + /** + * Gets the full Y coordinate, including sub-tile offset. + * + * @return The entity's Y position as a double. + */ public double getPositionY() { return position.y() + subTileY; } + + /* Setters */ + /** + * Sets the entity's tile-based position. + * + * @param newPos The new tile position to set. + */ public void setPosition(Position newPos) { this.position = newPos; } + + /** + * Sets the entity's sub-tile X offset. + * + * @param newX The new sub-tile X coordinate. + */ public void setSubTileX(float newX) { this.subTileX = newX; } + + /** + * Sets the entity's sub-tile Y offset. + * + * @param newY The new sub-tile Y coordinate. + */ public void setSubTileY(float newY) { this.subTileY = newY; } + + /** + * Sets the entity's collision radius. + * + * @param newRad The new radius value. + */ public void setRadius(double newRad) { this.radius = newRad; } } diff --git a/pacman/model/src/main/java/com/gr15/pacman/model/entities/EntityUtils.java b/pacman/model/src/main/java/com/gr15/pacman/model/entities/EntityUtils.java index fd52acb..355a6f4 100644 --- a/pacman/model/src/main/java/com/gr15/pacman/model/entities/EntityUtils.java +++ b/pacman/model/src/main/java/com/gr15/pacman/model/entities/EntityUtils.java @@ -1,11 +1,29 @@ package com.gr15.pacman.model.entities; /** - * Util + * Utility class providing helper methods + * for working with {@link Entity} objects. + * + * <p> + * This class includes methods for calculating distances + * and detecting collisions + * between entities in the game world, + * taking into account their sub-tile positions and radii. + * </p> + * + * <p>This class is final and cannot be instantiated.</p> */ + public final class EntityUtils { - + /** + * Calculates the Euclidean distance between + * two entities based on their position and sub-tile offsets. + * + * @param arg0 the first entity. + * @param arg1 the second entity. + * @return the distance between the centers of the two entities. + */ public static double distance(Entity arg0, Entity arg1) { double arg0X = arg0.getPosition().x() + arg0.getSubTileX(); double arg0Y = arg0.getPosition().y() + arg0.getSubTileY(); @@ -15,6 +33,14 @@ public final class EntityUtils { return Math.hypot(arg0X - arg1X, arg0Y - arg1Y); } + /** + * Determines whether two entities have collided + * based on the distance between their centers and their combined radii. + * + * @param arg0 the first entity. + * @param arg1 the second entity. + * @return true if the entities have collided; false otherwise. + */ public static boolean hasCollided(Entity arg0, Entity arg1) { double arg0X = arg0.getPosition().x() + arg0.getSubTileX(); double arg0Y = arg0.getPosition().y() + arg0.getSubTileY(); diff --git a/pacman/model/src/main/java/com/gr15/pacman/model/entities/Items.java b/pacman/model/src/main/java/com/gr15/pacman/model/entities/Items.java index 3b09a54..d4ecc13 100644 --- a/pacman/model/src/main/java/com/gr15/pacman/model/entities/Items.java +++ b/pacman/model/src/main/java/com/gr15/pacman/model/entities/Items.java @@ -1,3 +1,17 @@ package com.gr15.pacman.model.entities; -public enum Items { PELLET, POWER_PELLET }; +/** + * Represents the different types of items that can appear in the game. + */ +public enum Items { + + /** + * A standard pellet. + */ + PELLET, + + /** + * A power pellet. + */ + POWER_PELLET +}; |