예제 #1
0
        public override void Death()
        {
            List <Player> playerList = (GameWorld.FindAll(p => p is Player).Cast <Player>().ToList());

            foreach (Player p in playerList)
            {
                p.ReceiveExp(0, this);
            }

            //Drop equipment/loot, remove itself from world, etc
            Tile tile = Tile;

            if (tile != null)
            {
                tile.RemoveImmediatly(this);
            }

            LootSack ls = new LootSack(this);

            tile.PutOnTile(ls);

            List <GameObject> changes = new List <GameObject>()
            {
                ls, Inventory, tile.OnTile
            };

            changes.AddRange(Inventory.Objects.Cast <GameObject>().ToList());
            changes.AddRange(Inventory.Items);
            LocalServer.SendToClients(new LevelChangedEvent(changes));

            base.Death();
        }
예제 #2
0
        private Tile LoadBossTile()
        {
            Tile t    = LoadFloorTile();
            Boss boss = new Boss(levelIndex);

            t.PutOnTile(boss);
            return(t);
        }
예제 #3
0
        private Tile LoadEndTile()
        {
            Tile t   = LoadFloorTile();
            End  end = new End(t, levelIndex, this);

            t.PutOnTile(end);
            return(t);
        }
예제 #4
0
        private Tile LoadDoorTile(string assetName = "spr_floor")
        {
            Tile t = LoadFloorTile("", assetName);

            Door door = new Door(t);

            t.PutOnTile(door);
            return(t);
        }
예제 #5
0
        private Tile LoadChestTile(int floorNumber = 1, string assetName = "spr_floor")
        {
            floorNumber++;
            Tile      t     = LoadFloorTile("", assetName);
            Container chest = new Container("Sprites/Containers/chest2_closed", "Sprites/Containers/chest2_open", "Sounds/creaking-door-2", levelIndex);

            for (int x = 0; x < chest.IBox.Columns; x++)
            {
                for (int y = 0; y < chest.IBox.Rows; y++)
                {
                    int  i = x % 4;
                    int  spawnChance;
                    Item newItem;
                    switch (i)
                    {
                        #region cases
                    case 0:
                        spawnChance = 50;
                        newItem     = new Potion(floorNumber);
                        break;

                    case 1:
                        spawnChance = 30;
                        newItem     = new WeaponEquipment(floorNumber);
                        break;

                    case 2:
                        spawnChance = 30;
                        newItem     = new BodyEquipment(floorNumber, 3);
                        break;

                    case 3:
                        spawnChance = 30;
                        newItem     = new RingEquipment("empty:64:64:10:Gold");
                        break;

                    default:
                        throw new Exception("wtf");
                        #endregion
                    }
                    if (spawnChance > GameEnvironment.Random.Next(100))
                    {
                        ItemSlot cS = chest.IBox.Get(x, y) as ItemSlot;
                        cS.ChangeItem(newItem);
                    }
                }
            }
            t.PutOnTile(chest);
            return(t);
        }
예제 #6
0
        public void LoadTiles(string path)
        {
            List <string> textLines  = new List <string>();
            StreamReader  fileReader = new StreamReader(path);
            string        line       = fileReader.ReadLine();
            int           width      = line.Length;

            while (line != null)
            {
                textLines.Add(line);
                line = fileReader.ReadLine();
            }
            //timelimit = int.Parse(textLines[textLines.Count - 1]);
            TileField tf = new TileField(textLines.Count, width, 0, "TileField");

            Add(tf);

            for (int y = 0; y < textLines.Count; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    Tile t = LoadTile(textLines[y][x], x, y);
                    tf.Add(t, x, y);
                }
            }
            //Putting the item one layer above the inventory box
            int inventoryLayer = layer + 1;
            int itemLayer      = layer + 2;

            #region ENEMY CODE (test)
            for (int i = 0; i < 2; i++)
            {
                Enemy testEnemy = new Enemy(0, Index, EnemyType.random, "Enemy" + i);
                testEnemy.SetStats();
                //First find all passable tiles then select one at random.
                List <GameObject> tileCandidates = tf.FindAll(obj => obj is Tile && (obj as Tile).Passable);
                Tile startTile = tileCandidates[GameEnvironment.Random.Next(tileCandidates.Count)] as Tile;
                startTile.PutOnTile(testEnemy);
            }
            #endregion
            tf.InitSpriteSheetIndexation();
        }
        /// <summary>
        /// Puts the Living object on a given tile (if possible)
        /// </summary>
        /// <param name="t">Destination tile</param>
        public virtual void MoveTo(Tile t)
        {
            Tile oldTile = Tile;

            if (oldTile != null)
            {
                oldTile.RemoveImmediatly(this);
            }

            if (!t.PutOnTile(this))
            {
                if (!oldTile.PutOnTile(this))
                {
                    throw new Exception();
                }
            }
            else if (Visible)
            { //Movement animation
                LocalServer.SendToClients(new LivingMoveAnimationEvent(this, t, "Sounds/Footsteps 2 steps"));
            }
        }
