Esempio n. 1
0
        public static void Draw(SpriteBatch sb)
        {
            sb.Draw(frontRenderTarget, Vector2.Zero, Color.White);
            sb.Draw(backRenderTarget, Vector2.Zero, Color.White);
            sb.Draw(shopRenderTarget, new Vector2(-2000, -2000), Color.White);

            foreach (Room room in shopRoomArray)
            {
                room.Draw(sb);
            }

            foreach (Boss boss in bossList)
            {
                if (boss.alive)
                {
                    boss.Draw(sb);
                }
            }

            foreach (Projectile p in projectilesOnScreenList)
            {
                p.Draw(sb);
            }

            foreach (Tile tile in rockTiles)
            {
                tile.Draw(sb);
            }

            foreach (Ladder l in shopLadders)
            {
                l.Draw(sb);
            }

            shopKeeper.Draw(sb);

            player.Draw(sb);


            foreach (Item i in itemsList)
            {
                i.Draw(sb);
            }

            foreach (Moveable_Object vase in vaseList)
            {
                vase.Draw(sb);
            }

            foreach (Enemy e in enemyList)
            {
                e.Draw(sb);
            }

            AmbientEffectManager.Draw(sb);

            HUD.Draw(sb);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates all of the activities in the Level class.
        /// </summary>
        /// <param name="gameTime"></param>
        public static void Update(GameTime gameTime)
        {
            oldKeyboardState = keyboardState;
            keyboardState    = Keyboard.GetState();

            player.Movement(gameTime);


            AmbientEffectManager.UpdateAmbientEffects(gameTime, currentCircle, player.middlepos);

            for (int p = 0; p < projectilesOnScreenList.Count; p++)
            {
                projectilesOnScreenList[p].Update(gameTime);


                for (int vase = 0; vase < vaseList.Count; vase++)
                {
                    projectilesOnScreenList[p].CheckTargetCollision(vaseList[vase]);

                    if (vaseList[vase].health <= 0)
                    {
                        if (rnd.Next(5) == 0)
                        {
                            Item coin = LoadWeaponsAndItems.Coin(vaseList[vase].middlepos);
                            itemsList.Add(coin);
                        }
                        AmbientEffectManager.AddShatteredVase(vaseList[vase].middlepos);
                        vaseList.RemoveAt(vase);
                        vase--;
                    }
                }

                for (int e = 0; e < enemyList.Count; e++)
                {
                    projectilesOnScreenList[p].CheckTargetCollision(enemyList[e]);

                    if (enemyList[e].health <= 0)
                    {
                        Item coin = LoadWeaponsAndItems.Coin(enemyList[e].middlepos);
                        itemsList.Add(coin);
                        enemyList.RemoveAt(e);
                        e--;
                    }
                }


                for (int b = 0; b < bossList.Count; b++)
                {
                    projectilesOnScreenList[p].CheckTargetCollision(bossList[b]);

                    if (bossList[b].health <= 0 && bossList[b].alive)
                    {
                        bossList[b].alive = false;
                        RemoveRockTiles();
                        itemsList.Add(LoadWeaponsAndItems.HealPotion(bossList[b].middlepos, 50));
                    }
                }

                if (projectilesOnScreenList[p].isColliding)
                {
                    projectilesOnScreenList.RemoveAt(p);
                    p--;
                }
            }

            for (int i = 0; i < itemsList.Count; i++)
            {
                if (player.hitbox.Intersects(itemsList[i].hitbox))
                {
                    if (itemsList[i].autoPickUp || (keyboardState.IsKeyDown(Keys.Enter) && oldKeyboardState.IsKeyUp(Keys.Enter)))
                    {
                        if (itemsList[i].itemType == Item.ItemType.weaponType)
                        {
                            if (!player.isAttacking && (itemsList[i].coinGain + currency) >= 0)
                            {
                                player.ChangeWeapon(itemsList[i].weaponItem);
                                currency += itemsList[i].coinGain;
                                HUD.UpdateCurrencyHUD(currency);
                                itemsList.RemoveAt(i);
                            }
                            break;
                        }
                        else if (itemsList[i].itemType == Item.ItemType.coin)
                        {
                            currency += itemsList[i].coinGain;
                            itemsList.RemoveAt(i);
                            HUD.UpdateCurrencyHUD(currency);
                            break;
                        }
                        else if ((itemsList[i].coinGain + currency) >= 0)
                        {
                            player.UpdatePlayerStats(itemsList[i].itemType, itemsList[i].multiplier);
                            currency += itemsList[i].coinGain;
                            HUD.UpdateCurrencyHUD(currency);
                            itemsList.RemoveAt(i);
                            break;
                        }
                    }
                }
            }

            foreach (Ladder l in shopLadders)
            {
                if (l.hitbox.Intersects(player.hitbox))
                {
                    l.showText = true;
                    if (keyboardState.IsKeyDown(Keys.Space) && oldKeyboardState.IsKeyUp(Keys.Space))
                    {
                        l.Moveplayer(player);
                        break;
                    }
                }
                else
                {
                    l.showText = false;
                }
            }

            for (int vase = 0; vase < vaseList.Count; vase++)
            {
                player.InflictMeleeDamage(vaseList[vase]);
                if (vaseList[vase].health <= 0)
                {
                    if (rnd.Next(5) == 0)
                    {
                        Item coin = LoadWeaponsAndItems.Coin(vaseList[vase].middlepos);
                        itemsList.Add(coin);
                    }
                    AmbientEffectManager.AddShatteredVase(vaseList[vase].middlepos);
                    vaseList.RemoveAt(vase);
                    vase--;
                }
            }

            for (int e = 0; e < enemyList.Count; e++)
            {
                enemyList[e].Update(gameTime);
                player.InflictMeleeDamage(enemyList[e]);
                if (enemyList[e].health <= 0)
                {
                    Item coin = LoadWeaponsAndItems.Coin(enemyList[e].middlepos);
                    itemsList.Add(coin);
                    enemyList.RemoveAt(e);
                    e--;
                }
            }

            for (int b = 0; b < bossList.Count; b++)
            {
                if (bossList[b].alive)
                {
                    bossList[b].Update(gameTime);
                }

                player.InflictMeleeDamage(bossList[b]);
                if (bossList[b].health <= 0 && bossList[b].alive)
                {
                    bossList[b].alive = false;
                    RemoveRockTiles();
                    itemsList.Add(LoadWeaponsAndItems.HealPotion(bossList[b].middlepos, 50));
                }
            }

            foreach (Tile t in endTileList)
            {
                if (t.hitbox.Intersects(player.hitbox))
                {
                    if (isBossRoom)
                    {
                        LoadNewCircle();
                    }
                    else
                    {
                        LoadBossRoom();
                    }
                    break;
                }
            }

            shopKeeper.Update(gameTime);

            Game1.camera.SetPosition(new Vector2(player.hitbox.X + player.hitbox.Width / 2, player.hitbox.Y + player.hitbox.Height / 2));
            HUD.Update(player.middlepos);
        }
Esempio n. 3
0
        /// <summary>
        /// Loads the layout of the circle.
        /// </summary>
        /// <param name="rnd">Random class.</param>
        public static void LoadLayout(Random rnd)
        {
            Room.wallTiles.Clear();
            generatedRoomList.Clear();
            backgroundRoomList.Clear();
            endTileList.Clear();
            enemySpawnTiles.Clear();
            enemyList.Clear();
            itemsList.Clear();
            vaseList.Clear();


            AmbientEffectManager.NewCircle();



            roomArray[Constants.startRoomCoords, Constants.startRoomCoords] = new Room(new Vector2(Constants.roomWidth * Constants.startRoomCoords, Constants.roomHeight * Constants.startRoomCoords), "spawnRoom.txt")
            {
                isSpawn = true
            };
            generatedRoomList.Add(roomArray[Constants.startRoomCoords, Constants.startRoomCoords]);
            player.SetPlayerPosition(roomArray[Constants.startRoomCoords, Constants.startRoomCoords].playerSpawnPoint);

            int chance;

            //Loopar tills vi har ett önskat antal rum.
            while (generatedRoomList.Count < minimumNoOfRooms)
            {
                for (int x = 0; x < roomArray.GetLength(0); x++)
                {
                    for (int y = 0; y < roomArray.GetLength(1); y++)
                    {
                        if (roomArray[x, y] != null)
                        {
                            if (x > 0)
                            {
                                if (roomArray[x - 1, y] == null)
                                {
                                    chance = rnd.Next(1, 101);
                                    if (chance == 1)
                                    {
                                        Room newRoom = new Room(new Vector2(Constants.roomWidth * (x - 1), Constants.roomHeight * y), "smallRoom.txt")
                                        {
                                            rightConnection = true
                                        };

                                        //newRoom.rightConnection = true;
                                        roomArray[x, y].leftConnection = true;
                                        roomArray[x - 1, y]            = newRoom;
                                        generatedRoomList.Add(newRoom);
                                    }
                                }
                            }

                            if (y > 0)
                            {
                                if (roomArray[x, y - 1] == null)
                                {
                                    chance = rnd.Next(1, 101);
                                    if (chance == 1)
                                    {
                                        Room newRoom = new Room(new Vector2(Constants.roomWidth * x, Constants.roomHeight * (y - 1)), "smallRoom.txt")
                                        {
                                            downConnection = true
                                        };
                                        roomArray[x, y].upConnection = true;
                                        roomArray[x, y - 1]          = newRoom;
                                        generatedRoomList.Add(newRoom);
                                    }
                                }
                            }

                            if (x + 1 < roomArray.GetLength(0))
                            {
                                if (roomArray[x + 1, y] == null)
                                {
                                    chance = rnd.Next(1, 101);
                                    if (chance == 1)
                                    {
                                        Room newRoom = new Room(new Vector2(Constants.roomWidth * (x + 1), Constants.roomHeight * y), "smallRoom.txt")
                                        {
                                            leftConnection = true
                                        };
                                        roomArray[x, y].rightConnection = true;
                                        roomArray[x + 1, y]             = newRoom;
                                        generatedRoomList.Add(newRoom);
                                    }
                                }
                            }

                            if (y + 1 < roomArray.GetLength(1))
                            {
                                if (roomArray[x, y + 1] == null)
                                {
                                    chance = rnd.Next(1, 101);
                                    if (chance == 1)
                                    {
                                        Room newRoom = new Room(new Vector2(Constants.roomWidth * x, Constants.roomHeight * (y + 1)), "smallRoom.txt")
                                        {
                                            upConnection = true
                                        };
                                        roomArray[x, y].downConnection = true;
                                        roomArray[x, y + 1]            = newRoom;
                                        generatedRoomList.Add(newRoom);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            for (int x = 0; x < shopRoomArray.GetLength(0); x++)
            {
                for (int y = 0; y < shopRoomArray.GetLength(1); y++)
                {
                    if (x == 1 && y == 1)
                    {
                        shopRoom            = new Room(new Vector2(Constants.roomWidth * x - 2000, Constants.roomHeight * y - 2000), "shopRoom.txt");
                        shopRoomArray[x, y] = shopRoom;
                    }
                    else
                    {
                        shopRoomArray[x, y] = new Room(new Vector2(Constants.roomWidth * x - 2000, Constants.roomHeight * y - 2000), "backRoom.txt");
                    }
                }
            }

            List <Room> topRooms = new List <Room>();

            //Loopar för att avgöra på vilka sidor room har connections
            for (int x = 0; x < roomArray.GetLength(0); x++)
            {
                for (int y = 0; y < roomArray.GetLength(1); y++)
                {
                    if (roomArray[x, y] != null)
                    {
                        if (y == 0)
                        {
                            topRooms.Add(roomArray[x, y]);
                        }
                        else if (roomArray[x, y - 1] == null)
                        {
                            topRooms.Add(roomArray[x, y]);
                        }

                        if (x > 0)
                        {
                            if (roomArray[x - 1, y] != null)
                            {
                                chance = rnd.Next(1, 11);
                                if (chance == 1)
                                {
                                    roomArray[x, y].leftConnection      = true;
                                    roomArray[x - 1, y].rightConnection = true;
                                }
                            }
                        }

                        if (y > 0)
                        {
                            if (roomArray[x, y - 1] != null)
                            {
                                chance = rnd.Next(1, 11);
                                if (chance == 1)
                                {
                                    roomArray[x, y].upConnection       = true;
                                    roomArray[x, y - 1].downConnection = true;
                                }
                            }
                        }

                        if (x + 1 < roomArray.GetLength(0))
                        {
                            if (roomArray[x + 1, y] != null)
                            {
                                chance = rnd.Next(1, 11);
                                if (chance == 1)
                                {
                                    roomArray[x, y].rightConnection    = true;
                                    roomArray[x + 1, y].leftConnection = true;
                                }
                            }
                        }

                        if (y + 1 < roomArray.GetLength(1))
                        {
                            if (roomArray[x, y + 1] != null)
                            {
                                chance = rnd.Next(1, 11);
                                if (chance == 1)
                                {
                                    roomArray[x, y].downConnection   = true;
                                    roomArray[x, y + 1].upConnection = true;
                                }
                            }
                        }
                    }
                    else
                    {
                        Room r = new Room(new Vector2(Constants.roomWidth * x, Constants.roomHeight * y), "backRoom.txt");
                        backgroundRoomList.Add(r);
                    }
                }
            }

            chance = rnd.Next(0, topRooms.Count);
            topRooms[chance].exitRoom = true; //Bestämmer vilket rum som ska leda till nästa krets

            bool shopLess = true;

            do
            {
                chance = rnd.Next(0, generatedRoomList.Count);

                if (!generatedRoomList[chance].isSpawn && !generatedRoomList[chance].exitRoom)
                {
                    generatedRoomList[chance].fileName = "smallRoom.txt";
                    shopLess       = false;
                    shopLadders[0] = new Ladder(SpriteSheetManager.upLadder, generatedRoomList[chance].middlepos, shopRoom.middlepos, "Press 'Space' to enter shop");
                    shopLadders[1] = new Ladder(SpriteSheetManager.downLadder, shopRoom.middlepos, generatedRoomList[chance].middlepos, "Press 'Space' to exit shop'");
                }
            }while (shopLess);

            foreach (Room r in generatedRoomList)
            {
                r.CreateLevel(rnd, currentCircle);
            }
            foreach (Room r in backgroundRoomList)
            {
                r.CreateLevel(rnd, currentCircle);
            }

            graphics.GraphicsDevice.SetRenderTarget(shopRenderTarget);
            graphics.GraphicsDevice.Clear(Color.Transparent);
            sb.Begin();

            foreach (Room room in shopRoomArray)
            {
                room.CreateLevel(rnd, currentCircle);
            }

            sb.End();
            graphics.GraphicsDevice.SetRenderTarget(null);

            enemyList = EnemyManager.spawnEnemies(enemySpawnTiles, currentCircle, rnd);

            DrawOnFrontRenderTarget();
            DrawOnBackRenderTarget();
        }