Beispiel #1
0
        public void Update(GameTime time, Vector3 hero_pos)
        {
            switch (STATE) // transitions
            {
                case EnemyState.Wait:
                    timer_ms += time.ElapsedGameTime.Milliseconds;
                    double distance = ( hero_pos - pos ).Length();
                    if( distance < FIGHTDISTANCE )
                    if (timer_ms > firerate_ms)
                    {
                        STATE = EnemyState.Fire;
                    }
                    break;
                case EnemyState.Fire:
                    STATE = EnemyState.Wait;
                    break;
                case EnemyState.Dead:
                    break;
                default:
                    STATE = EnemyState.Wait;
                    break;
            }

            switch (STATE)
            {
                case EnemyState.Wait:
                    break;
                case EnemyState.Fire:
                    break;
                case EnemyState.Dead:
                    break;
            }
        }
 /// <summary>
 /// Construct new Enemy from EnemyData structure, a texture for the enemy, and a texture for its cannon balls
 /// </summary>
 /// <param name="e">EnemyData structure that holds all initialization data.  Loaded from the main game using the ContentPipeline</param>
 /// <param name="tex">Texture representing this enemy</param>
 /// <param name="cBTex">Texture representing enemy cannon balls</param>
 public Enemy(EnemyData e, Texture2D tex, Texture2D cBTex)
     : base(e,tex,cBTex)
 {
     range = e.range;
     score = e.score;
     state = EnemyState.Chasing;
 }
    void CheckState()
    {
        if( bKnockBack )
        {
            state = EnemyState.KnockBack;
        }
        else  if( !bKnockBack && state == EnemyState.KnockBack)
        {
            state = EnemyState.Idle;
        }

        if( fAttackCurrent > fAttackTime + (fAttackWait*2) )
        {
            fAttackCurrent = 0;
            state = EnemyState.Idle;
            attack.SetActive(false);
        }
        else if( bAttacked != true && (state == EnemyState.Attack || ( state != EnemyState.Attack && Vector3.Distance( transform.position , manager.GetActivePlayer().transform.position ) < fAttackDistance) ) )
        {
            state = EnemyState.Attack;
        }

        if( state != EnemyState.KnockBack && state != EnemyState.Dead && state != EnemyState.Attack)
        {
            state = EnemyState.Move;
        }
        else if( state == EnemyState.Dead)
        {
            Die();
        }
        //		else
        //		{
        //			state = EnemyState.Idle;
        //		}
    }
