Exemple #1
0
 public void Stop(World world)
 {
     world.Player.jumpHeightModifier *= 1.2f;
 }
Exemple #2
0
 public void Use(World world)
 {
     world.Player.movementSpeedModifier *= 2f;
 }
Exemple #3
0
 public bool CanUse(World world)
 {
     return true;
 }
Exemple #4
0
 public void Stop(World world)
 {
     Monster.SpeedModifier *= 2;
 }
Exemple #5
0
        public void Generate(World world)
        {
            string[] areaBorderNameRight = { "SecondRightBorder", "ThirdRightBorder" }; //The names of area borders.
            string[] areaBorderNameLeft = { "SecondLeftBorder", "ThirdLeftBorder" };

            //Enemy types for each area
            List<List<Type>> enemyTypes = new List<List<Type>>();
            enemyTypes.Add(new List<Type>() { typeof(SlimeMonster), typeof(MeleeMonster) });
            enemyTypes.Add(new List<Type>() { typeof(SlimeMonster), typeof(ShootingMonster), typeof(MeleeMonster), typeof(Turret) });
            enemyTypes.Add(new List<Type>() { typeof(ShootingMonster), typeof(MeleeMonster), typeof(Turret) });

            //The first part of the second area has no turrets yet.
            List<Type> enemyTypesStartSecondArea = new List<Type>() { typeof(SlimeMonster), typeof(ShootingMonster), typeof(MeleeMonster) };

            //Define and initialize variables
            bool[,] isRoom = new bool[WorldWidth, WorldHeight]; //Whether this is a room.
            int[,] area = new int[WorldWidth, WorldHeight]; //The area (for example, 0 for the starting area)
            string[,] theme = new string[WorldWidth, WorldHeight]; //The general appearance.
            bool[,] CanHaveRightExit = new bool[WorldWidth, WorldHeight]; //Whether this room can potentially have a right exit.
            bool[,] CanHaveBottomExit = new bool[WorldWidth, WorldHeight]; //Whether this room can potentially have a right exit.
            List<RoomExit>[,] roomExits = new List<RoomExit>[WorldWidth, WorldHeight];
            List<string>[,] guaranteedSpecialBlocks = new List<string>[WorldWidth, WorldHeight]; //Guaranteed blocks.
            int[,] enemies = new int[WorldWidth, WorldHeight];
            for (int i = 0; i < WorldWidth; i++)
                for (int j = 0; j < WorldHeight; j++)
                {
                    roomExits[i, j] = new List<RoomExit>();
                    guaranteedSpecialBlocks[i, j] = new List<string>();
                    isRoom[i, j] = false;
                    area[i, j] = 0;
                    theme[i, j] = "";
                    CanHaveRightExit[i, j] = true;
                    CanHaveBottomExit[i, j] = true;
                    enemies[i, j] = 0;
                }

            //Your own position and the position of the boss.
            int startingY = WorldHeight / 2 + World.Random.Next(-1, 1);
            int bossY = WorldHeight / 2 + World.Random.Next(-1, 1);

            isRoom[0, startingY] = true; //Starting room
            guaranteedSpecialBlocks[0, startingY].Add("PlayerStart");

            isRoom[1, startingY] = true; //Room right of starting room.
            guaranteedSpecialBlocks[1, startingY].Add("GunPickup");
            guaranteedSpecialBlocks[1, startingY].Add(areaBorderNameRight[0]);

            //Other rooms (main areas).
            int areaTwoBorderStart = 3, areaThreeBorderStart = 5;
            for (int i = 2; i < WorldWidth; i++)
                for (int j = 0; j < WorldHeight; j++)
                {
                    bool isTopOrBottomArea = j == 0 || j == WorldHeight - 1;
                    isRoom[i, j] = true;

                    //Set the area
                    if (i >= areaThreeBorderStart + World.Random.Next(2) - (isTopOrBottomArea ? 1 : 0))
                        area[i, j] = 2;
                    else if (i >= areaTwoBorderStart + World.Random.Next(2) - (isTopOrBottomArea ? 1 : 0))
                        area[i, j] = 1;
                    else
                        area[i, j] = 0;

                    //Set the theme
                    if (World.Random.Next(100) < (isTopOrBottomArea ? 60 : 20)) //Generate cramped rooms. There are more of 'em at the top and bottom.
                        theme[i, j] = "Cramped";
                    else if (World.Random.Next(100) < 20) //Generate an open room
                        theme[i, j] = "Open";
                    else if (area[i, j] == 2 && World.Random.Next(100) < 50) //Generate a room with lots of spikes
                        theme[i, j] = "Spiky";
                    else if (World.Random.Next(100) < 10) //Create a room with windows
                        theme[i, j] = "Windowed";

                    //These areas have a normal amount of enemies, with more enemies in later areas.
                    if (area[i, j] == 0)
                        enemies[i, j] = World.Random.Next(2, 3);
                    else
                        enemies[i, j] = World.Random.Next(3, 6) + area[i, j];
                }

            //There should only be one enemy in the third room.
            enemies[2, startingY] = 1;

            //Add a wrench pickup and a rocket pickup. The rocket pickup should have some distance from the starting area.
            int wrenchPos, rocketPos;
            do
            {
                wrenchPos = World.Random.Next(1, WorldHeight - 1);
            }
            while (Math.Abs(wrenchPos - startingY) < 1);

            if (World.Random.Next(2) == 0)
                rocketPos = 0;
            else
                rocketPos = WorldHeight - 1;

            guaranteedSpecialBlocks[areaTwoBorderStart + 1, wrenchPos].Add("WrenchPickup");
            guaranteedSpecialBlocks[areaThreeBorderStart + 1, rocketPos].Add("RocketPickup");

            //Other rooms (secondary areas)
            for (int i = 0; i < 2; i++)
                for (int j = 0; j < WorldHeight; j++)
                {
                    if (j != startingY)
                    {
                        isRoom[i, j] = true;
                        area[i, j] = 2;
                        CanHaveBottomExit[i, j] = false;

                        //Set if we need a right exit.
                        if ((j == startingY - 1 || j == startingY + 1) && i == 0)
                            CanHaveRightExit[i, j] = true;
                        else if ((j == 0 || j == WorldHeight - 1) && i == 1)
                            CanHaveRightExit[i, j] = true;
                        else
                            CanHaveRightExit[i, j] = false;

                        //And do the same for the bottom exit.
                        if (j != startingY - 1)
                            CanHaveBottomExit[i, j] = true;
                        else
                            CanHaveBottomExit[i, j] = false;

                        //These areas often have lots of enemies
                        enemies[i, j] = World.Random.Next(6, 10);
                    }
                }

            //Add three max health upgrades somewhere
            guaranteedSpecialBlocks[World.Random.Next(3, WorldWidth - 1), World.Random.Next(0, WorldHeight - 1)].Add("MaxHPDropPickup");
            guaranteedSpecialBlocks[WorldWidth - 1, World.Random.Next(bossY)].Add("MaxHPDropPickup");
            guaranteedSpecialBlocks[WorldWidth - 1, World.Random.Next(bossY + 1, WorldHeight)].Add("MaxHPDropPickup");

            //Add the special bonus gun upgrade
            guaranteedSpecialBlocks[0, 0].Add("GunUpgradePickup");

            //Add the huge health upgrade
            guaranteedSpecialBlocks[0, WorldHeight - 1].Add("HugeMaxHPDropPickup");

            //And the drone upgrade
            guaranteedSpecialBlocks[1, WorldHeight - 1].Add("DroneUpgradePickup");

            //Add the boss room.
            CanHaveBottomExit[WorldWidth - 1, bossY - 1] = false; //The room above can't have a bottom exit.
            CanHaveBottomExit[WorldWidth - 1, bossY] = false; //The boss room can't have a bottom exit.
            enemies[WorldWidth - 1, bossY] = 0; //The boss room has no normal enemy spawns
            theme[WorldWidth - 1, bossY] = "Boss"; //The theme is "boss"
            //Add a right exit to it.
            roomExits[WorldWidth - 1, bossY].Add(new RoomExit(new Point(LevelWidth / LevelGenerator.BlockWidth - 1, LevelHeight / LevelGenerator.BlockHeight - 1), Direction.Right));
            guaranteedSpecialBlocks[WorldWidth - 1, bossY].Add("LeftBossDoorBorder");
            guaranteedSpecialBlocks[WorldWidth - 1, bossY].Add("RightBossDoorBorder");
            guaranteedSpecialBlocks[WorldWidth - 1, bossY].Add("BossPortal");
            //Add nine "normal tiles"
            for (int i = 0; i < 9; i++)
                guaranteedSpecialBlocks[WorldWidth - 1, bossY].Add("NormalBossRoomTile");
            guaranteedSpecialBlocks[WorldWidth - 2, bossY].Add("RightRocketBorder");  //Add a border so players must have the rocket launcher.

            //Place the exits
            for (int i = 0; i < WorldWidth; i++)
                for (int j = 0; j < WorldHeight; j++)
                {
                    //Place exits.
                    if (i < WorldWidth - 1 && isRoom[i, j] && isRoom[i + 1, j] && CanHaveRightExit[i, j])
                    {
                        int nextY;
                        if (j == bossY && i == WorldWidth - 2)
                            nextY = LevelHeight / LevelGenerator.BlockHeight - 1;
                        else
                            nextY = World.Random.Next(LevelHeight / LevelGenerator.BlockHeight);
                        roomExits[i, j].Add(new RoomExit(new Point(LevelWidth / LevelGenerator.BlockWidth - 1, nextY), Direction.Right));
                        roomExits[i + 1, j].Add(new RoomExit(new Point(0, nextY), Direction.Left));

                        if (area[i, j] < area[i + 1, j])
                            guaranteedSpecialBlocks[i, j].Add(areaBorderNameRight[area[i + 1, j] - 1]);
                        else if (area[i, j] > area[i + 1, j])
                            guaranteedSpecialBlocks[i + 1, j].Add(areaBorderNameLeft[area[i, j] - 1]);
                    }
                    if (j < WorldHeight - 1 && isRoom[i, j] && isRoom[i, j + 1] && CanHaveBottomExit[i, j] && (area[i, j] == area[i, j + 1]))
                    {
                        int nextX = World.Random.Next(LevelWidth / LevelGenerator.BlockWidth);
                        roomExits[i, j].Add(new RoomExit(new Point(nextX, LevelHeight / LevelGenerator.BlockHeight - 1), Direction.Down));
                        roomExits[i, j + 1].Add(new RoomExit(new Point(nextX, 0), Direction.Up));
                    }
                }

            //And generate the levels.
            for (int i = 0; i < WorldWidth; i++)
                for (int j = 0; j < WorldHeight; j++)
                {
                    List<Type> levelEnemyTypes = enemyTypes[area[i, j]];
                    if (i == 3 && area[i, j] == 1)
                        levelEnemyTypes = enemyTypesStartSecondArea;

                    if (isRoom[i, j])
                        levelGenerator.Generate(world, new Vector2(LevelWidth * World.TileWidth * i, LevelHeight * World.TileHeight * j), roomExits[i, j],
                            guaranteedSpecialBlocks[i, j], theme[i, j], enemies[i, j], levelEnemyTypes);
                }

            //Add the "hack this game" object
            world.AddObject(new HackThisGame());

            //Add the map object
            world.AddObject(new Map());

            //Add the GUI object
            world.AddObject(new GUI());

            //Autotile the world.
            Autotile(world);
        }
Exemple #6
0
        protected override void Initialize()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            drawWrapper = new DrawWrapper(spriteBatch, GraphicsDevice, assetManager);
            audioWrapper = new AudioWrapper(assetManager);

            world = new World();
            mainMenu = new MainMenu(drawWrapper);

            Graphics.PreferMultiSampling = true;
            Graphics.SynchronizeWithVerticalRetrace = true;
            Graphics.PreferredBackBufferWidth = 24 * 20 * 2;
            Graphics.PreferredBackBufferHeight = 24 * 15 * 2;

            Graphics.ApplyChanges();

            IsFixedTimeStep = true;

            TargetElapsedTime = TimeSpan.FromMilliseconds(1000f / 60f);

            IsMouseVisible = true;

            base.Initialize();
        }
Exemple #7
0
 public void Use(World world)
 {
     Monster.SpeedModifier *= 2f;
 }
 public bool CanUse(World world)
 {
     return world.Player.HitPoints < world.Player.MaxHitPoints;
 }
 public void Use(World world)
 {
     world.Player.HitPoints = Math.Min(world.Player.MaxHitPoints, world.Player.HitPoints + 30);
 }
Exemple #10
0
 public bool CanUse(World world)
 {
     return world.Player.CollectedScrap > 0;
 }
Exemple #11
0
 public void Use(World world)
 {
     world.AddObject(new Drone(), world.Player.Position);
 }
