Example #1
0
        public void SetTile(Vector2Int position, HexTile.MaterialEnum material)
        {
            int index = position.y * tilesW + position.x;

            tiles[index]          = new HexTile();
            tiles[index].height   = Random.value;
            tiles[index].material = material;

            //redraw = true;
        }
        void Update()
        {
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                EnableEscMenu(!Paused);
            }
            else if (!Paused)
            {
                // place something
                if (grabbed != null)
                {
                    Ray        ray = camera.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;

                    if (Physics.Raycast(ray, out hit, 100f, LayerMask.GetMask("Terrain")))
                    {
                        Vector3 placePosition = hit.point;

                        grabbed.transform.position = placePosition;

                        if (Input.GetMouseButtonDown(0))
                        {
                            HexTile tile = GetTileAtMousePosition();

                            if (tile != null)
                            {
                                ///TODO Clean this up
                                Goat goat = grabbed.GetComponent <Goat>();
                                if (goat != null)
                                {
                                    goats.Add(goat);
                                    UpdatePotentialEnergy();
                                }

                                Cow cow = grabbed.GetComponent <Cow>();
                                if (cow != null)
                                {
                                    cows.Add(cow);
                                    UpdatePotentialEnergy();
                                }

                                Wolf wolf = grabbed.GetComponent <Wolf>();
                                if (wolf != null)
                                {
                                    wolves.Add(wolf);
                                    UpdatePotentialEnergy();
                                }

                                grabbed.Grabbed = false;
                                grabbed         = null;
                            }
                        }
                    }
                    else
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            // operation was cancelled
                            Destroy(grabbed.gameObject);
                            grabbed = null;
                        }
                    }
                }
                else if (IsExpansionMode)
                {
                    Ray        ray = camera.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;

                    if (Physics.Raycast(ray, out hit, 100f, LayerMask.GetMask("Terrain")))
                    {
                        Vector3 placePosition = hit.point;

                        if (Input.GetMouseButtonDown(0))
                        {
                            HexTile tile = GetTileAtMousePosition();

                            if (tile != null)
                            {
                                if (tile.IsEmpty)
                                {
                                    HexTile.MaterialEnum material = (terrain.TileCount < 9) ? HexTile.MaterialEnum.Grass : HexTile.MaterialEnum.Rock;

                                    terrain.SetTile(tile.tilePosition, material);
                                    SetExpansionMode(false);
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (Input.GetMouseButtonDown(0))
                    {
                        Ray        ray = camera.ScreenPointToRay(Input.mousePosition);
                        RaycastHit hit;

                        if (Physics.Raycast(ray, out hit, 100f))
                        {
                            Goat goat = hit.collider.gameObject.GetComponentInParent <Goat>();
                            if (goat != null && goats.Contains(goat))
                            {
                                // consume the goat
                                player.energy += PlayerStats.potentialEnergyGoat;
                                overlayController.SetEnergyValue(player.energy);

                                // using the single dead function here
                                // may want to also have a sacrifice animation
                                goat.GotDead();
                            }
                            Cow cow = hit.collider.gameObject.GetComponentInParent <Cow>();
                            if (cow != null && cows.Contains(cow))
                            {
                                // consume the cow
                                player.energy += PlayerStats.potentialEnergyCow;
                                overlayController.SetEnergyValue(player.energy);

                                // kill the cow
                                cow.GotDead();
                            }
                            Wolf wolf = hit.collider.gameObject.GetComponentInParent <Wolf>();
                            if (wolf != null && wolves.Contains(wolf))
                            {
                                // consume the cow
                                player.energy += PlayerStats.potentialEnergyWolf;
                                overlayController.SetEnergyValue(player.energy);

                                // kill the cow
                                wolf.GotDead();
                            }
                        }
                    }
                }
            }
        }