Beispiel #4
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (Cutscene.current != null) return;
        if (state == EnemyState.Patrolling) {
            // Reverse direction if at destination
            if ((Vector2)transform.position == patrolEnd) {
                Vector3 temp = patrolEnd;
                patrolEnd = patrolStart;
                patrolStart = temp;
            }

            transform.position = Vector2.MoveTowards(transform.position, patrolEnd, runSpeed * Time.deltaTime);

            if (canFollow) {
                if (Vector2.Distance(Player.S.transform.position, transform.position) < sightRange)
                    state = EnemyState.Following;
            }
        } else if (state == EnemyState.Following) {
            transform.position = Vector2.MoveTowards(transform.position, Player.S.transform.position, followSpeed * Time.deltaTime);
            if (Vector2.Distance(Player.S.transform.position, transform.position) > sightRange)
                state = EnemyState.Patrolling;
        }
        if (Vector2.Distance(Player.S.transform.position, transform.position) < attackRange) {
            if (Time.time > nextAttackTime) {
                Player.S.TakeDamage(attackDamage);
                nextAttackTime = Time.time + attackSpeed;
            }
        }
    }
        private void Initialize(Vector2 entryPosition)
        {
            this.ScaleSize(0.5M);
            this.Visible = true;
            this.randomDropChance = 10;

            _maxSpeed = 150;

            _state = EnemyState.Entering;

            this.targetEntryPosition = entryPosition;
            this.exitPosition = new Vector2(-50, -50);

            this._maxShotTime = 1000;
            this._shotTimer = this._maxShotTime;
            this._shotCount = 0;

            this._lastPlayerPositions = new Queue<Vector2>();

            this._lifeTimer = 10000;

            this.Velocity = Vector2.Zero;

            _weapons = new List<IWeapon>();

            //Point pellet gun
            _weapons.Add(new PelletGun(this.centerPosition, new Vector2(0, this.Height / 2), new Vector2(0, 250), 300d));
        }
 public void Reset()
 {
     state = EnemyState.Idle;
     gs.Enemy.width = 100f;
     gs.Enemy.height = 160f;
     gs.Enemy.position = gs.startEnemyPos;
 }
        void FixedUpdate()
        {
            GetComponent<Animator>().SetBool("IsAttacking", false);

            switch (State)
            {
                case EnemyState.Idle:
                    if (CanSeePlayer())
                    {
                        State = EnemyState.Detect;
                        GetComponent<Animator>().SetBool("IsMoving", true);
                    }
                    break;
                case EnemyState.Patrolling:
                    if (CanSeePlayer())
                    {
                        State = EnemyState.Detect;
                        GetComponent<Animator>().SetBool("IsMoving", true);
                    }
                    break;
                case EnemyState.Searching:
                    SearchState();
                    break;
                case EnemyState.Detect:
                    AlertState();
                    break;
            }
        }
        private void InitializeDefaultEnemy(Vector2 TargetEntryPoint)
        {
            this.ScaleSize(0.5M);

            _screenPasses = 0;
            _maxPasses = 3;
            this.Visible = true;

            _maxSpeed = 150;

            _state = EnemyState.Entering;

            this.targetEntryPoint = TargetEntryPoint;

            this.Velocity = Vector2.Zero;

            _weapons = new List<IWeapon>();

            //Top Left pellet gun
            _weapons.Add(new PelletGun(this.centerPosition, new Vector2(-this.Width / 2, -this.Height / 2), new Vector2(-250, -250), 300d));
            //Top Right pellet gun
            _weapons.Add(new PelletGun(this.centerPosition, new Vector2(this.Width / 2, -this.Height / 2), new Vector2(250, -250), 300d));
            //Bottom Left pellet gun
            _weapons.Add(new PelletGun(this.centerPosition, new Vector2(-this.Width / 2, this.Height / 2), new Vector2(-250, 250), 300d));
            //Bottom Right pellet gun
            _weapons.Add(new PelletGun(this.centerPosition, new Vector2(this.Width / 2, this.Height / 2), new Vector2(250, 250), 300d));
        }
        /// <summary>
        /// Updates this enemy instance
        /// </summary>
        /// <param name="gameTime">The time elapsed since the last update</param>
        public override void Update(GameTime gameTime)
        {
            switch (_state)
            {
                case EnemyState.Entering:
                    if (Entering(gameTime))
                    {
                        _state = EnemyState.Attacking;
                        this.Velocity = (this.Position.X < ManicShooter.ScreenSize.Width / 2) ? new Vector2(_maxSpeed, 0) : new Vector2(-_maxSpeed, 0);
                    }
                    break;
                case EnemyState.Attacking:
                    if (HorizontalPasses(gameTime)) _state = EnemyState.Leaving;
                    break;
                case EnemyState.Leaving:
                    LeaveScreen(gameTime.ElapsedGameTime);

                    if (this.IsOffScreen()) this.Destroy();
                    break;
            }

            ApplyVelocity(gameTime.ElapsedGameTime);
            UpdateWeaponPositions();

            base.Update(gameTime);
        }
Beispiel #10
0
 // Use this for initialization
 void Awake()
 {
     body = gameObject.GetComponent<Rigidbody2D> ();
     player = GameObject.FindGameObjectWithTag("Player").transform;
     enemyState = EnemyState.Chase;
     spriteRenderer = gameObject.GetComponent<SpriteRenderer> ();
 }
Beispiel #11
0
 public Enemy(Texture2D loadedTexture, Vector2 position, int frameCount, int framesPerSec, Action<Enemy, double> ai)
     : base(loadedTexture, position, 0f, 1f, 1f, frameCount, framesPerSec)
 {
     this.Ai = ai;
     this.State = EnemyState.Idle;
     this.Direction = Directions.Left;
 }
Beispiel #12
0
 public void Die()
 {
     ES = EnemyState.Dead;
     anim.CrossFade("Dead", 0.2f);
     //fade out and destroy?
     StartCoroutine("FadeOut");
 }
Beispiel #13
0
	public void StopMoving(){
		Animation ani = gameObject.GetComponent<Animation> ();
		if(ani){
			//ani.Stop();
			STATE = EnemyState.Stop;
		}
	}
    /*In here there is a switch-statement which handles which method that is going
        * to be updating, this is chosen by the currentState of the enemy.
         It is in here that you will add your own EnemyState.yourState-case and call for your own method below*/
    public virtual void Update()
    {
        playerPosition = (GameObject.Find ("Player").transform.position);
        distance = Vector3.Distance(playerPosition, transform.position);
        switch (currentState) {
        case EnemyState.initializing:
            /*filling in the player reference for easier access*/
            /*playerReference = GameObject.Find ("Player");*/
            currentState = EnemyState.idle;
            break;
        case EnemyState.idle:
            Idle();
            break;
        case EnemyState.sawPlayer:
            SawPlayer();
            break;
        case EnemyState.chasing:
            Chasing();

            break;
        case EnemyState.attacking:
            Attacking();

            currentState = EnemyState.idle;
            break;
        case EnemyState.fleeing:
            Fleeing();

            currentState = EnemyState.idle;
            break;
        default:
            break;
        }
    }
 public void SetState(EnemyState state)
 {
     this.state = state;
     switch (state)
     {
         case EnemyState.IDLE:
             GetComponent<Animator>().SetBool("isHit", false);
             GetComponent<Animator>().SetBool("isKnock", false);
             transform.localScale = new Vector3(1, 1, 1);
             break;
         case EnemyState.HIT:
             GetComponent<Animator>().SetBool("isHit", true);
             if (attack)
                 attack.Play();
             break;
         case EnemyState.KNOCK:
             GetComponent<Animator>().SetBool("isKnock", true);
             transform.localScale = new Vector3(-1, 1, 1);
             if (attack)
                 attack.Play();
             break;
         case EnemyState.DEAD:
             GetComponent<Animator>().SetBool("isDead", true);
             GetComponent<TargetState>().IsDead = true;
             if (die)
                 die.Play();
             break;
     }
 }
Beispiel #16
0
	void Start () {
		player = GameManager.instance.Player;
		spiral = new SpiralMotionEnemyState(this, player);

		currentState = spiral;
		currentState.StartState();
	}
 public void Die()
 {
     currentState = EnemyState.DEAD;
     isDead = true;
     audio.PlayDie();
     StartCoroutine(DieCoroutine());
 }
Beispiel #18
0
    public void InCombat()
    {
        PatrolPath enemyPatrol = GetComponent<PatrolPath>() as PatrolPath;

        // Turn towards player
        if (enemyState == EnemyState.ENEMY_PATROLLING)
        {
            // Stop the enemy from Patrolling
            enemyPatrol.Disable();

            enemyState = EnemyState.ENEMY_AGGRO;
        }

        if (enemyState == EnemyState.ENEMY_AGGRO)
        {
            // Change direction towards player
            if (ChangeDirection(playerTransform.position))
            {
                // Walk towards the player
                Vector3 faceDirection = playerTransform.position - transform.position;
                transform.position = transform.position + (faceDirection * (MovementSpeed * Time.smoothDeltaTime));

                if (Vector3.Distance(transform.position, playerTransform.position) <= AttackRadius)
                {
                    enemyState = EnemyState.ENEMY_ATTACKING;
                }
            }
        }

        if (enemyState == EnemyState.ENEMY_ATTACKING)
        {
            if (Vector3.Distance(transform.position, playerTransform.position) >= AttackRadius)
            {
                enemyState = EnemyState.ENEMY_AGGRO;
            }
        }

        if (enemyState == EnemyState.ENEMY_EVADE)
        {
            // Move back towards the disabled position
            if (ChangeDirection(enemyPatrol.GetDisabledPosition()))
            {
                Vector3 faceDirection = enemyPatrol.GetDisabledPosition() - transform.position;
                transform.position = transform.position + (faceDirection * (MovementSpeed * Time.smoothDeltaTime));

                if (Vector3.Distance(transform.position, enemyPatrol.GetDisabledPosition()) < 0.01f)
                {
                    enemyState = EnemyState.ENEMY_PATROLLING;
                    enemyPatrol.Enable();
                    inCombat = false;
                }
            }
        }

        if (Vector3.Distance(transform.position, enemyPatrol.GetDisabledPosition()) >= PlayerChaseRadius)
        {
            enemyState = EnemyState.ENEMY_EVADE;
        }
    }
Beispiel #19
0
 void Awake()
 {
     createNewHeading();
     dreamManager = GameObject.FindGameObjectWithTag("DreamManager").GetComponent<LDDreamManager>();
     currentDreamState = LDDreamManager.DreamState.forest;
     damageTimer = damageFrequency;
     currentState = EnemyState.searching;
 }
 public Enemy(ContentManager content, string assetMoveLeft, string assetMoveRight, string assetHitLeft, string assetHitRight, Vector2 position, int level, float frameTime, int numberOfFrames, bool looping)
     : base(content, assetMoveLeft, assetMoveRight, assetHitLeft, assetHitRight, position, level, frameTime, numberOfFrames, looping)
 {
     this.enemyState = EnemyState.Chill;
     this.Position = position;
     this.startPositionX = position.X;
     this.startPositionY = position.Y;
 }
 public void Guard()
 {
     state = EnemyState.Guard;
     timer = GUARD_TIME;
     gs.Enemy.width = 100f;
     gs.Enemy.height = 160f;
     gameObject.audio.PlayOneShot ( gs.defSFX );
 }
    public void Initialize(LevelMap map)
    {
        this.map = map;

        setNewGoal();
        computePathToGoal();
        state = EnemyState.Wander;
    }
 public void Die()
 {
     state = EnemyState.Dying;
     timer = DYING_TIME;
     gs.Enemy.width = 160f;
     gs.Enemy.height = 120f;
     gameObject.audio.PlayOneShot ( gs.enemyDieSFX );
 }
    IEnumerator StartedMoving(float time)
    {
        MyState = EnemyState.Moving;

        yield return new WaitForSeconds(time);

        MyState = EnemyState.Idle;
    }
Beispiel #25
0
	// Update is called once per frame
	void Update () {
		if(STATE.Equals(EnemyState.Run)){
			transform.position = new Vector3(transform.position.x  , transform.position.y, transform.position.z - 0.1f);
		}else if (STATE.Equals(EnemyState.Stop)){
			transform.position = new Vector3(transform.position.x  , transform.position.y, transform.position.z + 2.0f);
			STATE = EnemyState.Die;
		}
	}
 public void Attack()
 {
     state = EnemyState.Prepare;
     timer = PREPARE_TIME;
     gs.Enemy.width = 100f;
     gs.Enemy.height = 160f;
     gameObject.audio.PlayOneShot ( gs.attackSFX );
 }
Beispiel #27
0
 public Enemy(Vector2 center)
 {
     Center = center;
     InitialPos = center;
     CurrentState = EnemyState.Patrol;
     initialLives = 1;
     health = new HealthBar(this.Center);
 }
 public Enemy(Vector2 center, string type)
 {
     Center = center;
     Width = WIDTH;
     Height = HEIGHT;
     Color = Color.Green;
     CurrentState = EnemyState.Patrol;
 }
 public Enemy(Vector2 center, float width, float height, Hero hero)
     : base(center, width, height)
 {
     this.hero = hero;
     setColor(Game.randomColor());
     enemyState = EnemyState.BEGIN;
     timer = new Timer(behaviorChangeTime);
 }
Beispiel #30
0
 public IEnumerator Attack()
 {
     Speed=0;
     ES=EnemyState.Attack;
     PlayerScript.HurtPlayer();
     yield return new WaitForSeconds(.5f);
     ES=EnemyState.Wait;
 }
