Commit 6c63753d authored by Ethan Liang's avatar Ethan Liang
Browse files

Merge remote-tracking branch 'origin/top-secret' into top-secret

# Conflicts:
#	app/src/main/AndroidManifest.xml
#	app/src/main/java/com/example/game2d/ChalkActivity.java
parents dd799e4d 39585bef
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="RenderSettings">
    <option name="showDecorations" value="true" />
  </component>
</project>
 No newline at end of file
+39 −25
Original line number Diff line number Diff line
@@ -5,11 +5,8 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.media.MediaPlayer;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;

@@ -43,6 +40,9 @@ public class ChalkGameClass extends View {
    //HEALTH SYSTEM
    private Bitmap lives[] = new Bitmap[2];
        private int lifecounter;
        private int lifeXstart;
        private int lifeY;


    private Bitmap pauseButton;
        private int pauseX = 1700;
@@ -58,11 +58,9 @@ public class ChalkGameClass extends View {
    public ChalkGameClass(Context context)
    {
        super(context);
        player[0] = BitmapFactory.decodeResource(getResources(), R.drawable.girl);
        player[1] = BitmapFactory.decodeResource(getResources(), R.drawable.girl_jump_big);

        ranGravity = (int) Math.floor(Math.random() * 5) + 1; //ranGravity is a random integer between 1 and 5
        Log.d("gravVal", Integer.toString(ranGravity));


        if(ranGravity%2 ==1)
            normGravity = true; //if ranGravity is odd, normal gravity is used where you jump up but rest at the bottom
@@ -70,13 +68,29 @@ public class ChalkGameClass extends View {
            normGravity = false; //if ranGravity is even, abnormal gravity is used where you jump down but rest at the top


        if(normGravity)
        if(normGravity) {
            playerY = 650; //make the player rest at the bottom if normal gravity
        else
            player[0] = BitmapFactory.decodeResource(getResources(), R.drawable.girl);
            player[1] = BitmapFactory.decodeResource(getResources(), R.drawable.girl_jump_big);
            backgroundImage= BitmapFactory.decodeResource(getResources(), R.drawable.background_normal);
            lives[0] = BitmapFactory.decodeResource(getResources(), R.drawable.hearts);
            lives[1] = BitmapFactory.decodeResource(getResources(), R.drawable.heart_grey);
            lifeY = 20;

        }
        else {
            playerY = 0; //make the player rest at the top if abnormal gravity
            player[0] = BitmapFactory.decodeResource(getResources(), R.drawable.girl_upsidedown);
            player[1] = BitmapFactory.decodeResource(getResources(), R.drawable.girl_jump_big_upsidedown);
            backgroundImage = BitmapFactory.decodeResource(getResources(), R.drawable.background_upsidedown);
            lives[0] = BitmapFactory.decodeResource(getResources(), R.drawable.hearts_upsidedown);
            lives[1] = BitmapFactory.decodeResource(getResources(), R.drawable.heart_grey_upsidedown);
            lifeY = 1060;
        }

        jumpcount = 0;
        backgroundImage = BitmapFactory.decodeResource(getResources(), R.drawable.background);
        lifeXstart = 1330;


        //Initializing the chalk array
        chalk[0] = BitmapFactory.decodeResource(getResources(), R.drawable.green_chalk);
@@ -86,8 +100,6 @@ public class ChalkGameClass extends View {
        chalk[4] = BitmapFactory.decodeResource(getResources(), R.drawable.blue_chalk);
        chalkPassed = 0;

        lives[0] = BitmapFactory.decodeResource(getResources(), R.drawable.hearts);
        lives[1] = BitmapFactory.decodeResource(getResources(), R.drawable.heart_grey);
        lifecounter = 3;

        pauseButton = BitmapFactory.decodeResource(getResources(), R.drawable.pause_new);
@@ -109,10 +121,10 @@ public class ChalkGameClass extends View {
        // allocation in onDraw.
        Matrix matrix = new Matrix();

        matrix = StretchMatrix(matrix, canvasWidth, canvasHeight, backgroundImage);

        canvas.drawBitmap(backgroundImage, matrix, null);

        matrix = StretchMatrix(matrix, canvasWidth, canvasHeight, backgroundImage);

        int minplayerY = 0;
        int floorHeight = 80;
        int maxplayerY = canvasHeight - player[0].getHeight() - floorHeight;
@@ -121,7 +133,7 @@ public class ChalkGameClass extends View {
        if(normGravity)
            playerY= playerY + playerSpeed; //makes character jump up and naturally fall down
        else
            playerY = playerY - playerSpeed; //makes character jump down and naturally float up
            playerY = playerY - 2* playerSpeed; //makes character jump down and naturally float up

        if (playerY < minplayerY) {
            playerY = minplayerY;
@@ -166,15 +178,14 @@ public class ChalkGameClass extends View {

                if(lifecounter == 0)  //if all lives used up
                {
                    Intent mainIntent = new Intent(getContext(), MainActivity.class);
                    mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    getContext().startActivity(mainIntent);
                    Intent RIPIntent = new Intent(getContext(), ChalkGameRIPActivity.class);
                    RIPIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    getContext().startActivity(RIPIntent);

                }
            }
            chalkX[ii] = chalkX[ii] - chalkXSpeed; //making the chalk move across the screen


            chalkX[ii] = chalkX[ii] - chalkXSpeed; //making the chalk move across the screen from right to left
            if (chalkX[ii] < 0)
            {
                chalkPassed++;
@@ -184,11 +195,12 @@ public class ChalkGameClass extends View {
                chalkY[ii] = (int) Math.floor(Math.random() * ((maxplayerY + player[0].getHeight()) - chalk[0].getHeight())) + chalk[0].getHeight(); //making the chalk appear at random  heights
            }


            if(chalkPassed == chalkNum * 3)
            {
                chalkX[ii] = chalkX[ii] - 200;
                chalkPassed = 0;
                Intent chalkQuestionIntent  = new Intent(getContext(), ChalkActivity.class);
                Intent chalkQuestionIntent  = new Intent(getContext(), ChalkToQuizActivity.class);
                chalkQuestionIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                getContext().startActivity(chalkQuestionIntent);
            }
@@ -197,7 +209,7 @@ public class ChalkGameClass extends View {
            {
                chalkCol-= 5;
            }
            //chalkY[ii] = chalkY[ii] - chalkYSpeed; //gravity

            canvas.drawBitmap(chalk[chalkCol], chalkX[ii], chalkY[ii],  null);
        }

@@ -205,8 +217,8 @@ public class ChalkGameClass extends View {

        for(int ii = 0; ii < 3; ii++)
        {
            int lifeX = (int) (1330 + lives[0].getWidth() * 1.5 * ii);
            int lifeY = 20;
            int lifeX = (int) (lifeXstart + lives[0].getWidth() * 1.5 * ii);


            if(ii < lifecounter)
            {
@@ -247,6 +259,8 @@ public class ChalkGameClass extends View {

       return fnMatrix;
    }


    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
+26 −0
Original line number Diff line number Diff line
package com.example.game2d;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class ChalkGameRIPActivity extends AppCompatActivity {
    private Button resButton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chalk_game_ripactivity);
        resButton = findViewById(R.id.ChalkRIPResume);
        resButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent ChalkRIPtrns = new Intent(ChalkGameRIPActivity.this,ChalkGameActivity.class);
                ChalkRIPtrns.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                startActivity(ChalkRIPtrns);
            }
        });
    }
}
 No newline at end of file
+28 −0
Original line number Diff line number Diff line
package com.example.game2d;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class ChalkToQuizActivity extends AppCompatActivity {
    private Button resButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chalk_to_quiz);
        resButton = findViewById(R.id.ChalktoQuizResume);

        resButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent Quiztrns = new Intent(ChalkToQuizActivity.this,ChalkActivity.class);
                Quiztrns.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                startActivity(Quiztrns);
            }
        });
    }
}
 No newline at end of file
+16 −6
Original line number Diff line number Diff line
@@ -46,12 +46,13 @@ public class FirebaseActivity extends AppCompatActivity {
    TextView nameScore, chalkScore;

    //public Map<String, Object> userScoreMap;
    public Map<String, Long> big_userScoreMap = new HashMap<>();
    //public Map<String, Long> big_userScoreMap = new HashMap<>();
    Scoreboard big_userScoreMap = new Scoreboard();

    int bestChalk;
    float percent;

    String username = "temp userame";
    String username = "scrub mommy";


    //access the average accuracy data from nameResultActivity (does not work)
@@ -108,7 +109,9 @@ public class FirebaseActivity extends AppCompatActivity {
            public void onClick(View view) {
                // switch back to main activity
                Intent intent = new Intent(FirebaseActivity.this, LeaderboardActivity.class);
                intent.putExtra("scoreboard_object", big_userScoreMap);
                startActivity(intent);

            }
        });
        //---------------------------------------------------------------------------------
@@ -126,7 +129,7 @@ public class FirebaseActivity extends AppCompatActivity {
        //db.collection("users").document("new33").set(user2);


        String userId = "e9kSCVavuhpXiIGNMkAh";
        String userId = "e9kSCVavuhpXiIGNMkAhhh";
        DocumentReference userRef = db.collection("leaderboard").document(userId);
        userRef.set(user2, SetOptions.merge());

@@ -147,6 +150,9 @@ public class FirebaseActivity extends AppCompatActivity {
                            for (QueryDocumentSnapshot document : task.getResult()) {
                                Map<String, Object> userScoreMap = document.getData();
                                Log.d(TAG, "ID: "+document.getId());
                                String name = (String) userScoreMap.get("username");
                                Double scores = (Double) userScoreMap.get("score");
                                /*
                                for (Map.Entry<String, Object> entry : userScoreMap.entrySet()) {
                                    //String user = entry.getKey();
                                    Object scoreObj = entry.getValue(); //this is the score value
@@ -154,15 +160,19 @@ public class FirebaseActivity extends AppCompatActivity {
                                    if (scoreObj instanceof Long) { //if it's the score_value
                                        score = (Long) scoreObj;
                                        //big_userScoreMap.put(document.getId(),score);
                                        Log.d(TAG,"BIG size : "+ big_userScoreMap.size());
                                        //Log.d(TAG,"BIG size : "+ big_userScoreMap.size());
                                        //Log.d(TAG, "User: " + user + ", Score: " + score);
                                    }
                                    else { //else it's the username
                                        Log.d(TAG,"the username: "+scoreObj.toString());
                                    }
                                    big_userScoreMap.put(scoreObj.toString(),score); // add <username,score> into the big
                                    big_userScoreMap.scoreboard.put(scoreObj.toString(), score);
                            }
                                 */
                                big_userScoreMap.scoreboard.put(name, scores);

                            }

                        } else {
                            Log.w(TAG, "Error getting documents.", task.getException());
                        }
Loading