Ejemplo n.º 1
0
        public void BuildWorldObject(Coord2D mouseIsoFlatCoord, Coord2D mouseIsoCoord)
        {
            Coord3D mouseIsoCoord3D = new Coord3D(mouseIsoCoord, Altitude);

            if (BuildMode == BuildMode.Cube)
            {
                // Create cube and add it to the layer map.
                var cube = CubeFactory.CreateCurrentCube(mouseIsoFlatCoord, mouseIsoCoord3D);
                if (!LayerMap.ContainsKey(mouseIsoCoord3D))
                {
                    LayerMap.Add(mouseIsoCoord3D, cube);
                }
                // Deal with the walkable tile table.
                foreach (var coord in mouseIsoCoord.AdjacentCoords())
                {
                    // If there are no solid objects above us,
                    if (!(LayerMap.ContainsKey(new Coord3D(mouseIsoCoord, Altitude + 1)) && LayerMap[new Coord3D(mouseIsoCoord, Altitude + 1)].IsSolid)) // not- contains key and sprite is solid
                    {
                        WalkableTileTable.Add(Altitude + 1, coord, mouseIsoCoord);
                    }
                    // Assuming the added cube is solid, the tile under us is no longer walkable.
                    if (cube.IsSolid)
                    {
                        WalkableTileTable.Remove(Altitude, coord, mouseIsoCoord);
                    }
                }
            }
            else if (BuildMode == BuildMode.Deco)
            {
                // Create deco and add it to the layer map.
                var deco = DecoFactory.CreateCurrentDeco(mouseIsoFlatCoord, mouseIsoCoord, Altitude);
                if (deco.OccupiedCoords.Any((c) => LayerMap.ContainsKey(c)) == false)
                {
                    LayerMap.Add(mouseIsoCoord3D, deco);
                    foreach (var coord in deco.OccupiedCoords)
                    {
                        if (coord != mouseIsoCoord3D)
                        {
                            LayerMap.Add(coord, new DecoReference(deco, mouseIsoCoord3D)
                            {
                                Coords = coord.To2D(), Altitude = coord.Z
                            });
                        }

                        foreach (var _coord in new Coord2D(coord.X, coord.Y).AdjacentCoords())
                        {
                            // Assuming the added deco is solid, the tiles under us are no longer walkable.
                            if (deco.IsSolid)
                            {
                                WalkableTileTable.Remove(Altitude, _coord, new Coord2D(coord.X, coord.Y));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void RemoveWorldObject(Coord2D mouseIsoFlatCoord, Coord2D mouseIsoCoord)
        {
            Coord3D mouseIsoCoord3D = new Coord3D(mouseIsoCoord, Altitude);

            if (BuildMode == BuildMode.Cube && LayerMap.ContainsKey(mouseIsoCoord3D))
            {
                var sprite = LayerMap[mouseIsoCoord3D];
                if (sprite is Cube)
                {
                    LayerMap.Remove(mouseIsoCoord3D);

                    foreach (var coord in mouseIsoCoord.AdjacentCoords())
                    {
                        WalkableTileTable.Remove(Altitude + 1, coord, mouseIsoCoord);
                    }

                    // If there is a cube below,
                    if (LayerMap.ContainsKey(new Coord3D(mouseIsoCoord, Altitude - 1)) && LayerMap[new Coord3D(mouseIsoCoord, Altitude - 1)] is Cube)
                    {
                        foreach (var coord in mouseIsoCoord.AdjacentCoords())
                        {
                            WalkableTileTable.Add(Altitude, coord, mouseIsoCoord);
                        }
                    }
                }
            }
            else if (BuildMode == BuildMode.Deco && LayerMap.ContainsKey(mouseIsoCoord3D))
            {
                var sprite = LayerMap[mouseIsoCoord3D];
                if (sprite is Deco deco)
                {
                    foreach (var coord in deco.OccupiedCoords)
                    {
                        LayerMap.Remove(coord);

                        // If there are cubes below,
                        var c = new Coord3D(new Coord2D(coord.X, coord.Y), Altitude - 1);
                        if (LayerMap.ContainsKey(c) && LayerMap[c] is Cube)
                        {
                            foreach (var _coord in new Coord2D(coord.X, coord.Y).AdjacentCoords())
                            {
                                WalkableTileTable.Add(Altitude, _coord, new Coord2D(coord.X, coord.Y));
                            }
                        }
                    }
                }
            }
        }