Exemple #12
0
        //Generate the level
        public void Generate(World world, Vector2 position, List<RoomExit> roomExits = null, List<string> guaranteedSpecialBlocks = null, string theme = "",
            int enemyNum = 0, List<Type> possibleEnemyTypes = null)
        {
            //Convert null arguments into default values
            roomExits = roomExits ?? new List<RoomExit>();
            guaranteedSpecialBlocks = guaranteedSpecialBlocks ?? new List<string>();
            possibleEnemyTypes = possibleEnemyTypes ?? new List<Type>();

            //Create vars
            World = world;

            //Create the basic grid for the level. This will contain the main path through the level.
            int hBlocks = Width / BlockWidth, vBlocks = Height / BlockHeight;
            LevelBlockRequirements[,] basicGrid = new LevelBlockRequirements[hBlocks, vBlocks];
            int[,] enemyNumber = new int[hBlocks, vBlocks];

            //List for positions with enemies
            FairRandomCollection<Point> pointsThatCanHaveEnemies = new FairRandomCollection<Point>();

            //By default, all sides are walls, unless this is the bossroom, in which case all sides (except the walls) are open.
            for (int i = 0; i < hBlocks; i++)
            {
                for (int j = 0; j < vBlocks; j++)
                {
                    pointsThatCanHaveEnemies.Add(new Point(i, j));

                    if (theme == "Boss")
                    {
                        basicGrid[i, j] = new LevelBlockRequirements(SideType.Exit);
                        if (i == 0)
                            basicGrid[i, j].LeftSideType = SideType.Wall;
                        if (j == 0)
                            basicGrid[i, j].TopSideType = SideType.Wall;
                        if (i == hBlocks - 1)
                            basicGrid[i, j].RightSideType = SideType.Wall;
                        if (j == vBlocks - 1)
                            basicGrid[i, j].BottomSideType = SideType.Wall;
                    }
                    else
                        basicGrid[i, j] = new LevelBlockRequirements(SideType.Wall);
                }
            }

            //Create exits where they should be
            foreach (RoomExit exit in roomExits)
            {
                if (exit.Direction == Direction.Left)
                    basicGrid[exit.Position.X, exit.Position.Y].LeftSideType = SideType.Exit;
                if (exit.Direction == Direction.Right)
                    basicGrid[exit.Position.X, exit.Position.Y].RightSideType = SideType.Exit;
                if (exit.Direction == Direction.Up)
                    basicGrid[exit.Position.X, exit.Position.Y].TopSideType = SideType.Exit;
                if (exit.Direction == Direction.Down)
                    basicGrid[exit.Position.X, exit.Position.Y].BottomSideType = SideType.Exit;

                //Level blocks with an exit can't have enemies
                pointsThatCanHaveEnemies.Remove(new Point(exit.Position.X, exit.Position.Y));
            }

            //Connect the exits
            ConnectPoints(basicGrid, roomExits.Select(exitPoint => exitPoint.Position).ToList());

            //Connect each now unconnected point to a connected point
            ConnectUnconnectedPoints(basicGrid);

            //Prune unneeded walls
            PruneWalls(basicGrid);

            //Create the actual level grid
            LevelBlock[,] levelGrid = new LevelBlock[hBlocks, vBlocks];

            //Get any border blocks from the guaranteed blocks.
            List<string> borderBlocks = guaranteedSpecialBlocks.Where(specialBlock => specialBlock.Contains("Border")).ToList();
            if (borderBlocks.Count != 0)
            {
                foreach (string borderBlock in borderBlocks)
                {
                    guaranteedSpecialBlocks.Remove(borderBlock);

                    //Check which direction should be used
                    Direction dir = Direction.Right;
                    if (borderBlock.Contains("Left")) dir = Direction.Left;
                    if (borderBlock.Contains("Right")) dir = Direction.Right;
                    if (borderBlock.Contains("Up")) dir = Direction.Up;
                    if (borderBlock.Contains("Down")) dir = Direction.Down;

                    //Find the exit.
                    RoomExit exit = roomExits.Find(ex => ex.Direction == dir);

                    //And make sure the block is placed there.
                    basicGrid[exit.Position.X, exit.Position.Y].Group = borderBlock;
                }
            }

            //And get the boss portal and place it on the bottom
            if (guaranteedSpecialBlocks.Contains("BossPortal"))
            {
                guaranteedSpecialBlocks.Remove("BossPortal");

                basicGrid[World.Random.Next(1, hBlocks - 1), vBlocks - 1].Group = "BossPortal";
            }

            //Handle any other guaranteed blocks
            foreach (string guaranteedBlock in guaranteedSpecialBlocks)
            {
                int i = 0, j = 0;
                do
                {
                    i = World.Random.Next(hBlocks);
                    j = World.Random.Next(vBlocks);
                }
                while (basicGrid[i, j].Group != "");
                basicGrid[i, j].Group = guaranteedBlock;
            }

            //Choose the level blocks
            for (int i = 0; i < hBlocks; i++)
            {
                for (int j = 0; j < vBlocks; j++)
                {
                    if (levelGrid[i, j] == null)
                    {
                        //Add the level theme
                        basicGrid[i, j].Theme += theme;

                        //Get a block that would fit at this position.
                        LevelBlock foundBlock = GetPossibleLevelBlock(basicGrid[i, j]);
                        if (foundBlock != null)
                            levelGrid[i, j] = foundBlock;
                        else
                            throw new Exception("There's no block that would fit here! Please create more blocks (of group '" + basicGrid[i, j].Group +
                                "') and add them to LevelBlocks.txt.");
                    }
                }
            }

            //Add enemies
            for (int i = 0; i < enemyNum; i++)
            {
                Point placeEnemyAt = pointsThatCanHaveEnemies.Get();
                enemyNumber[placeEnemyAt.X, placeEnemyAt.Y]++;
            }

            //And place them
            for (int i = 0; i < hBlocks; i++)
            {
                for (int j = 0; j < vBlocks; j++)
                {
                    levelGrid[i, j].Place(World, specialTiles, (int) position.X + i * BlockWidth * World.TileWidth,
                        (int) position.Y + j * BlockHeight * World.TileHeight, basicGrid[i, j].LeftSideType == SideType.Wall,
                        basicGrid[i, j].RightSideType == SideType.Wall, basicGrid[i, j].TopSideType == SideType.Wall,
                        basicGrid[i, j].BottomSideType == SideType.Wall, j == vBlocks - 1, enemyNumber[i, j], possibleEnemyTypes);
                }
            }
        }
