Ejemplo n.º 1
0
 private void spriteUpdate(int xValue, int posNeg, GameLevel level)
 {
     foreach (Sprites sprite in level.spriteArray)
     {
         if (sprite != null)
         {
             sprite.X       += xValue * posNeg;
             sprite.Collrect = new Rectangle(sprite.X, sprite.Y, sprite.Width, sprite.Height);
             if (sprite.GetType() == typeof(Finish) && position.X >= sprite.X)
             {
                 marioWin();
             }
         }
     }
     foreach (Rocket rocket in level.rocketList)
     {
         rocket.X += xValue * posNeg;
     }
 }
Ejemplo n.º 2
0
 private void GameThread_DoWork(object sender, DoWorkEventArgs e)
 {
     video.Fill(Color.Cyan);
     level.Update();
     level.Draw();
     if (level.hero.dead && !gameOverMusic)
     {
         gameOverMusic = true;
         musicThread   = new Thread(() => AudioPlaybackThread(@"Music\Sad Violin - MLG Sound Effects (HD).mp3", 30));
         musicThread.Start();
     }
     if (level.ended)
     {
         if (level.hero.dead)
         {
             if (level.level == 1)
             {
                 level = new GameLevel(video, @"Sprites\levels\level1", 1);
             }
             else if (level.level == 2)
             {
                 level = new GameLevel(video, @"Sprites\levels\level2", 2);
             }
         }
         else if (level.hero.win)
         {
             if (level.level == 2)
             {
                 game  = false;
                 init  = true;
                 intro = new IntroScreen(video);
             }
             else
             {
                 level = new GameLevel(video, @"Sprites\levels\level2", 2);
             }
         }
         musicThread = new Thread(() => AudioPlaybackThread(@"Music\Super MLG Bros. (Air Horn Remix).mp3", 30));
         musicThread.Start();
         gameOverMusic = false;
     }
 }
Ejemplo n.º 3
0
        public override void UpdatePosition(GameLevel level)
        {
            X       += Velocity;
            Collrect = new Rectangle(X, Y, Width, Height);

            if (Velocity > 0)
            {
                int block = CollDet.CollDetection(Collrect, "right", level);
                if (block >= 0)
                {
                    X        -= block;
                    Velocity *= -1;
                }
            }
            else
            {
                int block = CollDet.CollDetection(Collrect, "left", level);
                if (block >= 0)
                {
                    X        += block;
                    Velocity *= -1;
                }
            }

            Y       += gravity;
            Collrect = new Rectangle(X, Y, Width, Height);

            int blockY = CollDet.CollDetection(Collrect, "down", level);

            if (blockY >= 0)
            {
                //Y = blockY - Height;
                Y       -= blockY;
                Collrect = new Rectangle(X, Y, Width, Height);
                gravity  = 0;
            }
            else
            {
                gravity += 5;
            }
        }
Ejemplo n.º 4
0
 public override void UpdatePosition(GameLevel level)
 {
     if (level.hero.position.X + level.hero.Width >= X)
     {
         drop = true;
     }
     if (drop)
     {
         Image    = new Surface(@"Sprites\enemies\angryStone.png");
         Y       += Velocity;
         Collrect = new Rectangle(X, Y, Image.Width, Image.Height);
         int block = CollDet.CollDetection(Collrect, "down", level);
         if (block >= 0)
         {
             //Y = block - Image.Height;
             Y -= block;
             level.spriteArray[startX, startY] = new AngryStoneGround(X, Y, Video);
             drop = false;
         }
     }
 }
Ejemplo n.º 5
0
        public int UpdatePosition(GameLevel level, bool checkHit = false)
        {
            if (!checkHit) // nodig zodat de raket niet 2maal zo snel gaat wanneer er gesprongen wordt
            {
                X -= xVelocity;

                Y += yVelocity;

                Collrect = new Rectangle(X, Y, Width, Height);
            }


            int heroHit = -5;


            if (!rocketDown)
            {
                if (checkHit)
                {
                    heroHit = CollDet.CollDetection(Collrect, "heroDown", level);
                }
                else
                {
                    CollDet.CollDetection(Collrect, "heroNotDown", level);
                }
            }


            int block = CollDet.CollDetection(Collrect, "left", level);

            if (block >= 0 || heroHit >= 0)
            {
                Image      = new Surface(@"Sprites\enemies\rocketDown.png");
                xVelocity  = 0;
                yVelocity  = 30;
                rocketDown = true;
            }

            return(heroHit);
        }
Ejemplo n.º 6
0
 public void CoinBlockHit(GameLevel level, int j, int i)
 {
     level.spriteArray[j, i]     = new CoinBlockHit(level.spriteArray[j, i].X, i, level.video);
     level.spriteArray[j, i - 1] = new Coin(level.spriteArray[j, i].X, i - 1, level.video);
 }
Ejemplo n.º 7
0
 public virtual void UpdatePosition(GameLevel level)
 {
 }
