public void Update(GameTime gameTime, ref Player player) { if ((state & TileState.Solid) == TileState.Solid || (state & TileState.Entrance) == TileState.Entrance) { Rectangle tileRect = new Rectangle((int)position.X, (int)position.Y, sourceRect.Width, sourceRect.Height); //Rectangle playerRect = new Rectangle((int)player.Image.Position.X, (int)player.Image.Position.Y, player.Image.SourceRect.Width, player.Image.SourceRect.Height); Rectangle playerRect = new Rectangle ((int)player.Image.Position.X, (int)(player.Image.Position.Y + (player.Image.SourceRect.Height / 2)), player.Image.SourceRect.Width, (int)(player.Image.SourceRect.Height / 2)); if (playerRect.Intersects(tileRect)) { if ((state & TileState.Entrance) == TileState.Entrance) { } Rectangle rectIntersection = Rectangle.Intersect (playerRect, tileRect); if (rectIntersection.Height == rectIntersection.Width) { if (player.Velocity.X < 0) { player.UpdateImagePositionX (tileRect.Right); player.Velocity = new Vector2 (0, player.Velocity.Y); } if (player.Velocity.X > 0) { player.UpdateImagePositionX (tileRect.Left - player.Image.SourceRect.Width); player.Velocity = new Vector2 (0, player.Velocity.Y); } if (player.Velocity.Y < 0) { //player.Image.Position.Y = tileRect.Bottom; player.UpdateImagePositionY (tileRect.Bottom - (player.Image.SourceRect.Height / 2)); player.Velocity = new Vector2 (player.Velocity.X, 0); } if (player.Velocity.Y > 0) { player.UpdateImagePositionY (tileRect.Top - player.Image.SourceRect.Height); player.Velocity = new Vector2 (player.Velocity.X, 0); } } if (rectIntersection.Height > rectIntersection.Width) { if (player.Velocity.X < 0) { player.UpdateImagePositionX (tileRect.Right); player.Velocity = new Vector2 (0, player.Velocity.Y); } if (player.Velocity.X > 0) { player.UpdateImagePositionX (tileRect.Left - player.Image.SourceRect.Width); player.Velocity = new Vector2 (0, player.Velocity.Y); } } if (rectIntersection.Width > rectIntersection.Height) { if (player.Velocity.Y < 0) { //player.Image.Position.Y = tileRect.Bottom; player.UpdateImagePositionY(tileRect.Bottom - (player.Image.SourceRect.Height / 2)); player.Velocity = new Vector2 (player.Velocity.X, 0); } if (player.Velocity.Y > 0) { player.UpdateImagePositionY (tileRect.Top - player.Image.SourceRect.Height); player.Velocity = new Vector2 (player.Velocity.X, 0); } } } } }
public void Update(GameTime gameTime, ref Player player) { if (InputManager.Instance.TouchPanelPressed () && BoundingBox.Contains (InputManager.Instance.TransformedTouchPosition)) { if (Inventory.Instance.PrerequisiteSongismHasBeenDiscovered (this.MissionSongismName)) { MissionCompleted = true; } else { InteractionBoundingBoxPosition.X = (int)(Camera2D.Instance.Position.X - (ScreenManager.Instance.GraphicsDevice.Viewport.Width / 2)) + 256; InteractionImage.UpdatePositionX ((int)InteractionBoundingBoxPosition.X); MissionCompleteInteractionImage.UpdatePositionX ((int)InteractionBoundingBoxPosition.X); InteractionBoundingBox.X = (int)InteractionBoundingBoxPosition.X; } OnClick (this, null); } else if (InputManager.Instance.TouchPanelPressed () && InteractionBoundingBox.Contains (InputManager.Instance.TransformedTouchPosition) && CurrentlyInteracting) { OnClick (this, null); if (MissionCompleted) { if (MissionReward != null) { Inventory.Instance.Items.Add (MissionReward); } SetNpcToInactive (); } } if (CurrentlyInteracting) { if (MissionCompleted) { MissionCompleteInteractionImage.Update (gameTime); } else { InteractionImage.Update (gameTime); } } else { Image.Update (gameTime); if ((State & Tile.TileState.Solid) == Tile.TileState.Solid) { Rectangle playerRect = new Rectangle ((int)player.Image.Position.X, (int)(player.Image.Position.Y + (player.Image.SourceRect.Height / 2)), player.Image.SourceRect.Width, (int)(player.Image.SourceRect.Height / 2)); if (playerRect.Intersects(BoundingBox)) { Rectangle rectIntersection = Rectangle.Intersect (playerRect, BoundingBox); if (rectIntersection.Height > rectIntersection.Width) { if (player.Velocity.X < 0) { player.UpdateImagePositionX (BoundingBox.Right); player.Velocity = new Vector2 (0, player.Velocity.Y); } if (player.Velocity.X > 0) { player.UpdateImagePositionX (BoundingBox.Left - player.Image.SourceRect.Width); player.Velocity = new Vector2 (0, player.Velocity.Y); } } if (rectIntersection.Width > rectIntersection.Height) { if (player.Velocity.Y < 0) { //player.Image.Position.Y = BoundingBox.Bottom; player.UpdateImagePositionY (BoundingBox.Bottom - (player.Image.SourceRect.Height / 2)); player.Velocity = new Vector2 (player.Velocity.X, 0); } if (player.Velocity.Y > 0) { player.UpdateImagePositionY (BoundingBox.Top - player.Image.SourceRect.Height); player.Velocity = new Vector2 (player.Velocity.X, 0); } } //if (player.Velocity.X < 0) //player.Image.Position.X = BoundingBox.Right; //else if (player.Velocity.X > 0) //player.Image.Position.X = BoundingBox.Left - player.Image.SourceRect.Width; //else if (player.Velocity.Y < 0) //player.Image.Position.Y = BoundingBox.Bottom; //else //player.Image.Position.Y = BoundingBox.Top - player.Image.SourceRect.Height; //player.Velocity = Vector2.Zero; } } } }
public void Update(GameTime gameTime, ref Player player) { if (InteractionType == Globals.MapEntranceInteractionType.Click) { if (InputManager.Instance.TouchPanelPressed () && BoundingBox.Contains (InputManager.Instance.TransformedTouchPosition)) { if (Locked) { if (!HasPrerequisiteSongism || (HasPrerequisiteSongism && Inventory.Instance.PrerequisiteSongismHasBeenDiscovered (PrerequisiteSongism))) { Locked = false; } } if (!Locked) { OnClick (this, null); } } } if (HasImage) { Image.Update(gameTime); } if ((State & Tile.TileState.Solid) == Tile.TileState.Solid) { //Rectangle playerRect = new Rectangle((int)player.Image.Position.X, (int)player.Image.Position.Y, player.Image.SourceRect.Width, player.Image.SourceRect.Height); Rectangle playerRect = new Rectangle ((int)player.Image.Position.X, (int)(player.Image.Position.Y + (player.Image.SourceRect.Height / 2)), player.Image.SourceRect.Width, (int)(player.Image.SourceRect.Height / 2)); if (playerRect.Intersects(BoundingBox)) { if (InteractionType == Globals.MapEntranceInteractionType.PlayerEnter) { OnPlayerEnter (this, null); } Rectangle rectIntersection = Rectangle.Intersect (playerRect, BoundingBox); if (rectIntersection.Height > rectIntersection.Width) { if (player.Velocity.X < 0) { player.UpdateImagePositionX (BoundingBox.Right); player.Velocity = new Vector2 (0, player.Velocity.Y); } if (player.Velocity.X > 0) { player.UpdateImagePositionX (BoundingBox.Left - player.Image.SourceRect.Width); player.Velocity = new Vector2 (0, player.Velocity.Y); } } if (rectIntersection.Width > rectIntersection.Height) { if (player.Velocity.Y < 0) { //player.Image.Position.Y = BoundingBox.Bottom; player.UpdateImagePositionY (BoundingBox.Bottom - (player.Image.SourceRect.Height / 2)); player.Velocity = new Vector2 (player.Velocity.X, 0); } if (player.Velocity.Y > 0) { player.UpdateImagePositionY (BoundingBox.Top - player.Image.SourceRect.Height); player.Velocity = new Vector2 (player.Velocity.X, 0); } } //if (player.Velocity.X < 0) //player.Image.Position.X = BoundingBox.Right; //else if (player.Velocity.X > 0) //player.Image.Position.X = BoundingBox.Left - player.Image.SourceRect.Width; //else if (player.Velocity.Y < 0) //player.Image.Position.Y = BoundingBox.Bottom; //else //player.Image.Position.Y = BoundingBox.Top - player.Image.SourceRect.Height; //player.Velocity = Vector2.Zero; } } }
public void Update(GameTime gameTime, ref Player player) { if (InputManager.Instance.TouchPanelPressed() && BoundingBox.Contains(InputManager.Instance.TransformedTouchPosition)) OnClick(this, null); Image.Update(gameTime); if ((State & Tile.TileState.Solid) == Tile.TileState.Solid) { //Rectangle playerRect = new Rectangle((int)player.Image.Position.X, (int)player.Image.Position.Y, player.Image.SourceRect.Width, player.Image.SourceRect.Height); Rectangle playerRect = new Rectangle ((int)player.Image.Position.X, (int)(player.Image.Position.Y + (player.Image.SourceRect.Height / 2)), player.Image.SourceRect.Width, (int)(player.Image.SourceRect.Height / 2)); if (playerRect.Intersects(BoundingBox)) { Rectangle rectIntersection = Rectangle.Intersect (playerRect, BoundingBox); if (rectIntersection.Height > rectIntersection.Width) { if (player.Velocity.X < 0) { player.UpdateImagePositionX (BoundingBox.Right); player.Velocity = new Vector2 (0, player.Velocity.Y); } if (player.Velocity.X > 0) { player.UpdateImagePositionX(BoundingBox.Left - player.Image.SourceRect.Width); player.Velocity = new Vector2 (0, player.Velocity.Y); } } if (rectIntersection.Width > rectIntersection.Height) { if (player.Velocity.Y < 0) { //player.Image.Position.Y = BoundingBox.Bottom; player.UpdateImagePositionY (BoundingBox.Bottom - (player.Image.SourceRect.Height / 2)); player.Velocity = new Vector2 (player.Velocity.X, 0); } if (player.Velocity.Y > 0) { player.UpdateImagePositionY (BoundingBox.Top - player.Image.SourceRect.Height); player.Velocity = new Vector2 (player.Velocity.X, 0); } } //if (player.Velocity.X < 0) //player.Image.Position.X = BoundingBox.Right; //else if (player.Velocity.X > 0) //player.Image.Position.X = BoundingBox.Left - player.Image.SourceRect.Width; //else if (player.Velocity.Y < 0) //player.Image.Position.Y = BoundingBox.Bottom; //else //player.Image.Position.Y = BoundingBox.Top - player.Image.SourceRect.Height; //player.Velocity = Vector2.Zero; } } }