public MarioModel(MarioSpriteFactory spriteFactory, Vector2 coordinates, Vector2 velocity) { //Mario states CurrentPowerupState = new MarioStandardState(this); CurrentPowerupState.Enter(null); leftFacing = false; canMoveDown = false; support = false; gravityAllowed = true; horizontalSpeed = 2; jumpSpeed = 3; heightJumped = 0; this.Position = coordinates; this.lives = 3; this.coins = 0; this.points = 0; this.time = 400; //this.powerupState = powerupState; //this.spriteFactory = spriteFactory; MarioSpriteFactory = spriteFactory; Sprite = new MarioSprite(this); Velocity = velocity; //DeadPositionFactor = powerupState.CollisionPositionFactor; //DeadPositionFactor = 1; }
public override void ThrowFire() { SoundFactory.Instance.ShootFire(); Rectangle source = Context.SourceRectangle; MarioSpriteFactory.GetFireThrow(ref source); Context.SourceRectangle = source; Stage.AddEntity(MarioSpriteFactory.Instance.MakeFireball(Context.Position, Context.SourceRectangle.X)); Context.ShotFireBall = true; }
public override void ActionDown() { if (Context.OnGround) { Leave(Previous); } else { Vector2 vel = Context.Velocity; vel.Y = 0f; Context.NeedsUpdating = true; Context.Velocity = vel; Context.SourceRectangle = MarioSpriteFactory.FallingJump(Context.SourceRectangle, Context.ActionStateEnum); } }
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; } }
public void Draw(SpriteBatch sprite) { if (Direction) { if (State == MarioState.Small || State == MarioState.SmallStar || State == MarioState.Dead || Frame == MarioFrame.Dying) { sprite.Draw(SpriteFactory.marioSpriteSheet, new Rectangle((int)Location.X, (int)Location.Y, MarioSpriteFactory.SMALL_MARIO_WIDTH, MarioSpriteFactory.SMALL_MARIO_HEIGHT), MarioSpriteFactory.Mario(Color, State, Frame), hitColor, 0f, new Vector2(0, 0), SpriteEffects.FlipHorizontally, 0f); } else { sprite.Draw(SpriteFactory.marioSpriteSheet, new Rectangle((int)Location.X, (int)Location.Y, MarioSpriteFactory.BIG_MARIO_WIDTH, MarioSpriteFactory.BIG_MARIO_HEIGHT), MarioSpriteFactory.Mario(Color, State, Frame), hitColor, 0f, new Vector2(0, 0), SpriteEffects.FlipHorizontally, 0f); } } else { if (State == MarioState.Small || State == MarioState.SmallStar || State == MarioState.Dead || Frame == MarioFrame.Dying) { sprite.Draw(SpriteFactory.marioSpriteSheet, new Rectangle((int)Location.X, (int)Location.Y, MarioSpriteFactory.SMALL_MARIO_WIDTH, MarioSpriteFactory.SMALL_MARIO_HEIGHT), MarioSpriteFactory.Mario(Color, State, Frame), hitColor); } else { sprite.Draw(SpriteFactory.marioSpriteSheet, new Rectangle((int)Location.X, (int)Location.Y, MarioSpriteFactory.BIG_MARIO_WIDTH, MarioSpriteFactory.BIG_MARIO_HEIGHT), MarioSpriteFactory.Mario(Color, State, Frame), hitColor); } } if (IsBounded) { if (State == MarioState.Small || State == MarioState.SmallStar || State == MarioState.Dead || Frame == MarioFrame.Dying) { BoundingBox.DrawRectangle(new Rectangle((int)Location.X, (int)Location.Y, MarioSpriteFactory.SMALL_MARIO_WIDTH, MarioSpriteFactory.SMALL_MARIO_HEIGHT), Microsoft.Xna.Framework.Color.Yellow); } else { BoundingBox.DrawRectangle(new Rectangle((int)Location.X, (int)Location.Y, MarioSpriteFactory.BIG_MARIO_WIDTH, MarioSpriteFactory.BIG_MARIO_HEIGHT), Microsoft.Xna.Framework.Color.Yellow); } } }