Added current project progress

This commit is contained in:
Trianta
2024-02-08 03:30:36 -06:00
parent 7dba45a259
commit c490c692aa
61 changed files with 5271 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Apple : MonoBehaviour
{
[Header("Set in Inspector")]
public static float bottomY = -20f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (transform.position.y < bottomY) {
Destroy(this.gameObject);
// Get a reference to the ApplePicker component of Main Camera
ApplePicker apScript = Camera.main.GetComponent<ApplePicker>();
// Call the public AppleDestroyed() method of apScript
apScript.AppleDestroyed();
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fa52df772d8d6bc38bc91e810b058232
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+63
View File
@@ -0,0 +1,63 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class ApplePicker : MonoBehaviour
{
[Header("Set in Inspector")]
public GameObject basketPrefab;
public int numBaskets = 3;
public float basketBottomY = -14f;
public float basketSpacingY = 2f;
public List<GameObject> basketList;
public Text roundGT;
// Start is called before the first frame update
void Start()
{
basketList = new List<GameObject>();
for (int i = 0; i < numBaskets; i++) {
GameObject tBasketGO = Instantiate<GameObject>(basketPrefab);
Vector3 pos = Vector3.zero;
pos.y = basketBottomY + (basketSpacingY * i);
tBasketGO.transform.position = pos;
basketList.Add(tBasketGO);
}
GameObject roundGO = GameObject.Find("RoundCounter");
roundGT = roundGO.GetComponent<Text>();
roundGT.text = "Round 1";
}
public void AppleDestroyed() {
// Destroy all of the falling apples
GameObject[] tAppleArray = GameObject.FindGameObjectsWithTag("Apple");
foreach (GameObject tGO in tAppleArray) {
Destroy(tGO);
}
// Destroy one of the baskets
// Get the index of the last Basket in basketList
int basketIndex = basketList.Count-1;
// Get a reference to that Basket GameObject
GameObject tBasketGO = basketList[basketIndex];
// Remove the Basket from the list and destroy the GameObject
basketList.RemoveAt(basketIndex);
Destroy(tBasketGO);
roundGT.text = "Round ";
roundGT.text += numBaskets - basketList.Count + 1;
// If there are no Baskets left, restart the game
if (basketList.Count == 0) {
roundGT.text = "Game Over";
SceneManager.LoadScene("_Scene_0");
}
}
// Update is called once per frame
void Update()
{
}
}
+12
View File
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fd8e7d68c03498908bbdec32bd6e4497
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- basketPrefab: {fileID: 5900264663031569433, guid: 7d297b7104ffaa61aa6abd9e6a593169, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+53
View File
@@ -0,0 +1,53 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AppleTree : MonoBehaviour
{
[Header("Set in Inspector")]
// Prefab for instantiating apples
public GameObject applePrefab;
// Speed at which the AppleTree moves
public float speed = 1f;
// Distance where AppleTree turns around
public float leftAndRightEdge = 10f;
// Chance that the AppleTree will change directions
public float chanceToChangeDirections = 0.1f;
// Rate at which Apples will be instantiated
public float secondsBetweenAppleDrops = 1f;
// Start is called before the first frame update
void Start()
{
// Dropping apples every second
Invoke("DropApple", 2f);
}
void DropApple() {
GameObject apple = Instantiate<GameObject>(applePrefab);
apple.transform.position = transform.position;
Invoke("DropApple", secondsBetweenAppleDrops);
}
// Update is called once per frame
void Update()
{
// Basic Movement
Vector3 pos = transform.position;
pos.x += speed * Time.deltaTime;
transform.position = pos;
// Changing Direction
if (pos.x < -leftAndRightEdge) {
speed = Mathf.Abs(speed);
} else if (pos.x > leftAndRightEdge) {
speed = -Mathf.Abs(speed);
}
}
// Update exactly 50 times per second
void FixedUpdate()
{
if (Random.value < chanceToChangeDirections) {
speed *= -1;
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d78fc739164ede72fa99b385bff2f749
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+53
View File
@@ -0,0 +1,53 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Basket : MonoBehaviour
{
[Header("Set Dynamically")]
public Text scoreGT;
// Start is called before the first frame update
void Start()
{
// Find a reference to the ScoreCounter GameObject
GameObject scoreGO = GameObject.Find("ScoreCounter");
// Get the Text Component of that GameObject
scoreGT = scoreGO.GetComponent<Text>();
// Set the starting number of points to 0
scoreGT.text = "0";
}
// Update is called once per frame
void Update()
{
// Get the current screen position of the mouse from Input
Vector3 mousePos2D = Input.mousePosition;
// The Camera's z position sets how far to push the mouse into 3D
mousePos2D.z = -Camera.main.transform.position.z;
// Convert the point from 2D screen space into 3D game world space
Vector3 mousePos3D = Camera.main.ScreenToWorldPoint(mousePos2D);
// Move the x position of this Basket to the x position of the Mouse
Vector3 pos = this.transform.position;
pos.x = mousePos3D.x;
this.transform.position = pos;
}
void OnCollisionEnter(Collision coll) {
// Find out what hit this basket
GameObject collidedWith = coll.gameObject;
if (collidedWith.tag == "Apple") {
Destroy(collidedWith);
// Parse the text of the scoreGT into an int
int score = int.Parse(scoreGT.text);
// Add points for catching the apple
score += 100;
// Convert the score back to a string and display it
scoreGT.text = score.ToString();
// Track the high score
if (score > HighScore.score) {
HighScore.score = score;
}
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 13b9927c3bf2b7d329a777e6a35c246a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+35
View File
@@ -0,0 +1,35 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HighScore : MonoBehaviour
{
static public int score = 1000;
// Start is called before the first frame update
void Start()
{
}
void Awake() {
// If the PlayerPrefs HighScore already exists, read it
if (PlayerPrefs.HasKey("HighScore")) {
score = PlayerPrefs.GetInt("HighScore");
}
// Assign the high score to HighScore
PlayerPrefs.SetInt("HighScore", score);
}
// Update is called once per frame
void Update()
{
Text gt = this.GetComponent<Text>();
gt.text = "High Score: " + score;
// Update the PlayerPrefs HighScore if necessary
if (score > PlayerPrefs.GetInt("HighScore")) {
PlayerPrefs.SetInt("HighScore", score);
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d6e8f266c1c0b32969649d60c1b40eee
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: