Esempio n. 1
0
        //call this after the constructor or with reset, nowhere else
        public void Begin()
        {
            currentActionState  = actionStates[MarioAction.Idle];
            PreviousActionState = currentActionState;

            currentPowerupState  = powerupStates[MarioPowerup.Normal];
            PreviousPowerupState = currentPowerupState;

            CurrentPowerupState.Enter();
            CurrentActionState.Enter();

            TransitionInvincible();
        }
Esempio n. 2
0
        public void TakeDamage(bool invinc = true)
        {
            if (!invincibleFrames.IsRunning)
            {
                this.invincibleFrames.Start();
                CurrentPowerupState.DamageTransition(null);
            }
            Debug.WriteLine("invincible frames: " + invincibleFrames.ElapsedMilliseconds);
            if (!invinc || this.invincibleFrames.ElapsedMilliseconds >= 2000)
            {
                //this.powerupState = this.powerupState.TakeDamage();
                CurrentPowerupState.DamageTransition(null);
                this.invincibleFrames.Restart();
            }

            Color = Color.Red;
        }
Esempio n. 3
0
 //keeping this since the side doesn't matter
 public void CollideWithItem(ICollidable collidable)
 {
     Debug.WriteLine("mario is colliding with an item");
     OnItemCollected((ItemModel)collidable);
     if (collidable is FireFlowerModel)
     {
         CurrentPowerupState.FireTransition(null);
         this.points += 1000;
     }
     else
     if (collidable is RedMushroomModel)
     {
         if (CurrentPowerupState is MarioStandardState)
         {
             CurrentPowerupState.SuperTransition(null);
         }
         this.points += 1000;
     }
     else
     if (collidable is GreenMushroomModel)
     {
         this.points += 1000;
         LifeOneUP();
     }
     else
     if (collidable is SuperStarModel)
     {
         this.points += 1000;
         //Mario gets invincibility for a bit
     }
     else
     if (collidable is CoinModel)
     {
         CollectCoin();
     }
 }
Esempio n. 4
0
 public void Fire()
 {
     //this.powerupState = FireState.Instance;
     CurrentPowerupState.FireTransition(null);
 }
Esempio n. 5
0
 public void Super()
 {
     //this.powerupState = SuperState.Instance;
     CurrentPowerupState.SuperTransition(null);
 }
Esempio n. 6
0
 public void Standard()
 {
     //this.powerupState = StandardState.Instance;
     CurrentPowerupState.StandardTransition(null);
 }
Esempio n. 7
0
        public void Update(GameTime gameTime)
        {
            if (this.time <= 0)
            {
                this.Kill();
            }
            CurrentPowerupState?.Update(gameTime);
            //DeadPositionFactor = powerupState.CollisionPositionFactor;
            if (DeadPositionFactor == 0)
            {
                Gravity(false);
            }
            Position += Velocity;

            //Debug.WriteLine("invincible frames: " + invincibleFrames.ElapsedMilliseconds);
            if (this.invincibleFrames.ElapsedMilliseconds >= 2000 /*|| !this.invincibleFrames.IsRunning*/)
            {
                Color = Color.White;
            }

            //position += new Vector2((int)(Velocity.X * gameTime.ElapsedGameTime.TotalSeconds), (int)(Velocity.Y * gameTime.ElapsedGameTime.TotalSeconds));
            //handle illegal state where mario is standard and crouching -- can arise when mario takes damage while crouching

            /* if (powerupState is StandardState && actionState is CrouchingState)
             * {
             *   this.actionState = IdlingState.Instance;
             * }*/
            if (CurrentPowerupState is MarioStandardState && actionState is CrouchingState)
            {
                this.actionState = IdlingState.Instance;
            }

            //this.texture = spriteFactory.GetSprite(this.actionState, this.powerupState, gameTime);
            this.texture = MarioSpriteFactory.GetSprite(this.actionState, CurrentPowerupState, gameTime);
            UpdateMarioHeight();



            //Update and send Max Velocity
            //UpdateMaxVelocity(80f);
            //check for max height
            if (this.Velocity.Y == -jumpSpeed)
            {
                //Debug.WriteLine("the Update code is being run at all");
                UpdateJump(false);
            }
            //Debug.WriteLine("Mario has support");
            //support is updated when: mario moves left or right, mario stops jumping, mario collides horrizontally
            if (IsMoving() == 1)
            {
                Gravity(support);
            }
            else
            {
                this.actionState = IdlingState.Instance;
            }
            //support = false;
            if (gameTime.TotalGameTime.TotalSeconds - lastUpdatedTime.TotalGameTime.TotalSeconds >= 1)
            {
                this.time--;
                lastUpdatedTime.TotalGameTime = gameTime.TotalGameTime;
            }

            MarioEventArgs newArgs = new MarioEventArgs()
            {
                Coins = this.coins, Lives = this.lives, Points = this.points, Time = this.time
            };

            if (!newArgs.Equals(lastMarioArgsPassed))
            {
                OnMarioGUIUpdated(newArgs);
            }
            lastMarioArgsPassed = newArgs;
            if (CurrentPowerupState is MarioDeadState)
            {
                if (!hasDied)
                {
                    hasDied = true;
                    lives--;
                }
                if (this.invincibleFrames.ElapsedMilliseconds >= 500)
                {
                    OnMarioDeath();
                }
            }
            if (warping)
            {
                this.Position = new Vector2(1660, 1136);
                warping       = false;
            }
        }
Esempio n. 8
0
 //call this before begin, nowhere else
 public void Reset()
 {
     CurrentPowerupState.Leave();
     CurrentActionState.Leave();
 }