first commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 304890e1473c6f043bddd6aedf753ed1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,11 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AnimatorDisabler : StateMachineBehaviour
|
||||
{
|
||||
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
|
||||
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
|
||||
{
|
||||
if (stateInfo.normalizedTime >= 1.0f)
|
||||
animator.enabled = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7d5bbcfccd21a24a95cf046c5166dc3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "Unity.TestTools.CodeCoverage.Sample.Asteroids",
|
||||
"references": [],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3ece71e594f242f595df589ae3414f7
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad033f3644482f24383a32bddafe2e9d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,62 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class AsteroidController : MonoBehaviour
|
||||
{
|
||||
public GameObject asteroidExplosion;
|
||||
|
||||
private int splitCount = 0;
|
||||
private Vector2 direction = Vector2.right;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
transform.rotation = Random.rotation;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(!GameManager.IsPaused)
|
||||
Move();
|
||||
}
|
||||
|
||||
public void Move()
|
||||
{
|
||||
transform.position += (Vector3) direction * Time.deltaTime / transform.localScale.x / 2.0f;
|
||||
if (Vector2.Distance(transform.position, Vector2.zero) > 20.0f)
|
||||
DestroyImmediate(gameObject);
|
||||
}
|
||||
|
||||
public void Split()
|
||||
{
|
||||
if(splitCount < 2)
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
AsteroidController asteroid = Instantiate(gameObject, transform.position, Quaternion.identity).GetComponent<AsteroidController>();
|
||||
asteroid.SetSplitCount(splitCount + 1);
|
||||
asteroid.SetDirection(new Vector2(Random.Range(-20.0f, 20.0f), Random.Range(-20.0f, 20.0f)));
|
||||
}
|
||||
GameManager.AddToScore(splitCount);
|
||||
Instantiate(asteroidExplosion, transform.position, transform.GetChild(0).rotation).transform.localScale = transform.localScale;
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
public void SetSplitCount(int value)
|
||||
{
|
||||
splitCount = value;
|
||||
transform.localScale = new Vector3(1.0f, 1.0f, 1.0f)/ (Mathf.Pow(2, splitCount));
|
||||
}
|
||||
|
||||
public int GetSplitCount()
|
||||
{
|
||||
return splitCount;
|
||||
}
|
||||
|
||||
public void SetDirection(Vector2 value)
|
||||
{
|
||||
direction = (value - (Vector2)transform.position).normalized;
|
||||
}
|
||||
|
||||
public Vector2 GetDirection()
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ffc52749732c4937a322d64623addf3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class DebrisController : MonoBehaviour
|
||||
{
|
||||
public GameObject explosionParticles;
|
||||
|
||||
public float impulse = 1.0f;
|
||||
public float debrisDuration = 0.5f;
|
||||
|
||||
private Rigidbody2D[] fragments;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (GameManager.effectsEnabled)
|
||||
{
|
||||
if (explosionParticles != null)
|
||||
{
|
||||
GameObject particles = Instantiate(explosionParticles, transform.position, Quaternion.identity);
|
||||
particles.transform.localScale = transform.localScale == Vector3.one ? transform.localScale : Vector3.one / 3.0f + transform.localScale / 2.0f;
|
||||
Destroy(particles, particles.GetComponent<ParticleSystem>().main.duration);
|
||||
}
|
||||
|
||||
fragments = GetComponentsInChildren<Rigidbody2D>();
|
||||
foreach (Rigidbody2D fragment in fragments)
|
||||
{
|
||||
fragment.AddForce((fragment.position - (Vector2)transform.position) * transform.localScale.x * impulse, ForceMode2D.Impulse);
|
||||
}
|
||||
Destroy(gameObject, debrisDuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d0340cb4fdc1a84dbc5c92daf754b55
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,143 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SpaceshipController : MonoBehaviour
|
||||
{
|
||||
public GameObject spaceshipDebris;
|
||||
public WeaponList weaponList;
|
||||
public Vector2 direction = Vector2.zero;
|
||||
|
||||
bool isColliding = false;
|
||||
|
||||
public enum Weapon
|
||||
{
|
||||
Basic,
|
||||
Laser
|
||||
}
|
||||
|
||||
public Weapon currentWeapon = Weapon.Basic;
|
||||
private GameObject weaponInstance;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!GameManager.IsPaused)
|
||||
Move();
|
||||
}
|
||||
|
||||
public void Move()
|
||||
{
|
||||
float horizontalAxis = Input.GetAxis("Horizontal");
|
||||
float verticalAxis = Input.GetAxis("Vertical");
|
||||
|
||||
if (verticalAxis > 0.0f)
|
||||
Thrust(verticalAxis);
|
||||
if (Mathf.Abs(horizontalAxis) > 0.0f)
|
||||
Turn(horizontalAxis);
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
Shoot();
|
||||
|
||||
transform.position += (Vector3)direction * Time.deltaTime * 4.0f;
|
||||
CalculatePositionOnCamera();
|
||||
}
|
||||
|
||||
public void Thrust(float power)
|
||||
{
|
||||
direction = Vector2.Lerp(direction, transform.up * power, Time.deltaTime * 4.0f);
|
||||
}
|
||||
|
||||
public void Turn(float delta)
|
||||
{
|
||||
transform.eulerAngles = new Vector3(0.0f, 0.0f, transform.eulerAngles.z - delta * 150.0f * Time.deltaTime);
|
||||
transform.GetChild(0).localEulerAngles = new Vector3(0.0f, -delta * 30.0f, 0.0f);
|
||||
}
|
||||
|
||||
public void Shoot(bool onMobile = false)
|
||||
{
|
||||
// If Weapon is Basic, the Prefabs/Weapons/Projectile prefab is instantiated
|
||||
// If Weapon is Laser, the Prefabs/Weapons/Laser prefab is instantiated
|
||||
|
||||
switch (currentWeapon)
|
||||
{
|
||||
case Weapon.Basic:
|
||||
ProjectileController projectile = Instantiate(weaponList.weapons[(int)currentWeapon].weaponPrefab, transform.position, Quaternion.identity).GetComponent<ProjectileController>();
|
||||
projectile.SetDirection(transform.up);
|
||||
break;
|
||||
case Weapon.Laser:
|
||||
if (weaponInstance != null)
|
||||
break;
|
||||
weaponInstance = Instantiate(weaponList.weapons[(int)currentWeapon].weaponPrefab, transform.position, Quaternion.identity);
|
||||
weaponInstance.transform.up = transform.up;
|
||||
weaponInstance.transform.parent = transform;
|
||||
break;
|
||||
default:
|
||||
Debug.LogError("Invalid weapon state.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
// Preventing multiple collision triggers on the same frame
|
||||
if (isColliding)
|
||||
return;
|
||||
|
||||
AsteroidController asteroidController = collision.gameObject.GetComponent<AsteroidController>();
|
||||
|
||||
if (asteroidController)
|
||||
{
|
||||
asteroidController.Split();
|
||||
if(GameManager.instance != null)
|
||||
GameManager.instance.RespawnShip();
|
||||
Instantiate(spaceshipDebris, transform.position, transform.GetChild(0).rotation);
|
||||
Destroy(gameObject);
|
||||
isColliding = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void CalculatePositionOnCamera()
|
||||
{
|
||||
if (Camera.main != null)
|
||||
{
|
||||
bool warped = false;
|
||||
|
||||
Vector2 positionOnCamera = Camera.main.WorldToViewportPoint(transform.position);
|
||||
if (positionOnCamera.x > 1.05f)
|
||||
{
|
||||
warped = true;
|
||||
transform.position = (Vector2)Camera.main.ViewportToWorldPoint(new Vector2(-0.05f, positionOnCamera.y));
|
||||
}
|
||||
else if (positionOnCamera.x < -0.05f)
|
||||
{
|
||||
warped = true;
|
||||
transform.position = (Vector2)Camera.main.ViewportToWorldPoint(new Vector2(1.05f, positionOnCamera.y));
|
||||
}
|
||||
else if (positionOnCamera.y > 1.05f)
|
||||
{
|
||||
warped = true;
|
||||
transform.position = (Vector2)Camera.main.ViewportToWorldPoint(new Vector2(positionOnCamera.x, -0.05f));
|
||||
}
|
||||
else if (positionOnCamera.y < -0.05f)
|
||||
{
|
||||
warped = true;
|
||||
transform.position = (Vector2)Camera.main.ViewportToWorldPoint(new Vector2(positionOnCamera.x, 1.05f));
|
||||
}
|
||||
|
||||
if (warped)
|
||||
{
|
||||
transform.GetChild(0).GetChild(0).GetComponent<EngineTrail>().ClearParticles();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateWeapon(int score)
|
||||
{
|
||||
Weapon weapon = Weapon.Basic;
|
||||
|
||||
if (score >= 8000)
|
||||
weapon = Weapon.Laser;
|
||||
|
||||
if (weapon == currentWeapon)
|
||||
return;
|
||||
|
||||
currentWeapon = weapon;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5aeff83e8c0bc4fb2b3d12ab3b2d49a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 400
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 867fb24d4d60d5141b99b22a52954c62
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class EngineTrail : MonoBehaviour
|
||||
{
|
||||
ParticleSystem ps;
|
||||
ParticleSystem.EmissionModule em;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (!GameManager.effectsEnabled)
|
||||
gameObject.SetActive(false);
|
||||
|
||||
ps = GetComponent<ParticleSystem>();
|
||||
em = ps.emission;
|
||||
em.enabled = true;
|
||||
}
|
||||
|
||||
public void ClearParticles()
|
||||
{
|
||||
StartCoroutine(Clear());
|
||||
}
|
||||
|
||||
IEnumerator Clear()
|
||||
{
|
||||
em.enabled = false;
|
||||
ps.Clear();
|
||||
yield return null;
|
||||
em.enabled = true;
|
||||
ps.Clear();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f2c27cb7e7d02014eab1dc6e617dbc18
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 102f521d3fefd5a46b63e4713e96cdfa
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,161 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class GameManager : MonoBehaviour
|
||||
{
|
||||
// Values and methods for testing
|
||||
public static bool effectsEnabled = true;
|
||||
public static bool startEnabled = true;
|
||||
public static bool updateEnabled = true;
|
||||
public static bool asteroidsEnabled = true;
|
||||
|
||||
public static void InitializeTestingEnvironment(bool start, bool update, bool effects, bool asteroids, bool paused)
|
||||
{
|
||||
effectsEnabled = effects;
|
||||
startEnabled = start;
|
||||
updateEnabled = update;
|
||||
asteroidsEnabled = asteroids;
|
||||
IsPaused = paused;
|
||||
}
|
||||
|
||||
public static GameManager instance;
|
||||
public static SpaceshipController spaceship;
|
||||
public static int score;
|
||||
public static int scoreSinceLastDeath;
|
||||
private static bool isPaused;
|
||||
|
||||
public GameObject spaceshipPrefab;
|
||||
public GameObject asteroidPrefab;
|
||||
|
||||
[HideInInspector]
|
||||
public float asteroidSpawnDelay = 1.0f;
|
||||
[HideInInspector]
|
||||
public float asteroidSpawnTimer = 0.0f;
|
||||
[HideInInspector]
|
||||
public int deaths = 0;
|
||||
|
||||
public const float SPACESHIP_RESPAWN_DELAY = 1.0f;
|
||||
public const float RELOAD_SCENE_DELAY = 3.0f;
|
||||
|
||||
public static bool IsPaused
|
||||
{
|
||||
get { return isPaused; }
|
||||
set { Time.timeScale = value ? 0.0f : 1.0f; isPaused = value; }
|
||||
}
|
||||
|
||||
public static bool SpaceshipIsActive() { return spaceship != null; }
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = this;
|
||||
else if (instance != this)
|
||||
Destroy(gameObject);
|
||||
|
||||
Time.timeScale = 1.0f;
|
||||
IsPaused = false;
|
||||
score = 0;
|
||||
scoreSinceLastDeath = 0;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (startEnabled)
|
||||
{
|
||||
spaceship = Instantiate(spaceshipPrefab, Vector3.zero, Quaternion.identity).GetComponent<SpaceshipController>();
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (updateEnabled && !IsPaused)
|
||||
{
|
||||
UpdateTimers();
|
||||
if (asteroidSpawnTimer <= 0.0f && asteroidsEnabled)
|
||||
SpawnAsteroids();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTimers()
|
||||
{
|
||||
if (asteroidSpawnTimer > 0.0f)
|
||||
asteroidSpawnTimer -= Time.deltaTime;
|
||||
}
|
||||
|
||||
public void RespawnShip(float delay = SPACESHIP_RESPAWN_DELAY)
|
||||
{
|
||||
StartCoroutine(RespawnShipCoroutine(delay));
|
||||
}
|
||||
|
||||
public IEnumerator RespawnShipCoroutine(float delay)
|
||||
{
|
||||
deaths++;
|
||||
if (LifeCounter.instance)
|
||||
LifeCounter.instance.SetLives(3 - deaths);
|
||||
yield return new WaitForSeconds(delay);
|
||||
|
||||
if (deaths < 3)
|
||||
{
|
||||
spaceship = Instantiate(spaceshipPrefab, Vector2.zero, Quaternion.identity).GetComponent<SpaceshipController>();
|
||||
}
|
||||
else
|
||||
{
|
||||
StartCoroutine(ReloadScene());
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnAsteroids()
|
||||
{
|
||||
AsteroidController asteroid;
|
||||
if (Camera.main != null)
|
||||
{
|
||||
Vector2 spawnPosition = Random.value > 0.5f ? Camera.main.ViewportToWorldPoint(new Vector2(Random.value > 0.5f ? Random.Range(-0.1f, -0.05f) : Random.Range(1.05f, 1.1f), Random.Range(-0.1f, 1.1f))) : Camera.main.ViewportToWorldPoint(new Vector2(Random.Range(-0.1f, 1.1f), Random.value > 0.5f ? Random.Range(-0.1f, -0.05f) : Random.Range(1.05f, 1.1f)));
|
||||
asteroid = Instantiate(asteroidPrefab, spawnPosition, Quaternion.identity).GetComponent<AsteroidController>();
|
||||
asteroid.SetDirection(Camera.main.ViewportToWorldPoint(new Vector2(Random.value, Random.value)));
|
||||
}
|
||||
else
|
||||
asteroid = Instantiate(asteroidPrefab, Vector2.zero, Quaternion.identity).GetComponent<AsteroidController>(); //for test purposes
|
||||
|
||||
float randomValue = Random.value;
|
||||
if (randomValue < 0.333f)
|
||||
asteroid.SetSplitCount(0); // big asteroid
|
||||
else if (randomValue > 0.666f)
|
||||
asteroid.SetSplitCount(1); // medium asteroid
|
||||
else
|
||||
asteroid.SetSplitCount(2); // small asteroid
|
||||
|
||||
asteroidSpawnTimer = asteroidSpawnDelay;
|
||||
}
|
||||
|
||||
IEnumerator ReloadScene()
|
||||
{
|
||||
yield return new WaitForSeconds(RELOAD_SCENE_DELAY);
|
||||
Scene scene = SceneManager.GetActiveScene();
|
||||
SceneManager.LoadScene(scene.name);
|
||||
}
|
||||
|
||||
public static void AddToScore(int splitCount)
|
||||
{
|
||||
switch (splitCount)
|
||||
{
|
||||
case 0:
|
||||
score += 1000;
|
||||
scoreSinceLastDeath += 1000;
|
||||
break;
|
||||
case 1:
|
||||
score += 500;
|
||||
scoreSinceLastDeath += 500;
|
||||
break;
|
||||
case 2:
|
||||
score += 250;
|
||||
scoreSinceLastDeath += 250;
|
||||
break;
|
||||
}
|
||||
|
||||
if (SpaceshipIsActive())
|
||||
spaceship.UpdateWeapon(scoreSinceLastDeath);
|
||||
if(ScoreCounter.instance)
|
||||
ScoreCounter.instance.StartCounting(score);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a714a81b1536b4426b80643ee6a61629
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8791fb1d8e87e63498d7d560b34eada0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class InGameMenuController : MonoBehaviour
|
||||
{
|
||||
private GameObject pauseMenu;
|
||||
private bool pauseMenuActive = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
pauseMenu = transform.GetChild(0).gameObject;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetButtonDown("Cancel"))
|
||||
ChangeMenuState(!pauseMenuActive);
|
||||
}
|
||||
|
||||
public void ChangeMenuState(bool isPaused)
|
||||
{
|
||||
if (pauseMenuActive == isPaused)
|
||||
return;
|
||||
|
||||
pauseMenu.SetActive(isPaused);
|
||||
|
||||
pauseMenuActive = isPaused;
|
||||
GameManager.IsPaused = isPaused;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf32140837e8cc14388b9522d4d48282
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 200
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,63 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class LifeCounter : MonoBehaviour
|
||||
{
|
||||
public static LifeCounter instance;
|
||||
|
||||
int previousLifeCount = 3;
|
||||
|
||||
Animator[] lives;
|
||||
|
||||
public Sprite lifeVisual;
|
||||
public Sprite emptyLifeVisual;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = this;
|
||||
else if (instance != this)
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
lives = transform.GetComponentsInChildren<Animator>();
|
||||
}
|
||||
|
||||
public void SetLives(int currentLives)
|
||||
{
|
||||
if (currentLives > 3)
|
||||
currentLives = 3;
|
||||
|
||||
if(currentLives <= previousLifeCount)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (i >= currentLives)
|
||||
{
|
||||
if (i < previousLifeCount)
|
||||
{
|
||||
lives[i].enabled = true;
|
||||
lives[i].SetTrigger("Remove");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
if (i <= currentLives)
|
||||
{
|
||||
if (i >= previousLifeCount)
|
||||
{
|
||||
lives[i].enabled = true;
|
||||
lives[i].SetTrigger("Recover");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
previousLifeCount = currentLives;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c00135462c6948043888456656db5a54
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,83 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ScoreCounter : MonoBehaviour {
|
||||
public static ScoreCounter instance;
|
||||
int currentScore = 0;
|
||||
int targetScore = 0;
|
||||
Text[] numbers;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (instance == null)
|
||||
instance = this;
|
||||
else if (instance != this)
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
numbers = transform.GetComponentsInChildren<Text>();
|
||||
}
|
||||
|
||||
Coroutine iterator;
|
||||
|
||||
public void StartCounting(int score)
|
||||
{
|
||||
targetScore = score;
|
||||
|
||||
if (iterator != null)
|
||||
StopCoroutine(iterator);
|
||||
iterator = StartCoroutine(IterateScore());
|
||||
}
|
||||
|
||||
public IEnumerator IterateScore () {
|
||||
while(currentScore < targetScore * 0.9f)
|
||||
{
|
||||
currentScore = (int)Mathf.Lerp(currentScore, targetScore, Time.deltaTime * 10.0f);
|
||||
SetScore(currentScore);
|
||||
yield return null;
|
||||
}
|
||||
SetScore(targetScore);
|
||||
StartCoroutine(Pop(targetScore.ToString().Length));
|
||||
}
|
||||
|
||||
public void SetScore(int score)
|
||||
{
|
||||
char[] charScore = score.ToString().ToCharArray();
|
||||
int scoreLength = charScore.Length;
|
||||
int k = 0;
|
||||
for(int i = 0; i < numbers.Length; i++)
|
||||
{
|
||||
if (i < numbers.Length - scoreLength)
|
||||
numbers[i].text = "0";
|
||||
else
|
||||
{
|
||||
numbers[i].text = charScore[k++].ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator Pop(int digits)
|
||||
{
|
||||
int index = numbers.Length - digits;
|
||||
float t = 0.0f;
|
||||
while (t < 1.0f)
|
||||
{
|
||||
Vector3 scale = t < 0.2f ? Vector3.one * (1.0f + t) : Vector3.Lerp(numbers[index].transform.localScale, Vector3.one, t);
|
||||
|
||||
for (int i = index; i < numbers.Length; i++)
|
||||
numbers[i].transform.localScale = scale;
|
||||
|
||||
t += Time.deltaTime * 10.0f;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
for (int i = index; i < numbers.Length; i++)
|
||||
numbers[i].transform.localScale = Vector3.one;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1adf9b0f5de63b4faf2f253148cb20e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a868f07139a86d449a8d8f83eb76e15
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BaseProjectile : MonoBehaviour
|
||||
{
|
||||
public bool destroyOnCollision = true;
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D collision)
|
||||
{
|
||||
AsteroidController asteroidController = collision.gameObject.GetComponent<AsteroidController>();
|
||||
|
||||
if (asteroidController)
|
||||
{
|
||||
if (collision.isActiveAndEnabled)
|
||||
asteroidController.Split();
|
||||
|
||||
if (destroyOnCollision)
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6d9489cb904b7d346ac5ba24652829c2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,36 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class LaserController : BaseProjectile
|
||||
{
|
||||
public bool isActive = true;
|
||||
public float duration = 0.75f;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!GameManager.IsPaused)
|
||||
{
|
||||
if (isActive)
|
||||
Expand();
|
||||
else
|
||||
Shrink();
|
||||
|
||||
duration -= Time.deltaTime;
|
||||
if (duration <= 0.0f)
|
||||
isActive = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Expand()
|
||||
{
|
||||
if (transform.localScale.y <= 25.0f)
|
||||
transform.localScale += Vector3.up * Time.deltaTime * 75.0f;
|
||||
}
|
||||
|
||||
private void Shrink()
|
||||
{
|
||||
transform.localScale -= Vector3.up * Time.deltaTime * 75.0f;
|
||||
transform.position += transform.up * Time.deltaTime * 75.0f;
|
||||
if (transform.localScale.y <= 0.0f)
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5db3784d30964d24aa8bad3aabc8a2d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ProjectileController : BaseProjectile
|
||||
{
|
||||
private Vector2 direction = Vector2.right;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!GameManager.IsPaused)
|
||||
Move();
|
||||
}
|
||||
|
||||
public void Move()
|
||||
{
|
||||
transform.position += (Vector3)direction * Time.deltaTime * 16;
|
||||
transform.up = direction;
|
||||
if (Vector2.Distance(transform.position, Vector2.zero) > 20.0f)
|
||||
DestroyImmediate(gameObject);
|
||||
}
|
||||
|
||||
public void SetDirection(Vector2 value)
|
||||
{
|
||||
direction = value;
|
||||
}
|
||||
|
||||
public Vector2 GetDirection()
|
||||
{
|
||||
return direction;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab65719fb77f94941b627fdedb501f31
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu(fileName = "WeaponData", menuName = "Weapon List", order = 1)]
|
||||
public class WeaponList : ScriptableObject
|
||||
{
|
||||
[System.Serializable]
|
||||
public struct Weapon
|
||||
{
|
||||
public string weaponName;
|
||||
public GameObject weaponPrefab;
|
||||
};
|
||||
|
||||
[SerializeField]
|
||||
public List<Weapon> weapons;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15d37c83db3355947a8633e4162238f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user