/// <summary> /// Collide against a Masklist. /// </summary> /// <param name="other"></param> /// <returns></returns> protected Boolean collideMasklist(Mask other) { Masklist m = (Masklist)other; return other.collide(this); }
/// <summary> /// Checks for collision with another Mask. /// </summary> /// <param name="mask">The other Mask to check against.</param> /// <returns>If the Masks overlap.</returns> public Boolean collide(Mask mask) { if (_check[mask._class] != null) return _check[mask._class](mask); if (mask._check[_class] != null) return mask._check[_class](this); return false; }
/// <summary> /// Constructor. Can be usd to place the Entity and assign a graphic and mask. /// </summary> /// <param name="x">X position to place the Entity.</param> /// <param name="y">Y position to place the Entity.</param> /// <param name="graphic">Graphic to assign to the Entity.</param> /// <param name="mask">Mask to assign to the Entity.</param> public Entity(float x = 0, float y = 0, Graphic graphic = null, Mask mask = null) { this.x = x; this.y = y; if (graphic != null) { this.graphic = graphic; } if (mask != null) { this.mask = mask; } HITBOX.assignTo(this); _class = this.GetType().FullName; }
/// <summary> /// Collide against an Entity. /// </summary> /// <param name="other"></param> /// <returns></returns> private Boolean collideMask(Mask other) { return parent.x - parent.originX + parent.width > other.parent.x - other.parent.originX && parent.y - parent.originY + parent.height > other.parent.y - other.parent.originY && parent.x - parent.originX < other.parent.x - other.parent.originX + other.parent.width && parent.y - parent.originY < other.parent.y - other.parent.originY + other.parent.height; }
/// <summary> /// Adds an Entity to the World with the Mask object. /// </summary> /// <param name="mask">Mask to assign the Entity.</param> /// <param name="type">Collision type of the Entity.</param> /// <param name="x">X position of the Entity.</param> /// <param name="y">Y position of the Entity.</param> /// <returns>The Entity that was added.</returns> public Entity addMask(Mask mask, string type, float x = 0, float y = 0) { Entity e = new Entity(x, y, null, mask); if (type != null) { e.type = type; } e.active = e.visible = false; return add(e); }