public void Add(Mask mask) { RectangleFP rect = mask.Bounds; FPInt minx = FPMath.Min(_bounds.Left, rect.Left); FPInt maxx = FPMath.Max(_bounds.Right, rect.Right); FPInt miny = FPMath.Min(_bounds.Top, rect.Top); FPInt maxy = FPMath.Min(_bounds.Bottom, rect.Bottom); _bounds = new RectangleFP(minx, miny, maxx - minx, maxy - miny); _components.Add(mask); }
public CompositeMask(Mask mask) { _type = MaskType.Point; _pos = mask.Position; _bounds = mask.Bounds; if (mask is CompositeMask) { _components = new List<Mask>((mask as CompositeMask)._components); } else { _components = new List<Mask>(); _components.Add(mask); } }
/*public override void Draw (SpriteBatch spriteBatch, Pen pen) { int x = (int)(_pos.X + _point.X); int y = (int)(_pos.Y + _point.Y); Draw2D.DrawRectangle(spriteBatch, new Rectangle(x, y, (int)_w, (int)_h), pen); }*/ public override bool TestOverlap(Mask mask) { switch (mask._type) { case MaskType.Point: return Collision.TestOverlap(mask as PointMask, this); case MaskType.Circle: return Collision.TestOverlap(mask as CircleMask, this); case MaskType.AXLine: return Collision.TestOverlap(mask as AXLineMask, this); case MaskType.AYLine: return Collision.TestOverlap(mask as AYLineMask, this); case MaskType.Line: return Collision.TestOverlap(mask as LineMask, this); case MaskType.AABB: return Collision.TestOverlap(this, mask as AABBMask); case MaskType.Triangle: return Collision.TestOverlap(this, mask as TriangleMask); case MaskType.Composite: return Collision.TestOverlap(this, mask as CompositeMask); } return false; }
public bool OverlapsEdgeAny(Mask mask) { RectangleFP rect = mask.Bounds; int minXId = (int)(rect.Left / _tileWidth); int maxXId = (int)(rect.Right / _tileWidth); int minYId = (int)(rect.Top / _tileHeight); int maxYId = (int)(rect.Bottom / _tileHeight); for (int x = minXId; x <= maxXId; x++) { if (x >= _width || x < 0) continue; for (int y = minYId; y <= maxYId; y++) { if (y >= _height || y < 0) continue; if (_grid[x, y] == null) { continue; } if (_grid[x, y].TestOverlapEdge(mask)) { return true; } } } return false; }
private Mask BuildCom(Mask m1, Mask m2) { CompositeMask com = new CompositeMask(m1); com.Add(m2); return com; }
public static bool TestOverlap(CompositeMask comMask, Mask mask) { return TestOverlap(mask, comMask); }
public static bool TestOverlap(Mask mask, CompositeMask comMask) { if (!mask.Bounds.Intersects(comMask.Bounds)) { return false; } foreach (Mask m in comMask._components) { if (mask.TestOverlap(m)) { return true; } } return false; }
public Collidable(Mask mask) { CollisionMask = mask; }
protected override void Load() { StaticSprite frame1 = new StaticSprite(); StaticSprite frame2 = new StaticSprite(); frame1.Load(Parent.Engine.Content, "Froggy", new Rectangle(0, 0, 34, 29)); frame1.Origin = new Vector2(17, 28); frame2.Load(Parent.Engine.Content, "Froggy", new Rectangle(34, 0, 34, 29)); frame2.Origin = new Vector2(18, 28); frame1.Scale = 2f; frame2.Scale = 2f; _sequence.Scale = 2f; _sequence.AddSprite(frame1, 0.5f); _sequence.AddSprite(frame2, 0.5f); _sequence.RepeatIndefinitely = true; _sequence.Start(); //_mask = new CircleMask(new PointFP(8, 8), 10); _mask = new AABBMask(new PointFP(-16, -32), new PointFP(16, 0)); _mask.Position = _position; Dictionary<PlatformAction, PlatformAction> cmap = new Dictionary<PlatformAction, PlatformAction>(); cmap[PlatformAction.Left] = PlatformAction.Left; cmap[PlatformAction.Right] = PlatformAction.Right; cmap[PlatformAction.Up] = PlatformAction.Up; cmap[PlatformAction.Down] = PlatformAction.Down; cmap[PlatformAction.Jump] = PlatformAction.Jump; cmap[PlatformAction.Action] = PlatformAction.Action; /*PaddleMovement<PaddleAction> behavior = new PaddleMovement<PaddleAction>(this, "player", cmap); behavior.Origin = new Vector2(400, 200); behavior.Range = 100; behavior.Speed = 120; behavior.Direction = PaddleDirection.Vertical; AddBehavior(behavior);*/ /*PlayerPlatformMovement<PlatformAction> behavior = new PlayerPlatformMovement<PlatformAction>(this, "player", cmap); behavior.AccelX = (FPInt)0.5; behavior.DecelX = (FPInt)0.25; behavior.MinVelocityX = (FPInt)(-3); behavior.MaxVelocityX = (FPInt)3; behavior.AccelY = (FPInt)0.4; behavior.MinVelocityY = -12; behavior.MaxVelocityY = 12; behavior.AccelStateY = PlatformAccelState.Accelerate;*/ //AddBehavior(behavior); CircleMovement circle = new CircleMovement(this, new PointFP(300, 300), 150, 1); AddBehavior(circle); }
public abstract bool TestOverlapEdge(Mask mask);