Ejemplo n.º 1
0
    bool ObstacleCheck(DIRS dir, int range)
    {
        Vector3Int mycell = GameModeManager.instance.gameGrid.GetWorldFlToCellPos(transform.position);
        Vector3Int test   = Vector3Int.zero;
        bool       fail   = false;

        switch (dir)
        {
        case DIRS.E_LEFT:
            for (int i = 0; i <= range; ++i)
            {
                test.Set(mycell.x - i, mycell.y, mycell.z);
                if (TileRefManager.instance.GetTileAtCellPos(TileRefManager.TILEMAP_TYPE.TILEMAP_SOLIDWALL, test) || TileRefManager.instance.GetTileAtCellPos(TileRefManager.TILEMAP_TYPE.TILEMAP_DESTRUCTIBLE, test))
                {
                    fail = true;
                    break;
                }
            }
            break;

        case DIRS.E_RIGHT:
            for (int i = 0; i <= range; ++i)
            {
                test.Set(mycell.x + i, mycell.y, mycell.z);
                if (TileRefManager.instance.GetTileAtCellPos(TileRefManager.TILEMAP_TYPE.TILEMAP_SOLIDWALL, test) || TileRefManager.instance.GetTileAtCellPos(TileRefManager.TILEMAP_TYPE.TILEMAP_DESTRUCTIBLE, test))
                {
                    fail = true;
                    break;
                }
            }
            break;

        case DIRS.E_UP:
            for (int i = 0; i <= range; ++i)
            {
                test.Set(mycell.x, mycell.y + i, mycell.z);
                if (TileRefManager.instance.GetTileAtCellPos(TileRefManager.TILEMAP_TYPE.TILEMAP_SOLIDWALL, test) || TileRefManager.instance.GetTileAtCellPos(TileRefManager.TILEMAP_TYPE.TILEMAP_DESTRUCTIBLE, test))
                {
                    fail = true;
                    break;
                }
            }
            break;

        case DIRS.E_DOWN:
            for (int i = 0; i <= range; ++i)
            {
                test.Set(mycell.x, mycell.y - i, mycell.z);
                if (TileRefManager.instance.GetTileAtCellPos(TileRefManager.TILEMAP_TYPE.TILEMAP_SOLIDWALL, test) || TileRefManager.instance.GetTileAtCellPos(TileRefManager.TILEMAP_TYPE.TILEMAP_DESTRUCTIBLE, test))
                {
                    fail = true;
                    break;
                }
            }
            break;
        }
        return(fail);
    }
Ejemplo n.º 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();
    }
Ejemplo n.º 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;
 }