Example #1
0
    protected override void ApplyCurrentPosition()
    {
        // set the position in the game world
        LocalPosition = level.GetCellPosition(currentGridPosition.X, currentGridPosition.Y);

        // stop moving
        velocity = Vector2.Zero;

        // if the current tile has the "empty" type, let the animal die
        Tile.Type tileType = level.GetTileType(currentGridPosition);
        if (tileType == Tile.Type.Empty)
        {
            Visible = false;
            return;
        }

        // If the current tile already contains another animal, then both animals should disappear!
        Animal otherAnimal = level.GetAnimal(currentGridPosition);

        if (otherAnimal != null)
        {
            level.RemoveAnimalFromGrid(currentGridPosition);
            Visible             = false;
            otherAnimal.Visible = false;

            // TODO: if the other animal matches, notify the game that we've made a pair

            return;
        }

        // In all other cases, the animal shouldn't disappear yet, so it's still part of the level.
        // Add the animal to the level's grid.
        level.AddAnimalToGrid(this, currentGridPosition);

        // if the current tile is a hole, mark this animal as "inside a hole"
        if (tileType == Tile.Type.Hole)
        {
            IsInHole = true;
        }
    }
Example #2
0
        public void UpdateTile(string type, string xPos, string yPos, string owner)
        {
            //Get Type
            Tile.Type tileType = Tile.Type.UNSEEN;
            switch (type)
            {
            case ("f"):
                tileType = Tile.Type.FOOD;
                break;

            case ("w"):
                tileType = Tile.Type.WATER;
                break;

            case ("a"):
                tileType = Tile.Type.ANT;
                break;

            case ("d"):
                tileType = Tile.Type.DEAD;
                break;
            }

            int x = Int32.Parse(xPos);
            int y = Int32.Parse(yPos);

            int playerNum = 0;

            if (owner.Length > 0)
            {
                playerNum = Int32.Parse(owner);
            }

            Tile.Owner tileOwner = owner.Length == 0 ? Tile.Owner.NONE : Tile.Owner.PLAYER1 + playerNum;
            Tile       newTile   = new Tile(tileType, x, y, tileOwner);

            this[x, y] = newTile;
        }
Example #3
0
    public void SetTileAt(int x, int y, Tile.Type type)
    {
        Vector2Int offset = GetTilemapPos(x, y);

        tiles = tileMaps[offset];
        int adjustedX = x - offset.x;
        int adjustedY = y - offset.y;

        if (tiles[adjustedX, adjustedY].type.ToString().Contains("Seed"))
        {
            OnSeedBreak(x, y, basicSeed);
        }
        else if (tiles[adjustedX, adjustedY].type.ToString().Contains("Ore"))
        {
            OnOreBreak(x, y, oreItem);
        }

        /*
         * tiles[adjustedX,adjustedY].type = type;
         *
         * tiles[adjustedX, adjustedY].tileClass = Tile.getClassFromType(type);*/
        tiles[adjustedX, adjustedY].modifyTileType(type);
    }
Example #4
0
    private List <List <Vector2Int> > GetRegions(Tile.Type tileType)
    {
        List <List <Vector2Int> > regions = new List <List <Vector2Int> >();

        int[,] mapFlags = new int[width, height];

        foreach (Tile tile in _tiles)
        {
            if (mapFlags[tile.position.x, tile.position.y] != 0 || tile.type != tileType)
            {
                continue;
            }

            List <Vector2Int> region = GetRegion(tile);
            regions.Add(region);

            foreach (Vector2Int position in region)
            {
                mapFlags[position.x, position.y] = 1;
            }
        }

        return(regions);
    }
Example #5
0
    public GameObject GameObjectFromTileType(Tile.Type spaceType)
    {
        GameObject tile = null;

        switch (spaceType)
        {
        case Tile.Type.Floor:
            tile = AllFloor [indexFloor];
            indexFloor++;
            break;

        case Tile.Type.Wall:
            tile = AllWall [indexWall];
            indexWall++;
            break;

        case Tile.Type.Platform:
            tile = AllPlatform [indexPlatform];
            indexPlatform++;
            break;

        case Tile.Type.Angle45Left:
            tile = AllAngleLeft45 [indexAngleLeft45];
            indexAngleLeft45++;
            break;

        case Tile.Type.Angle45Right:
            tile = AllAngleRight45 [indexAngleRight45];
            indexAngleRight45++;
            break;

        case Tile.Type.Ladder:
            tile = AllLadder [indexLadder];
            indexLadder++;
            break;

        case Tile.Type.LadderBottom:
            tile = AllLadderBottom [indexLadderBottom];
            indexLadderBottom++;
            break;

        case Tile.Type.LadderTop:
            tile = AllLadderTop [indexLadderTop];
            indexLadderTop++;
            break;

        case Tile.Type.Spawn:
            tile = AllPlayer [indexPlayer];
            indexPlayer++;
            break;

        case Tile.Type.Exit:
            tile = AllExit [indexExit];
            indexExit++;
            break;

        case Tile.Type.Movable:
            tile = AllMovable [indexMovable];
            indexMovable++;
            break;
        }

        return(tile);
    }
