Merge branch 'master' of https://github.com/new-00-0ne/System-Purge
This commit is contained in:
commit
8adb845f00
Binary file not shown.
Binary file not shown.
@ -8,11 +8,11 @@ public class Enemy : Controller{
|
||||
private state currentState;
|
||||
public LayerMask enemyMask;
|
||||
public bool rightdirection;
|
||||
public float[] time = new float[10];
|
||||
|
||||
// Use this for initialization
|
||||
void Start ()
|
||||
{
|
||||
rightdirection = true;
|
||||
isAir = false;
|
||||
print("start");
|
||||
changestate(new idle());
|
||||
}
|
||||
|
@ -7,7 +7,9 @@ public class idle : state
|
||||
{
|
||||
private ISceneObject manager;
|
||||
private Enemy enemy;
|
||||
private float time = 0;
|
||||
public float time;
|
||||
private Rigidbody2D myBody;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
Idle();
|
||||
@ -22,7 +24,7 @@ public class idle : state
|
||||
public void Idle()
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
if (time >= 3)
|
||||
if (time >= enemy.time[0])
|
||||
enemy.changestate(new wander());
|
||||
}
|
||||
}
|
||||
|
@ -25,12 +25,10 @@ public class seeking : state
|
||||
public void Execute()
|
||||
{
|
||||
seeplayer();
|
||||
if (isSee)
|
||||
if (!isSee)
|
||||
enemy.changestate(new idle());
|
||||
else
|
||||
Chase();
|
||||
|
||||
|
||||
}
|
||||
public void Exit(){}
|
||||
public void onTriggerEnter(Collider2D other){}
|
||||
@ -63,7 +61,7 @@ public class seeking : state
|
||||
public void Chase()
|
||||
{
|
||||
Vector2 myVel = myBody.velocity;
|
||||
if(!enemy.rightdirection)
|
||||
if(enemy.rightdirection)
|
||||
myVel.x = myTrans.right.x * speed;
|
||||
else
|
||||
myVel.x = myTrans.right.x * -speed;
|
||||
|
@ -5,33 +5,51 @@ using GameUtils;
|
||||
|
||||
public class wander : state
|
||||
{
|
||||
private Enemy enemy;
|
||||
public LayerMask enemyMask;
|
||||
public float speed;
|
||||
public float speed = 1;
|
||||
public bool flyPattern=true; // false is x-axis, true is y axis YOU HAPPY???? good
|
||||
public float maxFlightDistance = 0; // if flight distance is 0, fly foreva, probably should never do.. lol
|
||||
float distanceFlown=0;
|
||||
Rigidbody2D myBody;
|
||||
Transform myTrans;
|
||||
BoxCollider2D hitBox;
|
||||
float myWidth, myHeight;
|
||||
private float time=0;
|
||||
float lastPos;
|
||||
bool goingUp = false;
|
||||
private Enemy enemy;
|
||||
public float time;
|
||||
public bool isSee;
|
||||
private int dis;
|
||||
private int r;
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
{
|
||||
time += Time.deltaTime;
|
||||
if (time >= 10)
|
||||
if (time >= enemy.time[1])
|
||||
enemy.changestate(new idle());
|
||||
seeplayer();
|
||||
CheckHead();
|
||||
Move();
|
||||
if (enemy.isAir)
|
||||
{
|
||||
flyPattern = true;
|
||||
hover();
|
||||
}
|
||||
else
|
||||
{
|
||||
CheckHead();
|
||||
Move();
|
||||
}
|
||||
}
|
||||
|
||||
public void Enter(Enemy enemy)
|
||||
{
|
||||
Debug.Log("Wander");
|
||||
time = 0;
|
||||
dis = 5;
|
||||
this.enemy = enemy;
|
||||
this.enemyMask = enemy.enemyMask;
|
||||
r = Mathf.CeilToInt((UnityEngine.Random.Range(0.0F, 1.0F)));
|
||||
if (r == 1.0F)
|
||||
this.enemy.rightdirection = false;
|
||||
else
|
||||
this.enemy.rightdirection = true;
|
||||
dis = 5;
|
||||
myTrans = enemy.transform;
|
||||
myBody = enemy.GetComponent<Rigidbody2D>();
|
||||
SpriteRenderer mySprite = enemy.GetComponent<SpriteRenderer>();
|
||||
@ -56,17 +74,25 @@ public class wander : state
|
||||
myTrans.eulerAngles = currentRot;
|
||||
}
|
||||
}
|
||||
|
||||
public void Move()
|
||||
{
|
||||
Vector2 myVel = myBody.velocity;
|
||||
myVel.x = -myTrans.right.x * speed;
|
||||
if (!enemy.rightdirection)
|
||||
{
|
||||
myVel.x = myTrans.right.x * -speed;
|
||||
}
|
||||
else
|
||||
{
|
||||
myVel.x = myTrans.right.x * speed;
|
||||
}
|
||||
myBody.velocity = myVel;
|
||||
}
|
||||
public void seeplayer()
|
||||
{
|
||||
Vector2 lineCastPos = myTrans.position.toVector2() - myTrans.right.toVector2() * myWidth + Vector2.up * myHeight;
|
||||
lineCastPos.y = lineCastPos.y - (myHeight * 1.2f);
|
||||
if(enemy.rightdirection)
|
||||
if(!enemy.rightdirection)
|
||||
{
|
||||
Debug.DrawLine(lineCastPos, lineCastPos + myTrans.right.toVector2() * -dis);
|
||||
isSee = Physics2D.Linecast(lineCastPos, lineCastPos + myTrans.right.toVector2() * -dis, enemy.enemyMask);
|
||||
@ -81,4 +107,57 @@ public class wander : state
|
||||
enemy.changestate(new seeking());
|
||||
}
|
||||
}
|
||||
public void hover()
|
||||
{
|
||||
Vector2 lineCastPos;
|
||||
//check to see if there's something in front of us before moving forward
|
||||
if (flyPattern == false)
|
||||
{
|
||||
lineCastPos = myTrans.position.toVector2() - myTrans.right.toVector2() * myWidth + Vector2.up * myHeight;
|
||||
lineCastPos.y = lineCastPos.y - (myHeight * 1.2f);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (goingUp)
|
||||
lineCastPos = myTrans.position.toVector2() + myTrans.up.toVector2() * myWidth - Vector2.up * myHeight;
|
||||
else
|
||||
{
|
||||
lineCastPos = myTrans.position.toVector2() - myTrans.up.toVector2() * myWidth + Vector2.right * myHeight;
|
||||
lineCastPos.x -= myWidth;
|
||||
lineCastPos.y += myHeight;
|
||||
}
|
||||
}
|
||||
Debug.DrawLine(lineCastPos, lineCastPos + Vector2.down * 0.05f);
|
||||
bool isBlockedY = Physics2D.Linecast(lineCastPos, lineCastPos + Vector2.down * 0.05f, enemyMask);
|
||||
Debug.DrawLine(lineCastPos, lineCastPos - myTrans.right.toVector2() * 0.05f);
|
||||
bool isBlockedX = Physics2D.Linecast(lineCastPos, lineCastPos - myTrans.right.toVector2() * 0.05f, enemyMask);
|
||||
//if hit wall on x-axis ground turn around
|
||||
if ((isBlockedX && flyPattern == false) || (distanceFlown > maxFlightDistance && maxFlightDistance != 0 && flyPattern == false))
|
||||
{
|
||||
Vector3 currentRot = myTrans.eulerAngles;
|
||||
currentRot.y += 180;
|
||||
myTrans.eulerAngles = currentRot;
|
||||
distanceFlown = 0;
|
||||
}
|
||||
//if hit wall on y-axis ground turn around
|
||||
else if ((isBlockedY && flyPattern == true) || (distanceFlown > maxFlightDistance && maxFlightDistance != 0 && flyPattern == true))
|
||||
{
|
||||
//Vector3 currentRot = myTrans.eulerAngles;
|
||||
//currentRot.x += 180;
|
||||
//myTrans.eulerAngles = currentRot;
|
||||
distanceFlown = 0;
|
||||
speed = -speed;
|
||||
goingUp = !goingUp;
|
||||
}
|
||||
//Vertickle movement
|
||||
if (flyPattern == true)
|
||||
{
|
||||
Vector2 myVel = myBody.velocity;
|
||||
myVel.y = -myTrans.up.y * speed;
|
||||
distanceFlown += Mathf.Abs(lastPos - myTrans.position.y);
|
||||
Debug.Log(myVel);
|
||||
myBody.velocity = myVel;
|
||||
lastPos = myTrans.position.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ public class Controller : MonoBehaviour
|
||||
public bool groundCast, isBoxColliding;
|
||||
private Vector3 commonGroundSearchPoint;
|
||||
private Vector2 jumpCheckObjectPosition;
|
||||
private Transform position;
|
||||
private Transform jumpCheckObject;
|
||||
|
||||
void Awake()
|
||||
@ -50,5 +51,4 @@ public class Controller : MonoBehaviour
|
||||
else{onGround = false;}
|
||||
}
|
||||
public virtual void HandleInput() { } // Note that one input should move the variable camera position object around the player...
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user