Example #1
0
        /// <summary>
        /// Makes it so that the enemy walks a random path
        /// </summary>
        public void randomWalk()
        {
            DiDo.Levels.Levels level = new DiDo.Levels.Levels();
            // Gets the tiles of the level and looks if they can be walked on

            if (this.random.Next(0, 30) == 1) // A chance of 1 to 29 that the enemy will walk
            {
                this.direction = random.Next(0, 4);
                // Calculates a random number and walks in the direction of that number
            }
            else
            {
                if (this.random.Next(0, 360) == 1)   // 1 on 120 chance that the enemy will shoot
                // Shoot if the enemy stands still

                {
                    this.currentWeapon.reload();
                    // Reload

                    if (this.currentWeapon.getAmmo() >= 1) // Looks if there are bullets in the magazine
                    {
                        float xPos = random.Next((int)(MainPage.player.x - 70), (int)(MainPage.player.x + 70));
                        float yPos = random.Next((int)(MainPage.player.y - 70), (int)(MainPage.player.y + 70));
                        // Makes the chance of shooting straigh very low

                        float xVel = (xPos - x) / 18;
                        float yVel = (yPos - y) / 18;
                        // Calculates the bullet velocity

                        if (xVel > 50)
                        {
                            xVel = 50;
                        }
                        if (yVel > 50)
                        {
                            yVel = 50;
                        }
                        // Makes it so that the bullets wont go to fast

                        MainPage.bullets.Add(new DiDo.Bullet(x, y, xVel, yVel, currentWeapon.getDamage(), name));
                        // Adds bullets to the list

                        this.currentWeapon.reduceAmmo();
                        // Reduces the ammo
                    }
                }
            }

            if (this.direction == 0)
            {
                Tile nextTile = level.getPlayerTile(this.x, this.y + 1, level.gekozenLevel); // Gets the information of the tile
                if (nextTile.CanWalk == true)                                                // Checks if the next tile can be walked on.
                {
                    this.y += stepSize;
                    // Walk down
                }
            }
            else if (this.direction == 1)
            {
                Tile nextTile = level.getPlayerTile(this.x + 1, this.y, level.gekozenLevel); // Gets the information of the tile
                if (nextTile.CanWalk == true)                                                // Checks if the next tile can be walked on.
                {
                    this.x += stepSize;
                    // Walk to the right
                }
            }
            else if (this.direction == 2)
            {
                Tile nextTile = level.getPlayerTile(this.x, this.y - 1, level.gekozenLevel); // Gets the information of the tile
                if (nextTile.CanWalk == true)                                                // Checks if the next tile can be walked on.
                {
                    this.y -= stepSize;
                    // Walk up
                }
            }
            else
            {
                Tile nextTile = level.getPlayerTile(this.x - 1, this.y, level.gekozenLevel); // Gets the information of the tile
                if (nextTile.CanWalk == true)                                                // Checks if the next tile can be walked on.
                {
                    this.x -= stepSize;
                    // Walk to the left
                }
            }
        }
Example #2
0
        public Rect weaponRect = new Rect(1150, 5, 300, 400); // Rectangle for the player ui element

        /// <summary>
        /// Initialisation of the mainpage for singleplayer
        /// </summary>
        public MainPage()
        {
            // Play background music
            //soundHandler();

            // Player selection
            if (ChooseCharacter.PlayerCharacter.Equals("Jeroen"))          // Jeroen is choosen as the player
            {
                player = new MyPlayer("Jeroen", 100, 100, 20, 5, 32, 96);  // Set the name and stats of the player
            }
            else if (ChooseCharacter.PlayerCharacter.Equals("Jeffrey"))    // Jeffreyis choosen as the player
            {
                player = new MyPlayer("Jeffrey", 100, 100, 30, 5, 32, 96); // Set the name and stats of the player
            }
            else if (ChooseCharacter.PlayerCharacter.Equals("Daan"))       // Daanis choosen as the player
            {
                player = new MyPlayer("Daan", 100, 100, 20, 5, 32, 96);    // Set the name and stats of the player
            }
            else if (ChooseCharacter.PlayerCharacter.Equals("Jordy"))      // Jordyis choosen as the player
            {
                player = new MyPlayer("Jordy", 150, 150, 10, 3, 32, 96);   // Set the name and stats of the player
            }
            else if (ChooseCharacter.PlayerCharacter.Equals("Matthew"))    // Matthewis choosen as the player
            {
                player = new MyPlayer("Matthew", 100, 100, 40, 5, 32, 96); // Set the name and stats of the player
            }
            else if (ChooseCharacter.PlayerCharacter.Equals("Hayri"))      // Hayriis choosen as the player
            {
                player = new MyPlayer("Hayri", 80, 80, 60, 8, 32, 96);     // Set the name and stats of the player
            }
            else if (ChooseCharacter.PlayerCharacter.Equals("Max"))        // Maxis choosen as the player
            {
                player = new MyPlayer("Max", 100, 100, 30, 6, 32, 96);     // Set the name and stats of the player
            }

            else if (ChooseCharacter.PlayerCharacter.Equals("Samus"))   // Samusis choosen as the player
            {
                player = new MyPlayer("Samus", 200, 200, 0, 5, 32, 96); // Set the name and stats of the player
            }

            controller = new ClientController(this, player.name, player.maxHealth, player.healthPoints, player.stamina, player.move_speed, player.x, player.y);
            // Add the player to the ClientController
            weapons = new List <Weapon>();
            // Create a list of weapons
            levels = new Levels.Levels();
            // Get the current level

            // Update the mousePointer, Needed to make the player sprite follow the mouse
            mousePoint = new Point();

            this.InitializeComponent();
            Window.Current.SizeChanged += Current_SizeChanged;

            // Set the key events
            Window.Current.CoreWindow.KeyDown += controller.CoreWindow_Keydown;
            Window.Current.CoreWindow.KeyUp   += controller.CoreWindow_Keyup;

            // Add the enemies
            this.enemies.Add(new Enemy("Freek", 50, randomHealth(), 0, 5, 50, 300));   // The AI Enemy 1
            this.enemies.Add(new Enemy("Albert", 50, randomHealth(), 0, 5, 50, 300));  // The AI Enemy 2
            this.enemies.Add(new Enemy("Karel", 50, randomHealth(), 0, 5, 500, 200));  // The AI Enemy 3
            this.enemies.Add(new Enemy("Tamara", 50, randomHealth(), 0, 5, 500, 400)); // The AI Enemy 4
            this.enemies.Add(new Enemy("Daphne", 50, randomHealth(), 0, 5, 500, 200)); // The AI Enemy 5
            this.enemies.Add(new Enemy("Jorn", 50, randomHealth(), 0, 5, 900, 300));   // The AI Enemy 6
            this.enemies.Add(new Enemy("Rachid", 50, randomHealth(), 0, 5, 900, 300)); // The AI Enemy 7
        }