Loading app/src/main/java/com/example/game2d/ChalkGameClass.java +18 −7 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ public class ChalkGameClass extends View { private boolean normGravity; private int playerX = 10; private int playerY; private int minplayerY; private int maxplayerY; private int playerSpeed; private boolean touch = false; private int jumpcount; Loading Loading @@ -80,8 +82,8 @@ public class ChalkGameClass extends View { selectedShortHair = preferences.getBoolean("shortHairSelection", false); chalkIndex = preferences.getInt("ChalkQuestionIndex", 0); ranGravity = (int) Math.floor(Math.random() * 5) + 1; //ranGravity is a random integer between 1 and 5 // ranGravity = (int) Math.floor(Math.random() * 5) + 1; //ranGravity is a random integer between 1 and 5 ranGravity = 2; if(ranGravity%2 ==1) normGravity = true; //if ranGravity is odd, normal gravity is used where you jump up but rest at the bottom else Loading Loading @@ -117,7 +119,7 @@ public class ChalkGameClass extends View { player[0] = BitmapFactory.decodeResource(getResources(), R.drawable.boy_idle_upsidedown); player[1] = BitmapFactory.decodeResource(getResources(), R.drawable.boy_jump_upsidedown); } backgroundImage = BitmapFactory.decodeResource(getResources(), R.drawable.background_upsidedown); backgroundImage = BitmapFactory.decodeResource(getResources(), R.drawable.unspide_down); lives[0] = BitmapFactory.decodeResource(getResources(), R.drawable.hearts_upsidedown); lives[1] = BitmapFactory.decodeResource(getResources(), R.drawable.heart_grey_upsidedown); } Loading Loading @@ -160,13 +162,20 @@ public class ChalkGameClass extends View { Matrix matrix = new Matrix(); canvas.drawBitmap(backgroundImage, matrix, null); int floorHeight = 70; matrix = StretchMatrix(matrix, canvasWidth, canvasHeight, backgroundImage); if (normGravity) { minplayerY = 0; int minplayerY = 0; int floorHeight = 80; int maxplayerY = canvasHeight - player[0].getHeight() - floorHeight; maxplayerY = canvasHeight - player[1].getHeight() - floorHeight; } else { minplayerY = 0 + floorHeight; maxplayerY = canvasHeight - player[1].getHeight(); } //PLAYER MECHANICS if(normGravity) playerY = playerY + playerSpeed; //makes character jump up and naturally fall down Loading Loading @@ -243,6 +252,7 @@ public class ChalkGameClass extends View { if(chalkIndex!=4) { bossMusic.stop(); Intent returnQuiz = new Intent(getContext(), ChalkToQuizActivity.class); returnQuiz.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); getContext().startActivity(returnQuiz); Loading @@ -257,6 +267,7 @@ public class ChalkGameClass extends View { } } bossMusic.start(); chalkCol = ii; while(chalkCol > 4) //keeping chalkCol between 0 and 4; { Loading app/src/main/java/com/example/game2d/Game.java +15 −4 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback { public static boolean canMove; private final Detector detector1; private final Detector detector2; private final Detector detector3; private GameLoop gameLoop; private Context gameContext; Loading Loading @@ -69,6 +70,7 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback { // initialize new detectors detector1 = new Detector(getContext(), player, (float) (width * 0.25), (float) (height * 0.17), 100); detector2 = new Detector(getContext(), player, (float) (width * 0.47), (float) (height * 0.17), 100); detector3 = new Detector(getContext(), player, (float) (width * 0.75), (float) (height * 0.17), 100); // copy other developers lol setFocusable(true); Loading Loading @@ -134,6 +136,7 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback { // draw single detectors detector1.draw(canvas); detector2.draw(canvas); detector3.draw(canvas); } // method to display how many updates per second (UPS) public void drawUPS(Canvas canvas) { Loading Loading @@ -166,13 +169,13 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback { player.update(); detector1.update(); detector2.update(); detector3.update(); // Check for collision with detectors if (Circle.isColliding(player, detector1)) { if (canMove) { // call method to start quiz activity startSecondActivity(); } Log.d("COLLISION", "DETECTOR"); canMove = false; } if (Circle.isColliding(player, detector2)) { Loading @@ -180,7 +183,13 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback { // call method to start chalk activity startChalkActivity(); } Log.d("COLLISION", "DETECTOR"); canMove = false; } if (Circle.isColliding(player, detector3)) { if (canMove) { // call method to start leaderboard activity startLeaderboardActivity(); } canMove = false; } } Loading @@ -197,12 +206,14 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback { public void startSecondActivity() { Intent intent = new Intent(gameContext, NameIntroActivity.class); gameContext.startActivity(intent); Log.d("COLLISION", "Starting name activity"); } // method to start chalk activity public void startChalkActivity() { Intent intent = new Intent(gameContext, ChalkIntroActivity.class); gameContext.startActivity(intent); Log.d("COLLISION", "Starting chalk activity"); } public void startLeaderboardActivity() { Intent intent = new Intent(gameContext, FirebaseActivity.class); gameContext.startActivity(intent); } } app/src/main/java/com/example/game2d/LeaderboardActivity.java +2 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ public class LeaderboardActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_leaderboard); Log.d("LEADERBOARD", "Leaderboard activity"); Window window = getWindow(); window.setFlags( Loading Loading @@ -77,6 +78,7 @@ public class LeaderboardActivity extends AppCompatActivity { // Sort map by values (descending scores) HashMap<String, Integer> sortedScoreMap = new HashMap<String, Integer>(); sortedScoreMap = (HashMap<String, Integer>) sortByValue(scoreMap); scoreboardObj.scoreboard = sortByValue(scoreboardObj.scoreboard); int ranking = 0; for (String username : scoreboardObj.scoreboard.keySet()) { Loading app/src/main/java/com/example/game2d/QuizToChalkActivity.java +1 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ public class QuizToChalkActivity extends AppCompatActivity { @Override public void onClick(View view) { Intent Chalktrns = new Intent(QuizToChalkActivity.this,ChalkGameActivity.class); Chalktrns.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_CLEAR_TASK); Chalktrns.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(Chalktrns); } }); Loading app/src/main/res/drawable/art_enlarged.png 0 → 100644 +2.92 KiB Loading image diff... Loading
app/src/main/java/com/example/game2d/ChalkGameClass.java +18 −7 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ public class ChalkGameClass extends View { private boolean normGravity; private int playerX = 10; private int playerY; private int minplayerY; private int maxplayerY; private int playerSpeed; private boolean touch = false; private int jumpcount; Loading Loading @@ -80,8 +82,8 @@ public class ChalkGameClass extends View { selectedShortHair = preferences.getBoolean("shortHairSelection", false); chalkIndex = preferences.getInt("ChalkQuestionIndex", 0); ranGravity = (int) Math.floor(Math.random() * 5) + 1; //ranGravity is a random integer between 1 and 5 // ranGravity = (int) Math.floor(Math.random() * 5) + 1; //ranGravity is a random integer between 1 and 5 ranGravity = 2; if(ranGravity%2 ==1) normGravity = true; //if ranGravity is odd, normal gravity is used where you jump up but rest at the bottom else Loading Loading @@ -117,7 +119,7 @@ public class ChalkGameClass extends View { player[0] = BitmapFactory.decodeResource(getResources(), R.drawable.boy_idle_upsidedown); player[1] = BitmapFactory.decodeResource(getResources(), R.drawable.boy_jump_upsidedown); } backgroundImage = BitmapFactory.decodeResource(getResources(), R.drawable.background_upsidedown); backgroundImage = BitmapFactory.decodeResource(getResources(), R.drawable.unspide_down); lives[0] = BitmapFactory.decodeResource(getResources(), R.drawable.hearts_upsidedown); lives[1] = BitmapFactory.decodeResource(getResources(), R.drawable.heart_grey_upsidedown); } Loading Loading @@ -160,13 +162,20 @@ public class ChalkGameClass extends View { Matrix matrix = new Matrix(); canvas.drawBitmap(backgroundImage, matrix, null); int floorHeight = 70; matrix = StretchMatrix(matrix, canvasWidth, canvasHeight, backgroundImage); if (normGravity) { minplayerY = 0; int minplayerY = 0; int floorHeight = 80; int maxplayerY = canvasHeight - player[0].getHeight() - floorHeight; maxplayerY = canvasHeight - player[1].getHeight() - floorHeight; } else { minplayerY = 0 + floorHeight; maxplayerY = canvasHeight - player[1].getHeight(); } //PLAYER MECHANICS if(normGravity) playerY = playerY + playerSpeed; //makes character jump up and naturally fall down Loading Loading @@ -243,6 +252,7 @@ public class ChalkGameClass extends View { if(chalkIndex!=4) { bossMusic.stop(); Intent returnQuiz = new Intent(getContext(), ChalkToQuizActivity.class); returnQuiz.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); getContext().startActivity(returnQuiz); Loading @@ -257,6 +267,7 @@ public class ChalkGameClass extends View { } } bossMusic.start(); chalkCol = ii; while(chalkCol > 4) //keeping chalkCol between 0 and 4; { Loading
app/src/main/java/com/example/game2d/Game.java +15 −4 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback { public static boolean canMove; private final Detector detector1; private final Detector detector2; private final Detector detector3; private GameLoop gameLoop; private Context gameContext; Loading Loading @@ -69,6 +70,7 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback { // initialize new detectors detector1 = new Detector(getContext(), player, (float) (width * 0.25), (float) (height * 0.17), 100); detector2 = new Detector(getContext(), player, (float) (width * 0.47), (float) (height * 0.17), 100); detector3 = new Detector(getContext(), player, (float) (width * 0.75), (float) (height * 0.17), 100); // copy other developers lol setFocusable(true); Loading Loading @@ -134,6 +136,7 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback { // draw single detectors detector1.draw(canvas); detector2.draw(canvas); detector3.draw(canvas); } // method to display how many updates per second (UPS) public void drawUPS(Canvas canvas) { Loading Loading @@ -166,13 +169,13 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback { player.update(); detector1.update(); detector2.update(); detector3.update(); // Check for collision with detectors if (Circle.isColliding(player, detector1)) { if (canMove) { // call method to start quiz activity startSecondActivity(); } Log.d("COLLISION", "DETECTOR"); canMove = false; } if (Circle.isColliding(player, detector2)) { Loading @@ -180,7 +183,13 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback { // call method to start chalk activity startChalkActivity(); } Log.d("COLLISION", "DETECTOR"); canMove = false; } if (Circle.isColliding(player, detector3)) { if (canMove) { // call method to start leaderboard activity startLeaderboardActivity(); } canMove = false; } } Loading @@ -197,12 +206,14 @@ public class Game extends SurfaceView implements SurfaceHolder.Callback { public void startSecondActivity() { Intent intent = new Intent(gameContext, NameIntroActivity.class); gameContext.startActivity(intent); Log.d("COLLISION", "Starting name activity"); } // method to start chalk activity public void startChalkActivity() { Intent intent = new Intent(gameContext, ChalkIntroActivity.class); gameContext.startActivity(intent); Log.d("COLLISION", "Starting chalk activity"); } public void startLeaderboardActivity() { Intent intent = new Intent(gameContext, FirebaseActivity.class); gameContext.startActivity(intent); } }
app/src/main/java/com/example/game2d/LeaderboardActivity.java +2 −0 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ public class LeaderboardActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_leaderboard); Log.d("LEADERBOARD", "Leaderboard activity"); Window window = getWindow(); window.setFlags( Loading Loading @@ -77,6 +78,7 @@ public class LeaderboardActivity extends AppCompatActivity { // Sort map by values (descending scores) HashMap<String, Integer> sortedScoreMap = new HashMap<String, Integer>(); sortedScoreMap = (HashMap<String, Integer>) sortByValue(scoreMap); scoreboardObj.scoreboard = sortByValue(scoreboardObj.scoreboard); int ranking = 0; for (String username : scoreboardObj.scoreboard.keySet()) { Loading
app/src/main/java/com/example/game2d/QuizToChalkActivity.java +1 −1 Original line number Diff line number Diff line Loading @@ -28,7 +28,7 @@ public class QuizToChalkActivity extends AppCompatActivity { @Override public void onClick(View view) { Intent Chalktrns = new Intent(QuizToChalkActivity.this,ChalkGameActivity.class); Chalktrns.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_CLEAR_TASK); Chalktrns.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); startActivity(Chalktrns); } }); Loading