Exemplo n.º 1
0
    public void AddRoad(RoadType type, int number)
    {
        var      tileSpawn = grid.CellToLocal(nextTilePosition);
        var      start     = tileSpawn - (nextRotation * Vector3.up * grid.cellSize.x / 2);
        Object   prefab    = null;
        Object   border    = null;
        RoadTile tile      = null;

        switch (type)
        {
        case RoadType.FORWARD:
            tile   = new ForwardRoadTile(start, nextRotation);
            prefab = objectStorage.GetForward(number);
            border = objectStorage.forwardComplete;
            break;

        case RoadType.LEFT:
            tile   = new LeftRoadTile(start, nextRotation);
            prefab = objectStorage.GetAngle(number);
            border = objectStorage.angleComplete;
            break;

        case RoadType.RIGHT:
            tile          = new RightRoadTile(start, nextRotation);
            prefab        = objectStorage.GetAngle(number);
            border        = objectStorage.angleComplete;
            nextRotation *= Quaternion.Euler(0, 180, 0);
            break;
        }
        GameObject.Instantiate(prefab, grid.CellToWorld(nextTilePosition), nextRotation, grid.gameObject.transform);
        GameObject.Instantiate(border, grid.CellToWorld(nextTilePosition) + new Vector3(0, 0, -1), nextRotation, grid.gameObject.transform);
        tiles.Add(tile);
        nextTilePosition += tile.GetNextTile();
        nextRotation      = tile.GetNextRotation();
    }
Exemplo n.º 2
0
    private GameObject TranslateGeneralRoad()
    {
        GameObject generalRoad;

        if (previousRoadTile == null)
        {
            generalRoad = roadPooler.Spawn("TDR_Begin_1", Vector3.zero, Quaternion.identity);
        }
        else
        {
            generalRoad = roadPooler.Spawn(previousRoadTile.NextRoadTileCapabilitiesHolder.GetNextRandomWeightedRoadTileName());

            ///for cinema
        }
        previousRoadTile = generalRoad.GetComponent <RoadTile>();
        previousRoadTile.ResetPhysicalEnvironment(allSpawnedRoadLength);
        generalRoad.transform.localPosition = Vector3.forward * allSpawnedRoadLength;

        //roadPooler.Spawn(previousRoadTile.NextRoadTileCapabilitiesHolder.GetNextRandomWeightedRoadTileName()).transform.localPosition = generalRoad.transform.localPosition + Vector3.right * 81.45f;
        //roadPooler.Spawn(previousRoadTile.NextRoadTileCapabilitiesHolder.GetNextRandomWeightedRoadTileName()).transform.localPosition = generalRoad.transform.localPosition - Vector3.right * 81.45f;

        //roadPooler.Spawn(previousRoadTile.NextRoadTileCapabilitiesHolder.GetNextRandomWeightedRoadTileName()).transform.localPosition = generalRoad.transform.localPosition + Vector3.right * 81.45f * 2;
        //roadPooler.Spawn(previousRoadTile.NextRoadTileCapabilitiesHolder.GetNextRandomWeightedRoadTileName()).transform.localPosition = generalRoad.transform.localPosition - Vector3.right * 81.45f * 2;

        allSpawnedRoadLength += roadLength;

        StartCoroutine(PhysicsBoundariesRebuild());

        return(generalRoad);
    }
Exemplo n.º 3
0
    void Update()
    {
        // Odszukaj drogę na jakiej jest samochód
        if (_actualTile == null)
        {
            if (Lane == RoadLane.RightLane)
            {
                _actualTile = RoadManager.LookForTileAtPosition(transform.position.y + 1);
            }
            else
            {
                _actualTile = RoadManager.LookForTileAtPosition(transform.position.y - 1);
            }
        }
        else
        {
            // Znajdz cel, jeżeli go nie ma
            if (_targetPosition == Vector2.zero)
            {
                FindNextPosition();
            }

            // Jezeli pojazd jest blisko celu i ma go wręcz przekroczyc, znajdz kolejny cel
            if (Vector3.Distance(transform.position, _targetPosition) < _velocity.magnitude)
            {
                // Następny punkt
                if (Lane == RoadLane.RightLane)
                {
                    _roadPointIndex += 1;
                }
                else
                {
                    _roadPointIndex -= 1;
                }

                //Koniec Trasy
                if (_roadPointIndex >= _actualTile.Path.EvenlySpacedPoints.Count)
                {
                    _actualTile     = RoadManager.LookForTileAtPosition(transform.position.y + 1);
                    _roadPointIndex = 0;
                }
                else if (_roadPointIndex < 0)
                {
                    _actualTile     = RoadManager.LookForTileAtPosition(transform.position.y - 1);
                    _roadPointIndex = _actualTile.Path.EvenlySpacedPoints.Count - 1;
                }

                // Znajdz kolejny cel
                FindNextPosition();
            }

            // Fizyka pojazdu
            _movementDirection = (_targetPosition - (Vector2)transform.position).normalized;
            _velocity          = _movementDirection * Speed * Time.deltaTime;

            // Update
            transform.position += (Vector3)_velocity;
            transform.rotation  = Quaternion.LookRotation(Vector3.forward, _movementDirection);
        }
    }