Example #6
0
    // Checks for collisions between the character and the level's tiles, and handles these collisions when needed.
    void HandleTileCollisions(Vector2 previousPosition)
    {
        isGrounded        = false;
        standingOnIceTile = false;
        standingOnHotTile = false;

        // determine the range of tiles to check
        Rectangle bbox            = BoundingBoxForCollisions;
        Point     topLeftTile     = level.GetTileCoordinates(new Vector2(bbox.Left, bbox.Top)) - new Point(1, 1);
        Point     bottomRightTile = level.GetTileCoordinates(new Vector2(bbox.Right, bbox.Bottom)) + new Point(1, 1);

        for (int y = topLeftTile.Y; y <= bottomRightTile.Y; y++)
        {
            for (int x = topLeftTile.X; x <= bottomRightTile.X; x++)
            {
                Tile.Type tileType = level.GetTileType(x, y);

                // ignore empty tiles
                if (tileType == Tile.Type.Empty)
                {
                    continue;
                }

                // ignore platform tiles if the player is standing below them
                Vector2 tilePosition = level.GetCellPosition(x, y);
                if (tileType == Tile.Type.Platform && localPosition.Y > tilePosition.Y && previousPosition.Y > tilePosition.Y)
                {
                    continue;
                }

                // if there's no intersection with the tile, ignore this tile
                Rectangle tileBounds = new Rectangle((int)tilePosition.X, (int)tilePosition.Y, Level.TileWidth, Level.TileHeight);
                if (!tileBounds.Intersects(bbox))
                {
                    continue;
                }

                // calculate how large the intersection is
                Rectangle overlap = CollisionDetection.CalculateIntersection(bbox, tileBounds);

                // if the x-component is smaller, treat this as a horizontal collision
                if (overlap.Width < overlap.Height)
                {
                    if ((velocity.X >= 0 && bbox.Center.X < tileBounds.Left) || // right wall
                        (velocity.X <= 0 && bbox.Center.X > tileBounds.Right))  // left wall
                    {
                        localPosition.X = previousPosition.X;
                        velocity.X      = 0;
                    }
                }

                // otherwise, treat this as a vertical collision
                else
                {
                    if (velocity.Y >= 0 && bbox.Center.Y < tileBounds.Top && overlap.Width > 6) // floor
                    {
                        isGrounded      = true;
                        velocity.Y      = 0;
                        localPosition.Y = tileBounds.Top;

                        // check the surface type: are we standing on a hot tile or an ice tile?
                        Tile.SurfaceType surface = level.GetSurfaceType(x, y);
                        if (surface == Tile.SurfaceType.Hot)
                        {
                            standingOnHotTile = true;
                        }
                        else if (surface == Tile.SurfaceType.Ice)
                        {
                            standingOnIceTile = true;
                        }
                    }
                    else if (velocity.Y <= 0 && bbox.Center.Y > tileBounds.Bottom && overlap.Height > 2) // ceiling
                    {
                        localPosition.Y = previousPosition.Y;
                        velocity.Y      = 0;
                    }
                }
            }
        }
    }
Example #7
0
File: Tile.cs Project: Porkka/CDIO4
 public Tile(Vector2 wPos)
 {
     this.type = Type.BACKGROUND;
     this.worldPosition = wPos;
 }
