コード例 #1
0
        // Returns true if player tried to create a bomb above another
        private bool CreateBomb(GameObject bombPrefab)
        {
            var p1 = GameObject.Find("Bomberman White");
            var p2 = GameObject.Find("Bomberman Black");

            Vector2Int p1Coords = Global.GetObjectCoordinates(p1);
            Vector2Int p2Coords = Global.GetObjectCoordinates(p2);

            if (p1Coords.x == p2Coords.x && p1Coords.y == p2Coords.y)
            {
                p1.layer = 10;
                p2.layer = 11;
            }
            else if (playerController.number == Number.PLAYER_1)
            {
                p1.layer = 10;
            }
            else if (playerController.number == Number.PLAYER_2)
            {
                p2.layer = 11;
            }


            Vector2Int bombCell = Global.GetObjectCoordinates(playerObject);

            // Player cannot create a bomb above another Bomb, a Hard Block or Soft Block
            switch (Floor.GetCoordinates(bombCell).GetValueOrDefault().contentEntity)
            {
            case Entity.BOMB: return(true);

            case Entity.HARD_BLOCK: return(false);

            case Entity.SOFT_BLOCK: return(false);
            }

            if (playerController.GetPlantedBombs() >= playerController.attributes.GetMaxBombSlots())
            {
                // Player is trying to create more bombs than it levels limit
                return(false);
            }


            // TODO: Change this default bomb to the bomb the player is currently using
            GameObject bomb = GameObject.Instantiate(bombPrefab);
            // TODO: Change this Bomb Class to Bomb Controller, after refactory
            var bombController = bomb.GetComponent <Bomb.BombController>();

            bombController.bombOwner = playerObject;
            playerController.IncreasePlantedBombs();
            // TODO: Check why do I need Instance ID instead the object reference?
            bombController.SetBombRadius(
                // Skull -> Low Power Effect
                (stateController.GetIllState() == IllState.LOW_POWER)? 0 : playerController.attributes.GetExtraRadius()
                );

            // Move bomb to correct place
            Vector3 newPos = Global.getCellsPosition(bombCell, 0);

            Floor.SetCoordinatesContent(bombCell, bomb, Entity.BOMB);
            bomb.transform.position = newPos;

            return(false);
        }