Beispiel #31
0
 // Update is called once per frame
 void Update()
 {
     state = FindObjectOfType <EnemyState>();
     if (state.HP > 0)
     {
         if (Vector3.Distance(state.transform.position, hades.transform.position) < 29 && !isout)
         {
             isout              = true;
             gameObject.layer   = 0;
             transform.position = state.transform.position;
         }
         if (isout)
         {
             attacktime -= Time.deltaTime;
             if (attacktime < 0f)
             {
                 rigidbody.position = state.transform.position;
                 gameObject.layer   = 2;
                 attacktime         = 1.8f;
                 isout = false;
             }
         }
     }
 }
Beispiel #32
0
    // Start is called before the first frame update
    void Start()
    {
        playerState  = GameObject.Find("PlayerState").GetComponent <PlayerState>();
        enemyState   = GameObject.Find("EnemyState").GetComponent <EnemyState>();
        battleStates = PerformAction.WAIT;
        HeroesInBattle.Add(GameObject.Find("Hero0"));
        HeroesInBattle.Add(GameObject.Find("Hero1"));
        HeroesInBattle.Add(GameObject.Find("Hero2"));
        HeroesInBattle.Add(GameObject.Find("Hero3"));
        EnemiesInBattle.Add(GameObject.Find("Enemy0"));
        EnemiesInBattle.Add(GameObject.Find("Enemy1"));
        EnemiesInBattle.Add(GameObject.Find("Enemy2"));
        EnemiesInBattle.Add(GameObject.Find("Enemy3"));
        SpawnUnits();
        HeroInput = HeroGUI.ACTIVATE;

        ActionPanel.SetActive(false);
        TargetSelectPanel.SetActive(false);
        //find spacer
        HeroPanelSpacer  = GameObject.Find("HeroPanelSpacer").transform;
        EnemyPanelSpacer = GameObject.Find("EnemyPanelSpacer").transform;
        CreateCharacterBars();
        battleStarted = true;


        advantageState = GameObject.Find("WorldState").GetComponent <WorldState>().advantageState;
        foreach (GameObject unit in HeroesInBattle)
        {
            unit.GetComponent <HeroStateMachine>().advantageState = advantageState;
        }

        foreach (GameObject unit in EnemiesInBattle)
        {
            unit.GetComponent <EnemyStateMachine>().advantageState = advantageState;
        }
    }
 //function responsible for attacking the player
 void Attack()
 {
     //zombie has stopped moving
     navAgent.velocity  = Vector3.zero;
     navAgent.isStopped = true;
     //the timer for the zombie attacks
     attack_Timer += Time.deltaTime;
     //enough time has passed to attack the player
     if (attack_Timer > wait_Before_Attack)
     {
         // play attack sound
         enemyAudio.PlayAttackSound();
         //play the attack animation
         enemy_Anim.Attack();
         //reset the timer for the next attack
         attack_Timer = 0f;
     }
     //if the player flees, chase them
     if (Vector3.Distance(transform.position, target.position) >
         attack_Distance + chase_After_Attack_Distance)
     {
         enemy_State = EnemyState.CHASE;
     }
 }
    //the functio responsible for the random patrolling of the zombie
    void Patrol()
    {
        // tell nav agent that he can move
        navAgent.isStopped = false;
        navAgent.speed     = walk_Speed;

        // add to the patrol timer
        patrol_Timer += Time.deltaTime;
        //if the timer for the patrol has reached its limit, start a new direction to patrol
        // and reset the timer
        if (patrol_Timer > patrol_For_This_Time)
        {
            SetNewRandomDestination();
            patrol_Timer = 0f;
        }
        //if the velocity of the enemy is not 0, then play the walking animation
        if (navAgent.velocity.sqrMagnitude > 0)
        {
            enemy_Anim.Walk(true);
        }
        else
        {
            enemy_Anim.Walk(false);
        }

        // test the distance between the player and the enemy
        if (Vector3.Distance(transform.position, target.position) <= chase_Distance)
        {
            //not walking anymore
            enemy_Anim.Walk(false);
            //going to chase state to start chasing the player
            enemy_State = EnemyState.CHASE;
            // play spotted audio
            enemyAudio.PlayScreamSound();
        }
    }
Beispiel #35
0
    void EnemyRandomState()
    {
        if ((state == EnemyState.Walk) || (state == EnemyState.Attack))
        {
            return;
        }

        int randomNum = Random.Range(0, 100);

        if (randomNum < 40)
        {
            state = EnemyState.Idle;
        }
        else if (randomNum > 40 && randomNum < 80)
        {
            state = EnemyState.Attack;
        }
        else
        {
            state = EnemyState.Idle;
        }

        UpdateEnemyState(state);
    }
Beispiel #36
0
    public void SetState(EnemyState nextState)
    {
        currentState = nextState;
        switch (currentState)
        {
        case EnemyState.Idle:
            animator.SetTrigger("Idle");

            break;

        case EnemyState.Walking:
            animator.SetTrigger("StartWalk");
            break;

        case EnemyState.Attacking:
            break;

        case EnemyState.Die:
            break;

        default:
            break;
        }
    }
Beispiel #37
0
    void CheckDistanceToPlayer()
    {
        switch (state)
        {
        case EnemyState.PATROLLING:
            if (Vector2.Distance(transform.position, player.position) < 4.0f)
            {
                lastKnownWaypoint = targetWaypoint;
                targetWaypoint    = player.transform;
                greivinVisto      = true;
                state             = EnemyState.FOLLOWING_PLAYER;
            }

            break;

        case EnemyState.FOLLOWING_PLAYER:
            if (greivinVisto)
            {
                lastKnownWaypoint = targetWaypoint;
                targetWaypoint    = player.transform;
            }
            break;
        }
    }
    void Patrol()
    {
        // tell nav agent that he can move
        navAgent.isStopped = false;
        navAgent.speed     = walk_Speed;

        // add to the patrol timer
        patrol_Timer += Time.deltaTime;

        if (patrol_Timer > patrol_For_This_Time)
        {
            SetNewRandomDestination();

            patrol_Timer = 0f;
        }

        if (navAgent.velocity.sqrMagnitude > 0)
        {
            enemy_Anim.Walk(true);
        }
        else
        {
            enemy_Anim.Walk(false);
        }

        // test the distance between the player and the enemy
        if (Vector3.Distance(transform.position, target.position) <= chase_Distance)
        {
            enemy_Anim.Walk(false);

            enemy_State = EnemyState.CHASE;

            // play spotted audio
            enemy_Audio.Play_ScreamSound();
        }
    } // patrol
Beispiel #39
0
    void StateChange()
    {
        float y_Pos = transform.position.y;
        float x_Pos = transform.position.x;

        if (y_Pos >= up_limitPos && currentState == EnemyState.UP)
        {
            //ステートセーブ
            previousState = currentState;
            currentState  = EnemyState.Idle;
        }

        if (y_Pos <= down_limitPos && currentState == EnemyState.DOWN)
        {
            //ステートセーブ
            previousState = currentState;
            currentState  = EnemyState.Idle;
        }

        if (x_Pos >= right_limitPos || x_Pos <= left_limitPos)
        {
            isRetrun = !isRetrun;
        }
    }
Beispiel #40
0
    private void AssignNewPath()
    {
        Vector2Int pathStart = _pathfinding.FindNearestWalkable(_rb.position);

        _path.Clear();
        // Debug.Log(_pathfinding.PathExist(_rb.position,_destination));
        var path = _pathfinding.GetPath(pathStart, Vector2Int.RoundToInt(_destination));

        state = EnemyState.Patrol;
        if (path == null)
        {
            SetDestination();
        }
        // if (mode == EnemyMode.Defend && path.Count <= 1) return;
        if (path != null)
        {
            foreach (var dest in path)
            {
                _path.Enqueue(dest);
            }
        }

        _waitingForPath = false;
    }
