We got fast fuckers now
This commit is contained in:
@@ -7,11 +7,13 @@ public class GameState : MonoBehaviour
|
||||
public GameObject shop;
|
||||
public GameObject ratbot;
|
||||
public GameObject gunThrower;
|
||||
public GameObject fastFucker;
|
||||
|
||||
int[] counts = new int[2];
|
||||
int[] counts = new int[3];
|
||||
enum CountIndex : uint {
|
||||
ratbot = 0,
|
||||
gunThrower = 1
|
||||
gunThrower = 1,
|
||||
fastFucker = 2
|
||||
}
|
||||
|
||||
void Start() {
|
||||
@@ -52,6 +54,7 @@ public class GameState : MonoBehaviour
|
||||
for (uint _ = 0; _ <= wave; _++) {
|
||||
GameObject newRatbot = Instantiate(
|
||||
SpawnRatbot(),
|
||||
// Spawn ratbots in a circle around the player
|
||||
Random.insideUnitCircle.normalized*20
|
||||
+ new Vector2 (
|
||||
playerPosition.x,
|
||||
@@ -59,6 +62,8 @@ public class GameState : MonoBehaviour
|
||||
),
|
||||
Quaternion.identity
|
||||
);
|
||||
// Set ratbot damageStrength and health
|
||||
// TODO: set speed
|
||||
newRatbot.GetComponent<Ratbot>().damageStrength
|
||||
= 5+wave*5;
|
||||
newRatbot.GetComponent<Ratbot>().health = 5+wave*2;
|
||||
@@ -66,12 +71,19 @@ public class GameState : MonoBehaviour
|
||||
wave++;
|
||||
}
|
||||
public GameObject SpawnRatbot() {
|
||||
// TODO: Convert this mess into a switch case
|
||||
if (counts[(uint)CountIndex.gunThrower] < wave/3
|
||||
&& wave > 3
|
||||
) {
|
||||
counts[(uint)CountIndex.gunThrower]++;
|
||||
return gunThrower;
|
||||
}
|
||||
if (counts[(uint)CountIndex.fastFucker] < wave/4
|
||||
&& wave > 2
|
||||
) {
|
||||
counts[(uint)CountIndex.fastFucker]++;
|
||||
return fastFucker;
|
||||
}
|
||||
return ratbot;
|
||||
}
|
||||
}
|
||||
|
||||
30
Assets/Scripts C#/Ratbots/FastFucker.cs
Normal file
30
Assets/Scripts C#/Ratbots/FastFucker.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
public class FastFucker : Ratbot
|
||||
{
|
||||
bool attack = true;
|
||||
void Update() {
|
||||
if (attack)
|
||||
MoveTowardsPlayer(moveSpeed*3);
|
||||
else
|
||||
MoveAwayFromPlayer(moveSpeed);
|
||||
}
|
||||
void MoveAwayFromPlayer(float speed) {
|
||||
controller.AddRelativeForce(
|
||||
(transform.position - player.transform.position)
|
||||
.normalized
|
||||
*speed
|
||||
*Time.deltaTime
|
||||
);
|
||||
}
|
||||
new void OnCollisionStay2D (Collision2D collision) {
|
||||
base.OnCollisionStay2D(collision);
|
||||
StartCoroutine("RunAway");
|
||||
}
|
||||
IEnumerator RunAway() {
|
||||
attack = false;
|
||||
yield return new WaitForSeconds (1F);
|
||||
attack = true;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts C#/Ratbots/FastFucker.cs.meta
Normal file
2
Assets/Scripts C#/Ratbots/FastFucker.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07603fdf7ab38f05493e2a22ef5cae06
|
||||
@@ -10,28 +10,33 @@ public class Ratbot : MonoBehaviour
|
||||
|
||||
public static GameState gameState;
|
||||
public static GameObject player;
|
||||
public Rigidbody2D controller;
|
||||
|
||||
void Start() {
|
||||
SetVars();
|
||||
}
|
||||
|
||||
public void SetVars() {
|
||||
controller = GetComponent<Rigidbody2D>();
|
||||
// Set gameState and player objects
|
||||
player = GameObject.FindGameObjectWithTag("Player");
|
||||
gameState = GameObject.FindGameObjectWithTag("GameController").GetComponent<GameState>();
|
||||
}
|
||||
|
||||
void Update() {
|
||||
MoveTowardsPlayer();
|
||||
MoveTowardsPlayer(moveSpeed);
|
||||
}
|
||||
|
||||
public void MoveTowardsPlayer() {
|
||||
Rigidbody2D controller = GetComponent<Rigidbody2D>();
|
||||
Vector2 direction = (player.transform.position - transform.position).normalized;
|
||||
controller.AddRelativeForce(direction*moveSpeed*Time.deltaTime);
|
||||
public void MoveTowardsPlayer(float speed) {
|
||||
controller.AddRelativeForce(
|
||||
(player.transform.position - transform.position)
|
||||
.normalized
|
||||
*speed
|
||||
*Time.deltaTime
|
||||
);
|
||||
}
|
||||
|
||||
void OnCollisionStay2D(Collision2D collision) {
|
||||
public virtual void OnCollisionStay2D(Collision2D collision) {
|
||||
// Deal damage when colliding with the player on a 0.5 second cooldown
|
||||
if (collision.gameObject.tag != "Player") return;
|
||||
if (lastDamageTime > Time.fixedTime-damageTimeoutSeconds) return;
|
||||
|
||||
Reference in New Issue
Block a user