Esempio n. 1
0
        protected override void LoadContent()
        {
            gameState   = GameState.Start;
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Constants.LoadConstants();
            graphics.PreferredBackBufferWidth  = Constants.windowWidth;
            graphics.PreferredBackBufferHeight = Constants.windowHeight;
            graphics.ApplyChanges();

            //kub = Content.Load<Texture2D>(@"kub");

            SpriteSheetManager.LoadContent(Content);
            SoundManager.LoadAudio(Content);
            LoadWeaponsAndItems.LoadAllWeaponsAndItems();
            EnemyManager.LoadEnemies();
            HUD.Load(Content);
            Menu.Load(Content);
            try
            {
                SavefileHandler.ReadFile("savefile.txt");
                saveFileExist = true;
            }
            catch
            {
                saveFileExist = false;
            }
            Menu.LoadButtons();

            camera = new Camera(GraphicsDevice.Viewport);
            Level.Load_Level(graphics, Content);

            MediaPlayer.IsRepeating = true;
        }
Esempio n. 2
0
        /// <summary>
        /// Reads savefile.
        /// </summary>
        /// <param name="filename">File to read from.</param>
        public static void ReadFile(string filename)
        {
            List <string> lines = File.ReadAllLines(filename).ToList();

            savedCircle = Convert.ToInt32(lines[0]);

            savedWeapon = LoadWeaponsAndItems.SavedWeaponFromList(lines[1]);

            savedHealth = (float)Convert.ToDouble(lines[2]);

            savedMaxHealth = (float)Convert.ToDouble(lines[3]);

            savedAttackSpeedMultiplier = (float)Convert.ToDouble(lines[4]);
            savedDamageMultiplier      = (float)Convert.ToDouble(lines[5]);
            savedSpeedMultiplier       = (float)Convert.ToDouble(lines[6]);
            savedCurrency = Convert.ToInt32(lines[7]);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates the whole room and all of its tiles.
        /// </summary>
        /// <param name="rnd">Random class.</param>
        /// <param name="currCircle">The current circle the game takes place on.</param>
        public void CreateLevel(Random rnd, int currCircle)
        {
            List <string> stringList = ReadFromFile(fileName);

            tileArray = new Tile[stringList[0].Length, stringList.Count];
            int frameY = currCircle - 1;

            for (int x = 0; x < tileArray.GetLength(0); x++)
            {
                for (int y = 0; y < tileArray.GetLength(1); y++)
                {
                    switch (stringList[y][x])
                    {
                    case 'C':

                        tileArray[x, y] = NewWallTile(x, y, frameY, rnd);
                        wallTiles.Add(tileArray[x, y]);

                        break;

                    case 'U':

                        if (!upConnection)
                        {
                            tileArray[x, y] = NewWallTile(x, y, frameY, rnd);
                            wallTiles.Add(tileArray[x, y]);
                        }
                        else
                        {
                            tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        }

                        break;

                    case 'L':

                        if (!leftConnection)
                        {
                            tileArray[x, y] = NewWallTile(x, y, frameY, rnd);

                            wallTiles.Add(tileArray[x, y]);
                        }
                        else
                        {
                            tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        }

                        break;

                    case 'R':

                        if (!rightConnection)
                        {
                            tileArray[x, y] = NewWallTile(x, y, frameY, rnd);
                            wallTiles.Add(tileArray[x, y]);
                        }
                        else
                        {
                            tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        }


                        break;

                    case 'D':

                        if (!downConnection)
                        {
                            tileArray[x, y] = NewWallTile(x, y, frameY, rnd);
                            wallTiles.Add(tileArray[x, y]);
                        }
                        else
                        {
                            tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        }

                        break;

                    case 'B':

                        tileArray[x, y] = NewWallTile(x, y, frameY, rnd);
                        //wallTiles.Add(tileArray[x, y]);

                        break;

                    case 'E':

                        if (exitRoom)
                        {
                            tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                            Tile endTile = new Tile(SpriteSheetManager.stairTile, new Rectangle(pos.X + Constants.tileSize * x, pos.Y + Constants.tileSize * y, Constants.tileSize, Constants.tileSize), 0, 0, false);
                            Level.endTileList.Add(endTile);
                        }
                        else if (!upConnection)
                        {
                            tileArray[x, y] = NewWallTile(x, y, frameY, rnd);
                            wallTiles.Add(tileArray[x, y]);
                        }
                        else
                        {
                            tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        }

                        break;

                    case 'F':

                        tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);

                        break;

                    case 'S':

                        tileArray[x, y]  = NewFloorTile(x, y, frameY, rnd);
                        playerSpawnPoint = tileArray[x, y].middlepos;

                        break;

                    case 'O':

                        tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        bossSpawnPoint  = tileArray[x, y].middlepos;

                        break;

                    case 'G':

                        Tile rockTile = new Tile(SpriteSheetManager.rock, new Rectangle(pos.X + Constants.tileSize * x, pos.Y + Constants.tileSize * y, Constants.tileSize, Constants.tileSize), 0, 0, true)
                        {
                            isRock = true
                        };
                        wallTiles.Add(rockTile);
                        Level.rockTiles.Add(rockTile);
                        tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);

                        break;

                    case 'e':

                        tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        Level.enemySpawnTiles.Add(tileArray[x, y]);

                        break;

                    case 'i':

                        tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);

                        Level.itemsList.Add(LoadWeaponsAndItems.NewStatUpgrade(tileArray[x, y].middlepos, false, rnd));

                        break;

                    case 'I':

                        tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        Level.itemsList.Add(LoadWeaponsAndItems.NewStatUpgrade(tileArray[x, y].middlepos, true, rnd));

                        break;

                    case 'w':

                        tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        Level.itemsList.Add(LoadWeaponsAndItems.NewWeaponItem(tileArray[x, y].middlepos, currCircle, false, rnd));

                        break;

                    case 'W':

                        tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        Level.itemsList.Add(LoadWeaponsAndItems.NewWeaponItem(tileArray[x, y].middlepos, currCircle, true, rnd));

                        break;

                    case 'K':
                        tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);

                        Level.shopKeeper = new NPC(SpriteSheetManager.shopKeeper, 0.5d, new Point(128, 128), new Vector2(pos.X + Constants.tileSize * x, pos.Y + Constants.tileSize * y), SpriteSheetManager.shopKeeperTextbox, new Point(200, 100));
                        break;

                    case '1':

                        tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        if (!upConnection && !exitRoom)
                        {
                            if (rnd.Next(2) == 0)
                            {
                                Level.NewVase(tileArray[x, y].middlepos);
                            }
                        }

                        break;

                    case '2':

                        tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        if (!rightConnection)
                        {
                            if (rnd.Next(2) == 0)
                            {
                                Level.NewVase(tileArray[x, y].middlepos);
                            }
                        }

                        break;

                    case '3':

                        tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        if (!downConnection)
                        {
                            if (rnd.Next(2) == 0)
                            {
                                Level.NewVase(tileArray[x, y].middlepos);
                            }
                        }

                        break;

                    case '4':

                        tileArray[x, y] = NewFloorTile(x, y, frameY, rnd);
                        if (!leftConnection)
                        {
                            if (rnd.Next(2) == 0)
                            {
                                Level.NewVase(tileArray[x, y].middlepos);
                            }
                        }

                        break;

                    case 'o':

                        tileArray[x, y] = NewInvisibleTile(x, y, frameY, rnd);
                        wallTiles.Add(tileArray[x, y]);

                        break;
                    }
                }
            }
        }
Esempio n. 4
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);
        }