コード例 #1
0
 void Patrol()
 {
     TileScript.MotionSpeed = BaseMotionSpeed;
     if (!TileScript.IsMoving)
     {
         bool[]    attemptedRotations = new bool[] { false, false, false, false };
         SRotation startingRotation   = Rotation;
         for (int i = 0; i < 3; i++) // three tries to try walking
         {
             attemptedRotations[(int)Rotation] = true;
             if (MoveForward()) // try moving forward
             {
                 break;
             }
             if (i != 2)
             {
                 Rotation = GetRightLeft(startingRotation, i == 0); // check right, then left
             }
             else // else look behind
             {
                 Rotation = GetBehind(startingRotation);
                 if (!MoveForward()) // try to go backwards, if not, then freeze he's stuck
                 {
                     CurrentMode = EnemyMode.IDLE;
                     break;
                 }
             }
         }
     }
 }
コード例 #2
0
    private void OnTriggerEnter(Collider other)
    {
        AudioSource noise = other.gameObject.GetComponent <AudioSource>();

        if (noise != null)
        {
            aiTrans.LookAt(noise.transform.position);

            if (CanSee(GameObject.FindGameObjectWithTag("Player")))
            {
                switch (aiBehavior)
                {
                case Behavior.AGGRESSIVE:
                    aiShoot.Shoot(aiData.shellForce);
                    aiMode = EnemyMode.CHASE;
                    break;

                case Behavior.NERVOUS:
                    aiShoot.Shoot(aiData.shellForce);
                    aiMode = EnemyMode.CHASE;
                    break;

                case Behavior.TIMID:
                    aiShoot.Shoot(aiData.shellForce);
                    aiMode = EnemyMode.RUN;
                    break;

                default:
                    break;
                }
            }
        }
    }
コード例 #3
0
ファイル: Enemy.cs プロジェクト: tmenezes/SpaceShooter2D
    public EnemyModeOptions(EnemyMode mode, GameObject path, EndOfPathInstruction endOfPathMode)
    {
        Mode = mode;
        Path = path != null?path.GetComponent <PathCreator>() : null;

        EndOfPathMode = endOfPathMode;
    }
コード例 #4
0
    public void BeSurprised()
    {
        if (currentMode != EnemyMode.FLEEING)
        {
            currentMode = EnemyMode.SURPRISED;
            dm.ShowReveal();
            Debug.Log("Surprise!");
            if (flipCycle != null)
            {
//			CancelFlipCycle ();
            }
            if (!unarmed)
            {
                unarmed = true;
                myAnim.SetBool("armed", false);
                Drop();
            }
            if (instance == null || instance.name != "Exclamation")
            {
                Destroy(instance);
                am.Play("alert");
                instance = Instantiate(exclamation, new Vector3(transform.position.x, transform.position.y + 2.5f), Quaternion.identity);
                instance.transform.parent = transform;
                Destroy(instance, 5f);
            }
        }
    }
コード例 #5
0
 //idle mode
 private void Idle()
 {
     if (personality == Personality.Turret)
     {
         return;
     }
     enemyMode = EnemyMode.Patrol;
 }
コード例 #6
0
    /// <summary>
    /// Inicia la IA del enemigo.
    /// </summary>
    public void StartAI()
    {
        isActive    = true;
        currentMode = defaultMode;

        StopCoroutine(WaitBetweenIterations(timeBetweenIterations));
        StartCoroutine(WaitBetweenIterations(timeBetweenIterations));
    }
