Loading app/src/main/java/com/example/game2d/Game.java +4 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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(); Loading Loading @@ -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"); Loading app/src/main/java/com/example/game2d/object/Player.java +5 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading
app/src/main/java/com/example/game2d/Game.java +4 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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(); Loading Loading @@ -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"); Loading
app/src/main/java/com/example/game2d/object/Player.java +5 −0 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading