Skip to content

Commit

Permalink
player increases in width per kill they make, moved variables to be e…
Browse files Browse the repository at this point in the history
…xposed in level editor
  • Loading branch information
nhstaple committed Jun 6, 2019
1 parent 50662f9 commit 8f8569d
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 27 deletions.
12 changes: 9 additions & 3 deletions ProjectFiles/FlatCell/Assets/Scenes/New Scene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ GameObject:
- component: {fileID: 206065357}
m_Layer: 0
m_Name: DotSpawner
m_TagString: Untagged
m_TagString: DotSpawner
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
Expand All @@ -149,6 +149,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 94b91f6b601fd694fbf9498ae299d530, type: 3}
m_Name:
m_EditorClassIdentifier:
Speed: 50
MaxHealth: 3
FireRate: 0.05
FireChance: 15
Damage: 1
--- !u!4 &206065358
Transform:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -575,7 +580,7 @@ GameObject:
- component: {fileID: 998048343}
m_Layer: 0
m_Name: Player
m_TagString: Untagged
m_TagString: Player
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
Expand Down Expand Up @@ -608,8 +613,9 @@ MonoBehaviour:
m_EditorClassIdentifier:
Speed: 100
BoostFactor: 4
MaxHealth: 10
MaxHealth: 5
FireRate: 0.25
Damage: 0
health: 0
armor: 0
dhieldMana: 0
Expand Down
11 changes: 9 additions & 2 deletions ProjectFiles/FlatCell/Assets/Scripts/DotProjectile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using UnityEngine;

using Projectile.Command;
using Weapon.Command;
using Geo.Command;

namespace Projectile.Command
{
Expand All @@ -18,8 +20,11 @@ public class DotProjectile : IProjectile

private float Counter = -1;

public DotProjectile(float Damage, float Piercing, float LifeTime)
public IWeapon Owner;

public DotProjectile(IWeapon gun, float Damage, float Piercing, float LifeTime)
{
this.Owner = gun;
this.Damage = Damage;
this.Piercing = Piercing;
this.LifeTime = LifeTime;
Expand All @@ -35,8 +40,10 @@ public void SetDamage(float Damage, float Piercing)
public GameObject Spawn(Vector3 Location)
{
Counter++;
IGeo owner = Owner.GetOwner();

// Create a new projectile object.
GameObject proj = new GameObject("Projectile" + Counter);
GameObject proj = new GameObject(owner.ToString() + " Projectile " + Counter);

// Add mesh components
proj.AddComponent<MeshRenderer>();
Expand Down
54 changes: 48 additions & 6 deletions ProjectFiles/FlatCell/Assets/Scripts/DotSpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,18 @@ public class DotSpawner : MonoBehaviour, ISpawner
private List<GameObject> Alive = new List<GameObject>();
private int counter = -1;

[SerializeField] public float Speed;
[SerializeField] public float MaxHealth;
[SerializeField] public float FireRate;
[SerializeField] public float FireChance;
[SerializeField] public float Damage;

GameObject player;

public void Start()
{

player = GameObject.FindWithTag("Player");
Alive.Add(player);
}

public void Spawn()
Expand All @@ -24,11 +33,16 @@ public void Spawn()
Location.x = UnityEngine.Random.Range(-SpawnOffset, SpawnOffset);
Location.z = UnityEngine.Random.Range(-SpawnOffset, SpawnOffset);
GameObject Dot = new GameObject("Dot" + counter);
// Dot.AddComponent<DotObject>();//Makes Dot a DotObject object (with component)
Dot.AddComponent<DotController>();//allows for AIController to be applied to dots
Dot.transform.position = Location;
Dot.transform.localScale = new Vector3(25, 25, 25);
// GameObject.Destroy(Dot, 5f);

// Add the ai controller and set it's values to the serialize field
DotController ai = Dot.AddComponent<DotController>();
ai.Speed = Speed;
ai.MaxHealth = MaxHealth;
ai.FireRate = FireRate;
ai.FireChance = FireChance;
ai.health = MaxHealth;
Alive.Add(Dot);
}
void Update()
Expand All @@ -45,12 +59,40 @@ void Update()
}
}

void Kill(GameObject Dot)
public void Kill(GameObject Dot, bool KilledByPlayer = false)
{
if(Alive.Contains(Dot))
if(Dot.ToString().Contains("Player"))
{
PlayerController controller = Dot.GetComponent<PlayerController>();
Transform t = controller.GetComponent<Transform>();
// Reset the player to spawn location.
t.position = new Vector3(0, 25, 0);
controller.health = controller.MaxHealth;
var score = controller.killHistory["Dot"];
controller.killHistory["Dot"] = (int)UnityEngine.Random.Range(score * 0.50f, score * 0.75f);
var scale = controller.transform.localScale;
if(score >= 25)
{
scale = new Vector3(50, 1, 1);
controller.SpawnOffset = controller.initSpawnOffset + 15;
}
else
{
scale = new Vector3(25 + score, 25 - score, 25 - score);
controller.SpawnOffset = controller.initSpawnOffset + (int)score;
}
controller.transform.localScale = scale;
Debug.Log("You died! Fool");
}
else if(Alive.Contains(Dot))
{
Alive.Remove(Dot);
Destroy(Dot);
if(KilledByPlayer)
{
PlayerController p = player.GetComponent<PlayerController>();
p.killHistory["Dot"] = p.killHistory["Dot"] + 5;
}
}
}
}
9 changes: 7 additions & 2 deletions ProjectFiles/FlatCell/Assets/Scripts/DotWeapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DotWeapon : IWeapon

