Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void handleCollision(GameObject OtherObject)
- {
- if(this.CollidesWith(OtherObject))
- {
- if(OtherObject is Stage)
- {
- float rightEdgeDistance = OtherObject.BoundRect.X - (Position.X + this.BoundRect.Width);
- float leftEdgeDistance = OtherObject.BoundRect.X + OtherObject.BoundRect.Width - Position.X;
- float TopEdgeDistance = OtherObject.BoundRect.Y - (Position.Y + this.BoundRect.Height);
- float BottomEdgeDistance = OtherObject.BoundRect.Y + OtherObject.BoundRect.Height - Position.Y;
- float Left_Right_SmallerDistance = Math.Min(Math.Abs(rightEdgeDistance), Math.Abs(leftEdgeDistance));
- float Top_Bottom_SmallerDistance = Math.Min(Math.Abs(TopEdgeDistance), Math.Abs(BottomEdgeDistance));
- float smallerDistance = Math.Min(Math.Abs(Left_Right_SmallerDistance), Math.Abs(Top_Bottom_SmallerDistance));
- if (smallerDistance == Math.Abs(leftEdgeDistance))
- {
- Position.X = OtherObject.BoundRect.X + OtherObject.BoundRect.Width;
- Velocity.X = 0;
- }
- else if (smallerDistance == Math.Abs(rightEdgeDistance))
- {
- Position.X = OtherObject.BoundRect.X - this.BoundRect.Width;
- Velocity.X = 0;
- }
- else if (smallerDistance == Math.Abs(BottomEdgeDistance))
- {
- Position.Y = OtherObject.BoundRect.Y + OtherObject.BoundRect.Height;
- Velocity.Y = 0;
- }
- else if (smallerDistance == Math.Abs(TopEdgeDistance))
- {
- Position.Y = OtherObject.BoundRect.Y - this.BoundRect.Height;
- Velocity.Y = 0;
- }
- }
- }
- public void inputHandler(GameTime gameTime,GameObject OtherObject)
- {
- Velocity = Vector2.Zero;
- if (Keyboard.GetState().IsKeyDown(Keys.W))
- Velocity.Y -= moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
- if (Keyboard.GetState().IsKeyDown(Keys.S))
- Velocity.Y += moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
- if (Keyboard.GetState().IsKeyDown(Keys.A))
- Velocity.X -= moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
- if (Keyboard.GetState().IsKeyDown(Keys.D))
- Velocity.X += moveSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
- handleCollision(OtherObject);
- Position += Velocity;
- }
- protected override void Update(GameTime gameTime)
- {
- if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
- this.Exit();
- for (int i = 0; i < 3; i++)
- player.Update(gameTime, stage[i]);
- powerUp.Update(gameTime,player);
- base.Update(gameTime);
- }
Add Comment
Please, Sign In to add comment