Esempio n. 1
0
        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);
     }
 }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        protected void Collide(ICollideable other)
        {
            Parent.Destroy();
            var asteroid = CreateOnScene <Asteroid>(Transform.Position + Transform.Direction);

            asteroid.Velocity            = Velocity;
            asteroid.Transform.Direction = Transform.Direction;
        }
Esempio n. 5
0
        private void OnCollided(ICollideable sender, Entities.IFlyEntity colidee)
        {
            var entity = colidee as IGatheringEntity;

            if (entity != null)
            {
                this.OnPickedUp(entity);
            }
        }
Esempio n. 6
0
        private void OnCollided(ICollideable sender, IFlyEntity other)
        {
            var damageEntity = other as IDamageEntity;

            if (damageEntity != null)
            {
                this.OnHit(damageEntity.Damaging);
            }
        }
Esempio n. 7
0
        public void Add(ICollideable shape)
        {
            if (shape.HasNode(hash))
            {
                return;
            }

            Bodies.Add(shape);
            shape.AddNode(hash);
        }
Esempio n. 8
0
 public override void GetCollided(ICollideable collider)
 {
     base.GetCollided(collider);
     if (this.IsCollideable())
     {
         if (collider.GetType() == typeof(Rat))
         {
             this.Die();
         }
     }
 }
Esempio n. 9
0
 public override void GetCollided(ICollideable collider)
 {
     if (collider.GetType() == typeof(Rat))
     {
         Console.WriteLine($"{this.ToString()} survived to rat attack");
     }
     else
     {
         this.Nuisible.GetCollided(collider);
     }
 }
Esempio n. 10
0
 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");
         }
     }
 }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
 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));
        }
Esempio n. 14
0
        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);
            }
        }
Esempio n. 15
0
 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);
     }
 }
Esempio n. 16
0
 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;
     }
 }
Esempio n. 17
0
        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;
                }
            }
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
 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);
     }
 }
Esempio n. 21
0
        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]);
                    }
                }
            }
        }
Esempio n. 22
0
 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;
     }
 }
Esempio n. 23
0
 public virtual void OnCollisionExit(ICollideable other)
 {
 }
Esempio n. 24
0
 public static void AddCollideableEntity(ICollideable entity)
 {
     collideableEntities.Add(entity);
 }
Esempio n. 25
0
        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;
        }
Esempio n. 26
0
 public static void AddObject(ICollideable obj)
 {
     CollisionManager.GetManager.collideableObjects.Add(obj);
 }
Esempio n. 27
0
 public bool RegisterCollisionBody(ICollideable coll)
 {
     return collideables.Add(coll);
 }
Esempio n. 28
0
 public bool UnregisterPhysicsBody(ICollideable coll)
 {
     return collideables.Remove(coll);
 }
Esempio n. 29
0
 public virtual void OnCollisionEnter(ICollideable other)
 {
 }
Esempio n. 30
0
 public virtual void OnCollisionStay(ICollideable other)
 {
 }
Esempio n. 31
0
 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;
 }
Esempio n. 33
0
 private void Collide(ICollideable other)
 {
     Parent.Destroy();
 }
Esempio n. 34
0
 public virtual void OnCollisionExit(ICollideable obj)
 {
 }
Esempio n. 35
0
        protected float? DistanceToIntersect(Ray ray, ICollideable gameObject)
        {
            BoundingSphere sphere = gameObject.GeometryData.BoundingSphere;
            sphere = sphere.Transform(gameObject.GeometryData.Prim.Transform);

            return  Ray.Intersects(sphere);
        }
Esempio n. 36
0
 public bool CollidesWith(ICollideable Collider)
 {
     return(Bounds.Intersects(Collider.Bounds));
 }
Esempio n. 37
0
 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;
     }
 }
Esempio n. 38
0
 public CollisionPair(ICollideable A, ICollideable B)
 {
     this.A = A;
     this.B = B;
 }
Esempio n. 39
0
 public bool CollidesWith(ICollideable other)
 {
     return(other.Positions.Any(p => p == Position));
 }
Esempio n. 40
0
 public Rectangle CollisionTest(ICollideable A, ICollideable B){
     return BroadCheck(A, B);
 }
Esempio n. 41
0
 public bool CollidesWith(ICollideable other)
 {
     return(GetBoundingBox().Intersects(other.GetBoundingBox()));
 }
Esempio n. 42
0
 public CollisionInfo(ICollideable obj, Rectangle intersection, Vector2 point)
 {
     this.collidingObject = obj;
     this.collisionRect = intersection;
     this.collisionPoint = point;
 }