示例#1
0
    void Update()
    {
        if (canProceed)
        {
            // check if the cell in front of me is blocked
            if (!ObstacleCheck(direction, 1))
            {
                Vector3Int destination = convertDirToVec3(); // not blocked, get next cell to go to depending on my direction
                SetDestination(destination);                 // move cell by cell
                canProceed = false;                          // until my sprite catches up to me, dont move
                cellsFree  = originalCellsFree;              // just resetting a variable
            }
            else
            {
                DIRS randDir = BomberGuide.getRandomDir(); // Blocked, get a random direction
                if (!ObstacleCheck(randDir, cellsFree))    // if i meet with a wall, i will find a new path with preferably as many cells free as the range provided
                {
                    direction = randDir;
                }
                else
                {
                    cellsFree--; // check from max range to 0
                }
            }
        }
        // Moving towards guide
        float dist  = Vector2.Distance(transform.position, bodyDestination);
        float speed = (movement.speed * Time.deltaTime);

        if (dist > speed)
        {
            Vector2 direction = (bodyDestination - transform.position).normalized;
            physBody.MovePosition((Vector2)transform.position + direction * speed);
        }
        else
        {
            canProceed = true; // tell guide that i reached
        }

        if (character.checkIfDead()) // no more health, destroy myself
        {
            int enemiesRemaining = GameModeManager.instance.getEnemiesLeft();
            enemiesRemaining -= 1;
            GameModeManager.instance.enemyLeftTxt.text = enemiesRemaining.ToString();
            //if (GameModeManager.instance.getSceneName().Equals("Level2"))
            //{
            //    if (enemiesRemaining < 2)
            //    {
            //        GameModeManager.instance.itemSpawner.spawnAnotherEnemy();
            //    }
            //}
            Destroy(this.gameObject);
        }

        animate();
    }
示例#2
0
 void Start()
 {
     m_MinionType      = MinionType.E_CREEP1;
     direction         = BomberGuide.getRandomDir();
     canProceed        = true;
     originalCellsFree = cellsFree;
     movement          = new MovementData(3);
     physBody          = transform.GetComponent <Rigidbody2D>();
     bodyDestination   = transform.position;
     GetComponent <DefaultCharacter>().InitChar();
     character   = GetComponent <DefaultCharacter>();
     animator    = transform.GetChild(4).GetChild(0).GetComponent <Animator>();
     minionState = MinionState.E_NEUTRAL;
 }