Loading app/src/main/java/com/example/game2d/Game.java +1 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading app/src/main/java/com/example/game2d/object/Circle.java +3 −3 Original line number Diff line number Diff line Loading @@ -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) { Loading app/src/main/java/com/example/game2d/object/Detector.java +23 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); } Loading Loading
app/src/main/java/com/example/game2d/Game.java +1 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading
app/src/main/java/com/example/game2d/object/Circle.java +3 −3 Original line number Diff line number Diff line Loading @@ -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) { Loading
app/src/main/java/com/example/game2d/object/Detector.java +23 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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); } Loading