Esempio n. 1
0
    /// <summary>
    /// Handles the events
    /// </summary>
    public void OnEvent(EVENT_TYPE eventType, Component sender, System.Object param = null)
    {
        switch (eventType)
        {
        case EVENT_TYPE.BOMB_DEPLOYED:
            // verifies if player was hit by the bomb
            GameObject bomb              = (GameObject)param;
            float      timeToExplode     = bomb.GetComponent <BombAI> ().timeToExplode;
            bool       isWithinBombRange = BombAI.IsWithinExplosionRange(bomb.transform.position, transform.position, map);
            // verifying if player is in the tiles affected by the explosion
            if (isWithinBombRange && tileBombRange == null)
            {
                Vector3 tilePos = transform.position;
                tilePos.y += 0.1f;
                // highlight tile that will be affected by the explosion
                tileBombRange = Instantiate(tileBombRangePrefab, tilePos, transform.rotation) as GameObject;
                tileBombRange.transform.localScale = Vector3.one * map.tileSize;
            }
            break;

        case EVENT_TYPE.BOMB_EXPLODED:
            Vector3 bombPosition = (Vector3)param;
            if (BombAI.IsWithinExplosionRange(bombPosition, transform.position, map) && tileBombRange != null)
            {
                Destroy(tileBombRange);
            }
            break;
        }
    }
Esempio n. 2
0
    void Update()
    {
        if (PauseResumeAI.Instance.IsGamePaused())
        {
            return;
        }

        if (dead)
        {
            return;
        }

        // check if it is whithin range of the last bomb that was noticed
        if (lastBombNoticed != null)
        {
            bool isWithinBombRange = BombAI.IsWithinExplosionRange(lastBombNoticed.transform.position, transform.position, map);
            if (isWithinBombRange)
            {
                // force the change of direction
                // to avoid the bomb
                lastTimeChangedDirection = 0.0f;
            }
        }

        float deltaChangeDirection = Time.time - lastTimeChangedDirection;
        float deltaDeployBomb      = Time.time - lastTimeDeployedBomb;

        if (deltaChangeDirection > timeToChangeDirection)
        {
            // generate random direction
            int random = Random.Range(0, 3);
            switch (random)
            {
            case 0:
                EventManager.Instance.PostNotification(EVENT_TYPE.PLAYER_TURN_UP, this, gameObject);
                break;

            case 1:
                EventManager.Instance.PostNotification(EVENT_TYPE.PLAYER_TURN_DOWN, this, gameObject);
                break;

            case 2:
                EventManager.Instance.PostNotification(EVENT_TYPE.PLAYER_TURN_LEFT, this, gameObject);
                break;

            case 3:
                EventManager.Instance.PostNotification(EVENT_TYPE.PLAYER_TURN_RIGHT, this, gameObject);
                break;
            }
            lastTimeChangedDirection = Time.time;
        }
        else if (deltaDeployBomb > timeToDeployBomb)
        {
            // deploys the bomb
            EventManager.Instance.PostNotification(EVENT_TYPE.BOMB_DEPLOY_COMMAND, this, gameObject);
            lastTimeDeployedBomb = Time.time;
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Handles the events
    /// </summary>
    public void OnEvent(EVENT_TYPE eventType, Component sender, System.Object param = null)
    {
        GameObject player = null;

        switch (eventType)
        {
        case EVENT_TYPE.BOMB_EXPLODED:
            // verifying if player is in the tiles affected by the explosion
            if (BombAI.IsWithinExplosionRange(sender.gameObject.transform.position, transform.position, map))
            {
                // if hit by the bomb the player dies
                animator.SetFloat("Speed_f", 0);
                animator.SetBool("Death_b", true);
                dead = true;
                EventManager.Instance.PostNotification(EVENT_TYPE.PLAYER_DIED, this, gameObject);
            }
            break;

        case EVENT_TYPE.PLAYER_TURN_UP:
            player = (GameObject)param;
            if (player != null && player.GetInstanceID() == gameObject.GetInstanceID())
            {
                prevDirection = moveDirection;
                moveDirection = Vector3.forward;
                UpdateDirection();
            }
            break;

        case EVENT_TYPE.PLAYER_TURN_DOWN:
            player = (GameObject)param;
            if (player != null && player.GetInstanceID() == gameObject.GetInstanceID())
            {
                prevDirection = moveDirection;
                moveDirection = Vector3.back;
                UpdateDirection();
            }
            break;

        case EVENT_TYPE.PLAYER_TURN_LEFT:
            player = (GameObject)param;
            if (player != null && player.GetInstanceID() == gameObject.GetInstanceID())
            {
                prevDirection = moveDirection;
                moveDirection = Vector3.left;
                UpdateDirection();
            }
            break;

        case EVENT_TYPE.PLAYER_TURN_RIGHT:
            player = (GameObject)param;
            if (player != null && player.GetInstanceID() == gameObject.GetInstanceID())
            {
                prevDirection = moveDirection;
                moveDirection = Vector3.right;
                UpdateDirection();
            }
            break;

        case EVENT_TYPE.BOMB_DEPLOY_COMMAND:
            player = (GameObject)param;
            if (player != null && player.GetInstanceID() == gameObject.GetInstanceID() && canDropBomb)
            {
                DeployBomb();
                lastTimeDroppedABomb = Time.time;
                canDropBomb          = false;
            }
            break;
        }
    }