Ejemplo n.º 1
0
        Vector3 GetNextDestination()
        {
            TDStep  step          = _firetruck.PopPathStep();
            TDStep  afterStep     = _firetruck.PeekPathStep();
            Vector3 nextPosition  = new Vector3();
            Vector3 afterPosition = new Vector3();

            if (step != null)
            {
                TDTile nextTile  = step.tile;
                TDTile afterTile = null;

                if (afterStep != null)
                {
                    afterTile        = afterStep.tile;
                    afterPosition    = map.GetPositionForTile(afterTile.GetX(), afterTile.GetY());
                    afterPosition.x += 0.5f;
                    afterPosition.z -= 0.5f;
                }

                nextPosition    = map.GetPositionForTile(nextTile.GetX(), nextTile.GetY());
                nextPosition.x += 0.5f;
                nextPosition.z -= 0.5f;

                //If nextPosition is to the right then trucks drive in the lower
                //of the horizontal lanes
                if (nextPosition.x > transform.position.x ||
                    (afterStep != null && afterPosition.x > transform.position.x))
                {
                    nextPosition.z -= 0.25f;
                    //If it's to the left then trucks drive in the upper lane
                }
                else if (nextPosition.x < transform.position.x ||
                         (afterStep != null && afterPosition.x < transform.position.x))
                {
                    nextPosition.z += 0.25f;
                }

                //If nextPosition is up the trucks drive in the right lane
                if (nextPosition.z > transform.position.z ||
                    (afterStep != null && afterPosition.z > transform.position.z))
                {
                    nextPosition.x += 0.25f;
                    //If it's down then trucks drive in the left lane
                }
                else if (nextPosition.z < transform.position.z ||
                         (afterStep != null && afterPosition.z < transform.position.z))
                {
                    nextPosition.x -= 0.25f;
                }
            }

            return(nextPosition);
        }
Ejemplo n.º 2
0
        //Creates a firetruck at the firehouse with
        //the tile at the given point as destination
        public void SpawnFireTruck(int x, int z)
        {
            truckCount++;

            Vector2 fireHouseTilePos;

            _map.Map.GetFireHouseCoordinates(out fireHouseTilePos);

            Vector3 truckPos = _map.GetPositionForTile(Mathf.FloorToInt(fireHouseTilePos.x),
                                                       Mathf.FloorToInt(fireHouseTilePos.y));

            truckPos.x += .5f;
            truckPos.z -= .5f;

            GameObject truck = (GameObject)Instantiate(firetruckPrefab);

            truck.transform.position = truckPos;

            EGFiretruck firetruck = truck.GetComponent <EGFiretruck>();

            firetruck.SetPosition(truckPos);
            firetruck.SetMap(_map);

            EGDispatcher.Instance.SendTruckToTile(firetruck, x, -z);
        }
Ejemplo n.º 3
0
        void UpdateSpread()
        {
            float delta = Time.deltaTime;

            Vector3 scale = transform.root.localScale;

            if (scale.x >= maxSize || tile.durability <= 0)
            {
                timeSinceSpreadAttempt += delta;

                if (timeSinceSpreadAttempt >= spreadInterval)
                {
                    int rand = Random.Range(0, spreadChance);
                    if (rand % spreadChance == 0)
                    {
                        List <TDTile> houses = map.Map.FindAdjacentFlammableTiles(tile);

                        if (houses.Count > 0)
                        {
                            rand = Random.Range(0, houses.Count);
                            TDTile tileToIgnite = houses[rand];
                            if (!tileToIgnite.OnFire && tile.durability > 0)
                            {
                                GameObject flame = (GameObject)Instantiate(spreadPrefab);

                                Vector3 flamePos = map.GetPositionForTile(tileToIgnite.GetX(), tileToIgnite.GetY());
                                flamePos.x += 0.5f;
                                flamePos.z -= 0.5f;

                                flame.transform.position = flamePos;

                                EGFlame egFlame = flame.GetComponent <EGFlame>();
                                egFlame.SetTile(tileToIgnite);
                                egFlame.SetMap(map);
                                egFlame.SetSpreadPrefab(spreadPrefab);

                                PopUpUIManager.Instance.ShowFireSpreadNPCMessage();

                                tileToIgnite.OnFire = true;
                            }
                        }

                        timeSinceSpreadAttempt = 0;
                    }
                }
            }
        }