Example #8
0
    public void Genererate()
    {
        /// create tile set
        tileSet        = new TileSet();
        tileSet.width  = TileSet.map.width;
        tileSet.height = TileSet.map.height;

        // create room types
        List <Tile.Type> roomTypes = new List <Tile.Type> ();

        Tile.Type type = Tile.Type.LivingRoom;

        /// debug interior : create fix list of rooms
        roomTypes.Add(Tile.Type.Bathroom);
        roomTypes.Add(Tile.Type.Bedroom);
        roomTypes.Add(Tile.Type.ChildBedroom);
        roomTypes.Add(Tile.Type.Kitchen);
        roomTypes.Add(Tile.Type.Toilet);

        // create hallway
        Coords hallway_Coords = tileSet.Center;
        Coords hallway_Dir    = new Coords(0, 1);
        int    a = 0;

        while (roomTypes.Count > 0)
        {
            // add new hallway tile
            Tile newHallwayTile = new Tile(hallway_Coords);
            newHallwayTile.SetType(Tile.Type.Hallway);

            if (tileSet.tiles.ContainsKey(hallway_Coords))
            {
                hallway_Coords += hallway_Dir;
                ++a;
                continue;
            }

            tileSet.Add(hallway_Coords, newHallwayTile);

            // set entrance door
            if (a == 0)
            {
                Item doorItem = Item.CreateNewItem("porte");
                doorItem.AddProperty("entrance", "true");
                // il n'y a plus réellement de porte dehors en fait non ?
                //doorItem.word.SetAdjective(TileSet.map.GetTile(TileSet.map.playerCoords).items[0].word.GetAdjective);
                doorItem.AddProperty("direction", "to south");

                newHallwayTile.AddItem(doorItem);
            }

            // check if room appears
            if (Random.value < chanceCreateRoom)
            {
                Coords side = new Coords(hallway_Dir.x, hallway_Dir.y);
                side.Turn();

                Coords coords = newHallwayTile.coords + side
                ;

                if (tileSet.tiles.ContainsKey(coords))
                {
                    continue;
                }

                Tile      newRoomTile = new Tile(coords);
                Tile.Type roomType    = roomTypes [Random.Range(0, roomTypes.Count)];
                newRoomTile.SetType(roomType);

                roomTypes.Remove(roomType);

                if (Random.value < chanceEnclosedRoom)
                {
                    newRoomTile.enclosed = true;
                }

                tileSet.Add(coords, newRoomTile);
            }

            hallway_Coords += hallway_Dir;

            if (Random.value < chanceHallwayTurn)
            {
                hallway_Dir.Turn();
            }

            ++a;
        }

        InitStoryTiles();

        // ADDING DOORS
        AddDoors();
    }
 // Create Tile
 public Tile CreateTile(Tile.Type tileType, byte tileNumber, byte tilePosition)
 {
     return(new Tile(tileType, tileNumber, tilePosition));
 }
Example #10
0
    public void CreateMapFromTexture()
    {
        TileSet.map = new TileSet();
        TileSet.SetCurrent(TileSet.map);

        int w = mainMap_Texture.width;
        int h = mainMap_Texture.height;

        TileSet.map.width  = w;
        TileSet.map.height = h;

        for (int x = 0; x < w; x++)
        {
            for (int y = 0; y < h; y++)
            {
                Coords c = new Coords(x, y);

                Color pixelColor = mainMap_Texture.GetPixel(x, y);

                Tile.Type tileType = Tile.Type.None;

                for (int i = 0; i < tileColors.Length; i++)
                {
                    // check for color match

                    Color tileColor = tileColors[i];

                    float tileColor_r = Mathf.Round(tileColor.r * 1000f);
                    float tileColor_g = Mathf.Round(tileColor.g * 1000f);
                    float tileColor_b = Mathf.Round(tileColor.b * 1000f);

                    float pixel_r = Mathf.Round(pixelColor.r * 1000f);
                    float pixel_g = Mathf.Round(pixelColor.g * 1000f);
                    float pixel_b = Mathf.Round(pixelColor.b * 1000f);

                    float tolerance = 3;

                    if (
                        pixel_r >= tileColor_r - tolerance && pixel_r <= tileColor_r + tolerance &&
                        pixel_g >= tileColor_g - tolerance && pixel_g <= tileColor_g + tolerance &&
                        pixel_b >= tileColor_b - tolerance && pixel_b <= tileColor_b + tolerance
                        )
                    {
                        Tile newTile = new Tile(c);

                        // get tile type from color
                        tileType = (Tile.Type)i;

                        if (tileType == Tile.Type.None)
                        {
                            break;
                        }

                        newTile.SetType(tileType);

                        TileSet.map.Add(c, newTile);

                        switch (tileType)
                        {
                        case Tile.Type.TownHouse:
                        case Tile.Type.Farm:
                        case Tile.Type.ForestCabin:
                        case Tile.Type.CountryHouse:
                            Interior.NewInterior(newTile);
                            break;

                        default:
                            break;
                        }
                        break;
                    }
                }

                if (tileType == Tile.Type.None)
                {
                }
            }
        }
    }
Example #11
0
 public Color GetTileColor(Tile.Type type)
 {
     return(tileColors [(int)type]);
 }
Example #12
0
 public void Paint(Coords c, Tile.Type tileType)
 {
     Paint(c, GetTileColor(tileType));
 }
Example #13
0
 static void AddTile(Point addTo, Tile.Type toAdd)
 {
     listsOfPointsByType[toAdd].Add(addTo);
     map[addTo] = toAdd;
     ModifiedPoints.Add(addTo);
 }
