Ejemplo n.º 1
0
 /// <summary>
 /// Allows the game to perform any initialization it needs to before starting to run.
 /// This is where it can query for any required services and load any non-graphic
 /// related content.  Calling base.Initialize will enumerate through any components
 /// and initialize them as well.
 /// </summary>
 protected override void Initialize()
 {
     gameOver = false;
     sound    = new Sound(Content);
     Global.Instance.MainGame = this;
     _levelReader             = new LevelReader(Content);
     currentLevel             = _levelReader.ReadLevel(0);
     mario = new Mario(0, 32, currentLevel, Content);
     currentLevel.ToAddGameObject(mario);
     camera = new Camera(GraphicsDevice.Viewport);
     _graphicalUserInterface = new GraphicalUserInterface(mario, Content);
     System.Windows.Forms.Form form = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(this.Window.Handle);
     form.Location = new System.Drawing.Point(Screen.PrimaryScreen.Bounds.Width / 2 - GraphicsDevice.Viewport.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2 - GraphicsDevice.Viewport.Height / 2);
     base.Initialize();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Checks if Goomba should Die or hit Mario instead
 /// </summary>
 /// <param name="mario">Used to check if Mario jumped on top of Goomba</param>
 public void CheckDeath(Mario mario)
 {
     if (!_isHit)
     {
         if (mario.VelocityY > 0.5)
         {
             mario.Jump();
             Die();
         }
         else
         {
             mario.GetHit();
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Ejects a coin
 /// </summary>
 /// <param name="mario">Used to check if Mario is below the CoinBlock and used to give a coin to Mario</param>
 public void Eject(Mario mario)
 {
     if (mario.VelocityY < 0 && !_hasBeenUsed && mario.Hitbox.Y >= Hitbox.Bottom)
     {
         Coin c = (Coin)Activator.CreateInstance(typeof(Coin), (int)Position.X / Global.Instance.GridSize, ((int)Position.Y - Hitbox.Height) / Global.Instance.GridSize, CurrentLevel, _contentManager, true);
         c.AddCoin(mario);
         CurrentLevel.ToAddGameObject(c);
         if (ContainAmount-- <= 0)
         {
             _animator.GetTextures(16, 0, 16, 16, 1, 1);
             Sprite       = _animator.GetCurrentTexture();
             _hasBeenUsed = true;
         }
     }
 }
Ejemplo n.º 4
0
        public override void Update()
        {
            Mario m = Global.Instance.MainGame.mario;

            //Checks if Mario is beneath the spike
            CheckFall(m);

            if (_goFall)
            {
                //Update hitbox to match current position
                UpdateHitbox();

                //Add gravity to vertical velocity
                AddGravity();

                //Update position
                UpdatePosition();

                //Check if Mario gets hit
                CheckHit(m);
            }
        }
Ejemplo n.º 5
0
        public bool IsColliding(Level lvl, int offsetX, int offsetY, out Tangible collObject) //TODO: Improve collision (collider class?)
        {
            bool collidesWithSolid = false;

            collObject = null;
            foreach (GameObject gameObject in lvl.GameObjects)
            {
                if (gameObject is Tangible)
                {
                    Tangible  tangibleObject = (Tangible)gameObject;
                    Rectangle testRect       = new Rectangle((int)tangibleObject.Position.X - offsetX, (int)tangibleObject.Position.Y - offsetY, tangibleObject.Hitbox.Width, tangibleObject.Hitbox.Height);

                    if (testRect.Intersects(Hitbox) && tangibleObject != this)
                    {
                        if (tangibleObject.IsSolid)
                        {
                            collidesWithSolid = true;
                            collObject        = tangibleObject;
                        }
                        if (this is Mario)
                        {
                            Mario mario = (Mario)this;
                            if (tangibleObject is Coin)
                            {
                                Coin coin = (Coin)tangibleObject;
                                coin.AddCoin((Mario)this);
                            }
                            else if (tangibleObject is MysteryBlock)
                            {
                                MysteryBlock mysteryBlock = (MysteryBlock)tangibleObject;
                                mysteryBlock.Eject(mario);
                            }
                            else if (tangibleObject is CoinBlock)
                            {
                                CoinBlock coinBlock = (CoinBlock)tangibleObject;
                                coinBlock.Eject(mario);
                            }
                            else if (tangibleObject is Mushroom)
                            {
                                Mushroom mushroom = (Mushroom)tangibleObject;
                                mushroom.CollectMushroom(mario);
                            }
                            else if (tangibleObject is OneUpMushroom)
                            {
                                OneUpMushroom oneUpMushroom = (OneUpMushroom)tangibleObject;
                                oneUpMushroom.CollectMushroom(mario);
                            }
                            else if (tangibleObject is Shell)
                            {
                                Shell shell = (Shell)tangibleObject;
                                shell.CheckHit(mario);
                            }
                            else if (tangibleObject is Koopa)
                            {
                                Koopa koopa = (Koopa)tangibleObject;
                                koopa.CheckDeath(mario);
                            }
                            else if (tangibleObject is Muncher)
                            {
                                mario.GetHit();
                            }
                            else if (tangibleObject is Goomba)
                            {
                                Goomba goomba = (Goomba)tangibleObject;
                                goomba.CheckDeath(mario);
                            }
                        }
                        else if (this is Shell)
                        {
                            if (tangibleObject is Goomba)
                            {
                                Goomba goomba = (Goomba)tangibleObject;
                                goomba.Die();
                            }
                            if (tangibleObject is Koopa)
                            {
                                Koopa koopa = (Koopa)tangibleObject;
                                koopa.DieWithoutShell();
                                collidesWithSolid = false;
                            }
                        }
                    }
                }
            }
            return(collidesWithSolid);
        }