public void StaticStateChange(String location, Fireball fireball, IStaticObject staticObject) { if (location == GameValues.CollisionDirectionTop || location == GameValues.CollisionDirectionBottom || staticObject.ToString() == "SuperMario.FloorTile") { fireball.Position = new Vector2(fireball.Position.X, staticObject.CollisionRectangle.Top - fireball.CollisionRectangle.Height); fireball.CollisionRectangle = new Rectangle((int)fireball.Position.X, (int)fireball.Position.Y, fireball.CollisionRectangle.Width, fireball.CollisionRectangle.Height); fireball.Velocity = new Vector2(fireball.Velocity.X, fireball.Velocity.Y * (-1)); } else { fireball.IsAlive = false; } }
public void StaticStateChange(String location, Item item, IStaticObject staticObject) { if (location == GameValues.CollisionDirectionTop) { new GenericStaticGroundCollisionCommand(item, staticObject).Execute(); } else if (location == GameValues.CollisionDirectionBottom) { if (item.ItemState.ToString() == "SuperMario.ItemStates.Star") { item.Velocity = new Vector2(item.Velocity.X, Vector2.Zero.Y); item.InAir = false; } new GenericStaticBottomCollisionCommand(item, staticObject).Execute(); } else if ((location == GameValues.CollisionDirectionRight || location == GameValues.CollisionDirectionLeft) && staticObject.ToString() != "SuperMario.FloorTile") { new GenericSideCollisionCommand(item).Execute(); } else { new GenericStaticBottomCollisionCommand(item, staticObject).Execute(); item.InAir = false; } }
public void StaticStateChange(String collisionDirection, IStaticObject staticObject) { if (staticObject.ToString() == "SuperMario.Flagpole" && !finishedCollidingWithFlagPole) { if (playableObject.PlayableObjectState.ToString() != "SuperMario.MarioStates.SmallMarioFlagSlide" && playableObject.PlayableObjectState.ToString() != "SuperMario.MarioStates.BigMarioFlagSlide" && playableObject.PlayableObjectState.ToString() != "SuperMario.MarioStates.FireMarioFlagSlide") { playableObject.Velocity = Vector2.Zero; playableObject.Acceleration = Vector2.Zero; playableObject.MaxVelocity = new Vector2(playableObject.MaxVelocity.X, GameValues.MarioStateMachineFlagpoleMarioYVelocity); SoundManager.Instance.OverWorldInstance.Stop(); SoundManager.Instance.PlayFlagSlideSound(); } if (playableObject.Acceleration.Y < Vector2.Zero.Y) { playableObject.Acceleration = Vector2.Zero; } new MarioCollidesWithFlagPoleCommand(playableObject).Execute(); Level.Instance.Flagpoles[0].SetScoreValue(playableObject.Position.Y); playableObject.Position = new Vector2(staticObject.CollisionRectangle.Left - playableObject.CollisionRectangle.Width + GameValues.MarioStateMachineFlagPoleCollisionRectangleWidthOffset, playableObject.Position.Y); staticObject.CollisionRectangle = GameValues.EmptyCollisionRectangle; playableObject.CollisionRectangle = new Rectangle((int)playableObject.Position.X, (int)playableObject.Position.Y, playableObject.CollisionRectangle.Width, playableObject.CollisionRectangle.Height); } else { if (collisionDirection == GameValues.CollisionDirectionTop) { } else if (collisionDirection == GameValues.CollisionDirectionBottom) { new MarioCollidesWithGroundCommand(playableObject).Execute(); if (!playableObject.IsEnteringPipe && !playableObject.IsExitingPipe) { playableObject.Position = new Vector2(playableObject.Position.X, staticObject.CollisionRectangle.Top - playableObject.CollisionRectangle.Height); playableObject.CollisionRectangle = new Rectangle((int)playableObject.Position.X, (int)playableObject.Position.Y, playableObject.CollisionRectangle.Width, playableObject.CollisionRectangle.Height); } KeyboardState keyboardState = Keyboard.GetState(); GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); if ((keyboardState.IsKeyDown(Keys.Down) || gamePadState.IsButtonDown(Buttons.LeftThumbstickDown) || gamePadState.IsButtonDown(Buttons.DPadDown)) && staticObject.ToString() == "SuperMario.Pipe" && playableObject.CollisionRectangle.Left > staticObject.CollisionRectangle.Left && playableObject.CollisionRectangle.Right < staticObject.CollisionRectangle.Right) { Pipe pipe = staticObject as Pipe; if (pipe.IsWarpPipe && !playableObject.IsEnteringPipe) { playableObject.IsEnteringPipe = true; SoundManager.Instance.PlayPowerDownSound(); } } } else if (collisionDirection == GameValues.CollisionDirectionRight) { Vector2 pipeExitPosition = Vector2.Zero; if (staticObject.ToString() == "SuperMario.Pipe") { Pipe pipe = staticObject as Pipe; if (pipe.IsHorizontalPipe) { playableObject.IsEnteringPipe = true; //command for pipe animation SoundManager.Instance.PlayPowerDownSound(); playableObject.InCoinRoom = false; foreach (Pipe pipeTemp in Level.Instance.Pipes) { if (pipeTemp.Position.X > pipeExitPosition.X && pipeTemp.Position.X != pipe.Position.X && pipeTemp.Position.X < pipe.Position.X) { pipeExitPosition = new Vector2(pipeTemp.Position.X, pipeTemp.Position.Y); } } } } if (pipeExitPosition.X != Vector2.Zero.X && pipeExitPosition.Y != Vector2.Zero.Y) { playableObject.IsExitingPipe = true; playableObject.Position = new Vector2(pipeExitPosition.X, pipeExitPosition.Y); } else { playableObject.Position = new Vector2(staticObject.CollisionRectangle.Left - playableObject.CollisionRectangle.Width + GameValues.MarioStateMachineCollisionRectangleWidthOffset, playableObject.Position.Y); } playableObject.CollisionRectangle = new Rectangle((int)playableObject.Position.X, (int)playableObject.Position.Y, playableObject.CollisionRectangle.Width, playableObject.CollisionRectangle.Height); if (playableObject.Velocity.X > Vector2.Zero.X) { playableObject.Velocity = new Vector2(GameValues.MarioStateMachineCollisionNewXVelocity, playableObject.Velocity.Y); } } else if (collisionDirection == GameValues.CollisionDirectionLeft) { playableObject.Position = new Vector2(staticObject.CollisionRectangle.Right, playableObject.Position.Y); playableObject.CollisionRectangle = new Rectangle((int)playableObject.Position.X, (int)playableObject.Position.Y, playableObject.CollisionRectangle.Width, playableObject.CollisionRectangle.Height); if (playableObject.Velocity.X < Vector2.Zero.X) { playableObject.Velocity = new Vector2(-GameValues.MarioStateMachineCollisionNewXVelocity, playableObject.Velocity.Y); } } if (playableObject.IsEnteringPipe && !playableObject.IsExitingPipe) { if (PipeBuffer >= GameValues.MarioStateMachinePipeBufferMin) { PipeBuffer = GameValues.MarioStateMachinePipeBuffer; playableObject.IsEnteringPipe = false; playableObject.MaxVelocity = new Vector2(playableObject.MaxVelocity.X, GameValues.PhysicsMaxYVelocity); playableObject.Position = new Vector2(Level.Instance.CoinRoomPosition.X + GameValues.LevelCellSize, (Level.Instance.CoinRoomPosition.Y / GameValues.LevelCellSize) + GameValues.MarioStateMachineEnteringPipeYPositionOffset); playableObject.InCoinRoom = true; } else { PipeBuffer++; //playableObject.Position = new Vector2(playableObject.Position.X, playableObject.Position.Y + 0.1f); playableObject.MaxVelocity = new Vector2(playableObject.MaxVelocity.X, GameValues.MarioStateMachineCollisionNewXVelocity); playableObject.Acceleration = Vector2.Zero; } } else if (playableObject.IsExitingPipe) { if (staticObject.ToString() == "SuperMario.Pipe") { if (playableObject.Position.Y <= staticObject.Position.Y - playableObject.CollisionRectangle.Height + GameValues.MarioStateMachineExitingPipeCollisionRectangleHeightOffset) { playableObject.IsEnteringPipe = false; playableObject.IsExitingPipe = false; playableObject.Position = new Vector2(playableObject.Position.X, staticObject.Position.Y - playableObject.CollisionRectangle.Height); } else { playableObject.Velocity = new Vector2(playableObject.Velocity.X, GameValues.MarioStateMachineExitingPipeNewYVelocity); } } } } }