Exemple #13
0
 public void Use(World world)
 {
     world.Player.ShootingSpeedMod = 0;
 }
Exemple #14
0
 public void Stop(World world)
 {
     world.Player.ShootingSpeedMod = 1;
 }
Exemple #15
0
 public void Use(World world)
 {
     world.Player.jumpHeightModifier /= 1.2f;
 }
 public bool CanUse(World world)
 {
     return world.Player.UnlockedWeapons.Contains(Weapon.Rocket);
 }
Exemple #17
0
        //Place a level block in a level. The preferred walls can be specified. These can only be guaranteed
        // if the level has the wall type (for example, preferLeftWall can be ignored if HasLeftWall is false).
        //If a wall isn't preferred at a position, an exit is used instead if Has*Exit is true.
        public void Place(World world, Dictionary<char, ISpecialTileDefinition> specialTiles, int x, int y, bool preferLeftWall = true,
            bool preferRightWall = true, bool preferTopWall = true, bool preferBottomWall = true, bool isBottomOfRoom = false, int numberOfEnemies = 0,
            List<Type> possibleEnemyTypes = null)
        {
            possibleEnemyTypes = possibleEnemyTypes ?? new List<Type>();

            int BlockID = random.Next(int.MaxValue);

            bool[,] isActuallyEmpty = new bool[Width, Height];
            bool[,] isActuallyWall = new bool[Width, Height];
            FairRandomCollection<Vector2> possibleEnemyPositions = new FairRandomCollection<Vector2>();
            FairRandomCollection<Vector2> possibleTurretPositions = new FairRandomCollection<Vector2>();

            //Place the tiles in the level
            for (int i = 0; i < Width; i++)
            {
                for (int j = 0; j < Height; j++)
                {
                    char data = Data[i, j];

                    //Check special tiles until we find a normal tile.
                    int loopCount = 0;

                    //Some tiles can be turned into walls if they end up on the sides of the level.
                    bool specialTileTurnsIntoWallOnSides = false;

                    while (specialTiles.ContainsKey(data))
                    {
                        specialTileTurnsIntoWallOnSides = specialTileTurnsIntoWallOnSides || specialTiles[data].CanBeWall;
                        List<string> specialKeywords = new List<string>(); //Contains the special keywords that are true at this moment.

                        if (preferLeftWall) specialKeywords.Add("LEFTWALL");
                        if (preferRightWall) specialKeywords.Add("RIGHTWALL");
                        if (preferTopWall) specialKeywords.Add("TOPWALL");
                        if (preferBottomWall) specialKeywords.Add("BOTTOMWALL");

                        data = specialTiles[data].GetTile(BlockID, specialKeywords);

                        if (loopCount > 1000)
                            throw new Exception("Possible infinite loop detected! Please change the level definition file.");
                    }

                    //If the special tile can be turned into a wall, check if this should happen.
                    if (specialTileTurnsIntoWallOnSides)
                    {
                        if (i == 0) //Left wall
                        {
                            if (preferLeftWall)
                                data = '1';
                        }
                        if (i == Width - 1) //Right wall
                        {
                            if (preferRightWall)
                                data = '1';
                        }
                        if (j == 0) //Top wall
                        {
                            if (preferTopWall)
                                data = '1';
                        }
                        if (j == Height - 1) //Bottom wall
                        {
                            if (preferBottomWall)
                                data = '1';
                        }
                    }

                    int baseX = x + World.TileWidth * i, baseY = y + World.TileHeight * j;
                    float centerX = baseX + World.TileWidth / 2, centerY = baseY + World.TileHeight / 2;
                    Rectangle stdCollisionRect = new Rectangle(baseX, baseY, World.TileWidth, World.TileHeight);

                    //If it's nothing or something the player can move through, and the bottom of the room, then add a jumpthrough.
                    if (data == '.' | data == '/' | data == '\\' && j == Height - 1 && isBottomOfRoom)
                        world.AddObject(new JumpThrough(new Rectangle(baseX, baseY, World.TileWidth, 1)));

                    if (data == '1') //A wall
                    {
                        world.AddObject(new Wall(stdCollisionRect));

                        isActuallyWall[i, j] = true;
                        if (j != 0 && isActuallyEmpty[i, j - 1])
                        {
                            //We can place an enemy here!
                            possibleEnemyPositions.Add(new Vector2(centerX, centerY - World.TileHeight + 10));
                        }
                    }
                    else if (data == 'T') //A tile
                        world.AddObject(new WindowTile(stdCollisionRect));
                    else if (data == 'D') //A gun door
                        world.AddObject(new GunDoor(), baseX + World.TileWidth / 2, baseY);
                    else if (data == 'M') //A melee door
                        world.AddObject(new MeleeDoor(), baseX + World.TileWidth / 2, baseY);
                    else if (data == 'C') //A rocket door
                        world.AddObject(new RocketDoor(), baseX + World.TileWidth / 2, baseY);
                    else if (data == 'B') //A boss door
                        world.AddObject(new BossDoor(), baseX + World.TileWidth / 2, baseY);
                    else if (data == 'O')
                        world.AddObject(new Portal(), baseX + 6, baseY);
                    else if (data == 'S') //Spikes
                        world.AddObject(new Spikes(), baseX, baseY + (int)(World.TileHeight * (100f / 128f)));
                    else if (data == 'G') //A gun pickup block
                        world.AddObject(new GunPickup(), centerX, centerY);
                    else if (data == 'U') //A gun upgrade pickup block
                        world.AddObject(new GunUpgrade(), centerX, centerY);
                    else if (data == 'W') //A wrench pickup block
                        world.AddObject(new WrenchPickup(), centerX, centerY);
                    else if (data == 'R') //A rocket pickup block
                        world.AddObject(new RocketPickup(), centerX, centerY);
                    else if (data == 'H') //A health pickup block
                        world.AddObject(new HealthDrop(10), centerX, centerY);
                    else if (data == 'A') //First health upgrade
                        world.AddObject(new MaxHPUpgrade(), centerX, centerY);
                    else if (data == 'E') //Huge health upgrade
                        world.AddObject(new HugeMaxHPUpgrade(), centerX, centerY);
                    else if (data == 'F') //Drone upgrade
                        world.AddObject(new DroneRangeUpgrade(), centerX, centerY);
                    else if (data == 'P') //The player
                    {
                        world.Player = new Player();
                        world.AddObject(world.Player, centerX, centerY);
                    }
                    else if (data == 'J') //A jumpthrough block
                        world.AddObject(new JumpThrough(new Rectangle(baseX, baseY, World.TileWidth, 1)));
                    else if (data == '\\') //A slope
                        world.AddObject(new SlopeLeft(stdCollisionRect));
                    else if (data == '/') //A slope
                        world.AddObject(new SlopeRight(stdCollisionRect));
                    else if (data == '.')
                    {
                        //Nothing
                        isActuallyEmpty[i, j] = true;

                        if (j != 0 && isActuallyWall[i, j - 1])
                        {
                            //We can place a turret here!
                            possibleTurretPositions.Add(new Vector2(centerX, baseY + 15));
                        }
                    }
                }
            }

            //Place some enemies.
            for (int i = 0; i < numberOfEnemies; i++)
            {
                if (possibleEnemyTypes.Contains(typeof(Turret)) && World.Random.Next(3) == 0)
                {
                    if (possibleTurretPositions.Count != 0)
                        world.AddObject(new Turret(), possibleTurretPositions.Get());
                }
                else if (possibleEnemyPositions.Count != 0)
                {
                    world.AddObject(Activator.CreateInstance(possibleEnemyTypes.Except(new List<Type>() { typeof(Turret) }).ToList().GetRandomItem())
                        as GameObject, possibleEnemyPositions.Get());
                }
            }
        }
 public void Stop(World world)
 {
     //Do nothing
 }
