Commit 44698136 authored by wayland bang's avatar wayland bang
Browse files

adding fixes to my previous commit

parents 378c1525 a915e899
fileFormatVersion: 2
<<<<<<< HEAD
guid: dafc79ccda6b647a085122f400c28480
=======
guid: 122249f9de258406bbaab645c0fbd4a5
>>>>>>> a915e8992ee61cd3ff5697887af86ce2fa8929b7
folderAsset: yes
timeCreated: 1476045420
licenseType: Free
......
fileFormatVersion: 2
guid: 90486bb225777485fab91ea48a030704
guid: d67d8611cbb544cc3891cd0c6faf3809
folderAsset: yes
timeCreated: 1479924870
licenseType: Free
......
fileFormatVersion: 2
guid: 4d89df6e8927247f2b76ad062384eed2
guid: 4c94a20efe0dc4788888bb996c758a01
folderAsset: yes
timeCreated: 1477333893
licenseType: Free
......
using UnityEngine;
using System.Collections;
/*
*
* targetDetectRadius:
* 5 units - walks towards hero
*
*
* attackRange:
* 2 unit - zombie needs to be close enough to Hero for a good chance to walk towards
* and touch the Hero.
*/
public class ZombieAI : MonoBehaviour
{
/* Number of seconds until a new AI action is determined */
public float intervalPerNewAction_sec;
/* The time when the AI action will be updated */
private float nextAction_sec;
/* Current action to perform in Update() */
private DecisionTree.Action curAction;
/* Current target to walk towards for RandomWalk(). This gets
updated to a new value every time a new AI decision is made */
private Vector2 curRndWalkTarget;
/* Attached radar child for detecting nearby gameObjects*/
public GameObject radar;
public string targetLayer;
public float targetDetectRadius = 5.0f;
public float attackRange = 2.0f;
/* API's to dependent gameobjects */
private RadarCtrl radarCtrl;
//private ZombieCtrl zombieCtrl;
private enemyScript zombieCtrl;
/* My target */
private GameObject hero;
/* AI is represented as a decision tree */
private DecisionTree decTree;
/* Spawner that I came from */
private Transform parentSpawn;
private RadarCtrl parentSpawnRadarCtrl;
void Start ()
{
//this.zombieCtrl = (ZombieCtrl)GetComponent<ZombieCtrl> ();
this.hero = GameObject.FindGameObjectWithTag("Player");
this.radarCtrl = (RadarCtrl) this.radar.GetComponent<RadarCtrl>();
BuildDecisionTree ();
NextAction ();
this.parentSpawn = this.transform.parent;
if (this.parentSpawn != null)
this.parentSpawnRadarCtrl = (RadarCtrl)this.parentSpawn.GetComponentInChildren<RadarCtrl> ();
}
/* Determine new AI action to perform */
void NextAction()
{
this.nextAction_sec = this.intervalPerNewAction_sec;
this.curAction = this.decTree.Search ();
this.curRndWalkTarget = GetNewRandomWalkTarget ();
}
void Update ()
{
/* If it's time to update the next action to execute, do so */
if (Time.time > this.nextAction_sec) {
NextAction ();
this.nextAction_sec = Time.time + this.intervalPerNewAction_sec;
}
/* Perform AI action */
this.curAction ();
}
void BuildDecisionTree()
{
DecisionTree isTargetInsideThreatZoneTree = new DecisionTree ((DecisionTree.Decision) IsTargetInsideThreatZone);
DecisionTree isInRangeTree = new DecisionTree ((DecisionTree.Decision) IsInRange);
DecisionTree attackTree = new DecisionTree ((DecisionTree.Action) Attack);
DecisionTree advanceTree = new DecisionTree ((DecisionTree.Action) Advance);
DecisionTree isIdleAnimationTree = new DecisionTree ((DecisionTree.Action) IdleAnimation);
isTargetInsideThreatZoneTree.SetLeft (isInRangeTree);
isTargetInsideThreatZoneTree.SetRight (isIdleAnimationTree);
this.decTree = isTargetInsideThreatZoneTree;
}
/* Decision methods */
/* Hero (i.e. target) is considered a threat if he is near me, or near my spawn point, or fired at me */
bool IsTargetInsideThreatZone()
{
if (this.radarCtrl.GetNumNearby (this.targetLayer, this.targetDetectRadius) > 0)
return true;
if (this.parentSpawn != null)
return (this.parentSpawnRadarCtrl.GetNumNearby (this.targetLayer, this.targetDetectRadius) > 0);
else
return false;
}
/* Am I within attack range (i.e. short distance to walk up and touch the Hero)? */
bool IsInRange()
{
return (this.radarCtrl.GetNumNearby (this.targetLayer, this.attackRange) > 0);
}
/* Action methods */
/* Attack my moving towards the hero */
void Attack()
{
if (this.name == "Zombie(Clone)") {
Debug.Log("Action: Attack()");
}
this.zombieCtrl.WalkTowardsHero ();
}
void Advance()
{
this.zombieCtrl.WalkTowardsHero ();
}
/* Get a random position */
Vector2 GetNewRandomWalkTarget()
{
Vector2 rndVector = new Vector2 (Random.Range(-100f,100f),
Random.Range(-100f,100f));
Vector2 myPos = this.transform.position;
/* Destination */
Vector2 rndTarget = new Vector2 (myPos.x + rndVector.x, myPos.y + rndVector.y);
return rndTarget;
}
void IdleAnimation()
{
/* Idle. Do nothing */
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 54aa85b4a416435438778955f5945149
timeCreated: 1476394005
guid: 13f96a2e9c6624f009f5ff2e091a118c
timeCreated: 1480213298
licenseType: Free
MonoImporter:
serializedVersion: 2
......
......@@ -31,7 +31,6 @@ public class EnemyDeathCtrl : DeathCtrl
{
GameObject loot = (GameObject) Instantiate (this.rndItemPrefab, this.transform.position,
Quaternion.identity, null);
}
}
}
......@@ -102,8 +102,38 @@ public class enemyScript : MonoBehaviour {
// //send message with calling recieveDamage(Will have int damage) within health script
//pass damage to sendMessage, Destroy other
// Destroy(other.gameobject)
}
public void WalkTowardsHero()
{
MoveTowards (this.player.transform.position);
}
public void MoveTowards(Vector3 targetPos, bool isInverse = false)
{
float speed = this.speed;
if (isInverse)
speed *= -1;
/* Walk towards target */
Vector3 newPos = Vector3.MoveTowards(this.transform.position, targetPos, speed);
this.transform.position = newPos;
/* Rotate facing towards target */
Vector2 direction = Vector2.zero;
if (speed > 0)
direction = targetPos - this.transform.position;
else
direction = this.transform.position - targetPos;
float directionAngle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
this.transform.rotation = Quaternion.AngleAxis(directionAngle, Vector3.forward);
}
void OnDrawGizmosSelected() {
// Display the explosion radius when selected
......
fileFormatVersion: 2
guid: 6e6bb3fc140db4e89aa90cbcf53eaf25
guid: 254a700a0e4b640e5abe9f7c157fd377
folderAsset: yes
timeCreated: 1479924870
licenseType: Free
......
fileFormatVersion: 2
guid: 6fcb17d7f421f4bc69fd8f40826ee566
guid: 760e656a65ae44f6698b835261977947
folderAsset: yes
timeCreated: 1477333793
licenseType: Free
......
fileFormatVersion: 2
guid: b8193b9e1ae094b7cb3ebd58a74cd6ed
guid: 3b148c2899d3a40d0b66ce776c70b89e
folderAsset: yes
timeCreated: 1477334519
licenseType: Free
......
fileFormatVersion: 2
guid: 5110b838530ca41e496f777295e2b20b
guid: 490e44a80fe8a420b846ed75236c4da8
folderAsset: yes
timeCreated: 1477334496
licenseType: Free
......
fileFormatVersion: 2
guid: 6a89423bd0e704867a110f8fc3d7fc24
guid: af413dbac5f22404db43788b04858697
folderAsset: yes
timeCreated: 1477334496
licenseType: Free
......
fileFormatVersion: 2
guid: d990fd53501dc4f2e89984a74ca738a2
guid: e80e84d84f8b14e71a2ab683139f68d8
folderAsset: yes
timeCreated: 1477692351
licenseType: Free
......
using UnityEngine;
using System.Collections;
public class HeroSpawnPoint : MonoBehaviour
{
protected GameObject hero;
void Start ()
{
this.hero = GameObject.FindGameObjectWithTag ("Player");
/* Teleport Hero to spawn point */
hero.transform.position = this.transform.position;
}
void Update ()
{
}
}
fileFormatVersion: 2
guid: a0a1a98abe88db349b13ec01fa4d1f2b
timeCreated: 1480210392
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: f74747c5c0fc3ff429984074c83570a5
timeCreated: 1480210380
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -6,6 +6,8 @@ public class HeroDeathCtrl : DeathCtrl
{
public Text deathTextUI;
public GameObject reviveStartingGun;
protected bool isDead;
protected HeroInventory heroInventory;
......@@ -52,6 +54,8 @@ public class HeroDeathCtrl : DeathCtrl
this.rb.isKinematic = true;
this.heroInventory.DropAllItems();
this.heroHealthCtrl.numLives--;
}
public void Revive()
......@@ -67,5 +71,16 @@ public class HeroDeathCtrl : DeathCtrl
this.spriteRend.enabled = true;
this.rb.isKinematic = false;
this.transform.position = GameObject.FindGameObjectWithTag ("PlayerSpawn").transform.position;
/* Spawn a weak pistol to give Hero a starting chance */
Vector3 gunSpawnPos = this.transform.position;
gunSpawnPos.x += 1.0f;
GameObject gun = (GameObject) Instantiate (this.reviveStartingGun, gunSpawnPos,
Quaternion.identity, null);
GameObject.FindGameObjectWithTag("ItemGenerator").GetComponent<ItemGeneratorCtrl>().
RemoveCloneStrFromName(gun);
}
}
using UnityEngine;
using System.Collections;
public class HeroGeneral : MonoBehaviour
{
void Awake ()
{
/* Allow this gameobject to persist between scenes */
DontDestroyOnLoad (this.gameObject);
}
void Start()
{
}
void Update ()
{
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment