public Potion(IShapeF bounds, Vector2 position, Texture2D texture) { Bounds = bounds; this.texture = texture; this.position = position; this.srcRect = new Rectangle(0, 0, texture.Width, texture.Height); }
public Player(SpriteSheet spriteSheet, Vector2 position, OrthographicCamera camera, ProgressBar fixProgress) { // Movement and Position parameters _movement = new Vector2(0f, 0f); _velocity = new Vector2(0f, 0f); _position = position; // Sprite parameters _sprite = new AnimatedSprite(spriteSheet); _currentAnimation = "idleRight"; _sprite.Play(_currentAnimation); // Sets local (player) _camera _camera = camera; // Collision Parameters Vector2 boundsStartPos = position; boundsStartPos.X -= _sprite.TextureRegion.Width / 4; Bounds = new RectangleF(boundsStartPos, new Size2(_sprite.TextureRegion.Width / 2, _sprite.TextureRegion.Height / 2)); // Progress bar parameter _fixProgress = fixProgress; Vector2 progressBarPos = _fixProgress.GetPosition(); progressBarPos.Y -= _sprite.TextureRegion.Height; _fixProgress.SetPosition(progressBarPos); _fixProgress.SetActive(false); // Health paramter _currentHp = _maxHp; }
private List <QuadtreeData> QueryWithoutReset(IShapeF area) { var result = new List <QuadtreeData>(); if (!NodeBounds.Intersects(area)) { return(result); } if (IsLeaf) { for (int i = 0, size = Contents.Count; i < size; i++) { if (Contents[i].Bounds.Intersects(area) && !Contents[i].Flag) { result.Add(Contents[i]); Contents[i].Flag = true; } } } else { for (int i = 0, size = Children.Count; i < size; i++) { var recurse = Children[i].QueryWithoutReset(area); result.AddRange(recurse); } } return(result); }
/// <summary> /// Over de Draw /// </summary> public static void Draw (this SpriteBatch bat, Texture2D texture, IShapeF shape, Color color) { bat.Draw (texture, shape.GetBoundingRectangle (), color); }
private void QueryWithoutReset(IShapeF area, List <QuadtreeData> recursiveResult) { if (!NodeBounds.Intersects(area)) { return; } if (IsLeaf) { foreach (QuadtreeData quadtreeData in Contents) { if (quadtreeData.Dirty == false && quadtreeData.Bounds.Intersects(area)) { recursiveResult.Add(quadtreeData); quadtreeData.MarkDirty(); } } } else { for (int i = 0, size = Children.Count; i < size; i++) { Children[i].QueryWithoutReset(area, recursiveResult); } } }
{/// <summary> /// Check if two shapes intersect. /// </summary> /// <param name="a">The first shape.</param> /// <param name="b">The second shape.</param> /// <returns>True if the two shapes intersect.</returns> public static bool Intersects(this IShapeF a, IShapeF b) { var intersects = false; if (a is RectangleF rectA && b is RectangleF rectB) { intersects = rectA.Intersects(rectB); }
public Flyer(Room room, IShapeF bounds, Texture2D texture) { this.room = room; Bounds = bounds; this.texture = texture; this.srcRect = new Rectangle(0, 0, texture.Width, texture.Height); PotionDropProbability = 0.4f; }
/// <summary> /// Check if two shapes intersect. /// </summary> /// <param name="shapeA">The first shape.</param> /// <param name="shapeB">The second shape.</param> /// <returns>True if the two shapes intersect.</returns> public static bool Intersects(this IShapeF shapeA, IShapeF shapeB) { var intersects = false; if (shapeA is RectangleF rectangleA && shapeB is RectangleF rectangleB) { intersects = rectangleA.Intersects(rectangleB); }
protected void CreateBoundsShape() { // Translates position into Transform and then converts that to a RectangleF; // Used to get correct sprite bounds for collision detection Transform2 transform = new Transform2(_position); RectangleF rectangle = _sprite.GetBoundingRectangle(transform); Bounds = rectangle; }
/// <summary> /// Queries the quadtree for targets that intersect with the given area. /// </summary> /// <param name="area">The area to query for overlapping targets</param> /// <returns>A unique list of targets intersected by area.</returns> public List <QuadtreeData> Query(IShapeF area) { var recursiveResult = new List <QuadtreeData>(); QueryWithoutReset(area, recursiveResult); for (var i = 0; i < recursiveResult.Count; i++) { recursiveResult[i].MarkClean(); } return(recursiveResult); }
public GameWorldArea(TiledMapObject obj) { this.details = obj; this.ID = obj.Identifier; this.bounds = null; if (obj is TiledMapPolygonObject) { var polyObj = (TiledMapPolygonObject)obj; var polygon = new PolygonF(polyObj.Points.Select(x => new Vector2(x.X, x.Y))); polygon.Offset(new Vector2(polyObj.Position.X, polyObj.Position.Y)); this.bounds = polygon; } else if (obj is TiledMapRectangleObject) { var rectObj = (TiledMapRectangleObject)obj; this.bounds = new RectangleF((int)rectObj.Position.X, (int)rectObj.Position.Y, (int)rectObj.Size.Width, (int)rectObj.Size.Height); } else { throw new ArgumentException("Invalid GameMapArea"); } if (obj.Properties != null) { String lifeDegen, speedModifier, slippery; if (obj.Properties.TryGetValue("life_degeneration", out lifeDegen)) { this.degenerationRatio = float.Parse(lifeDegen, CultureInfo.InvariantCulture); } if (obj.Properties.TryGetValue("speed_modifier", out speedModifier)) { this.speedModifier = float.Parse(speedModifier, CultureInfo.InvariantCulture); } else { this.speedModifier = 1.0f; } if (obj.Properties.TryGetValue("slippery", out slippery)) { this.slippery = Boolean.Parse(slippery); } } }
/// <summary> /// Calculate a's penetration into b /// </summary> /// <param name="a">The penetrating shape.</param> /// <param name="b">The shape being penetrated.</param> /// <returns>The distance vector from the edge of b to a's Position</returns> public static Vector2 CalculatePenetrationVector(this IShapeF a, IShapeF b) { if (!a.Intersects(b)) { return(Vector2.Zero); } var penetrationVector = a switch { RectangleF rectA when b is RectangleF rectB => PenetrationVector(rectA, rectB), CircleF circA when b is CircleF circB => PenetrationVector(circA, circB), CircleF circA when b is RectangleF rectB => PenetrationVector(circA, rectB), RectangleF rectA when b is CircleF circB => PenetrationVector(rectA, circB), _ => throw new NotSupportedException("Shapes must be either a CircleF or RectangleF") }; return(penetrationVector); }
/// <summary> /// Calculate a's penetration into b /// </summary> /// <param name="a">The penetrating shape.</param> /// <param name="b">The shape being penetrated.</param> /// <returns>The distance vector from the edge of b to a's Position</returns> private static Vector2 CalculatePenetrationVector(IShapeF a, IShapeF b) { switch (a) { case RectangleF rectA when b is RectangleF rectB: return(PenetrationVector(rectA, rectB)); case CircleF circA when b is CircleF circB: return(PenetrationVector(circA, circB)); case CircleF circA when b is RectangleF rectB: return(PenetrationVector(circA, rectB)); case RectangleF rectA when b is CircleF circB: return(PenetrationVector(rectA, circB)); } throw new NotSupportedException("Shapes must be either a CircleF or RectangleF"); }
public Door(BOIC game, RectangleF displayShape, Direction direction) { this.game = game; this.direction = direction; Bounds = new RectangleF(new Point2(displayShape.X - (displayShape.Width / 2), displayShape.Y - (displayShape.Height / 2)), new Size2(displayShape.Width, displayShape.Height)); _particleTexture = new Texture2D(game.GraphicsDevice, 1, 1); _particleTexture.SetData(new[] { Color.White }); TextureRegion2D textureRegion = new TextureRegion2D(_particleTexture); _particleEffect = new ParticleEffect(autoTrigger: false) { Position = displayShape.Position, Emitters = new List <ParticleEmitter> { new ParticleEmitter(textureRegion, 500, TimeSpan.FromSeconds(2.5), Profile.BoxUniform(displayShape.Width, displayShape.Height)) { Parameters = new ParticleReleaseParameters { Speed = new Range <float>(0f, 75f), Quantity = 3, Rotation = new Range <float>(-1f, 1f), Scale = new Range <float>(3.0f, 4.0f) }, Modifiers = { new RotationModifier { RotationRate = -2.1f }, new RectangleContainerModifier { Width = (int)displayShape.Width, Height = (int)displayShape.Height, RestitutionCoefficient = 0.1f }, new LinearGravityModifier { Direction = -Vector2.UnitY, Strength = 30f }, } } } }; }
public Wall(Vector2 point1, Vector2 point2, IShapeF Bounds) { this.point1 = point1; this.point2 = point2; this.Bounds = Bounds; }
/// <summary> /// Queries the quadtree for targets that intersect with the given area. /// </summary> /// <param name="area">The area to query for overlapping targets</param> /// <returns>A unique list of targets intersected by area.</returns> public List <QuadtreeData> Query(IShapeF area) { Reset(); return(QueryWithoutReset(area)); }
public Wall(Vector2 position, Size2 size) { RectangleF r = new RectangleF(position, size); Bounds = r; }
public RectangleCollider(RectangleF bounds) { Bounds = bounds; }
public override void LoadContent(ContentManager contentManager) { _texture = contentManager.Load <Texture2D>("Paddle/Paddle"); Bounds = new RectangleF(Position.X - (_texture.Width / 2), Position.Y, _texture.Width, _texture.Height); }
public MapBoundary(IShapeF Bounds) { this.Bounds = Bounds; }
public static Vector2 GetSupportVector(this IShapeF shape, Vector2 direction) => shape switch {
/// <summary> /// Inicaliza un <see cref="Botón"/> de una forma arbitraria. /// </summary> /// <param name="screen">Screen.</param> /// <param name="shape">Forma del botón</param> public Botón (Moggle.Screens.IScreen screen, IShapeF shape) : this (screen) { Bounds = shape; }