Anda di halaman 1dari 5

using UnityEngine;

using System.Collections;

public abstract class MU_Move : MonoBehaviour


{
// different variables are declared
protected GameObject mAttackTarget;//target to attack
public bool mBL_Attacking = false;
public float mFL_Speed = 5.0f;
protected Vector3 mV3_NextPos;
protected Vector3 mV3_CurrentPos;
protected Vector3 mV3_TargetPos;
protected bool mBL_Moving = false;
protected GameObject mGO_Character;
protected MU_Level_Manager mLM_LevelManager;
public MU_FSM mFSMBrain;
protected State mStartState = State.walk;

////////////////////////////////////////////MY INPUT AND


STATS////////////////////////////////////////
public int Stamina;
public int Armour;
public int charstrength;
public int DamagePoints;

// Use this for initialization


public virtual void Start()
{
// set up for when the level is first started/run
mLM_LevelManager =
GameObject.Find("Level_Manager").GetComponent<MU_Level_Manager>();//sets
mlmlevelmanager as a component defined in the MU level manager class as level
manager
mV3_CurrentPos = mGO_Character.transform.position;//sets the current
position vector3 variable to hold the same value as the characters transform
postion
mV3_NextPos = mV3_CurrentPos;//sets the current position to the next
position variable
mV3_TargetPos = mV3_CurrentPos;// sets the target position variable as the
new current position variable
mBL_Moving = false;//sets boolean to false(unchanged)
mFSMBrain = gameObject.AddComponent<MU_FSM>();
mFSMBrain.Initialize(mStartState, this);
}
void StopEmitter()//turns off particle emitter by setting the emit boolean to
false
{
ParticleEmitter emitter =
transform.GetComponentInChildren<ParticleEmitter>();
emitter.emit = false;
}
// Update is called once per frame
public void Animate()
{
if (!mLM_LevelManager.isPaused())
Move();
}
public void attributechangerforenemies()
{
if (mGO_Character.tag == "FireSkeleton")
{
mGO_Character.transform.position =
Vector3.MoveTowards(mGO_Character.transform.position, mV3_CurrentPos, mFL_Speed * 2
* Time.deltaTime);
}
else if (mGO_Character.tag == "WaterSkeleton")
{
mGO_Character.transform.position =
Vector3.MoveTowards(mGO_Character.transform.position, mV3_CurrentPos, mFL_Speed *
0.5f * Time.deltaTime);
}
else if (mGO_Character.tag == "EarthSkeleton")
{
mGO_Character.transform.position =
Vector3.MoveTowards(mGO_Character.transform.position, mV3_CurrentPos, mFL_Speed *
0.1f * Time.deltaTime);
}
else if (mGO_Character.tag == "Enemy")
{
mGO_Character.transform.position =
Vector3.MoveTowards(mGO_Character.transform.position, mV3_CurrentPos, mFL_Speed *
Time.deltaTime);
}
else if (mGO_Character.tag == "Player")
{
mGO_Character.transform.position =
Vector3.MoveTowards(mGO_Character.transform.position, mV3_CurrentPos, mFL_Speed *
Time.deltaTime);
}
else if (mGO_Character.tag == "PatrolEnemy")
{
mGO_Character.transform.position =
Vector3.MoveTowards(mGO_Character.transform.position, mV3_CurrentPos, mFL_Speed *
Time.deltaTime);
}
}
public virtual void Move()
{
if (Vector3.Distance(mV3_CurrentPos, mGO_Character.transform.position) >
0.01f)//checks if the distance between the character gameobjects transform position
and the current position is greater then 0.01f
{
mBL_Moving = true;//sets the moving boolean to true
transform.LookAt(mV3_CurrentPos);//looks at the value of the vector
currentpos
attributechangerforenemies();
}
else//does not move game object
{
mGO_Character.transform.position = mV3_CurrentPos;
mBL_Moving = false;
ChooseNextPosition();
}
}
public void ChooseNextPosition()
{
mBL_Moving = false;
mGO_Character.transform.position = mV3_CurrentPos;
float tFL_Dx = (mV3_TargetPos.x - mV3_CurrentPos.x);//calculates the
difference beetween x and z of targeted position and current position
float tFL_Dz = (mV3_TargetPos.z - mV3_CurrentPos.z);
float tFL_Angle = Mathf.Atan2(tFL_Dx, tFL_Dz);// used to find the angleof
the desired position
int mIN_Choice = Random.Range(-1, 1);
if (mIN_Choice == 0)
{
if (Mathf.Abs(tFL_Dx) > 0.1f)
{
mV3_NextPos.x = mV3_CurrentPos.x + Mathf.Round(1.4f *
Mathf.Sin(tFL_Angle));
mV3_NextPos.z = mV3_CurrentPos.z;
}
}
else
{
if (Mathf.Abs(tFL_Dz) > 0.1f)
{
mV3_NextPos.x = mV3_CurrentPos.x;
mV3_NextPos.z = mV3_CurrentPos.z + Mathf.Round(1.4f *
Mathf.Cos(tFL_Angle));
}
}
CheckForCollision();
}
public void CheckForCollision()
{
if (mV3_NextPos.x < 0 || mV3_NextPos.x >
mLM_LevelManager.mAR_GO_PlayArea.GetLength(0))
{
mV3_NextPos.x = mV3_CurrentPos.x;
}
if (mV3_NextPos.z < 0 || mV3_NextPos.z >
mLM_LevelManager.mAR_GO_PlayArea.GetLength(1))
{
mV3_NextPos.z = mV3_CurrentPos.z;
}
mLM_LevelManager.mIN_Xpos = (int)mV3_NextPos.x;
mLM_LevelManager.mIN_Zpos = (int)mV3_NextPos.z;

if ((mLM_LevelManager.GetPlayAreaObject()) && (mV3_NextPos !=


mV3_TargetPos) && mLM_LevelManager.GetPlayAreaObject() != mGO_Character)
{
int tIN_NewX = Random.Range(-1, 2);
int tIN_NewZ = Random.Range(-1, 2);
int tIN_Choice;
tIN_Choice = Random.Range(-1, 1);
if (tIN_Choice == 0)
{
while ((mV3_CurrentPos.x + tIN_NewX) < 0 || (mV3_CurrentPos.x +
tIN_NewX) > mLM_LevelManager.mAR_GO_PlayArea.GetLength(0))
{
tIN_NewX = Random.Range(-1, 2);
}
mV3_NextPos.x = mV3_CurrentPos.x + tIN_NewX;
mV3_NextPos.z = mV3_CurrentPos.z;
}
else
{
while ((mV3_CurrentPos.z + tIN_NewZ) < 0 || (mV3_CurrentPos.z +
tIN_NewZ) > mLM_LevelManager.mAR_GO_PlayArea.GetLength(1))
{
tIN_NewZ = Random.Range(-1, 2);
}
mV3_NextPos.x = mV3_CurrentPos.x;
mV3_NextPos.z = mV3_CurrentPos.z + tIN_NewZ;
}
mLM_LevelManager.mIN_Xpos = (int)mV3_NextPos.x;
mLM_LevelManager.mIN_Zpos = (int)mV3_NextPos.z;
}
if ((mLM_LevelManager.GetPlayAreaObject() == null) && !mBL_Moving)
{
mLM_LevelManager.mIN_Xpos = (int)mV3_CurrentPos.x;
mLM_LevelManager.mIN_Zpos = (int)mV3_CurrentPos.z;

GameObject tGO_CharObject = mLM_LevelManager.GetPlayAreaObject();


mLM_LevelManager.SetPlayAreaObject(null);

mLM_LevelManager.mIN_Xpos = (int)mV3_NextPos.x;
mLM_LevelManager.mIN_Zpos = (int)mV3_NextPos.z;
mLM_LevelManager.SetPlayAreaObject(tGO_CharObject);

mV3_CurrentPos = mV3_NextPos;
}
}

//public methods for changing private data


// methods used to return some data that is private
public Vector3 GetNextPos()
{
return mV3_NextPos;
}
public void SetNextPos(Vector3 vV3_Pos)
{
mV3_NextPos = vV3_Pos;
}
public Vector3 GetCurrentPos()
{
return mV3_CurrentPos;
}
public void SetCurrentPos(Vector3 vV3Pos)
{
mV3_CurrentPos = vV3Pos;
}
public Vector3 GetTargetPos()
{
return mV3_TargetPos;
}
public void SetTargetPos(Vector3 vV3Pos)
{
mV3_TargetPos = vV3Pos;
}
public bool IsMoving()
{
return mBL_Moving;
}
//getters and setter for hp/str/def
public GameObject AttackTarget
{
set
{
this.mAttackTarget = value;
}
get
{
return this.mAttackTarget;
}
}
}