protected virtual void OnMarioGUIUpdated(MarioEventArgs args) { if (MarioGUIUpdated != null) { MarioGUIUpdated(this, args); } }
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; } }