public void UpdateTexture() { Rectangle source = SourceRectangle; PowerStateType power = PowerStateEnum; if (PowerStateEnum == PowerStateType.Star) { power = PowerState.Previous; } MarioSpriteFactory.SetSourceRectangle(ref source, power, ActionStateEnum); SourceRectangle = source; }
private void HandleRunningUpdate(GameTime gameTime) { if (lastChange > 16) { if (CurrentFrame == 2) { dir = -1; } else if (CurrentFrame == 0) { dir = 1; } CurrentFrame += dir; Rectangle source = SourceRectangle; //to handle invincibility while walking PowerStateType power = PowerStateEnum; if (Invincible) { if (useSource)//useSource was switched in invincable { power = PowerState.Previous; useSource = true; } } if (PowerStateEnum == PowerStateType.Star) { power = PowerState.Previous; } if (ActionStateEnum == ActionStateType.Decaying && source.X >= MarioSpriteFactory.RightFacingStart) { MarioSpriteFactory.Running(ref source, CurrentFrame, power, ActionStateType.WalkingRight); } else { MarioSpriteFactory.Running(ref source, CurrentFrame, power, ActionStateEnum); } SourceRectangle = source; lastChange = 0; } else { lastChange += (int)gameTime.ElapsedGameTime.TotalMilliseconds; } }
//private methods for update private void HandleInvincibilityUpdate(GameTime gameTime) { if (invincibleCurrentTime >= InvincibleTime) { Invincible = false; useSource = true; Rectangle sourceInv = SourceRectangle; PowerStateType power = PowerStateEnum; if (PowerStateEnum == PowerStateType.Star) { power = PowerState.Previous; } MarioSpriteFactory.SetSourceRectangle(ref sourceInv, power, ActionStateEnum); SourceRectangle = sourceInv; invincibleCurrentTime = 0; sourceInvincibleChange = 0; } else { invincibleCurrentTime += (int)gameTime.ElapsedGameTime.TotalMilliseconds; if (sourceInvincibleChange >= SourceChangeTime) { PowerStateType power; if (useSource) { if (PowerStateEnum != PowerStateType.Star) { power = PowerStateEnum; } else { power = PowerState.Previous; } useSource = false; } else { if (PowerStateEnum != PowerStateType.Star) { power = PowerState.Previous; } else { power = ((MarioPowerStateStar)PowerState).previousState.Previous; } useSource = true; } Rectangle sourceInv = SourceRectangle; MarioSpriteFactory.SetSourceRectangle(ref sourceInv, power, ActionStateEnum); if (ActionStateEnum == ActionStateType.WalkingLeft || ActionStateEnum == ActionStateType.WalkingRight)//need to handle walking as this will update faster than animation frame { MarioSpriteFactory.Walking(ref sourceInv, CurrentFrame, power, ActionStateEnum); } SourceRectangle = sourceInv; sourceInvincibleChange = 0; } else { sourceInvincibleChange += (int)gameTime.ElapsedGameTime.TotalMilliseconds; } } }