Exemple #19
0
        protected override void Update(GameTime gameTime)
        {
            var inputHelper = InputHelper.Instance;

            Profiler.LogEventEnd("FinalizeStep");

            Profiler.LogGameStepStart();

            Profiler.LogEventStart("Update");
            inputHelper.Update();

            //updating menus or world
            switch (currentState)
            {
                //updates mainmenu and handles all interactions
                case GameState.MainMenu:
                    mainMenu.Update(gameTime, inputHelper);
                    if (mainMenu.ExitGame)
                        Exit();
                    else if (mainMenu.Options)
                    {
                        previousState = currentState;
                        currentState = GameState.Options;
                        optionsMenu = new OptionsMenu(drawWrapper, Graphics, audioWrapper, inputHelper);
                        mainMenu = null;
                    }
                    else if (mainMenu.Start)
                    {
                        world.Initialize();
                        currentState = GameState.Playing;
                        mainMenu = null;
                    }
                    break;
                //updates playing state and handles death of player
                case GameState.Playing:
                    world.Update(gameTime);
                    if (inputHelper.KeyboardCheckPressed(Keys.Escape) || inputHelper.GamePadCheckPressed(Buttons.Start))
                    {
                        currentState = GameState.Paused;
                        pauseMenu = new PauseMenu(drawWrapper);
                    }
                    if (world.Player.Dead)
                    {
                        currentState = GameState.GameOver;
                        gameOverMenu = new GameOverMenu(drawWrapper, world.Player.Score);
                    }
                    //Win state
                    if (world.Player.Position.X > World.TileWidth * (WorldGenerator.LevelWidth * WorldGenerator.WorldWidth - 0.5f))
                    {
                        currentState = GameState.Won;
                        //Play a victory sound!
                        audioWrapper.Play("Audio/GameSounds/win");
                        wonMenu = new WonMenu(drawWrapper, world.Player.Score);
                    }
                    break;
                //updates pause menu and all interactions
                case GameState.Paused:
                    pauseMenu.Update(gameTime, inputHelper);
                    if (pauseMenu.Resume)
                    {
                        currentState = GameState.Playing;
                    }
                    else if (pauseMenu.Options)
                    {
                        previousState = currentState;
                        currentState = GameState.Options;
                        optionsMenu = new OptionsMenu(drawWrapper, Graphics, audioWrapper, inputHelper);
                        pauseMenu = null;
                    }
                    else if (pauseMenu.Quit)
                    {
                        currentState = GameState.MainMenu;
                        world = new World();
                        LoadContent();
                        mainMenu = new MainMenu(drawWrapper);
                        pauseMenu = null;
                    }
                    break;
                //updates options menu and all interactions
                case GameState.Options:
                    optionsMenu.Update(gameTime);
                    if (optionsMenu.Quit)
                    {
                        //goes back to previous gamestate
                        if (previousState == GameState.Paused)
                            currentState = GameState.Playing;
                        else
                        {
                            currentState = GameState.MainMenu;
                            mainMenu = new MainMenu(drawWrapper);
                        }
                        optionsMenu = null;
                    }
                    break;
                //updates game over screen and all interactions
                case GameState.GameOver:
                    gameOverMenu.Update(gameTime, inputHelper);
                    audioWrapper.StopOrPlayMusic(false);
                    if (gameOverMenu.Restart)
                    {
                        world = new World();
                        LoadContent();
                        world.Initialize();
                        currentState = GameState.Playing;
                        gameOverMenu = null;
                    }
                    else if (gameOverMenu.Quit)
                    {
                        world = new World();
                        LoadContent();
                        currentState = GameState.MainMenu;
                        gameOverMenu = null;
                        mainMenu = new MainMenu(drawWrapper);
                    }
                    break;
                //updates won screen and all interactions
                case GameState.Won:
                    wonMenu.Update(gameTime, inputHelper);
                    audioWrapper.StopOrPlayMusic(false);
                    if (wonMenu.Restart)
                    {
                        world = new World();
                        LoadContent();
                        world.Initialize();
                        currentState = GameState.Playing;
                        wonMenu = null;
                    }
                    else if (wonMenu.Quit)
                    {
                        world = new World();
                        LoadContent();
                        currentState = GameState.MainMenu;
                        wonMenu = null;
                        mainMenu = new MainMenu(drawWrapper);
                    }
                    break;
            }

            Profiler.LogEventEnd("Update");
        }
 public void Use(World world)
 {
     world.Player.RocketAmmo += 3;
 }
