Exemplo n.º 1
0
 public bool IntersectsWith(ICollider collider)
 {
     if (collider.GetType() == typeof(BoxCollider))
     {
         return(IntersectsWith((BoxCollider)collider));
     }
     else if (collider.GetType() == typeof(CirlceCollider))
     {
         return(IntersectsWith((CirlceCollider)collider));
     }
     return(false);
 }
Exemplo n.º 2
0
        public bool IsCollide(ICollider Collider)
        {
            if (typeof(Circle) == Collider.GetType())
            {
                return(CircleCollision(Collider));
            }
            else if (typeof(Polygon) == Collider.GetType())
            {
                PolygonCollision(Collider);
            }

            return(false);
        }
Exemplo n.º 3
0
        public bool IsCollide(ICollider collider)
        {
            if (collider.GetType() == typeof(Circle))
            {
                return(CircleCollision(collider));
            }
            else if (collider.GetType() == typeof(Point))
            {
                return(PointCollision(collider));
            }

            return(false);
        }
Exemplo n.º 4
0
 public void EventMethod(ICollider collider)
 {
     if (collider.GetType() == typeof(Polygon))
     {
         MessageBox.Show("Collide", "Circle<>Linse", new string[] { "walsiw" });
     }
 }
Exemplo n.º 5
0
        public virtual void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
#if DEBUG
            Color color = Color.White;

            switch (this)
            {
            case Player _:
                color = Color.Green;
                break;

            case Coin _:
                color = Color.Red;
                break;

            case Wall _:
                color = Color.Blue;
                break;
            }

            if (Collider.Active)
            {
                spriteBatch.Draw(
                    Collider.GetType() == typeof(CollisionRectangle) ? game.pixel : game.circle,
                    Collider.ToRectangle(),
                    new Color(color, 20)
                    );
            }
#endif
        }
Exemplo n.º 6
0
        public void ItemPickedUp(ICollider collidable)
        {
            Type eType = collidable.GetType();

            switch (eType.Name)
            {
            case "BoomerangItem":
                inventory.Add(typeof(Boomerang));
                break;

            case "BowItem":
                inventory.Add(typeof(Bow));
                break;

            case "BombItem":
                inventory.Add(typeof(Bomb));
                bombCount += 1;
                break;

            case "DungeonKey":
                keyCount += 1;
                break;

            case "Heart":
                if (player.link_health == 5 || player.link_health == 6)
                {
                    player.link_health = 6;
                }
                else
                {
                    player.link_health += 2;
                }
                break;

            case "Rupee":
                rupeeCount += 1;
                break;

            case "Triforce":
                keyCount += 1;
                break;

            case "DungeonMap":
                inventory.Add(typeof(DungeonMap));
                break;

            default:
                Debug.Print("ERROR: could not find IEquipable. @ Inventory Manager.");
                break;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Dopisać testy jednostkowe
        /// </summary>
        /// <param name="collider"></param>
        /// <returns></returns>
        public bool IsCollide(ICollider collider)
        {
            bool isCollide = false;

            if (typeof(Circle) == collider.GetType())
            {
                isCollide = CircleCollision(collider);
            }
            else if (typeof(Line) == collider.GetType())
            {
                isCollide = LineCollision(collider);
            }
            else if (typeof(Polygon) == collider.GetType())
            {
                isCollide = PolygonCollision(collider);
            }

            if (isCollide == true && OnCollision != null)
            {
                OnCollision(collider);
            }

            return(isCollide);
        }
Exemplo n.º 8
0
        public bool IsCollide(ICollider Collider)
        {
            Type colliderType = Collider.GetType();

            if (colliderType == typeof(Point))
            {
                return(InteractionWithPoint(Collider));
            }
            else if (colliderType == typeof(Circle))
            {
                return(InteractionWithCircle(Collider));
            }

            return(false);
        }
Exemplo n.º 9
0
        public ICollider CollisionWith(ICollider collider)
        {
            if (collider is BoxCollider box)
            {
                return new BoxCollider
                       {
                           X      = Max(Min(X, X + Width), Min(box.X, box.X + box.Width)),
                           Y      = Max(Min(Y, Y + Height), Min(box.Y, box.Y + box.Height)),
                           Width  = IntersectLines(X, X + Width, box.X, box.X + box.Width),
                           Height = IntersectLines(Y, Y + Height, box.Y, box.Y + box.Height)
                       }
            }
            ;

            throw new ArgumentException("Неизвестный коллайдер " + collider.GetType());
        }

        IRectangle ICollider.AxisAlignedBoundingBox()
        {
            // Потому что Сергей не любит стрелочки, но любит философию
            return(this);
        }
Exemplo n.º 10
0
        public void HandleCollision(ICollider subject, ICollider target, CollisionSides side)
        {
            Type subjectType = subject.GetType();
            Type targetType  = target.GetType();

            if (targetType == typeof(EmptyRoomNotifier))
            {
                Console.WriteLine("die");
            }
            Tuple <Type, Type, CollisionSides> key = new Tuple <Type, Type, CollisionSides>(subjectType, targetType, side);

            if (keySet.Contains(key))
            {
                Type commandType = commandMap[key];
                Console.WriteLine(commandType);
                ICommand commandClass = parseConstructor(subject, target, side, commandType);

                if (commandClass != null)
                {
                    commandClass.Execute();
                }
            }
        }
Exemplo n.º 11
0
        public ICommand parseConstructor(ICollider subject, ICollider target, CollisionSides side, Type commandType)
        {
            Type targetType  = target.GetType();
            Type subjectType = subject.GetType();

            // Search for a valid constructor for this commandType.
            List <Type[]> signatures = new List <Type[]> {
                new Type[] { targetType },
                new Type[] { typeof(Game1) },
                new Type[] { targetType, typeof(CollisionSides) },
                new Type[] { targetType, typeof(Room) },
                new Type[] { subjectType, targetType, typeof(CollisionSides) },
                new Type[] { subjectType, targetType, typeof(Room) },
                new Type[] { typeof(Game1), subjectType, targetType, typeof(CollisionSides) },
            };

            ConstructorInfo commandConstructor = null;

            foreach (Type[] signature in signatures)
            {
                commandConstructor = commandType.GetConstructor(signature);
                if (commandConstructor != null)
                {
                    break;
                }
            }
            if (commandConstructor == null)
            {
                return(null);
            }

            // Now invoke the constructor.
            switch (commandConstructor.GetParameters().Length)
            {
            case 1:
                if (commandConstructor.GetParameters()[0].ParameterType == typeof(Game1))
                {
                    return((ICommand)commandConstructor.Invoke(new object[] { myGame }));
                }
                else
                {
                    return((ICommand)commandConstructor.Invoke(new object[] { target }));
                }

            case 2:
                if (commandConstructor.GetParameters()[1].ParameterType == typeof(Room))
                {
                    return((ICommand)commandConstructor.Invoke(new object[] { target, myRoom }));
                }
                else
                {
                    return((ICommand)commandConstructor.Invoke(new object[] { target, side }));
                }

            case 3:
                if (commandConstructor.GetParameters()[2].ParameterType == typeof(Room))
                {
                    return((ICommand)commandConstructor.Invoke(new object[] { subject, target, myRoom }));
                }
                else
                {
                    return((ICommand)commandConstructor.Invoke(new object[] { subject, target, side }));
                }

            case 4:
                return((ICommand)commandConstructor.Invoke(new object[] { myGame, subject, target, side }));

            default:
                return(null);
            }
        }