예제 #8
0
        private TileField GenerateTiles(List <Room> rooms, List <Tuple <Room, Room> > hallwayPairs)
        {
            //Get the highest coordinates so we know the size of the TileField.
            int highestX = int.MinValue;
            int highestY = int.MinValue;

            foreach (Room r in rooms)
            {
                if (r.BoundingBox.Right > highestX)
                {
                    highestX = r.BoundingBox.Right;
                }
                if (r.BoundingBox.Bottom > highestY)
                {
                    highestY = r.BoundingBox.Bottom;
                }
            }

            //Make the tilefield and fill with default Tiles.
            TileField tf = new TileField(highestY + 1, highestX + 1, 0, "TileField");

            Add(tf);
            for (int x = 0; x < tf.Columns; x++)
            {
                for (int y = 0; y < tf.Rows; y++)
                {
                    tf.Add(new Tile(), x, y);
                }
            }

            List <Tuple <XNAPoint, XNAPoint> > hallways = new List <Tuple <XNAPoint, XNAPoint> >();

            //Find good points for the hallways connect to.
            foreach (Tuple <Room, Room> pair in hallwayPairs)
            {
                Vector2 center1 = pair.Item1.BoundingBox.Center.ToVector2();
                Vector2 center2 = pair.Item2.BoundingBox.Center.ToVector2();

                //Vector from center of room1 to center of room2 and vice versa
                Vector2 v1 = center2 - center1;
                Vector2 v2 = center1 - center2;

                Collision.Side s1 = CalculateExitSide(pair.Item1, v1);
                Collision.Side s2 = CalculateExitSide(pair.Item2, v2);

                v1.Normalize();
                v2.Normalize();

                XNAPoint cRelExit1 = CalculateExit(v1, center1, s1, pair.Item1.BoundingBox.GetMiddleOfSide(s1)).ToPoint();
                XNAPoint cRelExit2 = CalculateExit(v2, center2, s2, pair.Item2.BoundingBox.GetMiddleOfSide(s2)).ToPoint();
                XNAPoint absExit1  = cRelExit1 + pair.Item1.BoundingBox.Center;
                XNAPoint absExit2  = cRelExit2 + pair.Item2.BoundingBox.Center;

                hallways.Add(new Tuple <XNAPoint, XNAPoint>(absExit1, absExit2));
            }

            //for each room, add floor tiles to the tilefield.
            for (int i = 0; i < rooms.Count; i++)
            {
                Room r      = rooms[i];
                int  width  = r.BoundingBox.Width;
                int  height = r.BoundingBox.Height;

                XNAPoint relCenter = r.BoundingBox.Center - r.BoundingBox.Location;

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        Tile tile = LoadFloorTile();
                        if (x == relCenter.X && y == relCenter.Y)
                        {
                            tile.AddDebugTag("Room", "" + i);
                        }
                        tf.Add(tile, x + r.BoundingBox.X, y + r.BoundingBox.Y);
                    }
                }
            }

            //Generate hallways
            foreach (Tuple <XNAPoint, XNAPoint> pair in hallways)
            {
                //Use the pathfinder to get a path from exitpoint to exitpoint.
                PathFinder pf = new PathFinder(tf);
                pf.EnableStraightLines();
                List <Tile> path = pf.ShortestPath(tf[pair.Item1.X, pair.Item1.Y] as Tile, tf[pair.Item2.X, pair.Item2.Y] as Tile, tile => true);

                Tile t = tf[pair.Item1.X, pair.Item1.Y] as Tile;
                t.AddDebugTag("ExitConnectionPoint", pair.Item2.X + "," + pair.Item2.Y);
                path.Add(t);

                //Add a floor tile for every tile in the path.
                foreach (Tile tile in path)
                {
                    Tile newTile = LoadFloorTile();
                    newTile.AddDebugTags(tile.DebugTags);
                    tf.Add(newTile, tile.TilePosition.X, tile.TilePosition.Y);
                }
            }

            //Exchange all remaining background tiles for Wall tiles.
            for (int x = 0; x < tf.Columns; x++)
            {
                for (int y = 0; y < tf.Rows; y++)
                {
                    Tile currentTile = tf[x, y] as Tile;
                    Tile aboveTile   = tf[x, y - 1] as Tile;
                    if (currentTile != null && aboveTile != null && currentTile.TileType == TileType.Background)
                    {
                        Tile newTile = LoadWallTile(x, y);
                        newTile.AddDebugTags(currentTile.DebugTags);
                        tf.Add(newTile, x, y);
                    }
                }
            }

            //Add starttiles
            for (int p = 0; p < 4; p++)
            {
                tf.Add(LoadStartTile(p + 1), rooms[0].Location.ToRoundedPoint().X + 1 + p % 2, rooms[0].Location.ToRoundedPoint().Y + 1 + p / 2);
            }

            //Generate EndTile
            List <Room> forEnd    = new List <Room>();
            List <Room> usedRooms = new List <Room>();

            for (int a = 0; a < hallwayPairs.Count; a++)
            {
                if (!forEnd.Contains(hallwayPairs[a].Item1))
                {
                    forEnd.Add(hallwayPairs[a].Item1);
                    usedRooms.Add(hallwayPairs[a].Item1);
                }
                if (!forEnd.Contains(hallwayPairs[a].Item2))
                {
                    forEnd.Add(hallwayPairs[a].Item2);
                    usedRooms.Add(hallwayPairs[a].Item2);
                }
            }

            for (int a = 0; a < hallwayPairs.Count; a++)
            {
                if (hallwayPairs[a].Item1 == rooms[0] || hallwayPairs[a].Item2 == rooms[0])
                {
                    if (forEnd.Contains(hallwayPairs[a].Item1))
                    {
                        forEnd.Remove(hallwayPairs[a].Item1);
                    }
                    if (forEnd.Contains(hallwayPairs[a].Item2))
                    {
                        forEnd.Remove(hallwayPairs[a].Item2);
                    }
                }
            }
            tf.Add(LoadEndTile(), forEnd[0].Location.ToRoundedPoint().X + 1, forEnd[0].Location.ToRoundedPoint().Y + 1);
            tf.Add(LoadChestTile(levelIndex), forEnd[0].Location.ToRoundedPoint().X + forEnd[0].Size.X - 2, forEnd[0].Location.ToRoundedPoint().Y + 1);

            //Door spawn
            for (int i = 0; i < usedRooms.Count; i++)
            {
                for (int x = rooms[i].Location.ToRoundedPoint().X; x < rooms[i].Location.ToRoundedPoint().X + rooms[i].Size.X; x++)
                {
                    if (!tf.IsWall(x, rooms[i].Location.ToRoundedPoint().Y - 1))
                    {
                        if (tf.IsWall(x + 1, rooms[i].Location.ToRoundedPoint().Y - 1) && tf.IsWall(x - 1, rooms[i].Location.ToRoundedPoint().Y - 1))
                        {
                            tf.Add(LoadDoorTile(), x, rooms[i].Location.ToRoundedPoint().Y - 1);
                        }
                    }
                    if (!tf.IsWall(x, rooms[i].Location.ToRoundedPoint().Y + rooms[i].Size.Y))
                    {
                        if (tf.IsWall(x + 1, rooms[i].Location.ToRoundedPoint().Y + rooms[i].Size.Y) && tf.IsWall(x - 1, rooms[i].Location.ToRoundedPoint().Y + rooms[i].Size.Y))
                        {
                            tf.Add(LoadDoorTile(), x, rooms[i].Location.ToRoundedPoint().Y + rooms[i].Size.Y);
                        }
                    }
                }
            }

            //Test chest spawn
            int chestAmount = Random.Next(1, 2);

            usedRooms.Remove(rooms[0]);
            for (int i = 0; i < chestAmount; i++)
            {
                int chestRoom = Random.Next(usedRooms.Count);
                usedRooms.Remove(rooms[chestRoom]);
                int xChest = rooms[chestRoom].Location.ToRoundedPoint().X + rooms[chestRoom].Size.X / 2;
                int yChest = rooms[chestRoom].Location.ToRoundedPoint().Y + rooms[chestRoom].Size.Y / 2;
                tf.Add(LoadChestTile(levelIndex), xChest, yChest);
            }
            //End test

            //Test enemy spawn
            int numberOfEnemys = 8;

            for (int n = 0; n < numberOfEnemys; n++)
            {
                Enemy             enemy          = new Enemy(0, Index, EnemyType.random, "Enemy");
                List <GameObject> spawnLocations = tf.FindAll(obj => obj is Tile && (obj as Tile).Passable && !(obj as Tile).Blocked);
                Tile spawnLocation = spawnLocations[GameEnvironment.Random.Next(spawnLocations.Count)] as Tile;
                spawnLocation.PutOnTile(enemy);
            }
            //End test

            //Must be last statement, executed after the Tilefield is done.
            tf.InitSpriteSheetIndexation();
            return(tf);
        }