Commit 24aecff2 authored by Elena Berrios's avatar Elena Berrios
Browse files

Prevent player movement while switching activities

parent 50866840
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback {
    Bitmap background;
    private final Joystick joystick;
    private final Player player;
    public static boolean canMove;
    private final Detector detector1;
    private final Detector detector2;

@@ -42,7 +43,7 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback {
        surfaceHolder.addCallback(this);
        // new gameloop object
        gameLoop = new GameLoop(this, surfaceHolder);

        canMove = true;

        // check screen height and width
        int height = getScreenHeight();
@@ -166,11 +167,13 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback {
        detector2.update();
        // Check for collision with detectors
        if (Circle.isColliding(player, detector1)) {
            canMove = false;
            // call method to start quiz activity
            startSecondActivity();
            Log.d("COLLISION", "DETECTOR");
        }
        if (Circle.isColliding(player, detector2)) {
            canMove = false;
            // call method to start chalk activity
            startChalkActivity();
            Log.d("COLLISION", "DETECTOR");
+5 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import android.util.Log;

import androidx.core.content.ContextCompat;

import com.example.game2d.Game;
import com.example.game2d.GameLoop;
import com.example.game2d.Joystick;
import com.example.game2d.R;
@@ -97,6 +98,10 @@ public class Player extends Circle {
            positionY = (int) (height * 0.3);
        }

        if (!Game.canMove) {
            velocityX = 0;
            velocityY = 0;
        }
        // update position
        positionX += velocityX;
        positionY += velocityY;