Initial commit

This commit is contained in:
2026-01-09 17:21:32 +00:00
parent 47d99afb55
commit 788c004e97
18699 changed files with 74041 additions and 1478326 deletions

View File

@@ -0,0 +1,36 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class CollisionHandler : MonoBehaviour
{
PlayerStats playerStats;
void Start()
{
playerStats = GetComponent<PlayerStats>();
}
void OnCollisionEnter(Collision other)
{
switch (other.gameObject.tag)
{
case "Friendly":
Debug.Log("Collided with Friendly object.");
break;
case "Finish":
playerStats.NextLevel();
break;
default:
float collisionDamage = other.gameObject.GetComponent<ObjectStats>()?.damage ?? 0;
playerStats.TakeDamage((int)collisionDamage);
break;
}
}
void OnTriggerEnter(Collider other)
{
switch (other.gameObject.tag)
{
case "Pickup":
other.gameObject.GetComponent<Pickup>()?.PickupItem(gameObject);
break;
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 27cdecd1687603540b5ee53e099781e7

View File

@@ -0,0 +1,66 @@
using UnityEngine;
using UnityEngine.InputSystem;
public class Movement : MonoBehaviour
{
[SerializeField] InputAction thrust;
[SerializeField] InputAction rotate;
[SerializeField] float thrustStrength = 10f;
[SerializeField] float rotationSpeed = 100f;
[SerializeField] float fuelConsumptionRate = 1f;
Rigidbody rb;
AudioSource audioSource;
PlayerStats playerStats;
void Start()
{
rb = GetComponent<Rigidbody>();
audioSource = GetComponent<AudioSource>();
playerStats = GetComponent<PlayerStats>();
}
void OnEnable()
{
thrust.Enable();
rotate.Enable();
}
void FixedUpdate()
{
ProcessThrust();
ProcessRotation();
}
private void ProcessThrust()
{
if (thrust.IsPressed())
{
rb.AddRelativeForce(Vector3.up * thrustStrength * Time.fixedDeltaTime);
playerStats.UseFuel(fuelConsumptionRate);
if (!audioSource.isPlaying)
{
audioSource.Play();
}
}
else
{
audioSource.Stop();
}
}
private void ProcessRotation()
{
float rotationInput = rotate.ReadValue<float>();
if(rotationInput < 0)
{
ApplyRotation(rotationSpeed);
}
else if(rotationInput > 0)
{
ApplyRotation(-rotationSpeed);
}
}
private void ApplyRotation(float rotationThisFrame)
{
rb.freezeRotation = true; // freezing rotation so we can manually rotate
transform.Rotate(Vector3.forward * rotationThisFrame * Time.fixedDeltaTime);
rb.freezeRotation = false; // unfreezing rotation so the physics system can take over
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9fa230e4809ffda47b33e5c13c4c4ed9

View File

@@ -0,0 +1,27 @@
using UnityEngine;
public class ObjectStats : MonoBehaviour
{
float curHealth = 100;
[SerializeField] float maxHealth = 100;
public float damage = 25f;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
curHealth = maxHealth;
}
// Update is called once per frame
void Update()
{
}
public void TakeDamage()
{
curHealth -= damage;
if (curHealth <= 0)
{
Destroy(gameObject);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 91a302ff8e3d8a24b89e234026b39ef7

36
Assets/Scripts/Pickup.cs Normal file
View File

@@ -0,0 +1,36 @@
using UnityEngine;
public class Pickup : MonoBehaviour
{
[SerializeField] enum PickupType { Health, Fuel, Time, Bomb }
[SerializeField] PickupType pickupType;
[SerializeField] float amount = 25f;
void Update()
{
SpinObject();
}
public void PickupItem(GameObject player)
{
PlayerStats playerStats = player.GetComponent<PlayerStats>();
switch (pickupType)
{
case PickupType.Health:
playerStats.TakeDamage(- (int)amount);
break;
case PickupType.Fuel:
playerStats.UseFuel(-amount);
break;
case PickupType.Time:
playerStats.AddTime(amount);
break;
case PickupType.Bomb:
playerStats.TakeDamage((int)amount);
break;
}
Destroy(gameObject);
}
void SpinObject()
{
transform.Rotate(new Vector3(0, 50, 0) * Time.deltaTime);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 4ddc8d509c2bc6b40bfa513ffc21dd46

View File

@@ -0,0 +1,90 @@
using UnityEngine;
using TMPro;
using UnityEngine.SceneManagement;
public class PlayerStats : MonoBehaviour
{
float curHealth;
[SerializeField] float maxHealth = 100;
float curFuel;
[SerializeField] float maxFuel = 100;
float curTime;
[SerializeField] float timeLimit = 300; // in seconds
[SerializeField] TextMeshProUGUI healthText, fuelText, timeText;
void Start()
{
curHealth = maxHealth;
curFuel = maxFuel;
curTime = timeLimit;
healthText.text = "Health: " + curHealth.ToString("F0");
fuelText.text = "Fuel: " + curFuel.ToString("F0");
timeText.text = "Time: " + timeLimit.ToString("F0");
}
void Update()
{
if (curTime > 0)
{
curTime -= 1 * Time.deltaTime;
int minutes = Mathf.FloorToInt(curTime / 60F);
int seconds = Mathf.FloorToInt(curTime - minutes * 60);
timeText.text = string.Format("{0:0}:{1:00}", minutes, seconds);
}
else
{
curTime = 0;
Destroy(gameObject);
ReloadLevel();
}
}
public void TakeDamage(int damage)
{
curHealth -= damage;
healthText.text = "Health: " + curHealth.ToString("F0");
if (curHealth <= 0)
{
curHealth = 0;
Destroy(gameObject);
ReloadLevel();
}
}
public void UseFuel(float amount)
{
curFuel -= amount;
fuelText.text = "Fuel: " + curFuel.ToString("F0");
if (curFuel <= 0)
{
curFuel = 0;
Destroy(gameObject);
ReloadLevel();
}
}
public void StopTime()
{
curTime = 0;
timeText.text = "0:00";
}
public void AddTime(float amount)
{
curTime += amount;
int minutes = Mathf.FloorToInt(curTime / 60F);
int seconds = Mathf.FloorToInt(curTime - minutes * 60);
timeText.text = string.Format("{0:0}:{1:00}", minutes, seconds);
}
void ReloadLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
SceneManager.LoadScene(currentSceneIndex);
}
public void NextLevel()
{
int currentSceneIndex = SceneManager.GetActiveScene().buildIndex;
int nextSceneIndex = currentSceneIndex + 1;
if (nextSceneIndex == SceneManager.sceneCountInBuildSettings)
{
nextSceneIndex = 0;
}
SceneManager.LoadScene(nextSceneIndex);
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: abf3cce9d8531084a8e8a5c86d2477f5