Example #14
0
            /// <summary>
            /// Generate a forest with some rocky areas
            /// </summary>
            /// <returns></returns>
            public override (Tile tile, FeaturesByLayer features) generateAt(Coordinate axialKey, FastNoise[] noiseLayers, Coordinate chunkKeyOffset = default)
            {
                /// get the tile type and height
                Coordinate noiseKey          = axialKey + chunkKeyOffset * RectangularBoard.ChunkWorldOffset;
                float      heightNoise       = noiseLayers[(int)NoiseLayers.Height].GetPerlinFractal(noiseKey.x * 20, noiseKey.z * 20);
                float      tileTypeNoise     = noiseLayers[(int)NoiseLayers.Terrain].GetPerlinFractal(noiseKey.x * 10, noiseKey.z * 10);
                int        scaledHeightValue = Mathf.Max((int)heightNoise.scale(20, 1), 7);

                Tile.Type tileType =
                    scaledHeightValue == 7
            ? Tile.Types.Water
            : tileTypeNoise > 0 && scaledHeightValue > 10
              ? Tile.Types.Rocky
              : Tile.Types.Grass;

                /// check for features
                FeaturesByLayer features = null;

                // trees
                if (tileType == Tile.Types.Grass)
                {
                    float forestNoise = noiseLayers[(int)NoiseLayers.Forest].GetCellular(noiseKey.x * 20, noiseKey.z * 10);
                    if (forestNoise >= 0)
                    {
                        features = new FeaturesByLayer {
                            {
                                TileFeature.Types.ConniferTrio.Layer,
                                new TileFeature(TileFeature.Types.ConniferTrio)
                            }
                        };
                    }
                }

                // rocks
                float cloudNoise = noiseLayers[(int)NoiseLayers.Clouds].GetCellular(noiseKey.x * 50, noiseKey.z * 50);

                if ((tileType == Tile.Types.Rocky || tileType == Tile.Types.Grass) && (features == null || !features.ContainsKey(TileFeature.Layer.Decoration)))
                {
                    bool  hasResouce = features?.ContainsKey(TileFeature.Layer.Resource) ?? false;
                    float rockNoise  = noiseLayers[(int)NoiseLayers.Forest].GetCellular(noiseKey.x * 35, noiseKey.z * 40);
                    if ((!hasResouce && tileType != Tile.Types.Grass && rockNoise >= 0) || rockNoise >= 0.5f)
                    {
                        TileFeature rockPile;
                        if (hasResouce)
                        {
                            rockPile = new TileFeature(TileFeature.Types.DecorativeRocks);
                        }
                        else
                        {
                            int rockSize = (int)cloudNoise.scale(0, (tileType == Tile.Types.Grass) ? 2 : 4);
                            if (rockSize == 3)
                            {
                                rockPile = new TileFeature(TileFeature.Types.IronVeinedRocks);
                            }
                            else
                            {
                                rockPile = new TileFeature(TileFeature.Types.RockPile);
                                rockPile.setRemainingInteractions(rockSize);
                            }
                        }
                        if (features == null)
                        {
                            features = new FeaturesByLayer {
                                {
                                    rockPile.type.Layer,
                                    rockPile
                                }
                            };
                        }
                        else
                        {
                            features.Add(
                                rockPile.type.Layer,
                                rockPile
                                );
                        }
                    }
                }

                // lilypads
                if (tileType == Tile.Types.Water)
                {
                    float lillyNoise = noiseLayers[(int)NoiseLayers.Clouds].GetPerlinFractal(noiseKey.x * 25 + 10, noiseKey.z * 25 + 25);
                    if (lillyNoise >= 0.3f)
                    {
                        features = new FeaturesByLayer {
                            {
                                TileFeature.Types.BloomingLilypads.Layer,
                                new TileFeature(TileFeature.Types.BloomingLilypads)
                            }
                        };
                    }
                    else if (lillyNoise >= 0.1f)
                    {
                        features = new FeaturesByLayer {
                            {
                                TileFeature.Types.SmallLilypads.Layer,
                                new TileFeature(TileFeature.Types.SmallLilypads)
                            }
                        };
                    }
                }

                // clouds
                if (cloudNoise >= 0.7f)
                {
                    int cloudMode = (int)cloudNoise.scale(0, 3);
                    if (features == null)
                    {
                        features = new FeaturesByLayer {
                            {
                                TileFeature.Types.WhiteClouds.Layer,
                                new TileFeature(TileFeature.Types.WhiteClouds, cloudMode)
                            }
                        };
                    }
                    else
                    {
                        features.Add(
                            TileFeature.Types.WhiteClouds.Layer,
                            new TileFeature(TileFeature.Types.WhiteClouds, cloudMode)
                            );
                    }
                }

                return(
                    new Tile(
                        tileType,
                        axialKey,
                        scaledHeightValue,
                        chunkKeyOffset
                        ),
                    features
                    );
            }
Example #15
0
 public Tile(Tile.Type type)
 {
     this.type = type;
     all.Add(this);
 }
Example #16
0
 public Tile(int x, int y, Tile.Type type)
 {
     this.param = new TileParam(x, y);
     this.type  = type;
     all.Add(this);
 }