Ejemplo n.º 1
0
 public override void Collide(Entity entity, EntityCategory entityCategory)
 {
     if (isExploded)
     {
         return;
     }
     Explosion();
     foreach (Entity entity1 in scene.entities)
     {
         if (entity1 == this)
         {
             continue;
         }
         if (CollisionCheck.CheckCollision(new RotRectangle(hitbox.RotationRad, hitbox.Center, new Vector2(120, 120)), entity1.Hitbox))
         {
             if (entity1.GetType() == typeof(Player) || entity1.GetType() == typeof(Cargo))
             {
                 entity1.TakeDamage(1);
             }
             else
             {
                 entity1.TakeDamage(damage);
             }
         }
     }
 }
Ejemplo n.º 2
0
        private void Search(Vector2 position, float pathWidth, Vector2 target, List <Vector2> path)
        {
            if (path.Count > 5)
            {
                return;
            }

            Vector2 direction = target - position;
            float   angle     = Geometry.DegToRad(1);

            while (true)
            {
                float distance         = 0;
                int   collisionCount   = 0;
                float shortestDistance = 0;// int.MaxValue;
                foreach (WorldObject worldObject in worldObjects)
                {
                    if (CollisionCheck.CheckCollision(position, direction, pathWidth, worldObject.Hitbox))
                    {
                        distance = Vector2.Distance(position, worldObject.Hitbox.Center);
                        if (collisionCount == 0)
                        {
                            shortestDistance = distance;
                        }

                        if (distance < shortestDistance)
                        {
                            shortestDistance = distance;
                        }
                        collisionCount++;
                    }
                }
                if (collisionCount > 0)
                {
                    direction.Normalize();
                    direction *= shortestDistance;
                    direction  = Geometry.Rotate(direction, angle);
                    angle     *= -1.2f;
                    if (angle > Math.PI)
                    {
                        return;
                    }
                }
                else
                {
                    position += direction;
                    path.Add(position);
                    if (Vector2.Distance(position, target) < 10)
                    {
                        return;
                    }
                    Search(position, pathWidth, target, path);
                    return;
                }
            }
        }
Ejemplo n.º 3
0
 private bool CheckCollisions(RotRectangle hitbox)
 {
     //if (worldObjects.Count == 0) return false;
     foreach (RotRectangle playerSpawnPosition in spawnPositons)
     {
         if (CollisionCheck.CheckCollision(hitbox, playerSpawnPosition))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
 private bool CheckCollisions(WorldObject worldObject1, List <WorldObject> worldObjects)
 {
     if (worldObjects.Count == 0)
     {
         return(false);
     }
     foreach (WorldObject worldObject in worldObjects)
     {
         if (worldObject.Equals(worldObject1))
         {
             continue;
         }
         if (CollisionCheck.CheckCollision(worldObject1.Hitbox, worldObject.Hitbox))
         {
             return(true);
         }
     }
     return(false);
 }