/** Script variables **/
// The owner of the weapon
private IGeo Owner;
public IGeo Owner;
// Keeps track of the player's last input values.
private Vector3 lastMove;
// Keeps track of the last time the weapon was shot.
Expand All @@ -27,7 +27,7 @@ public class DotWeapon : IWeapon
public DotWeapon(IGeo GeoOwner , float Offset, float Rate)
{
this.Owner = GeoOwner;
this.Projectile = new DotProjectile(Damage, Piercing, ProjectileLifetime);
this.Projectile = new DotProjectile(this, Damage, Piercing, ProjectileLifetime);
this.FireRate = Rate;
}

Expand Down Expand Up @@ -66,5 +66,10 @@ public void Fire(Vector3 movementDir, Vector3 pos, float push, float SpawnOffset

return;
}

public IGeo GetOwner()
{
return Owner;
}
}
}
20 changes: 15 additions & 5 deletions ProjectFiles/FlatCell/Assets/Scripts/GeoObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
using Weapon.Command;
using Geo.Command;
using Projectile.Command;
using Spawner.Command;

public class GeoObject : MonoBehaviour, IGeo
{
/** Geo Stats **/
[SerializeField] public float Speed = 100.0f;
[SerializeField] public float BoostFactor = 4.0f;
[SerializeField] public float MaxHealth = 5.0f;
[SerializeField] public float FireRate = 0.25f;
[SerializeField] public float Speed;
[SerializeField] public float BoostFactor;
[SerializeField] public float MaxHealth;
[SerializeField] public float FireRate;
[SerializeField] public float Damage;

public float health;
public float armor = 0.0f;
Expand All @@ -27,6 +30,7 @@ public class GeoObject : MonoBehaviour, IGeo
public Vector3 movementDirection;
public float currentSpeed;
public Vector3 prevPos;
public bool killedByPlayer = false;


// Start is called before the first frame update
Expand Down Expand Up @@ -56,7 +60,9 @@ public void Update()
{
if (health <= 0)
{
Destroy(this.gameObject);
GameObject spawner = GameObject.FindWithTag("DotSpawner");
ISpawner controller = spawner.GetComponent<DotSpawner>();
controller.Kill(this.gameObject, killedByPlayer);
}
}

Expand Down Expand Up @@ -100,6 +106,10 @@ public void OnCollisionEnter(Collision collision)
Destroy(collision.gameObject, .1f);
ProjectileObject bullet = collision.gameObject.GetComponent<ProjectileObject>();
health -= bullet.GetDamage();
if(health <= 0 && collision.gameObject.ToString().Contains("Player"))
{
killedByPlayer = true;
}
}

return;
Expand Down
2 changes: 2 additions & 0 deletions ProjectFiles/FlatCell/Assets/Scripts/ISpawner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ public enum EGeoSpawnType
public interface ISpawner
{
void Spawn();

void Kill(GameObject Dot, bool KilledByPlayer);
}
}
2 changes: 2 additions & 0 deletions ProjectFiles/FlatCell/Assets/Scripts/IWeapon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public interface IWeapon

// Fires a projectile.
void Fire(Vector3 movementDir, Vector3 pos, float push, float SpawnOffset);

IGeo GetOwner();
}
}
27 changes: 19 additions & 8 deletions ProjectFiles/FlatCell/Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class PlayerController : DotObject
DotSpawner factory;
private float spawnCounter = 0.5f;
private int spawnCount = 10;
public Dictionary<string, int> killHistory;

/** Cosmetics **/
[SerializeField] private float trailDecay = 1f;
Expand All @@ -32,6 +33,7 @@ public class PlayerController : DotObject
//if shield is on, maybe disable other actions
private int shieldOn;
private float ShieldTimer;
public float initSpawnOffset;

private bool GrowFlag = false;

Expand All @@ -43,6 +45,9 @@ public class PlayerController : DotObject
weaponSelect = 1;
shieldOn = 0;
ShieldTimer = 0.0f;
killHistory = new Dictionary<string, int>();
killHistory.Add("Dot", 0);
initSpawnOffset = SpawnOffset;
}

void Awake()
Expand All @@ -57,14 +62,6 @@ void Awake()
base.Update();
gameObject.GetComponent<Rigidbody>().velocity = Vector3.zero;
/*
SpawnCounter += Time.deltaTime;
if(SpawnCounter >= 0.5)
{
Debug.Log("Spawned");
Factory.Spawn();
SpawnCounter = 0;
}
if(transform.localScale.x <= 25 && GrowFlag)
{
transform.localScale += new Vector3(0.1f, 0.00f, 0.0f);
Expand All @@ -83,6 +80,20 @@ void Awake()
}
*/

// Check for incremental evolution.

if (killHistory["Dot"] >= 25)
{
transform.localScale = new Vector3(50, 1, 1);
SpawnOffset = initSpawnOffset + 15;
}
else
{
transform.localScale = new Vector3(25 + killHistory["Dot"], 25 - killHistory["Dot"], 25 - killHistory["Dot"]);
SpawnOffset = initSpawnOffset + (int)killHistory["Dot"];
}


if(shield != null && shieldOn == 1)
{
Debug.Log("Shield On");
Expand Down
3 changes: 2 additions & 1 deletion ProjectFiles/FlatCell/ProjectSettings/TagManager.asset
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
--- !u!78 &1
TagManager:
serializedVersion: 2
tags: []
tags:
- DotSpawner
layers:
- Default
- TransparentFX
Expand Down

0 comments on commit 8f8569d

Please sign in to comment.