public static bool PowerupsCollision(PowerupBoxes b)
        {
            Rectangle rec1 = new Rectangle(GameScreen.playerX, GameScreen.playerY, GameScreen.playerW, GameScreen.playerH);
            Rectangle rec2 = new Rectangle(b.x, b.y, b.size, b.size);

            //check for collision
            if (rec1.IntersectsWith(rec2))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #2
0
        public void LoadLevel()
        {
            //XML File Thing
            Enemy.Clear();
            Platforms.Clear();
            Powerups.Clear();

            string NewName, NewX, NewY;

            NewName = NewX = NewY = " ";

            string    fileName = "Resources/Level" + level + ".xml";
            XmlReader reader   = XmlReader.Create(fileName);

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Text)
                {
                    NewName = reader.ReadString();
                    reader.ReadToNextSibling("x");
                    NewX = reader.ReadString();
                    reader.ReadToNextSibling("y");
                    NewY = reader.ReadString();

                    if (NewName == "enemy")
                    {
                        Enemies n = new Enemies(Convert.ToInt32(NewX), Convert.ToInt32(NewY), 35);
                        Enemy.Add(n);
                    }
                    if (NewName == "platform")
                    {
                        Platform p = new Platform(Convert.ToInt32(NewX), Convert.ToInt32(NewY), 30);
                        Platforms.Add(p);
                    }
                    if (NewName == "powerup")
                    {
                        PowerupBoxes b = new PowerupBoxes(Convert.ToInt32(NewX), Convert.ToInt32(NewY), 30);
                        Powerups.Add(b);
                    }
                    if (NewName == "end")
                    {
                        Ending q = new Ending(Convert.ToInt32(NewX), Convert.ToInt32(NewY), 50);
                        End.Add(q);
                    }
                }
            }
        }
Beispiel #3
0
        private void GameTimer_Tick(object sender, EventArgs e)
        {
            //to change player image and to more right
            if (rightArrowDown == true && jumpActivated == false)
            {
                playerX += 10;
                PlayerImageChange();
            }

            //to jump
            if (upArrowDown == true || spaceDown == true)
            {
                Jump();
            }

            //to change player image and to more left
            if (leftArrowDown == true && jumpActivated == false)
            {
                playerX -= 10;
                PlayerImageChange();
            }

            //enemy collision
            foreach (Enemies n in Enemy)
            {
                if (Enemies.EnemiesCollision(n) == "Right" || Enemies.EnemiesCollision(n) == "Left")
                {
                    lives--;
                    playerX = 20;
                    playerY = 275;
                }
                else if (Enemies.EnemiesCollision(n) == "Top")
                {
                    Enemy.Remove(n);
                    break;
                }
            }

            //powerups collision
            foreach (PowerupBoxes b in Powerups)
            {
                if (PowerupBoxes.PowerupsCollision(b) == true)
                {
                    lives++;
                    Powerups.Remove(b);
                    break;
                }
            }

            //death
            if (lives == 0)
            {
                //play sound
                deathSound.Play();
                //go to game over screen
                Reset();
                //Remove this screen
                gameTimer.Enabled = false;
                Form f = this.FindForm();
                f.Controls.Remove(value: this);

                //Move Drectly to Game Screen
                GameOverScreen os = new GameOverScreen();
                f.Controls.Add(os);

                //put into the middle of the screen
                os.Location = new Point((f.Width - os.Width) / 2, (f.Height - os.Height) / 2);
                os.Focus();
            }

            //to switch levels or go to win screen
            foreach (Ending q in End)
            {
                if (Ending.EndingCollision(q) == true)
                {
                    if (level == 1 || level == 2 || level == 3 || level == 4)
                    {
                        level  += 1;
                        playerX = 20;
                        playerY = 275;
                        LoadLevel();
                    }
                    else
                    {
                        //go to win screen
                        Reset();
                        //stop sound
                        backgroundSound.Stop();
                        //Remove this screen
                        gameTimer.Enabled = false;
                        Form f = this.FindForm();
                        f.Controls.Remove(value: this);

                        //Move Drectly to Game Screen
                        WinScreen ws = new WinScreen();
                        f.Controls.Add(ws);

                        //put into the middle of the screen
                        ws.Location = new Point((f.Width - ws.Width) / 2, (f.Height - ws.Height) / 2);
                        ws.Focus();
                    }
                }
            }

            EnemyImageChange();

            Refresh();
        }