コード例 #7
0
    void OnCollisionStay2D(Collision2D coll)
    {
        if (currentMode != EnemyMode.TRANQUILIZED)
        {
            collided = coll.gameObject.name;

            if (coll.gameObject.layer == 13 && currentMode != EnemyMode.FLEEING)
            {
                target = new Vector3(initialPosition.x, transform.position.y, transform.position.z);
            }
            else if (coll.gameObject.layer == 13 && currentMode == EnemyMode.FLEEING)
            {
                currentMode = EnemyMode.F****D;
            }
            if (coll.gameObject.tag == "Crate" && currentMode == EnemyMode.FLEEING)
            {
                currentMode = EnemyMode.F****D;
            }
            else if (coll.gameObject.tag == "Crate" && currentMode != EnemyMode.FLEEING)
            {
                if (transform.position.x < coll.gameObject.transform.position.x)
                {
                    target = new Vector3(transform.position.x - 15f, transform.position.y, transform.position.z);
                }
                if (transform.position.x > coll.gameObject.transform.position.x)
                {
                    target = new Vector3(transform.position.x + 15f, transform.position.y, transform.position.z);
                }
            }
            if (coll.gameObject.name == "Player" && currentMode != EnemyMode.FLEEING && currentMode != EnemyMode.F****D)
            {
                GameObject player = GameObject.FindGameObjectWithTag("Player");
                target = player.transform.position;
                if (player.GetComponent <PlayerController> ().currentMode != PlayerMode.LOCKER && player.GetComponent <PlayerController> ().currentMode != PlayerMode.ELEVATOR)
                {
                    alertManager.lastSeenPosition = player.transform.position;
                    alertManager.HighAlert();
                    if (currentMode != EnemyMode.ALERTED && currentMode != EnemyMode.PURSUING)
                    {
                        currentMode = EnemyMode.ALERTED;
                    }
                    if (player.GetComponent <PlayerController> ().aiming&& unarmed)
                    {
                        currentMode = EnemyMode.FLEEING;
                        Vector3 point = player.transform.position;
                        if (transform.position.x < point.x)
                        {
                            target = new Vector3(transform.position.x - 15f, transform.position.y, transform.position.z);
                        }
                        else if (transform.position.x > point.x)
                        {
                            target = new Vector3(transform.position.x + 15f, transform.position.y, transform.position.z);
                        }
                    }
                }
            }
        }
    }
コード例 #8
0
 public void Wake()
 {
     StopCoroutine(tranqRoutine);
     myAnim.SetBool("sleeping", false);
     LoadCollider(originalCollider);
     Destroy(instance);
     sleepCollider.enabled = false;
     currentMode           = EnemyMode.CONFUSED;
 }
コード例 #9
0
    IEnumerator UpdateMode()
    {
        yield return(new WaitForSeconds(init_time));

        mode = EnemyMode.PEACE;
        yield return(new WaitForSeconds(30.0f));

        mode = EnemyMode.ATTACK;
    }
コード例 #10
0
    // Use this for initialization
    //void Start () {
    //    Spawn();
    //}

    public void Init()
    {
        mode = EnemyMode.SPAWNING;

        health = maxHealth;

        game = GetComponentInParent <GameContent>();

        mesh.material.color = new Color(125f / 255f, 21f / 255f, 15f / 255f);
    }
コード例 #11
0
    //##########################################################################################//
    // Positioning methods                                                                      //
    //##########################################################################################//

    private void SetupPosition()
    {
        movementTargetTransform.parent = transform.parent;
        Debug.Log(transform.parent);

        transform.LookAt(shootingTargetTransform);

        movementTargetTransform.position = shootingTargetTransform.position + preferredRange * (Quaternion.AngleAxis(Random.Range(-25, 25), shootingTargetTransform.up) * -transform.forward * shootingTargetTransform.transform.lossyScale.x);

        mode = EnemyMode.POSITIONING;
    }
コード例 #12
0
 public void NotifyEnemyTypeSelected(EnemyType type, EnemyMode mode = EnemyMode.Default)
 {
     if (type == EnemyType.Asteroid1)
     {
         _asteroidLastCreationTime = Time.time;
     }
     else
     {
         _lastCreationTime = Time.time;
     }
 }
コード例 #13
0
ファイル: Enemy.cs プロジェクト: MyEyes/BGJ5
 public Enemy(Vector2 pos, Map map, ContentManager Content) : base(map, Content)
 {
     light          = map.lightMap.GetAntiLight();
     light.Radius   = Health / 5.0f;
     light.Color    = Color.White;
     light.Position = pos;
     Size           = new Vector2(24, 24);
     Position       = pos;
     mode           = EnemyMode.RandomWalk;
     _eyeOffset     = -Size / 2 + new Vector2(1, 0);
     NewTargetPos();
 }
