public int Retrieve(ref ICollideable[] shapes, ICollideable shape) { int ll = 0; Entity a = shape.GetEntity(); Entity b; for (int i = 0; i < a.Nodes.Count; i++) { _node = Nodes[a.Nodes[i]]; for (int j = 0; j < _node.Bodies.Count; j++) { _temp = _node.Bodies[j]; b = _temp.GetEntity(); if (Phys2D.MaskHasLayer(a.Type, b.Type) && !shapes.ContainsID(b.ID, ll)) { shapes[ll] = _temp; ll++; if (ll >= shapes.Length) { return(ll); } } } } return(ll); }
public void Collide(ICollideable other) { if (Collided != null) { Collided(other); } }
private void PlayerAttackCollision(ICollideable collision, IEnemy roomEnemy) { if (!_player.Alive || _enemiesAttackThrottle.ContainsKey(roomEnemy) || !collision.CollidesWith(roomEnemy.Bounds)) { return; } collision.EnemyEffect(roomEnemy).Execute(); _enemiesAttackThrottle[roomEnemy] = ThrottleFrameDuration; if (roomEnemy.Alive) { return; } if (--_enemyCount == 0) { foreach (var door in _room.Doors.Values) { door.Activate(); } } if (roomEnemy is Stalfos || roomEnemy is Goriya || roomEnemy is WallMaster) { AddDroppedItem(roomEnemy.Bounds.Location); } }
protected void Collide(ICollideable other) { Parent.Destroy(); var asteroid = CreateOnScene <Asteroid>(Transform.Position + Transform.Direction); asteroid.Velocity = Velocity; asteroid.Transform.Direction = Transform.Direction; }
private void OnCollided(ICollideable sender, Entities.IFlyEntity colidee) { var entity = colidee as IGatheringEntity; if (entity != null) { this.OnPickedUp(entity); } }
private void OnCollided(ICollideable sender, IFlyEntity other) { var damageEntity = other as IDamageEntity; if (damageEntity != null) { this.OnHit(damageEntity.Damaging); } }
public void Add(ICollideable shape) { if (shape.HasNode(hash)) { return; } Bodies.Add(shape); shape.AddNode(hash); }
public override void GetCollided(ICollideable collider) { base.GetCollided(collider); if (this.IsCollideable()) { if (collider.GetType() == typeof(Rat)) { this.Die(); } } }
public override void GetCollided(ICollideable collider) { if (collider.GetType() == typeof(Rat)) { Console.WriteLine($"{this.ToString()} survived to rat attack"); } else { this.Nuisible.GetCollided(collider); } }
public virtual void GetCollided(ICollideable collider) { if (this.IsCollideable()) { Console.WriteLine($" {this.ToString()} is getting collided by {collider.ToString()}"); if (collider.GetType() == typeof(Zombie) && this.GetType() != typeof(Zombie)) { this.Zombify(); Console.WriteLine($" {this.ToString()} turned into a Zombie. B"); } } }
private bool PrepList(Collider shape, ICollideable host) { _tempNodes.Clear(); host.SetOOB(!Bounds.Overlaps(shape.bounds)); if (host.IsOOB()) { return(true); } AddToNode(shape.bounds.min - CenterOffsetRaw, shape.bounds.max - CenterOffsetRaw); return(false); }
public virtual void Collide(ICollideable collided) { if (this.IsCollideable()) { Console.WriteLine($" {this.ToString()} is colliding {collided.ToString()}"); collided.GetCollided(this); if (collided.GetType() == typeof(Zombie) && this.GetType() != typeof(Zombie)) { this.Zombify(); Console.WriteLine($" {this.ToString()} turned into a Zombie. A"); } } }
public bool Colide(ICollideable other) { Rectangle fRectangle = new Rectangle() { X = this.X, Y = this.Y, Height = this.Height, Width = this.Width }; Rectangle sRectangle = new Rectangle() { X = other.X, Y = other.Y, Height = other.Height, Width = other.Width }; return(fRectangle.IntersectsWith(sRectangle)); }
public void Update(Collider shape) { ICollideable host = shape.Host; bool skip = PrepList(shape, host); if (skip) { return; } for (int i = 0; i < _tempNodes.Count; i++) { Nodes[_tempNodes[i]].Add(host); } }
public bool Collides(ICollideable collider, int additionalOffset = 0) { if (this == collider) { return(false); } if (this.BoundingBox.X < collider.BoundingBox.X) { return(this.BoundingBox.X + this.BoundingBox.Width + additionalOffset >= collider.BoundingBox.X); } else { return(collider.BoundingBox.X + collider.BoundingBox.Width + additionalOffset >= this.BoundingBox.X); } }
public bool Collides(ICollideable collider, int additionalOffset = 0) { if (this == collider) { return false; } if(this.BoundingBox.X < collider.BoundingBox.X) { return this.BoundingBox.X + this.BoundingBox.Width + additionalOffset >= collider.BoundingBox.X; } else { return collider.BoundingBox.X + collider.BoundingBox.Width + additionalOffset >= this.BoundingBox.X; } }
public override void OnCollisionEnter(ICollideable other) { Entity ent = other.GetEntity(); if (ent.Type != EntityType.WORLD && ent.Type != EntityType.PLAYER) { ent.Despawn(false); switch (TakeDamage(ent.Damage)) { case 2: if (ent.Type == EntityType.BULLET_PLR) { int multiplier = Type == EntityType.ENEMY | Type == EntityType.ENEMY_MELEE ? 1 : 10; Player plr = Program.Player; plr.SpecialMeter += 0.00025f * MaxHealth; switch (Program.Difficulty) { case Difficulty.EASY: plr.Score += 10 * MaxHealth * multiplier; break; case Difficulty.MEDIUM: plr.Score += 25 * MaxHealth * multiplier; break; case Difficulty.HARD: plr.Score += 50 * MaxHealth * multiplier; break; case Difficulty.YOURE_DEAD: plr.Score += 100 * MaxHealth * multiplier; break; } } Die(); break; case 1: _hurtTimer = 0; _shouldFlash = true; Sprite = _damageSprite; break; } } }
private void PlayerAttackCollision(ICollideable collision, IEnemy roomEnemy) { if (!_player.Alive || _enemiesAttackThrottle.ContainsKey(roomEnemy) || !collision.CollidesWith(roomEnemy.Bounds)) { return; } collision.EnemyEffect(roomEnemy).Execute(); _enemiesAttackThrottle[roomEnemy] = ThrottleFrameDuration; if (roomEnemy.Alive) { return; } AddDroppedItem(roomEnemy.Bounds.Location); }
public List <CollisionEvent> GetCollisions(ICollideable player) { List <CollisionEvent> collisions = new List <CollisionEvent>(); foreach (ICollideable stationary in collideables) { if (stationary.CollidesWith(player)) { Vector2 depth = stationary.Bounds.GetIntersectionDepth(player.Bounds); float absDepthX = Math.Abs(depth.X); float absDepthY = Math.Abs(depth.Y); collisions.Add(new CollisionEvent(absDepthY < absDepthX ? CollisionSide.Vertical : CollisionSide.Horizontal, stationary, depth)); } } return(collisions); }
public bool CollidesForAttack(ICollideable collider, bool isMovingRight, int additionalXOffset = 0) { if ((collider as AttackingGameObject) != null) { if ((collider as AttackingGameObject).Health == 0) { return(false); } } if (this == collider || !this.Collides(collider, additionalXOffset)) { return(false); } if (isMovingRight) { return(this.Position.X < collider.Position.X); } else { return(this.Position.X > collider.Position.X); } }
private void CheckCollisions() { // Detect collisions for (int i = 0; i < objectsInScene.Count; i++) { ICollideable possibleCollideable = objectsInScene[i] as ICollideable; if (possibleCollideable == null) { continue; } if (!possibleCollideable.IsCurrentlyCollideable) { continue; } for (int j = i + 1; j < objectsInScene.Count; j++) { ICollideable secondCollideable = objectsInScene[j] as ICollideable; if (secondCollideable == null) { continue; } if (!secondCollideable.IsCurrentlyCollideable) { continue; } float distanceBetweenObjects = (float)(Math.Pow(objectsInScene[i].position.X - objectsInScene[j].position.X, 2) + Math.Pow(objectsInScene[i].position.Y - objectsInScene[j].position.Y, 2)); float sumOfRadii = (float)(Math.Pow(possibleCollideable.Radius + secondCollideable.Radius, 2)); if (distanceBetweenObjects < sumOfRadii) { possibleCollideable.Collided(objectsInScene[j]); secondCollideable.Collided(objectsInScene[i]); } } } }
public static void CenterRelativeToEdge(Rectangle origin, string edge, ICollideable toBeCentered) { if (edge == "up") { toBeCentered.X = origin.Center.X - toBeCentered.Hitbox.Width / 2; toBeCentered.Y = origin.Top - toBeCentered.Hitbox.Height; } else if (edge == "down") { toBeCentered.X = origin.Center.X - toBeCentered.Hitbox.Width / 2; toBeCentered.Y = origin.Bottom; } else if (edge == "right") { toBeCentered.X = origin.Right; toBeCentered.Y = origin.Center.Y - toBeCentered.Hitbox.Height / 2; } else if (edge == "left") { toBeCentered.X = origin.Left - toBeCentered.Hitbox.Width; toBeCentered.Y = origin.Center.Y - toBeCentered.Hitbox.Height / 2; } }
public virtual void OnCollisionExit(ICollideable other) { }
public static void AddCollideableEntity(ICollideable entity) { collideableEntities.Add(entity); }
protected Rectangle BroadCheck(ICollideable A, ICollideable B) { int xMin = Math.Max(A.Bounds.Left, B.Bounds.Left); int xMax = Math.Min(A.Bounds.Right, B.Bounds.Right); int yMin = Math.Max(A.Bounds.Top, B.Bounds.Top); int yMax = Math.Min(A.Bounds.Bottom, B.Bounds.Bottom); if (xMin <= xMax && yMin <= yMax) { return new Rectangle(xMin, yMin, xMax - xMin, yMax - yMin); } return Rectangle.Empty; }
public static void AddObject(ICollideable obj) { CollisionManager.GetManager.collideableObjects.Add(obj); }
public bool RegisterCollisionBody(ICollideable coll) { return collideables.Add(coll); }
public bool UnregisterPhysicsBody(ICollideable coll) { return collideables.Remove(coll); }
public virtual void OnCollisionEnter(ICollideable other) { }
public virtual void OnCollisionStay(ICollideable other) { }
private CollisionData ManageCollisions(CollisionDetector detect, ICollideable left, ICollideable right, float duration) { CollisionData data = new CollisionData(); data.restitution = this.Restitution; data.friction = this.Friction; detect.FindContacts(left.GeometryData.Prim, right.GeometryData.Prim, data); return data; }
public Collider(ICollideable host, Vector2 offset, ColliderBase[] colliders) { Host = host; Offset = offset; CollisionShapes = colliders; }
private void Collide(ICollideable other) { Parent.Destroy(); }
public virtual void OnCollisionExit(ICollideable obj) { }
protected float? DistanceToIntersect(Ray ray, ICollideable gameObject) { BoundingSphere sphere = gameObject.GeometryData.BoundingSphere; sphere = sphere.Transform(gameObject.GeometryData.Prim.Transform); return Ray.Intersects(sphere); }
public bool CollidesWith(ICollideable Collider) { return(Bounds.Intersects(Collider.Bounds)); }
public bool CollidesForAttack(ICollideable collider, bool isMovingRight, int additionalXOffset = 0) { if ((collider as AttackingGameObject) != null) { if ((collider as AttackingGameObject).Health == 0) { return false; } } if (this == collider || !this.Collides(collider, additionalXOffset)) { return false; } if (isMovingRight) { return this.Position.X < collider.Position.X; } else { return this.Position.X > collider.Position.X; } }
public CollisionPair(ICollideable A, ICollideable B) { this.A = A; this.B = B; }
public bool CollidesWith(ICollideable other) { return(other.Positions.Any(p => p == Position)); }
public Rectangle CollisionTest(ICollideable A, ICollideable B){ return BroadCheck(A, B); }
public bool CollidesWith(ICollideable other) { return(GetBoundingBox().Intersects(other.GetBoundingBox())); }
public CollisionInfo(ICollideable obj, Rectangle intersection, Vector2 point) { this.collidingObject = obj; this.collisionRect = intersection; this.collisionPoint = point; }