Example #1
0
    // Use this for initialization
    void Start()
    {
        canDrop  = true;
        movement = new MovementData(3);
        {
            delay = gameObject.AddComponent <TimerRoutine>();
            delay.initTimer(6f);
            delay.executedFunction = resetBomb;
        }
        bombRange  = 1;
        sightRange = bombRange + 4;
        BoxCollider2D col = gameObject.AddComponent <BoxCollider2D>();

        col.size      = new Vector2(1f * sightRange, 1f);
        col.isTrigger = true;
        col           = gameObject.AddComponent <BoxCollider2D>();
        col.size      = new Vector2(1f, 1f * sightRange);
        col.isTrigger = true;
        dmgBody       = transform.parent.GetChild(2).gameObject;
        dmgBody.GetComponent <DefaultCharacter>().InitChar();
        e_state     = BomberState.E_NEUTRAL;
        bombRef     = null;
        prevCellPos = GameModeManager.instance.gameGrid.GetWorldFlToCellPos(transform.position);
        physBody    = transform.parent.GetComponent <Rigidbody2D>();
        anim        = transform.parent.GetChild(3).GetChild(0).GetComponent <Animator>();
        guide       = transform.parent.GetComponent <BomberGuide>();
        colcount    = 0;
        once        = false;
    }
Example #2
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();
    }
Example #3
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;
 }