Exemplo n.º 1
0
    public void OnTriggerExit(Collider col)
    {
        BaseStructureClass structure = col.gameObject.GetComponent <BaseStructureClass>();

        if (structure != null)
        {
            if (col is BoxCollider)
            {
                // Structure is within Range.
                nearbyStructuresQueue.Remove(structure);

                if (structure == nearbyStructureActive)
                {
                    if (nearbyStructuresQueue.Count > 0)
                    {
                        nearbyStructureActive = nearbyStructuresQueue[0];
                    }
                    else
                    {
                        nearbyStructureActive = null;
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a handle to an instantiated GameObject, or null, if one was unable
        /// to be spawned. Will be spawned on top of a tile.
        ///
        /// Takes an object to spawn, the rotation to orient it, and the grid coordinate to spawn it.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="rot"></param>
        /// <param name="coord"></param>
        /// <returns></returns>
        public BaseStructureClass SetObjAtMapGridCoord(BaseStructureClass obj, Quaternion rot, Vector2 coord)
        {
            if (!GetTileAtMapGridCoord(coord).isFlat || !IsCoordWithinMap(coord))
            {
                return(null);
            }

            int x = (int)coord.x;
            int z = (int)coord.y;

            float x_pos;
            float y_pos = GetTopOfTileYPosition(coord);
            float z_pos;

            x_pos = x * tileSize + tileSize / 2.0f;
            z_pos = z * tileSize + tileSize / 2.0f;

            BaseStructureClass newStructure = Instantiate(obj, new Vector3(x_pos, y_pos, z_pos), rot);

            MapTile tile = GetTileAtMapGridCoord(coord);

            newStructure.transform.parent = tile.transform;
            newStructure.tileCoord        = coord;

            tile.hasStructure = true;
            tile.structure    = newStructure;

            if (!levelRef.PC.inEditMode)
            {
                levelRef.GetComponent <SpawnManager>().spawnedStructures.Add(newStructure);
            }

            return(newStructure);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a handle to an instantiated GameObject, or null, if one was unable
        /// to be spawned. Will be spawned on top of a tile.
        ///
        /// Takes an object to spawn, and the rotation to orient it.
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="rot"></param>
        /// <returns></returns>
        public BaseStructureClass SetObjAtCursorLocation(BaseStructureClass obj, Quaternion rot)
        {
            Vector2 location = GetTileCoordAtCursorPosition();

            // make sure we actually hit the map.
            if (location.y >= 0 && IsPlaceableOnTile(location))
            {
                float x_pos;
                float y_pos = GetTopOfTileYPosition(location);
                float z_pos;

                x_pos = location.x * tileSize + tileSize / 2.0f;
                z_pos = location.y * tileSize + tileSize / 2.0f;

                BaseStructureClass newStructure = Instantiate(obj, new Vector3(x_pos, y_pos, z_pos), rot);

                MapTile tile = GetTileAtMapGridCoord(location);

                newStructure.transform.parent = tile.transform;
                newStructure.tileCoord        = location;

                tile.hasStructure = true;
                tile.structure    = newStructure;

                if (!levelRef.PC.inEditMode)
                {
                    levelRef.GetComponent <SpawnManager>().spawnedStructures.Add(newStructure);
                }

                return(newStructure);
            }

            return(null);
        }
    /// <summary>
    /// For initial placement of the castle at game-start.
    /// Places the player castle at user's choice.
    /// </summary>
    private void PlaceStructure(BaseStructureClass structure)
    {
        if (Input.GetMouseButtonDown(0) && !levelRef.GetComponent <MainLevel>().isPaused)
        {
            // If we hit our UI, don't do anything -- EventSystem will handle it.
            if (wasUIClicked())
            {
                return;
            }

            BaseStructureClass structureHandle = levelRef.tileMapRef.SetObjAtCursorLocation(structure, Quaternion.Euler(0, 0, 0));
            if (structureHandle == null)
            {
                // Invalid Placement;
                MapTile tile = levelRef.tileMapRef.GetTileAtCursorPosition();

                if (tile != null)
                {
                    tile.InvalidPlacement();
                    levelRef.audioRef.PlaySFX("ClickInvalid");
                }
                else
                {
                    levelRef.audioRef.PlaySFX("Click");
                }

                return;
            }

            Wall wallObj = structureHandle.GetComponent <Wall>();
            if (wallObj != null)
            {
                wallObj.currentShape = spawnManagerRef.wallTowerRef;
                wallObj.currentYRot  = 0.0f;
                wallObj.UpdateShape();
            }

            if (levelRef.GetComponent <MainLevel>().gameState == MainLevel.GameState.PLACECASTLE)
            {
                levelRef.GetComponent <MainLevel>().SetCastleRef(structureHandle.GetComponent <Castle>());
                levelRef.GetComponent <MainLevel>().SetGameState(MainLevel.GameState.BUILDPHASE);
            }
            else
            {
                levelRef.GetComponent <MainLevel>().RemoveCurrency(structure.structurePrice);
            }

            Destroy(preview);
            isHoldingObject = false;
        }
    }
    public void SpawnStructureFromUIButton(BaseStructureClass structure)
    {
        selection = structure.gameObject;

        if (preview != null)
        {
            Destroy(preview);
        }

        preview         = Instantiate(structure.gameObject, new Vector3(100.0f, 100.0f, 100.0f), Quaternion.Euler(0, 0, 0));
        isHoldingObject = true;
        preview.GetComponent <BaseStructureClass>().isPreviewObject = true;

        preview.GetComponent <BaseStructureClass>().SetEnabled(false);
    }
Exemplo n.º 6
0
    public void OnTriggerEnter(Collider col)
    {
        BaseStructureClass structure = col.gameObject.GetComponent <BaseStructureClass>();

        if (structure != null)
        {
            if (col is BoxCollider)
            {
                // Structure is within Range.
                nearbyStructuresQueue.Add(structure);
                if (nearbyStructuresQueue.Count == 1)
                {
                    nearbyStructureActive = structure;
                }
            }
        }
    }
    public void FillDetailsMenu(BaseStructureClass structure)
    {
        currentStructure = structure;

        detailsMenu.transform.GetChild(1).GetComponent <UnityEngine.UI.Text>().text = structure.buildingName;
        detailsMenuHealthBar.value = structure.currentHealth / structure.maxHealth;

        string structureDetails = "Health: " + structure.currentHealth.ToString() + "/" + structure.maxHealth.ToString() + "\n";

        structureDetails += "Armor: " + structure.armor.ToString() + "\n";
        structureDetails += "Upgrades: " + structure.currentUpgrades.ToString() + "/" + structure.maxNumUpgrades.ToString() + "\n";
        detailsMenu.transform.GetChild(3).GetComponent <UnityEngine.UI.Text>().text = structureDetails;

        Button detailsButton = detailsMenu.transform.GetChild(4).GetComponent <Button>();

        detailsButton.interactable = CanStructureUpgrade();
        // if player has enough currency:
        if (detailsButton.interactable)
        {
            // Set button text to GREEN UPGRADE
            detailsButton.transform.GetChild(0).GetComponent <Text>().color = Color.green;
            detailsButton.transform.GetChild(0).GetComponent <Text>().text  = "Upgrade!";
        }
        else
        {
            if (structure.currentUpgrades == structure.maxNumUpgrades)
            {
                detailsButton.transform.GetChild(0).GetComponent <Text>().color = Color.gray;
                detailsButton.transform.GetChild(0).GetComponent <Text>().text  = "MAX!";
            }
            else
            {
                // Set button to RED CURRENTAMOUNT/COST
                detailsButton.transform.GetChild(0).GetComponent <Text>().color = Color.red;

                int currency = Mathf.FloorToInt(mainLevelRef.currency);
                int cost     = Mathf.FloorToInt(currentStructure.upgradePrice);

                detailsButton.transform.GetChild(0).GetComponent <Text>().text = currency.ToString() + "/" + cost.ToString();
            }
        }

        detailsMenu.transform.GetChild(4).GetComponent <Button>().interactable = CanStructureUpgrade();
    }
Exemplo n.º 8
0
    // Update is called once per frame
    protected virtual void Update()
    {
        healthBar.transform.parent.forward = Camera.main.transform.forward; ////// ?????????????????????????????????????????? Can this move to start()?

        // If a building was destroyed or built, check to make sure we don't need a new path to our target.
        if (numStructures != spawnManagerRef.spawnedStructures.Count || targetStructure == null)
        {
            // If ResetPath() returns false, a path could not be created. Castle Destroyed, game over!
            if (!ResetPath())
            {
                anim.SetBool("Victory", true);
                this.enabled = false;
                return;
            }
        }

        // Another structure is within our range but is not our current target.
        // Add it to our queue of attackable structures.
        if (nearbyStructureActive != targetStructure)
        {
            // If the structure is destroyed, check for other structures in our nearby structures queue.
            if (nearbyStructureActive == null && nearbyStructuresQueue.Count > 0)
            {
                nearbyStructureActive = nearbyStructuresQueue[0];
                nearbyStructuresQueue.RemoveAt(0);
            }

            // Enemy Pathing
            if (path.Count > 0)
            {
                // If the tile the enemy is standing on is the same as the next tile in the path, update the next tile to be the one after that.
                if (tileMapRef.GetTileCoordFromWorldPos(this.transform.position) == tileMapRef.GetTileCoordFromWorldPos(nextTile.transform.GetChild(0).transform.position))
                {
                    nextTile = path.Pop();
                }
            }

            // If the tile we are standing on isn't the next tile in our path, move toward it.
            if (tileMapRef.GetTileAtMapGridCoord(tileMapRef.GetTileCoordFromWorldPos(this.transform.position)) != nextTile)
            {
                this.transform.position = Vector3.MoveTowards(this.transform.position, nextTile.transform.GetChild(0).transform.position, Time.deltaTime * 5);
                this.transform.LookAt(nextTile.transform.GetChild(0).position);
            }
        }

        // If there is a structure nearby, attack it.
        if (nearbyStructureActive != null)
        {
            if (attackTimer <= 0)
            {
                attackTimer = 1.0f / attackSpeed;
                mainLevelRef.audioRef.PlaySFX("EnemyAttack");
                nearbyStructureActive.TakeDamage(damage);
                anim.SetBool("RUN", false);
                anim.SetBool("Attack", true);
                this.transform.LookAt(nearbyStructureActive.transform.position);
            }
            else
            {
                attackTimer -= Time.deltaTime;
            }
        }
    }
Exemplo n.º 9
0
 public void SetTarget(BaseStructureClass target)
 {
     targetStructure = target;
 }
    // PlayMode function
    // Don't call if paused
    // if(Input.GetMouseButtonDown(0))
    // Right-click to dismiss UI -- UIMenuRef.CloseMenu(UIMenuRef.contextMenu);
    void PlayModeClickInput()
    {
        // If we hit our UI, don't do anything -- EventSystem will handle it.
        if (wasUIClicked())
        {
            return;
        }

        // We will only place something if we are actively holding something.
        if (isHoldingObject)
        {
            PlaceStructure(selection.GetComponent <BaseStructureClass>());
        }
        else
        {
            // Click was not on UI, and we are not holding anything. Grab the tile position.
            Vector2 clickCoord = levelRef.tileMapRef.GetTileCoordAtCursorPosition();

            // if we clicked somewhere on the map
            if (clickCoord.y >= 0)
            {
                levelRef.audioRef.PlaySFX("Click");

                // Make sure the context menu is open
                if (!UIMenuRef.contextMenu.isOpen)
                {
                    UIMenuRef.OpenMenu(UIMenuRef.contextMenu);
                }


                MapTile tile = levelRef.tileMapRef.GetTileAtMapGridCoord(clickCoord);

                // if the tile we clicked has a structure
                if (tile.hasStructure)
                {
                    BaseStructureClass structure = tile.structure.GetComponent <BaseStructureClass>();

                    UIMenuRef.FillDetailsMenu(structure);

                    // Close BuildMenu, if open
                    if (UIMenuRef.buildMenu.isOpen)
                    {
                        UIMenuRef.CloseMenu(UIMenuRef.buildMenu);
                    }

                    // Open buildingDetailsMenu;
                    UIMenuRef.OpenMenu(UIMenuRef.detailsMenu);
                }
                else
                {
                    // Close DetailsMenu, if open
                    if (UIMenuRef.detailsMenu.isOpen)
                    {
                        UIMenuRef.CloseMenu(UIMenuRef.detailsMenu);
                    }

                    // Open buildMenu;
                    UIMenuRef.OpenMenu(UIMenuRef.buildMenu);
                }
            }
        }
    }