Exemplo n.º 4
0
    private void SpawnRoad(Map levelData)
    {
        // Check if there are layers
        if (levelData.Layers == null || levelData.Layers.Length == 0)
        {
            return;
        }

        // Setting the mainlayer to the first layer
        Layer mainLayer = levelData.Layers[0];

        short[,] tileNumbers = mainLayer.GetTileArray();

        for (int row = 0; row < mainLayer.Height; row++)
        {
            for (int col = 0; col < mainLayer.Width; col++)
            {
                int tileNumber = tileNumbers[col, row];
                if (tileNumber > 0)
                {
                    _rTile = new RoadTile();
                    _rTile.SetFrame(tileNumber - 1);
                    _rTile.x = col * _rTile.width + _rTile.width / 2;
                    _rTile.y = row * _rTile.height + _rTile.height / 2;
                    AddChild(_rTile);
                }
            }
        }
    }
Exemplo n.º 5
0
        private void TestGetColorIndexAt(byte[] gfx, byte[] palData)
        {
            Palette  palette = new Palette(null, 0, palData);
            RoadTile tile    = new RoadTile(gfx, palette, RoadTileGenre.Road, palette);

            this.TestGetColorIndexAt(gfx, palette, tile);
        }
Exemplo n.º 6
0
    public void Update()
    {
        if (RoadTiles.Count > 0)
        {
            RoadTile lastTile  = RoadTiles[RoadTiles.Count - 1];
            RoadTile firstTile = RoadTiles[0];

            float distanceToLastTile = (lastTile.transform.position.y + lastTile.EndPoint.position.y) -
                                       Car.transform.position.y;
            float distanceToFirstTile = Car.transform.position.y -
                                        (firstTile.transform.position.y + firstTile.EndPoint.position.y);

            //Debug.Log("Car:" + Car.transform.position.y + "  |firstTilePos:"+ firstTile.transform.position.y + "  |first tile endpoint:" + firstTile.EndPoint.position.y + " |distance:" + distanceToFirstTile);
            if (lastTile.Setted && distanceToLastTile < DistanceToAppear)
            {
                AddTile();
            }

            if (distanceToFirstTile > DistanceToDisappear)
            {
                RemoveTile();
            }
        }
        else
        {
            AddTile();
        }
    }
Exemplo n.º 7
0
        void DeleteEntity(string uid, dynamic obj)
        {
            Location location = Location.ParseToLocation(obj);
            bool     success  = false;

            if (buildings.ContainsKey(location))
            {
                Building b = new Building();
                buildings.TryRemove(location, out b);
                success = true;
            }
            else if (roadTiles.ContainsKey(location))
            {
                RoadTile r = new RoadTile();
                roadTiles.TryRemove(location, out r);
                success = true;
            }

            if (success)
            {
                Entity e = new Entity();
                e.location      = location;
                e.tileTimestamp = UpdateTile(location);
                Packet okPacket = new Packet(Constants.Networking.PacketTypes.ENTITY_DELETE, e);
                server.broadcastPackets.Add(okPacket);
            }
            else
            {
                dynamic errorReason = new ExpandoObject();
                errorReason.reason = Constants.Networking.PacketTypes.FailReason.ILLEGAL_LOCATION;
                Packet errorPacket = new Packet(Constants.Networking.PacketTypes.OPERATION_FAILED, errorReason);
                server.GetClient(uid).outgoingPackets.Add(errorPacket);
            }
        }