コード例 #14
0
ファイル: UnitMode.cs プロジェクト: mrome007/RedemptionTD
    public static UnitMode CreateUnitMode(WeaponMode weapon     = WeaponMode.NONE,
                                          EnemyMode enemy       = EnemyMode.NONE,
                                          ResourceMode resource = ResourceMode.NONE)
    {
        var unitMode = new UnitMode();

        unitMode.WeaponMode   = weapon;
        unitMode.EnemyMode    = enemy;
        unitMode.ResourceMode = resource;

        return(unitMode);
    }
コード例 #15
0
 //EnemyPersonalities
 private void ScardyClause()
 {
     //Hides/Shoots and hides
     if (fov.CanSee(target.gameObject) && hearing.CanHear(target.gameObject))
     {
         enemyMode = EnemyMode.Flee;
     }
     else if (!hearing.CanHear(target.gameObject))
     {
         enemyMode = EnemyMode.Patrol;
     }
     EnemyModeStateMachine();
 }
コード例 #16
0
    public void Tranquilize(float strength)
    {
        currentMode = EnemyMode.TRANQUILIZED;
//		dm.ShowTranquilized ();
        if (tranqRoutine == null)
        {
            tranqRoutine = StartCoroutine("Sleep", strength);
        }
        else
        {
            StopCoroutine(tranqRoutine);
            tranqRoutine = StartCoroutine("Sleep", strength);
        }
    }
コード例 #17
0
 // Use this for initialization
 protected override void Start()
 {
     timerColor      = 0;
     red             = false;
     em              = EnemyMode.Tank;
     projectileTimer = projectileCooldown + 1;
     switchTimer     = 0;
     steering        = GetComponent <SteeringForces> ();
     speed           = 50f;
     attack          = 1;
     health          = 65f;
     direction       = transform.forward;
     velocity        = new Vector3(0, 0, 0);
 }
コード例 #18
0
 public void ForgetTarget()
 {
     if (instance == null || instance.name != "QuestionMark")
     {
         dm.ShowAbandon();
         Destroy(instance);
         instance = Instantiate(question, new Vector3(transform.position.x, transform.position.y + 2.5f), Quaternion.identity);
         instance.transform.parent = transform;
         Destroy(instance, 5f);
     }
     forgotten   = true;
     currentMode = EnemyMode.PATROLLING;
     target      = new Vector3(initialPosition.x - patrolDistance, transform.position.y, transform.position.z);
 }
コード例 #19
0
    void AttackCycle()
    {
        // Attack if possible
        if (CanAttack())
        {
            hPBehaviour.decreaseHP(power);
        }

        // Finish attacking if so
        if (!CanAttack())
        {
            CancelInvoke("AttackCycle");
            mode = EnemyMode.Seek;
        }
    }
コード例 #20
0
 public void Avoid()
 {
     if (avoidingStep == 1)
     {
         aiMotor.Turn(-1 * aiData.turnSpeed);
     }
     else if (avoidingStep == -1)
     {
         aiMotor.Turn(1 * aiData.turnSpeed);
     }
     else if (avoidingStep == 0)
     {
         aiMode = defaultMode;
     }
 }
コード例 #21
0
    public void NoticeTarget()
    {
        if (instance == null || instance.name != "Exclamation")
        {
            dm.ShowAlert();
            forgotten = false;
            Destroy(instance);
            am.Play("alert");
            instance = Instantiate(exclamation, new Vector3(transform.position.x, transform.position.y + 2.5f), Quaternion.identity);
            instance.transform.parent = transform;
            Destroy(instance, 5f);
            currentMode = EnemyMode.PURSUING;
//			CancelFlipCycle ();
        }
    }
コード例 #22
0
    IEnumerator Sleep(float length)
    {
        myAnim.SetBool("sleeping", true);
        dm.Clear();
        instance = Instantiate(zzzz, new Vector3(transform.position.x, transform.position.y), Quaternion.identity);
        instance.transform.parent = transform;
        LoadCollider(sleepCollider);
        yield return(new WaitForSeconds(length));

        myAnim.SetBool("sleeping", false);
        LoadCollider(originalCollider);
        Destroy(instance);
        sleepCollider.enabled = false;
        currentMode           = EnemyMode.CONFUSED;
        yield return(new WaitForSeconds(0f));
    }
