public CollisionTestSettings(Type entityType, CollisionBoxType myBoxType, CollisionBoxType otherBoxType, float maxZDistance = 10) { this.requiredType = entityType; this.collisionBoxType1 = myBoxType; this.collisionBoxType2 = otherBoxType; this.requiredFlags = PhysicsFlags.None; this.maxZDistance = maxZDistance; }
public bool IsMeetingEntity(Entity other, CollisionBoxType collisionBoxType, int maxZDistance = 10) { if (collisionBoxType == CollisionBoxType.Hard) { return(IsHardMeetingEntity(other)); } return(IsSoftMeetingEntity(other, maxZDistance)); }
//----------------------------------------------------------------------------- // Custom Collision Setup //----------------------------------------------------------------------------- public Rectangle2F GetCollisionBox(CollisionBoxType type) { if (type == CollisionBoxType.Hard) { return(collisionBox); } return(softCollisionBox); }
public CollisionBox(Player player) { this.player = null; type = CollisionBoxType.Attackbox; color = Color.White; rectangle = new Rectangle(0, 0, 0, 0); damage = 0; knockBack = 0; }
public CollisionTestSettings(Type entityType, Rectangle2F myBox, Rectangle2F otherBox, float maxZDistance = 10) { this.requiredType = entityType; this.collisionBox1 = myBox; this.collisionBox2 = otherBox; this.collisionBoxType1 = CollisionBoxType.Custom; this.collisionBoxType2 = CollisionBoxType.Custom; this.requiredFlags = PhysicsFlags.None; this.maxZDistance = maxZDistance; }
// Return a list of entities colliding with this entity. public IEnumerable <T> GetEntitiesMeeting <T>(Rectangle2I myCollisionBox, CollisionBoxType otherCollisionBoxType, int maxZDistance = 10) where T : Entity { CollisionTestSettings settings = new CollisionTestSettings(typeof(T), myCollisionBox, otherCollisionBoxType, maxZDistance); for (int i = 0; i < entity.RoomControl.Entities.Count; i++) { T other = entity.RoomControl.Entities[i] as T; if (other != null && CollisionTest.PerformCollisionTest(entity, other, settings).IsColliding) { yield return(other); } } }
// Return a list of tiles colliding with this entity (solidity is ignored). public IEnumerable <Tile> GetTilesMeeting(Vector2F position, CollisionBoxType collisionBoxType) { // Find the rectangular area of nearby tiles to collide with. Rectangle2F myBox = GetCollisionBox(collisionBoxType); myBox.Point += position; myBox.Inflate(2, 2); Rectangle2I area = entity.RoomControl.GetTileAreaFromRect(myBox, 1); // Iterate the tiles in the area. foreach (Tile t in entity.RoomControl.GetTilesInArea(area)) { if (t.CollisionModel != null && CollisionModel.Intersecting(t.CollisionModel, t.Position, collisionBox, position)) { yield return(t); } } }
private Point2I ledgeTileLocation; // The tile location of the ledge we are currently passing over, or (-1, -1) if not passing over ledge. //----------------------------------------------------------------------------- // Constructors //----------------------------------------------------------------------------- // By default, physics are disabled. public PhysicsComponent(Entity entity) { this.isEnabled = false; this.flags = PhysicsFlags.None; this.entity = entity; this.velocity = Vector2F.Zero; this.zVelocity = 0.0f; this.previousVelocity = Vector2F.Zero; this.previousZVelocity = 0.0f; this.gravity = GameSettings.DEFAULT_GRAVITY; this.maxFallSpeed = GameSettings.DEFAULT_MAX_FALL_SPEED; this.collisionBox = new Rectangle2F(-1, -1, 2, 2); this.softCollisionBox = new Rectangle2F(-1, -1, 2, 2); this.topTile = null; this.isColliding = false; this.autoDodgeDistance = 6; this.autoDodgeSpeed = 1.0f; this.hasLanded = false; this.reboundVelocity = Vector2F.Zero; this.ledgeAltitude = 0; this.ledgeTileLocation = new Point2I(-1, -1); this.roomEdgeCollisionBoxType = CollisionBoxType.Hard; this.crushMaxGapSize = 0; this.edgeClipAmount = 1; this.collisionInfo = new CollisionInfo[Directions.Count]; this.previousCollisionInfo = new CollisionInfo[Directions.Count]; for (int i = 0; i < Directions.Count; i++) { collisionInfo[i].Clear(); previousCollisionInfo[i].Clear(); } this.MovementCollisions = new bool[4]; this.ClipCollisionInfo = new CollisionInfoNew[4]; for (int i = 0; i < 4; i++) { ClipCollisionInfo[i] = new CollisionInfoNew(); } }
public bool IsCollidingWith(Entity other, CollisionBoxType myBoxType, CollisionBoxType otherBoxType, int maxZDistance = 10) { return(CollisionTest.PerformCollisionTest(entity, other, new CollisionTestSettings(null, myBoxType, otherBoxType, maxZDistance)).IsColliding); }
public bool IsCollidingWith(Entity other, CollisionBoxType collisionBoxType, int maxZDistance = 10) { return(IsCollidingWith(other, collisionBoxType, collisionBoxType, maxZDistance)); }
//----------------------------------------------------------------------------- // Collision Iteration //----------------------------------------------------------------------------- public IEnumerable <Tile> GetTilesMeeting(CollisionBoxType collisionBoxType) { return(GetTilesMeeting(entity.Position, collisionBoxType)); }