Commit fb62d6aa authored by Elena Berrios's avatar Elena Berrios
Browse files

Documentation for Detector class

parent 1c885ce8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -174,6 +174,7 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback {
        detector2.update();
        detector3.update();
        detector4.update();

        // Check for collision with detectors
        if (Circle.isColliding(player, detector1)) {
            if (canMove) {
+3 −3
Original line number Diff line number Diff line
@@ -16,9 +16,9 @@ public abstract class Circle extends GameObject{
    /** Constructs a circle that can be drawn to the screen.
     * @param context the current context
     * @param color the color of the drawn circle, defined in the res/values/colors.xml file
     * @param positionX an x-coordinate for the center of the circle
     * @param positionY a y-coordinate for the center of the circle
     * @param radius the radius (in pixels) of the circle
     * @param positionX an x-coordinate for the circle's center
     * @param positionY a y-coordinate for the circle's center
     * @param radius the circle's radius (in pixels)
     * @return the newly constructed Circle object
     */
    public Circle(Context context, int color, float positionX, float positionY, double radius) {
+23 −1
Original line number Diff line number Diff line
@@ -7,14 +7,31 @@ import androidx.core.content.ContextCompat;

import com.example.game2d.R;

/**
 * Detector is a circle that is not drawn to the screen. It is used to detect collisions with the
 * player.
 */
public class Detector extends Circle {
    private final Player player;

    /**
     * Constructs a detector with the specified position and radius.
     * @param context the current context
     * @param player the player object to detect collisions with
     * @param positionX the x-coordinate for the circle's center
     * @param positionY the y-coordinate for the circle's center
     * @param radius the circle's radius (in pixels)
     * @return the newly constructed Detector object
     */
    public Detector(Context context, Player player, float positionX, float positionY, double radius) {
        super(context, ContextCompat.getColor(context, R.color.detector), positionX, positionY, radius);
        this.player = player;
    }

    /**
     * Updates the position of the detector based on its velocity.
     * Velocity is always set to zero.
     */
    public void update() {
        velocityX = 0;
        velocityY = 0;
@@ -22,6 +39,11 @@ public class Detector extends Circle {
        positionY += velocityY;
    }

    /**
     * Can draw the detector circle to the screen.
     * Uncomment to make the detector visible for testing and debugging.
     * @param canvas the canvas to which the object will be drawn
     */
    public void draw(Canvas canvas) {
        // canvas.drawCircle((float) positionX, (float) positionY, (float) radius, paint);
    }