コード例 #23
0
ファイル: Enemy.cs プロジェクト: yplusone/AR-Shooter
    // Update is called once per frame
    void Update()
    {
        float step = speed * Time.deltaTime;

        switch (mode)
        {
        case EnemyMode.INIT:
            if (Vector3.Distance(transform.position, target_dest) > 0.1f)
            {
                transform.position = Vector3.MoveTowards(transform.position, target_dest, step);
            }
            else
            {
                mode = EnemyMode.PEACE;
            }
            break;

        case EnemyMode.PEACE:
            if (Vector3.Distance(transform.position, target_dest) > 0.1f)
            {
                transform.position = Vector3.MoveTowards(transform.position, target_dest, step);
            }
            else
            {
                target_dest = new Vector3(Random.Range(-radis * 2, radis * 2), Random.Range(radis * 2, radis / 10), Random.Range(-radis * 2, radis * 2));
                transform.LookAt(target_dest);
            }
            if (Vector3.Distance(player.transform.position, transform.position) < hateRadis)
            {
                mode = EnemyMode.ATTACK;
            }
            break;

        case EnemyMode.ATTACK:
            target_dest = player.transform.position;
            transform.LookAt(target_dest);
            if (Vector3.Distance(transform.position, target_dest) > 0.1f)
            {
                transform.position = Vector3.MoveTowards(transform.position, target_dest, step);
            }
            else
            {
                Destroy(gameObject);
            }
            break;
        }
    }
コード例 #24
0
    bool StartChase()
    {
        var player = Player.Current;

        if (player == null)
        {
            return(false);
        }
        if (ShouldChase && LOSCheck(playerDirection, TileX, TileY, player.TileX, player.TileY))
        {
            CurrentMode = EnemyMode.CHASE;
            Rotation    = playerDirection;
            GetComponent <SoundLoader>().Play("sb-bully");
            return(true);
        }
        return(false);
    }
コード例 #25
0
    public void Resting()
    {
        aiMotor.TurnTowards(GameObject.FindGameObjectWithTag("Rest").transform.position, aiData.turnSpeed);
        aiMotor.Move(aiData.frontSpeed);


        while (aiData.health < aiData.maxHealth)
        {
            aiData.health += 1;
        }


        if (aiData.health == aiData.maxHealth)
        {
            aiMode = defaultMode;
        }
    }
コード例 #26
0
 private void Turret()
 {
     //Stays still and fires
     if (fov.CanSee(target.gameObject) && hearing.CanHear(target.gameObject))
     {
         enemyMode = EnemyMode.Attack;
     }
     else if (hearing.CanHear(target.gameObject))
     {
         enemyMode = EnemyMode.Rotate;
     }
     else if (!hearing.CanHear(target.gameObject))
     {
         enemyMode = EnemyMode.Idle;
     }
     EnemyModeStateMachine();
 }
コード例 #27
0
 void Chase()
 {
     TileScript.MotionSpeed = ChasingSpeed;
     if (!TileScript.IsMoving)
     {
         if (!ShouldChase) // stop chasing when they're not in view
         {
             CurrentMode = EnemyMode.PATROL;
             return;
         }
         if (!MoveForward())    // motion blocked
         {
             if (!StartChase()) // player is still lined up
             {
                 CurrentMode = EnemyMode.PATROL;
             }
         }
     }
 }
コード例 #28
0
    private IEnumerator resetToIdle()
    {
        if (previousMode != mode)
        {
            previousMode = mode;
            yield return(new WaitForSeconds(1f));
        }

        if (previousMode == EnemyMode.Dazzled)
        {
            CurrentEnemyState = EnemyState.Deactivated;
        }
        else
        {
            ActionManager.Singleton.Clear();
            CurrentEnemyState = EnemyState.Idle;
        }

        yield break;
    }
コード例 #29
0
    // method that will switch the attack modes of the enemey
    protected void SwitchModes()
    {
        // switch attack mode to that of a tank
        if (em == EnemyMode.Forward && switchTimer > switchCooldown)
        {
            switchTimer = 0;
            speed       = 10f;
            em          = EnemyMode.Tank;
        }

        // switch attack mode to that of a rushing enemy
        if (em == EnemyMode.Tank && switchTimer > switchCooldown)
        {
            switchTimer     = 0;
            speed           = 50f;
            projectileTimer = 0;
            em = EnemyMode.Forward;
        }

        // increment the timer for switching
        switchTimer += Time.deltaTime;
    }