Exemplo n.º 8
0
    void OnSceneGUI(SceneView sceneView)
    {
        if (!Application.isEditor || Application.isPlaying || !initSuccessful || currentScene.name != "MapScene")
        {
            return;
        }

        HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));

        if (Event.current.button == 0)
        {
            if (Event.current.type == EventType.MouseDown)
            {
                var tile = GetMousePositionTile <RoadTile>();

                if (tile != null)
                {
                    selectedTile    = tile;
                    selectedTilePos = lastClickedTilePosition;

                    mask = GetMaskFromTile(tilemap, selectedTilePos);
                }

                Repaint();
            }
            else if (Event.current.type == EventType.MouseDrag)
            {
                //SetTerritoryTile(GetMousePosition());
                //Repaint();
            }
        }
    }
Exemplo n.º 9
0
    public void PropagateRoad(RoadTile caller)
    {
        isVisited = true;

        if (caller != null)
        {
            nextTile = caller;
        }

        Collider[] n = Physics.OverlapSphere(transform.position, r, LayerMask.GetMask("Road"));

        bool isPropagated = false;

        foreach (Collider neighbour in n)
        {
            RoadTile road = neighbour.GetComponentInParent <RoadTile>();

            if (!road.isVisited)
            {
                road.PropagateRoad(this);
                isPropagated = true;
            }
        }

        if (!isPropagated)
        {
            isStart = true;
            startParticle.SetActive(true);
        }
    }
Exemplo n.º 10
0
    private List <RoadTile> GetNeighborList(RoadTile currentNode)
    {
        List <RoadTile> neighborList = new List <RoadTile>();

        if (grid.ContainsKey(currentNode.location + new Vector3Int(0, 1, 0)))   //top
        {
            neighborList.Add(grid[currentNode.location + new Vector3Int(0, 1, 0)]);
        }
        if (grid.ContainsKey(currentNode.location + new Vector3Int(1, 0, 0)))   //right
        {
            neighborList.Add(grid[currentNode.location + new Vector3Int(1, 0, 0)]);
        }
        if (grid.ContainsKey(currentNode.location + new Vector3Int(0, -1, 0)))   //bottom
        {
            neighborList.Add(grid[currentNode.location + new Vector3Int(0, -1, 0)]);
        }
        if (grid.ContainsKey(currentNode.location + new Vector3Int(-1, 0, 0)))   //left
        {
            neighborList.Add(grid[currentNode.location + new Vector3Int(-1, 0, 0)]);
        }

        if (debug)
        {
            Debug.Log($"{currentNode.location} found {neighborList.Count} neighbors");
            foreach (RoadTile road in neighborList)
            {
                Debug.Log($"Found neighbor at {road.location}");
            }
        }
        return(neighborList);
    }
Exemplo n.º 11
0
    private RoadTile GenerateNextTile()
    {
        //var randWidth = Random.Range();

        RoadTile tmpTile = new RoadTile();

        return(tmpTile);
    }
Exemplo n.º 12
0
    public override void SetTile(Vector3Int location, GridTile tile)
    {
        RoadTile roadTile = (RoadTile)tile;

        tiles[location]   = roadTile;
        roadTile.roadGrid = this;
        roadTile.transform.SetParent(this.transform);
        UpdateNeighbors(location);
    }
Exemplo n.º 13
0
 static void RenderRoads(RoadTile tile, string layer, Action <Way> render)
 {
     foreach (var way in tile.Roads)
     {
         if (way.Tags.GetValueOrDefault("layer", "0") == layer)
         {
             render(way);
         }
     }
 }
Exemplo n.º 14
0
        public void loadDefaultMapTest()
        {
            IMapTile[][] expected = new IMapTile[5][];
            expected[0]    = new IMapTile[6];
            expected[1]    = new IMapTile[6];
            expected[2]    = new IMapTile[6];
            expected[3]    = new IMapTile[6];
            expected[4]    = new IMapTile[6];
            expected[0][0] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][1] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][2] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][3] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][4] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[0][5] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[1][0] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[1][1] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[1][2] = new RoadTile(RoadTile.RoadType.TopRight);
            expected[1][3] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[1][4] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[1][5] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][0] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][1] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][2] = new RoadTile(RoadTile.RoadType.Vertical);
            expected[2][3] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][4] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[2][5] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[3][0] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[3][1] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[3][2] = new RoadTile(RoadTile.RoadType.BottomLeft);
            expected[3][3] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[3][4] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[3][5] = new RoadTile(RoadTile.RoadType.Horizontal);
            expected[4][0] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][1] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][2] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][3] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][4] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);
            expected[4][5] = new BackgroundTile(BackgroundTile.BackgroundType.Plain);

            IMapTile[][] actual = MapLoader.loadDefaultMap();

            Assert.IsTrue(actual.Length > 0 && actual[0].Length > 0, "Map has not a valid dimension");
            Assert.AreEqual(expected.Length, actual.Length, "Constructed map has a different height");
            Assert.AreEqual(expected[0].Length, actual[0].Length, "Constructed map has a different width");

            for (int i = actual.Length; i-- > 0;)
            {
                for (int j = actual[0].Length; j-- > 0;)
                {
                    int hashA = expected[i][j].GetHashCode();
                    int hashB = actual[i][j].GetHashCode();
                    Assert.AreEqual(expected[i][j], actual[i][j], "Constructed map got a different tile at (" + i + "," + j + ")");
                }
            }
        }