Exemple #21
0
 public bool CanUse(World world)
 {
     //Once the gun has been collected, there is an ok chance that there are monsters or will be monsters soon.
     return world.Player.UnlockedWeapons.Contains(Weapon.Gun);
 }
Exemple #22
0
 public void Stop(World world)
 {
     world.Player.movementSpeedModifier /= 2f;
 }
Exemple #23
0
 public void Use(World world)
 {
     Monster.SpeedModifier /= 2;
 }
Exemple #24
0
        //Automatically choose the correct tiles for relevant objects within the game world.
        void Autotile(World world)
        {
            //Create an array for objects that are walls and initialize it.
            bool[,] isWall = new bool[LevelWidth * WorldWidth, LevelHeight * WorldHeight],
                isLeftSlope = new bool[LevelWidth * WorldWidth, LevelHeight * WorldHeight],
                isRightSlope = new bool[LevelWidth * WorldWidth, LevelHeight * WorldHeight];

            //Do the same for an array that defines background tile positions.
            bool[,] doNotCreateBackground = new bool[LevelWidth * WorldWidth, LevelHeight * WorldHeight];
            doNotCreateBackground.Initialize();

            //Set the isWall variable to true at the position of all walls.
            IEnumerable<Wall> walls = world.GameObjects.Where(w => w is Wall).Select(w => w as Wall);
            foreach (Wall wall in walls)
            {
                isWall[wall.BoundingBox.X / World.TileWidth, wall.BoundingBox.Y / World.TileHeight] = true;
            }

            //Left slopes
            IEnumerable<SlopeLeft> lSlopes = world.GameObjects.Where(s => s is SlopeLeft).Select(s => s as SlopeLeft);
            foreach (SlopeLeft slope in lSlopes)
            {
                isLeftSlope[slope.BoundingBox.X / World.TileWidth, slope.BoundingBox.Y / World.TileHeight] = true;
            }

            //Right slopes
            IEnumerable<SlopeRight> rSlopes = world.GameObjects.Where(s => s is SlopeRight).Select(s => s as SlopeRight);
            foreach (SlopeRight slope in rSlopes)
            {
                isRightSlope[slope.BoundingBox.X / World.TileWidth, slope.BoundingBox.Y / World.TileHeight] = true;
            }

            foreach (Wall wall in walls)
            {
                string tileName = "Tileset/foreground";
                wall.BasicConnectionSprite = "Tileset/connection";

                Point positionIndex = new Point(wall.BoundingBox.Left / World.TileWidth,
                    wall.BoundingBox.Top / World.TileHeight);

                bool isTop = positionIndex.Y <= 0,
                    isRight = positionIndex.X >= LevelWidth * WorldWidth - 1,
                    isBottom = positionIndex.Y >= LevelHeight * WorldHeight - 1,
                    isLeft = positionIndex.X <= 0;

                if (isTop || isWall[positionIndex.X, positionIndex.Y - 1])
                {
                    tileName += "U";
                }
                if (isRight || isWall[positionIndex.X + 1, positionIndex.Y])
                {
                    tileName += "R";
                }
                if (isBottom || isWall[positionIndex.X, positionIndex.Y + 1])
                {
                    tileName += "D";
                }
                if (isLeft || isWall[positionIndex.X - 1, positionIndex.Y])
                {
                    tileName += "L";
                }

                if (!isTop && !isLeft && tileName.Contains("U") && tileName.Contains("L") && !isWall[positionIndex.X - 1, positionIndex.Y - 1])
                {
                    wall.ShouldShowTopLeftConnection = true;
                }

                if (!isTop && !isRight && tileName.Contains("U") && tileName.Contains("R") && ! isWall[positionIndex.X + 1, positionIndex.Y - 1])
                {
                    wall.ShouldShowTopRightConnection = true;
                }

                if (!isBottom && !isLeft && tileName.Contains("D") && tileName.Contains("L") && ! isWall[positionIndex.X - 1, positionIndex.Y + 1])
                {
                    wall.ShouldShowBottomLeftConnection = true;
                }

                if (!isBottom && !isRight && tileName.Contains("D") && tileName.Contains("R") && ! isWall[positionIndex.X + 1, positionIndex.Y + 1])
                {
                    wall.ShouldShowBottomRightConnection = true;
                }

                wall.SetSprite(tileName);

                //Create a background image
                if (tileName.Contains("URDL"))
                {
                    doNotCreateBackground[positionIndex.X, positionIndex.Y] = true;
                }
            }

            /*for (int i = 0; i < LevelWidth * WorldWidth; i++)
                for (int j = 0; j < LevelHeight * WorldHeight; j++)
                {
                    if (!doNotCreateBackground[i, j])
                    {
                        BackgroundTile bgt = new BackgroundTile(new Rectangle(i * (int) World.TileWidth, j * (int) World.TileHeight,
                            (int) World.TileWidth, (int) World.TileHeight));
                        world.AddObject(bgt);
                        bgt.SetSprite("BackgroundTileset/background" + World.Random.Next(1, 5));
                    }
                }*/
        }