Ejemplo n.º 1
0
        /* The CheckSpawn() function checks if a wild Pokemon battle will be triggered on this frame.
         * It is only called when the player's StepCheck bit is true, so it is only called once every step. */
        private void CheckSpawn()
        {
            /* This Random object will be needed for a lot of things later. */
            Random r = new Random();

            /* Each MapLayer in the map needs to be checked for a Tile with its Spawn bit set to true. */
            foreach (MapLayer layer in world.CurrentMap.MapLayers)
            {
                /* If tile that the player is standing on in the layer has its Spawn bit set to true, a battle may happen. */
                if (layer.GetTile(player.Sprite.TileLocation.X, player.Sprite.TileLocation.Y).Spawn)
                {
                    /* This condition determines whether an actual battle happens or not.
                     * If a random double between 0 and 187.5 is less than the level's grass encounter rate, then a battle will happen.
                     * The most likely a battle can be to happen is a VeryCommon encounter rate, which is 10.0.
                     * With a VeryCommon encounter rate, the chance of a battle occurring is 10/187.5.
                     * The least likely a battle can be to happen is with a VeryRare encounter rate, which has a chance of 1.25/187.5.
                     * Note the the encounter rate is not how likely it is for a certain Pokemon to be battled - it is how likely that a battle will happen at all. */
                    if ((r.NextDouble() * 187.5) < World.CurrentLevel.GrassEncounterRate)
                    {
                        /* A new array of ProportionValue<PokemonSpawn> objects is created with the length of the GrassSpawns in the current level.
                         * GrassSpawns is a list of PokemonSpawn objects for the level's grass, stating what Pokemon at what level can be encountered.
                         * The spawns array is filled with ProportionValues created using the PokemonSpawn's Percentage property, and the PokemonSpawn object itself. */
                        ProportionValue <PokemonSpawn>[] spawns = new ProportionValue <PokemonSpawn> [World.CurrentLevel.GrassSpawns.Count];
                        for (int i = 0; i < spawns.Length; i++) // NOTE TO SELF: IT WOULD BE MORE EFFICIENT TO CREATE THE ARRAY IN A HIGHER SCOPE, SINCE IT IS PART OF THE LEVEL, BUT THIS WILL DO FOR NOW.
                        {
                            spawns[i] = ProportionValue.Create(World.CurrentLevel.GrassSpawns[i].Percentage, World.CurrentLevel.GrassSpawns[i]);
                        }

                        /* The encounter for the spawn is found proportionally from the array using ChooseByRandom().
                         * A new Pokemon object is created using the encounter data's ID, gender, and minimum/maximum levels.
                         * The wild Pokemon's level is chosen randomly between the minimum and maximum level in the selected PokemonSpawn.
                         * The moveset is currently just "Scratch". Although dynamic moveset generation is not part of the user requirements,
                         * I could add it if I have time by choosing the last four moves that the species can learn before it reaches its level. */
                        PokemonSpawn encounter = spawns.ChooseByRandom();
                        Pokemon      p         = new Pokemon(DataManager.PokemonSpecies[encounter.ID], Pokemon.GetGender(DataManager.PokemonSpecies[encounter.ID].GenderRatio), new[] { DataManager.Moves["Scratch"], null, null, null }, (byte)PkmnUtils.RandomInclusive(encounter.MinLevel, encounter.MaxLevel), null);

                        /* A wild battle is essentially a fight against an enemy team of one Pokemon.
                         * The BattleScreen.InitBattle() is called, which sends the player and enemy to the screen and sets the battle background index to zero.
                         * Finally, the BattleScreen is pushed on to the state stack. */
                        GameRef.BattleScreen.InitBattle(player.Team, p, 0);
                        Change(ChangeType.Push, GameRef.BattleScreen);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /* This method creates the WorldScreen's World. */
        private void CreateWorld()
        {
            /* The commented out block of code here creates a test Beery item and adds it to the level.
             * As it is not quite working and not in the user requirements, it is not being used. */
            /* Berry testBerry = new Berry(BerryType.Razz);
             * BaseSprite testBaseSprite = new BaseSprite(itemTexture, new Rectangle(64, 32, 32, 32), new Point(10, 10));
             * ItemSprite testItemSprite = new ItemSprite(testBaseSprite, testBerry);
             * level.Items.Add(testItemSprite); */

            /* A new World object is created using references to the game and the window rectangle.
             * Its list of Levels is set to DataManager.Levels (the master Level list).
             * The starting level index is currently "Level 1" (the first area in the engine). */
            World world = new World(GameRef, GameRef.ScreenRectangle);

            world.Levels            = DataManager.Levels;
            world.CurrentLevelIndex = "Level 1";

            /* The list of spawns for the first level is initialized.
             * In the future, spawns may be editable in the level editor, but it's not a part of the user requirements.
             * The two spawns added to the list mean that if a battle is triggered in the first level,
             * there is a 50% chance it will be a Lv2-3 Caterpie, and a 50% chance it will be a Lv2-3 Metapod. */
            List <PokemonSpawn> firstSpawns = new List <PokemonSpawn>();
            PokemonSpawn        spawn       = new PokemonSpawn(0.5, 10, 2, 3);

            firstSpawns.Add(spawn);
            spawn = new PokemonSpawn(0.5, 11, 2, 3);
            firstSpawns.Add(spawn);

            /* The second level's spawn list has two entries.
             * There is a three quarter chance of encountering a Pidgey between Lv4-5.
             * There is a quarter chance of encountering a Pidgeotto between Lv4-5. */
            List <PokemonSpawn> secondSpawns = new List <PokemonSpawn>();

            spawn = new PokemonSpawn(0.75, 16, 4, 5);
            secondSpawns.Add(spawn);
            spawn = new PokemonSpawn(0.25, 17, 4, 5);
            secondSpawns.Add(spawn);

            /* There are three PokemonSpawn objects in the third level's list.
             * 60% of the time, the player will run into a Lv6-7 Abra.
             * 30% of the time, the player will run into a Lv6-7 Kadabra.
             * 10% of the time, the player will run into a Lv6-7 Alakazam. */
            List <PokemonSpawn> thirdSpawns = new List <PokemonSpawn>();

            spawn = new PokemonSpawn(0.6, 63, 6, 7);
            thirdSpawns.Add(spawn);
            spawn = new PokemonSpawn(0.3, 64, 6, 7);
            thirdSpawns.Add(spawn);
            spawn = new PokemonSpawn(0.1, 65, 6, 7);
            thirdSpawns.Add(spawn);

            /* The spawns are added to the correct levels, as well as an encounter rate of VeryCommon.
             * The WorldScreen.World is then set to the World that was just created. */
            world.Levels["Level 1"].GrassSpawns        = firstSpawns;
            world.Levels["Level 1"].GrassEncounterRate = EncounterRate.VeryCommon;
            world.Levels["Level 2"].GrassSpawns        = secondSpawns;
            world.Levels["Level 2"].GrassEncounterRate = EncounterRate.VeryCommon;
            world.Levels["Level 3"].GrassSpawns        = thirdSpawns;
            world.Levels["Level 3"].GrassEncounterRate = EncounterRate.VeryCommon;
            WorldScreen.World = world;
        }