Exemplo n.º 15
0
        void CreateEntity(string uid, dynamic obj)
        {
            obj.timestamp = DateTime.UtcNow.ToString();
            int      price       = -1;
            Location location    = new Location(-1, -1);
            Building building    = new Building();
            RoadTile roadTile    = new RoadTile();
            Entity   entity      = Entity.ParseToEntity(obj);
            dynamic  errorReason = new ExpandoObject();

            if (entity.entityType.Equals(EntityType.BUILDING))
            {
                building = Building.ParseToBuilding(obj);
                price    = building.size * building.size * Constants.Gameplay.BASE_BUILDING_COST;
                location = building.location;
            }

            if (entity.entityType.Equals(EntityType.ROAD))
            {
                roadTile = RoadTile.ParseToRoadTile(obj);
                price    = Constants.Gameplay.ROAD_TILE_COST;
                location = roadTile.location;
            }

            if (city.money - price > 0)
            {
                if (!ValidateLocation(location))
                {
                    if (entity.entityType.Equals(EntityType.BUILDING))
                    {
                        buildings.TryAdd(location, building);
                    }
                    else if (entity.entityType.Equals(EntityType.ROAD))
                    {
                        roadTiles.TryAdd(location, roadTile);
                    }
                    obj.tileTimestamp = UpdateTile(location);
                    Packet okPacket = new Packet(Constants.Networking.PacketTypes.ENTITY_CREATE, obj);
                    server.broadcastPackets.Add(okPacket);
                    return;
                }
                else
                {
                    errorReason.reason = Constants.Networking.PacketTypes.FailReason.ILLEGAL_LOCATION;
                }
            }
            else
            {
                errorReason.reason = Constants.Networking.PacketTypes.FailReason.NO_MONEY;
            }
            Packet errorPacket = new Packet(Constants.Networking.PacketTypes.OPERATION_FAILED, errorReason);

            server.GetClient(uid).outgoingPackets.Add(errorPacket);
        }