Ejemplo n.º 8
0
        public int CollDetection(Rectangle collRect, string position, GameLevel level)
        {
            if (position == "heroDown")
            {
                if (level.hero.CollRect.IntersectsWith(collRect))
                {
                    return(level.hero.CollRect.Y + level.hero.CollRect.Height - collRect.Y);
                }
            }
            if (position == "heroNotDown")
            {
                if (level.hero.CollRect.IntersectsWith(collRect))
                {
                    level.hero.marioDeath();
                }
            }

            for (int i = 0; i < level.map.Hoogte; i++)
            {
                for (int j = 0; j < level.map.Breedte; j++)
                {
                    if (level.spriteArray[j, i] != null && level.spriteArray[j, i].Collrect.IntersectsWith(collRect))
                    {
                        if (level.spriteArray[j, i].GetType() == typeof(Coin) && level.hero.CollRect == collRect)
                        {
                            level.spriteArray[j, i] = null;
                            level.CoinCount++;
                        }
                        if (level.spriteArray[j, i] != null)
                        {
                            if (level.hero.CollRect.IntersectsWith(collRect)) //nodig omdat collrect om 1 of andere reden de coll rect van de sprite geeft
                            {
                                if (level.spriteArray[j, i].GetType() == typeof(EnemyShell) || level.spriteArray[j, i].GetType() == typeof(AngryStone))
                                {
                                    level.hero.marioDeath();
                                }
                                if (level.spriteArray[j, i].GetType() == typeof(Spikes))
                                {
                                    Spikes spike = (Spikes)level.spriteArray[j, i];
                                    spike.ShowSpikes();
                                    level.hero.marioDeath();
                                }
                            }

                            if (!(level.spriteArray[j, i].GetType()).IsSubclassOf(typeof(Enemy)) && level.spriteArray[j, i].GetType() != typeof(Coin))
                            {
                                if (level.spriteArray[j, i].GetType() == typeof(InvisibleWall))
                                {
                                    InvisibleWall wall = (InvisibleWall)level.spriteArray[j, i];
                                    wall.ShowWall();
                                }
                                if (position == "left")
                                {
                                    if (level.hero.CollRect.X == collRect.X || level.spriteArray[j, i].GetType() != typeof(Cannon)) // nodig voor rocket bug
                                    {
                                        return(level.spriteArray[j, i].Collrect.X + level.spriteArray[j, i].Width - collRect.X);
                                    }
                                }
                                if (position == "right")
                                {
                                    return(collRect.X + collRect.Width - level.spriteArray[j, i].Collrect.X);
                                }
                                if (position == "up")
                                {
                                    if (level.spriteArray[j, i].GetType() == typeof(CoinBlock))
                                    {
                                        CoinBlock coinBlock = (CoinBlock)level.spriteArray[j, i];
                                        coinBlock.CoinBlockHit(level, j, i);
                                    }
                                    return(level.spriteArray[j, i].Y + level.spriteArray[j, i].Height - collRect.Y);
                                }
                                if (position == "down")
                                {
                                    return(collRect.Y + collRect.Height - level.spriteArray[j, i].Y);
                                }
                            }
                        }
                    }
                }
            }
            return(-5);
        }
Ejemplo n.º 9
0
        public void Update(GameLevel level)
        {
            if (!dead)
            {
                if (left) //indien we het linkerpijltje indrukken
                {
                    spriteUpdate(xVelocity, 1, level);

                    int block = collDet.CollDetection(CollRect, "left", level); //check of de collision rectangle snijdt met een blok

                    if (block >= 0)                                             //indien ja
                    {
                        spriteUpdate(block, -1, level);
                    }
                }
                if (right) //indien we het rechterpijltje indrukken
                {
                    spriteUpdate(xVelocity, -1, level);

                    int block = collDet.CollDetection(CollRect, "right", level); //check of de collision rectangle snijdt met een blok

                    if (block >= 0)                                              //indien ja
                    {
                        spriteUpdate(block, 1, level);
                    }
                }


                if (up) // indien we spatie indrukken
                {
                    jumpImage();

                    if (upEnable) // indien we net aan de jump beginnen
                    {
                        upEnable = false;
                        gravity  = 42; // we stellen de gravity in op 42, bij een normale jump zal dit de max. gravity zijn
                    }

                    gravityAndPositionUpdate(-1);

                    int block = collDet.CollDetection(CollRect, "up", level); // check of de bovenste collision rectangle snijdt met een blok
                    if (block >= 0 || gravity <= 0)
                    {
                        up   = false; // aangezien we een blok raken of op ons hoogste punt zijn, moeten we stoppen met springen en zetten we up dus op false
                        down = true;  // aangezien we gestopt zijn met springen moet mario naar beneden vallen, dus we zettend down op true
                    }

                    visibleRectangle.X = 0; // aangezien we bij het springen een andere sprite gebruiken, moeten we de X coö van de visible rectangle op 0 zetten
                }

                if (down) // indien we vallen
                {
                    jumpImage();

                    upEnable = false;

                    gravityAndPositionUpdate(1);

                    int block = collDet.CollDetection(CollRect, "down", level); // check of de onderste collision rectangle snijdt met een blok

                    touchingGround(block);

                    if (!upEnable) //voor rocket
                    {
                        bool checkHit = true;

                        foreach (Rocket rocket in level.rocketList)
                        {
                            int rocketY = rocket.UpdatePosition(level, checkHit);

                            touchingGround(rocketY);
                        }
                    }

                    if (position.Y >= Video.Height)
                    {
                        marioDeath();
                    }
                }
                if (left || right)  // indien we de rechterpijl- of linkerpijltoets indrukken en we niet aan het springen zijn
                {
                    visibleRectangle.X += visibleRectangle.Width;
                    if (visibleRectangle.X >= Image.Width) // indien de visible rectangle aan het einde van de sprite is
                    {
                        visibleRectangle.X = 0;            // X coö van de visible rectangle wordt weer naar de eerste afbeelding van de sprite gezet
                    }
                }
                if (!left && !right)
                {
                    visibleRectangle.X = 0;
                }
            }
            else
            {
                position.Y -= xVelocity;
                if (position.Y <= 100)
                {
                    xVelocity = 0;
                }
            }
        }
Ejemplo n.º 10
0
 protected virtual void LoadLevel(GameLevel level)
 {
     LoadScene(level.Scene.Name);
 }