Beispiel #41
0
    /**
     * This enemy will make a mad dash towards the player.
     *
     * FacePlayer() will flip the enemy in the direction of the player, making it so that the
     * force will always propel the enemy towards the player.
     *
     * Once it initiates the sprint the enemy will keep charging towards the player untill
     * the BlindSprint() time has passed, then it will check to see if the player is still
     * visable and if not will return to the idle state.
     */
    private void Sprint()
    {
        if (type == EnemyType.runner && Mathf.Abs(GetComponent <Rigidbody2D>().velocity.x) >= sprintMinSpeed)
        {
            anim.SetBool("sprint", true);
        }

        FacePlayer();
        GetComponent <Rigidbody2D>().AddForce(transform.right * (-moveSpeed * 5));

        if (!delayCoroutineStarted) // Trigger only once!
        {
            StartCoroutine(BlindSprint());
        }

        if (!isBlinded)
        {
            IsTargetInRange();
            if (!playerSpotted)
            {
                _state = EnemyState.idle;
            }
        }
    }
Beispiel #42
0
    IEnumerator CheckMonsterState()
    {
        while (true)
        {
            yield return(new WaitForSeconds(0.5f));

            float dist = Vector3.Distance(playerTr.position, transform.position);

            if (isDie)
            {
                if (!isRespawn)
                {
                    enemyState = EnemyState.ENEMY_DIE;

                    GameObject Coin = Instantiate(Resources.Load <GameObject>("Prefabs/Enemy/coin"), this.gameObject.transform.position, this.gameObject.transform.rotation);
                    Coin.GetComponent <Coin>().Price = int.Parse((gameObject.GetComponent <Health>().MaxGauge * 10).ToString()) + int.Parse((Random.Range(-10, 20)).ToString());

                    yield return(new WaitForSeconds(2.0f));

                    enemyState = EnemyState.ENEMY_RESPAWN;
                }
            }
            else if (dist <= attackDist)
            {
                enemyState = EnemyState.ENEMY_ATTACK;
            }
            else if (dist <= traceDist)
            {
                enemyState = EnemyState.ENEMY_TRACE;
            }
            else
            {
                enemyState = EnemyState.ENEMY_IDLE;
            }
        }
    }
Beispiel #43
0
    public virtual void ChangeState(EnemyState currentState)
    {
        switch (currentState)
        {
        case EnemyState.idle:
            Idle();
            break;

        case EnemyState.pacing:
            Pace();
            break;

        case EnemyState.approaching:
            Approach();
            break;

        case EnemyState.attacking:
            Attack();
            break;

        case EnemyState.fleeing:
            Flee();
            break;

        case EnemyState.wandering:
            Wander();
            break;

        case EnemyState.waiting:
            Wait();
            break;

        default:
            break;
        }
    }
Beispiel #44
0
 public void gotoRoam()
 {
     //Debug.Log("go to roam");
     changeAnim(2);
     checkClosestPlayer();
     if (Time.fixedTime >= dashStamp)
     {
         if (seesPlayer)
         {
             pathFind();
         }
         else
         {
             randomPathfind(); // if player just made a dash, move in random direction
         }
     }
     else
     {
         randomPathfind();
     }
     newMoveSpeed(1);
     moveStamp    = Time.time + roamTime;
     currentState = EnemyState.Roam;
 }
Beispiel #45
0
        private void PatrolMove(GameTime gameTime)
        {
            if (tileDestination == null)
            {
                return;
            }
            var direction  = Directions.Normalize(level.Map.ConvertToWindowCoordinates((Vector2i)tileDestination) - Position);
            var moveVector = speed * direction * gameTime.DeltaTime;

            if (level.Map.GetTileGidInLayer((Vector2i)tileDestination, level.Map.collisionTiles) != Map.Wall &&
                !CheckCollisions(moveVector))
            {
                Position += moveVector;
                var oldRotation = Rotation;
                Rotation = GetRotationDependingOnDirection(moveVector);
                if (Directions.IsVectorsEqual(Position, pointDestination))
                {
                    tileDestination = null;
                    state           = EnemyState.Patrol;
                }
                viewZone.Position = Position;
                viewZone.Rotate((Rotation - oldRotation) * (float)Math.PI / 180);
            }
        }