Exemplo n.º 16
0
        private void TestGenerateGraphics(byte[] palData, byte[] gfx)
        {
            Palette pal = new Palette(null, 0, palData);

            RoadTile tile  = new RoadTile(gfx, pal, RoadTileGenre.Road, pal);
            RoadTile tile2 = new RoadTile(new byte[gfx.Length], pal, RoadTileGenre.Road, pal);

            tile2.Bitmap = tile.Bitmap; // Trigger graphics update

            Assert.AreEqual(gfx, tile2.Graphics);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Checks for utilities on the entranceroad tile.
 /// </summary>
 protected void DrawPower()
 {
     power = false;
     water = false;
     if (entranceRoad != null)
     {
         RoadTile r = entranceRoad.GetComponent <RoadTile>();
         power = r.power;
         water = r.water;
     }
 }
Exemplo n.º 18
0
    //Set all slowdown roads at the start
    void Start()
    {
        Collider[] n = Physics.OverlapSphere(transform.position, range, LayerMask.GetMask("Road"));

        foreach (Collider neighbour in n)
        {
            RoadTile road = neighbour.GetComponentInParent <RoadTile>();
            road.speedMultiplier -= speedMultiplayer;
            road.ActivateSlowdownParticle();
            roadTiles.Add(road);
        }
    }
Exemplo n.º 19
0
    private void Awake()
    {
        //Get main camera;
        camera = Camera.main;

        List <RoadTile> tilePrefabs = new List <RoadTile>();

        activeTileMap = new Dictionary <Vector2, RoadTile>();

        prefabObjects.RemoveAll((t) =>
        {
            RoadTile tile = t.GetComponent <RoadTile>();

            if (tile != null)
            {
                tilePrefabs.Add(tile);
            }
            return(tile == null);
        }
                                );

        Dictionary <RoadTile.Type, RoadTile> tileCatalogue = new Dictionary <RoadTile.Type, RoadTile>();

        foreach (RoadTile tile in tilePrefabs)
        {
            if (!tileCatalogue.ContainsKey(tile.TileType))
            {
                tileCatalogue.Add(tile.TileType, tile);
            }
        }

        roadTilePool = new CataloguePool <RoadTile.Type, RoadTile>(initialCountFromEach, transform, tileCatalogue);
        foreach (RoadTile tile in roadTilePool.InitializePool())
        {
            tile.InitializeAsPoolItem();
        }

        Rotator rotator = rotatorPrefab.GetComponent <Rotator>();

        rotatorPool = new SingularPool <Rotator>(initialCountFromEach, transform, rotator);
        foreach (Rotator item in rotatorPool.InitializePool())
        {
            item.InitializeAsPoolItem();
        }

        InstallTile(RoadTile.Type.Straight, Vector3.zero, Vector3.forward);
        standingTilePosition = lastOutDirection;
        lastOutDirection     = GetNewOutDirection(RoadTile.Type.Straight, lastOutDirection);


        Generate();
    }
Exemplo n.º 20
0
    public static RoadTile ParseToRoadTile(dynamic obj)
    {
        RoadTile tile = new RoadTile();

        try {
            tile.entityType = obj.entityType;
            tile.location   = new Location(obj.location.x, obj.location.y);
            return(tile);
        } catch {
            Console.WriteLine("Error parsing object to RoadTile");
            return(null);
        }
    }
Exemplo n.º 21
0
    public Vector2[] LookForPositionsOnSameY(float y)
    {
        RoadTile tile = LookForTileAtPosition(y);

        if (tile != null)
        {
            return(tile.LookForPositionsOnSameY(y));
        }
        else
        {
            return(new Vector2[0]);
        }
    }
Exemplo n.º 22
0
        private static RoadTileset GetRoadTileset(Palettes palettes, byte[] tilePaletteIndexes, byte[][] tileGfx, RoadTileGenre[] tileGenres)
        {
            RoadTile[] tiles        = new RoadTile[RoadTileset.TileCount];
            Palette    firstPalette = palettes[0];

            for (int i = 0; i < tileGfx.Length; i++)
            {
                Palette palette = palettes[tilePaletteIndexes[i]];
                tiles[i] = new RoadTile(tileGfx[i], palette, tileGenres[i], firstPalette);
            }

            return(new RoadTileset(tiles));
        }
Exemplo n.º 23
0
    private RoadTile GetLowestFCostNode(List <RoadTile> roadNodeList)
    {
        RoadTile lowestFCostNode = roadNodeList[0];

        foreach (RoadTile RoadTile in roadNodeList)
        {
            if (RoadTile.fCost < lowestFCostNode.fCost)
            {
                lowestFCostNode = RoadTile;
            }
        }

        return(lowestFCostNode);
    }
Exemplo n.º 24
0
    public void ReturnToPool(RoadTile tile)
    {
        tile.ApplyReturnProcess();

        if (tile.TileType != RoadTile.Type.Straight)
        {
            RotatorLink rotatorLink = tile.GetComponent <RotatorLink>();
            Rotator     rotator     = rotatorLink.DetachRotator();
            rotator.ApplyReturnProcess();
            rotatorPool.ReturnToPool(rotator);
        }

        roadTilePool.ReturnToPool(tile.TileType, tile);
        activeTileMap.Remove(tile.MapPosition);
    }
Exemplo n.º 25
0
    public void makeACarGo(RoadTile start, RoadTile end)
    {
        var car           = Instantiate(data.carModel);
        var carPathfinder = car.GetComponent <CarPathfinder>();

        carPathfinder.roadManager = this;
        carPathfinder.startTile   = start;
        carPathfinder.endTile     = end;

        carPathfinder.originalStart = start;
        carPathfinder.originalEnd   = end;
        carPathfinder.SetColor();

        carPathfinder.planAndGo();
    }
Exemplo n.º 26
0
    public List <Vector3Int> GetMoveMap(int moveDistance, Vector3Int position)
    {
        List <Vector3Int> map         = new List <Vector3Int>();
        Vector3Int        curPosition = position;

        for (int rotation = 0; rotation < 4; ++rotation)
        {
            Vector3Int moveVector;
            TileBase   tile;
            if (rotation == 0)
            {
                moveVector = new Vector3Int(0, 1, 0);
            }
            else if (rotation == 1)
            {
                moveVector = new Vector3Int(1, 0, 0);
            }
            else if (rotation == 2)
            {
                moveVector = new Vector3Int(0, -1, 0);
            }
            else
            {
                moveVector = new Vector3Int(-1, 0, 0);
            }
            for (int step = 1; step <= moveDistance; ++step)
            {
                curPosition += moveVector;
                tile         = CurrentTilemap.GetTile(curPosition);
                if (tile is RoadTile)
                {
                    RoadTile roadTile = tile as RoadTile;
                    if (roadTile.isBlock)
                    {
                        break;
                    }
                    if (roadTile.isTaken)
                    {
                        break;
                    }
                }
                map.Add(curPosition);
            }
            curPosition = position;
        }
        return(map);
    }
Exemplo n.º 27
0
    IEnumerator EnemySpawn()
    {
        yield return(new WaitForSeconds(currentWave.timeBetweenSpawns));

        enemiesRemainingToSpawn--;

        RoadTile randomWaypoint = spawnTiles[Random.Range(0, spawnTiles.Length)];

        EnemySO enemyData    = currentEnemySet.enemyData;
        Enemy   spawnedEnemy = Instantiate(enemyData.enemyModel, randomWaypoint.transform.position,
                                           Quaternion.identity).GetComponent <Enemy>();

        spawnedEnemy.Init(enemyData, randomWaypoint);
        spawnedEnemy.OnDeath += OnEnemyDeath;

        _canSpawn = true;
    }
Exemplo n.º 28
0
    void SpawnEntity(dynamic obj)
    {
        Entity e = Entity.ParseToEntity(obj);

        if (!entityManager.ValidateTimestamp(e.tileTimestamp, e.location))
        {
            return;
        }
        if (e.entityType.Equals(EntityType.BUILDING))
        {
            SpawnBuilding(Building.ParseToBuilding(obj));
        }
        else if (e.entityType.Equals(EntityType.ROAD))
        {
            SpawnRoad(RoadTile.ParseToRoadTile(e));
        }
    }
Exemplo n.º 29
0
            public TileSwallower swallow(string line)
            {
                // '\d' represents a single so that we can extract a single
                Regex           tileExtractor = new Regex(@"(\d+)-(\d+)-(\d+)-(\d+)");
                MatchCollection tileMatchs    = tileExtractor.Matches(line);

                foreach (Match tileMatch in tileMatchs)
                {
                    //read tile code, house flag and garbage amount
                    var backgroundCode = Int32.Parse(tileMatch.Groups[1].Value);
                    var roadCode       = Int32.Parse(tileMatch.Groups[2].Value);
                    var houseCode      = Int32.Parse(tileMatch.Groups[3].Value);
                    var garbageAmount  = Int32.Parse(tileMatch.Groups[4].Value);

                    var hasRoad  = roadCode > 0;
                    var hasHouse = houseCode > 0;

                    IMapTile tile;                                 //empty tile
                    if (hasRoad)                                   //Plain
                    {
                        var roadType = RoadCorrespondor(roadCode); //tile orientation
                        tile = new RoadTile(roadType);
                        if (hasHouse)
                        {
                            var houseType = HouseCorrespondor(houseCode);
                            tile = new HouseTile(
                                roadType,
                                houseType,
                                TrashType.Paper,
                                garbageAmount);
                        }
                    }
                    else
                    {
                        var backgroundType = BackgroundCorrespondor(backgroundCode); //tile orientation
                        tile = new BackgroundTile(backgroundType);
                    }
                    AddTile(tile);
                    //decrease remaining needed item
                    remainingTilesToComplete--;
                }

                //chained call so return yourself
                return(this);
            }
Exemplo n.º 30
0
    public int IsTileAvailable(Vector3Int coords)
    {
        TileBase tile = CurrentTilemap.GetTile(coords);

        if (tile is RoadTile)
        {
            RoadTile roadTile = tile as RoadTile;
            if (roadTile.isBlock)
            {
                return(1);
            }
            if (roadTile.isTaken)
            {
                return(2);
            }
        }
        return(0);
    }