コード例 #30
0
    void OnCollisionEnter(Collision collision)
    {
        // on collision, means the enemy just reached an enemy it will have to attack
        // so, start its attacking cycle, until the collided building is dead or the enemy itself adies
        // (there's an extra condition in the future when the target gets far away somehow)


        var gameObject = collision.collider.gameObject;

        // Discard collision if not a building (or player, for testing) or already attacking
        var tag = gameObject.tag;

        if (tag != "Building" || mode == EnemyMode.Attack)
        {
            return;
        }

        mode        = EnemyMode.Attack;
        hPBehaviour = gameObject.GetComponent <HPBehaviour>();

        InvokeRepeating("AttackCycle", 0, period);
    }
コード例 #31
0
ファイル: Enemy.cs プロジェクト: robcrocombe/Toast
        public Enemy(Vector2 spawnPosition, EnemyType enemyType, List<Enemy> enemyList, EnemyMode emode)
        {
            // Set initial position and the race of the enemy, passed as params
            Position = spawnPosition;
            type = enemyType;
            mode = emode;

            int spriteWidth = 40;
            int spriteHeight = 64;
            ID = enemyList.Count() - 1;

            //Set properties depending on race of enemy
            switch (enemyType)
            {
                case EnemyType.Baconite:
                    //Race characteristics
                    speedInPixels = 7;
                    weaponRange = 300;
                    accuracy = 0.7f;
                    fireRateInGameLoops = 40;

                    //Sprite
                    //spriteWidth = 100;
                    //spriteHeight = 100;
                    Texture = baconiteTexture;
                    break;

                case EnemyType.EggMan:
                    //Race characteristics
                    speedInPixels = 5;
                    weaponRange = 250;
                    accuracy = 0.8f;
                    fireRateInGameLoops = 30;

                    //Sprite Size
                    spriteWidth = 40;
                    spriteHeight = 64;
                    Texture = eggManTexture;
                    break;

                case EnemyType.Cerealian:
                    //Race characteristics
                    speedInPixels = 7;
                    weaponRange = 600;
                    accuracy = 0.6f;
                    fireRateInGameLoops = 60;

                    //Sprite Size
                    spriteWidth = 100;
                    spriteHeight = 100;
                    Texture = cerealianTexture;
                    break;

                case EnemyType.Porrigian:
                    //Race characteristics
                    speedInPixels = 4;
                    weaponRange = 700;
                    accuracy = 0.45f;
                    fireRateInGameLoops = 60;

                    //Sprite Size
                    spriteWidth = 100;
                    spriteHeight = 100;
                    Texture = porrigianTexture;
                    break;
            }

            Bounds = new Rectangle((int)Position.X, (int)Position.Y, spriteWidth, spriteHeight);
        }
コード例 #32
0
    private void GenerateEnemyFromList(List<EnemyInfo> eiList)
    {
        GameObject go = null;
        foreach(var ei in eiList){
            switch(ei.kind){
            case EnemyKind.NORMAL:
            case EnemyKind.ZAKO:
                go = InstantiateNormalEnemy (3f, ei.pointX, ei.pointY, ei.hp);
                break;
            case EnemyKind.BOSS_1:
                go = InstantiateBoss (ei.pointX,ei.pointY,ei.hp);
                break;
            }
            if(ei.isBoss){
                nowEnemyMode = EnemyMode.BOSS;
            }

            //移動情報をここでaddComponentする?
            go = SetMoveLogic(go,ei);

            enemyInfoList.Remove (ei);
        }
    }
コード例 #33
0
 private void InitStageEnemyInfo(int stageNum)
 {
     var enemyInfoMasterTable = new EnemyInfoMasterTable();
     enemyInfoMasterTable.Load(stageNum);
     passedTimeFromStart = 0f;
     enemyInfoList = enemyInfoMasterTable.All;
     enemyInfoList.OrderByDescending (ei => ei.timing);
     enemyCoroutine = GenerateEnemyFromCSVCoroutine();
     nowEnemyMode = EnemyMode.NORMAL;
 }