public HitBase GetHit(Vector position, ICamera camera, WorldTransform worldTransform) { var rectangle = new Rectangle( worldTransform.Offset.X + this.x, worldTransform.Offset.Y + this.y, this.width, this.height) .Scale(camera.ZoomFactor) .Translate(camera.GetSceneTranslationVector(worldTransform.ParallaxScrollingVector)); return rectangle.Intercept(position) ? new RectangleHit(this) : null; }
public HitBase GetHit(Vector position, ICamera camera, WorldTransform worldTransform) { for (var i = 0; i < this.MapSize.Width; i++) for (var j = 0; j < this.MapSize.Height; j++) { var hexDistance = this.HexSize.Width - (this.HexSize.Width - this.TopEdgeLength) / 2; var halfHeight = this.HexSize.Height / 2; var rectangle = new Rectangle( this.Offset.X + i * hexDistance, this.Offset.Y + j * this.HexSize.Height + (i % 2 == 1 ? halfHeight : 0), this.HexSize.Width, this.HexSize.Height); var mapPosition = position .Translate(-camera.GetSceneTranslationVector(this.ParallaxScrollingVector)) .Scale(1.0f / camera.ZoomFactor); var x1 = (this.HexSize.Width - this.TopEdgeLength) / 2; var x2 = x1 + this.TopEdgeLength; var polygone = new[] { new Vector(rectangle.X + x1, rectangle.Y), new Vector(rectangle.X + x2, rectangle.Y), new Vector(rectangle.X + this.HexSize.Width, rectangle.Y + halfHeight), new Vector(rectangle.X + x2, rectangle.Y + this.HexSize.Height), new Vector(rectangle.X + x1, rectangle.Y + this.HexSize.Height), new Vector(rectangle.X, rectangle.Y + halfHeight) }; if (MathUtil.IsHitPolygone(polygone, mapPosition)) return new HexHit(new Point(i, j)); } return null; }
public HitBase GetHit(Vector position, ICamera camera, WorldTransform worldTransform) { for (var i = 0; i < this.MapSize.Width; i++) for (var j = 0; j < this.MapSize.Height; j++) { var tileRectangle = new Rectangle( this.Offset.X + i * this.TileSize.Width, this.Offset.Y + j * this.TileSize.Height, this.TileSize.Width, this.TileSize.Height) .Scale(camera.ZoomFactor) .Translate(camera.GetSceneTranslationVector(this.ParallaxScrollingVector)); if (tileRectangle.Intercept(position)) return new TileHit(new Point(i, j)); } return null; }
public HitBase GetHit(Vector position, ICamera camera, WorldTransform worldTransform, Sprite sprite) { var source = this.definitions[sprite.SpriteName]; var spriteRectangle = new Rectangle( worldTransform.Offset.X + sprite.Position.X, worldTransform.Offset.X + sprite.Position.Y, source.Rectangle.Width, source.Rectangle.Height) .Scale(camera.ZoomFactor) .Translate(camera.GetSceneTranslationVector(worldTransform.ParallaxScrollingVector)); return spriteRectangle.Intercept(position) ? new SpriteHit(sprite) : null; }