Skip to content
Snippets Groups Projects
Commit 6c8682b9 authored by mitchelkovacs's avatar mitchelkovacs
Browse files

inbetween worlds has random platforms and enemies

parents c8a99d2f 43526433
No related branches found
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
......@@ -17,6 +17,10 @@ public class ArenaCombatControl : MonoBehaviour {
private bool canRefill = false;
private float attackSpeedCooldown;
private float blockCoolDown;
public bool kicked;
public static bool kick = false;
public static bool attack = false;
public static bool block = false;
// fields to modify player stats based on weapons -- now in CharacterLook script!! *****
/*
public WeaponStats[] weapons;
......@@ -37,14 +41,14 @@ public class ArenaCombatControl : MonoBehaviour {
void Update() {
float h = Input.GetAxis("Horizontal");
float i = Input.GetAxis("Vertical");
kicked = EnemyAI.isEnemyKicking;
Movement(h);
FlipPlayer(h);
RotatePlayerZaxis(h);
Attack();
Block();
Jump();
// Kick();
Kick();
}
......@@ -63,27 +67,36 @@ public class ArenaCombatControl : MonoBehaviour {
attackSpeedCooldown -= Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space) && attackSpeedCooldown <= 0) {
//attackSpeedCooldown = weapons[currentWeapon].attackSpeed;
attack = true;
myAnimator.SetBool("attack", true);
}
else {
attack = false;
myAnimator.SetBool("attack", false);
}
}
/*
private void Kick() {
if (Input.GetKeyDown(KeyCode.F)) {
kick = true;
myAnimator.SetBool("kick", true);
}
else {
kick = false;
myAnimator.SetBool("kick", false);
}
}
*/
private void Block() {
// blockCoolDown -= Time.deltaTime;
// Debug.Log(blockCoolDown);
Debug.Log(block);
if (canBlock == true && Input.GetKey(KeyCode.E)) {
block = true;
if (kicked == true) {
block = false;
}
Debug.Log("blocking");
myAnimator.SetBool("block", true);
Player.velocity = Vector2.zero;
......@@ -93,12 +106,14 @@ public class ArenaCombatControl : MonoBehaviour {
}
if (blockCoolDown < 0) {
block = false;
canRefill = false;
canBlock = false;
}
if (canBlock == false) {
Debug.Log("filling");
block = false;
myAnimator.SetBool("block", false);
blockCoolDown += Time.deltaTime;
}
......@@ -109,10 +124,20 @@ public class ArenaCombatControl : MonoBehaviour {
}
if (Input.GetKeyUp(KeyCode.E)) {
block = false;
Debug.Log("KeyOff");
myAnimator.SetBool("block", false);
canMove = true;
canRefill = true;
}
if (kicked == true) {
block = false;
Debug.Log("KeyOff");
myAnimator.SetBool("block", false);
canMove = true;
canRefill = true;
blockCoolDown = 0;
}
if (canRefill == true) {
......
......@@ -5,6 +5,7 @@ public class EnemyAI : MonoBehaviour {
public DecisionTree root;
private Transform target;
private Rigidbody2D Player;
private Rigidbody2D Enemy;
private Animator myAnimator;
public float enemyHealth, original;
......@@ -20,9 +21,15 @@ public class EnemyAI : MonoBehaviour {
public bool actionDelay = false;
public float searchDelay = 0.2f;
public float searchCoolDown = 0;
public static bool isEnemyKicking = false;
public float kickCoolDown = 0;
public float kickTimer;
public float aggressiveTimer;
public bool aggressiveCheck = false;
public bool isAggressive = false;
public bool isPlayerAttacking = false;
public bool isPlayerBlocking = false;
public bool isPlayerKicking = false;
public float randomActionCoolDown = 0;
public float randomAction;
public float randomAcioionSpeed;
......@@ -30,9 +37,10 @@ public class EnemyAI : MonoBehaviour {
void Start() {
aggressiveTimer = 5;
randomSpeed = Random.Range(3f, 5f);
kickTimer = 5;
randomSpeed = Random.Range(0, 1f);
attackSpeed = randomSpeed;
randomAcioionSpeed = Random.Range(1, 5);
randomAcioionSpeed = Random.Range(0, 2f);
randomAction = randomAcioionSpeed;
enemyHealth = Random.Range(50, 500);
original = enemyHealth;
......@@ -43,6 +51,7 @@ public class EnemyAI : MonoBehaviour {
root = new DecisionTree();
// Debug.Log("start");
target = GameObject.FindGameObjectWithTag("Player").transform; //look at the player
// Player = GameObject.FindGameObjectWithTag("Player").GetComponent<Rigidbody2D>();
myAnimator = GetComponent<Animator>(); //required for animation *******
Enemy = GetComponent<Rigidbody2D>();
BuildDecisionTree();
......@@ -51,7 +60,11 @@ public class EnemyAI : MonoBehaviour {
void Update() {
AggressiveCoolDown();
BlockCheck();
AttackCheck();
KickCheck();
coolDown -= Time.deltaTime;
kickCoolDown -= Time.deltaTime;
randomActionCoolDown -= Time.deltaTime;
if (actionDelay == true) {
searchCoolDown -= Time.deltaTime;
......@@ -73,7 +86,6 @@ public class EnemyAI : MonoBehaviour {
spaceBarCounter++;
// Debug.Log(spaceBarCounter);
aggressiveCheck = true;
}
if (aggressiveCheck == true) {
aggressiveTimer -= Time.deltaTime;
......@@ -87,6 +99,29 @@ public class EnemyAI : MonoBehaviour {
}
}
public void BlockCheck() {
isPlayerBlocking = ArenaCombatControl.block;
Debug.Log(isPlayerBlocking + "Enemy");
if (isPlayerBlocking == false) {
myAnimator.SetBool("kick", false);
}
}
public void AttackCheck() {
isPlayerAttacking = ArenaCombatControl.attack;
}
public void KickCheck() {
isPlayerKicking = ArenaCombatControl.kick;
}
public void HpCheck() {
playerHealth = PlayerStats.curHealth;
}
public void ChangeHealthBare(int damage) {
GameObject healthbar = GameObject.Find("healthbarFulle");
float newsize = healthbar.transform.localScale.x - ((damage / original) * 0.3f);
......@@ -105,8 +140,15 @@ public class EnemyAI : MonoBehaviour {
public bool d_isPlayerAttacking() {
if (Input.GetKeyDown(KeyCode.Space) && Vector3.Distance(transform.position, target.position) < 6f) {
// Debug.Log(spaceBarCounter);
if (isPlayerAttacking == true) {
return true;
}
Debug.Log("Player Not Attacking");
return false;
}
public bool d_isPlayerKicking() {
if (isPlayerKicking == true) {
return true;
}
return false;
......@@ -114,8 +156,8 @@ public class EnemyAI : MonoBehaviour {
public bool d_inAttackRange() {
if (Vector3.Distance(transform.position, target.position) < 1.5f && Vector3.Distance(transform.position, target.position) > 1f) {
isEnemyKicking = false;
if (Vector3.Distance(transform.position, target.position) < 2f && Vector3.Distance(transform.position, target.position) > 1f) {
myAnimator.SetBool("speed", false);
return true;
}
......@@ -126,7 +168,7 @@ public class EnemyAI : MonoBehaviour {
}
else {
myAnimator.SetBool("kick", false);
myAnimator.SetBool("attack", false);
myAnimator.SetBool("block", false);
// Debug.Log("In Zone- not");
......@@ -162,26 +204,31 @@ public class EnemyAI : MonoBehaviour {
}
public bool d_isPlayerBlocking() {
if (Input.GetKeyDown(KeyCode.E) && Vector3.Distance(transform.position, target.position) < 6f) {
return false;
if (isPlayerBlocking == true) {
return true;
}
return true;
return false;
}
public bool d_isPlayerHpLow() {
if ((playerHealthOriginal / 2) > PlayerStats.getHealth()) {
if ((playerHealthOriginal / 2) > playerHealth) {
Debug.Log("Player Half Health");
return true;
}
Debug.Log("Player Full Health");
return false;
}
public bool d_isHpLow() {
if ((original / 2) > enemyHealth) {
Debug.Log("Enemy Half Health");
return true;
}
Debug.Log("Enemy Full Health");
return false;
}
......@@ -212,6 +259,11 @@ public class EnemyAI : MonoBehaviour {
}
}
public void a_push() {
actionDelay = true;
Player.AddForce(new Vector2(-250, 500));
}
public void a_superAttack() {
myAnimator.SetFloat("speed", 0f);
Debug.Log("attacking");
......@@ -223,6 +275,11 @@ public class EnemyAI : MonoBehaviour {
Enemy.AddForce(new Vector2(-250, 500));
}
public void a_jump() {
actionDelay = true;
Enemy.AddForce(new Vector2(0, 500));
}
public void a_block() {
Debug.Log("Block");
actionDelay = true;
......@@ -232,13 +289,30 @@ public class EnemyAI : MonoBehaviour {
}
public void a_randomAction() {
public void a_kick() {
actionDelay = true;
isEnemyKicking = true;
if (kickCoolDown <= 0) {
kickCoolDown = kickTimer;
Debug.Log("kicking");
myAnimator.SetBool("kick", true);
Enemy.velocity = Vector2.zero;
}
else {
myAnimator.SetBool("kick", false);
myAnimator.SetBool("attack", true);
}
}
public void a_randomAction() {
Debug.Log("Action");
float x = Random.Range(0, 250);
actionDelay = true;
if (randomActionCoolDown <= 0) {
Debug.Log(x);
//Debug.Log(x);
randomActionCoolDown = randomAction;
if (x < 125) {
......@@ -255,7 +329,28 @@ public class EnemyAI : MonoBehaviour {
}
public void a_randomBlock() {
float x = Random.Range(0, 250);
actionDelay = true;
if (randomActionCoolDown <= 0) {
//Debug.Log(x);
randomActionCoolDown = randomAction;
if (x < 125) {
a_block();
}
if (x >= 125 && x <= 200) {
a_jumpBack();
}
if (x > 200) {
a_jump();
}
}
}
//template for a 'poison' special attack. Will slowly and gradually drain players health over time.
......@@ -307,6 +402,12 @@ public class EnemyAI : MonoBehaviour {
DecisionTree RandomAction = new DecisionTree();
RandomAction.setAction(a_randomAction);
DecisionTree RandomBlock = new DecisionTree();
RandomBlock.setAction(a_randomBlock);
DecisionTree Kick = new DecisionTree();
Kick.setAction(a_kick);
DecisionTree JumpBack = new DecisionTree();
JumpBack.setAction(a_jumpBack);
......@@ -324,9 +425,14 @@ public class EnemyAI : MonoBehaviour {
// Decisions
DecisionTree isPlayerBlocking = new DecisionTree();
isPlayerBlocking.setDecision(d_isPlayerBlocking);
isPlayerBlocking.setLeft(Kick);
isPlayerBlocking.setRight(Attack);
DecisionTree GettingAttacked = new DecisionTree();
GettingAttacked.setDecision(d_isPlayerAttacking);
GettingAttacked.setLeft(Block);
GettingAttacked.setLeft(RandomBlock);
GettingAttacked.setRight(Attack);
DecisionTree PlayerHP = new DecisionTree();
......@@ -334,19 +440,27 @@ public class EnemyAI : MonoBehaviour {
PlayerHP.setLeft(Attack);
PlayerHP.setRight(GettingAttacked);
DecisionTree PlayerHP2 = new DecisionTree();
PlayerHP2.setDecision(d_isPlayerHpLow);
PlayerHP2.setLeft(Attack);
PlayerHP2.setRight(MoveAway);
DecisionTree PlayerHP3 = new DecisionTree();
PlayerHP3.setDecision(d_isPlayerHpLow);
PlayerHP3.setLeft(Attack);
PlayerHP3.setRight(isPlayerBlocking);
DecisionTree EnemyHP = new DecisionTree();
EnemyHP.setDecision(d_isHpLow);
EnemyHP.setLeft(PlayerHP2);
EnemyHP.setRight(Attack);
EnemyHP.setRight(PlayerHP3);
DecisionTree GettingAttacked2 = new DecisionTree();
GettingAttacked2.setDecision(d_isPlayerAttacking);
GettingAttacked2.setLeft(RandomAction);
GettingAttacked2.setRight(EnemyHP);
//Random Action Trees
DecisionTree Random01 = new DecisionTree();
......@@ -357,7 +471,7 @@ public class EnemyAI : MonoBehaviour {
//Random Action Trees
DecisionTree Random02 = new DecisionTree();
Random02.setDecision(d_randomDecision75);
Random02.setLeft(EnemyHP);
Random02.setLeft(GettingAttacked2);
Random02.setRight(RandomAction);
......@@ -375,8 +489,6 @@ public class EnemyAI : MonoBehaviour {
root.setLeft(Aggressiveness);
root.setRight(IsPlayerTooClose);
}
......
No preview for this file type
File added
File added
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment