예제 #1
0
 public bool ObjectPosition(float x, float y, Type type)
 {
     if (SuperList.TryGetValue(type, out list) && list.Count != 0)
     {
         foreach (CollideableGameObject obj in list)
         {
             if (obj.X == x && obj.Y == y)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #2
0
 public bool BoxRotateCollision(Type type)
 {
     if (SuperList.TryGetValue(type, out list) && list.Count != 0)
     {
         foreach (CollideableGameObject obj in list)
         {
             if (obj == this)
             {
                 continue;
             }
             if (CheckEdges(this, obj))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
예제 #3
0
 public CollideableGameObject BoxCollision(int ExtraX, int ExtraY, Type type)
 {
     if (SuperList.TryGetValue(type, out list) && list.Count != 0)
     {
         foreach (CollideableGameObject obj in list)
         {
             if (obj == this)
             {
                 continue;
             }
             if (BoxX + ExtraX + BoxWidth > obj.BoxX && BoxX - ExtraX * Math.Sign(ExtraX) < obj.BoxX + obj.BoxWidth &&
                 BoxY + ExtraY + BoxHeight > obj.BoxY && BoxY - ExtraY * Math.Sign(ExtraY) < obj.BoxY + obj.BoxHeight)
             {
                 obj.Collision = true;
                 return(obj);
             }
         }
     }
     return(null);
 }
예제 #4
0
        public override void Update()
        {
            Depth = Y;
            if (Form)
            {
                if (Keyboard.IsKeyDown(Keys.Up))
                {
                    Y -= speed;
                }
                if (Keyboard.IsKeyDown(Keys.Down))
                {
                    Y += speed;
                }
                if (Keyboard.IsKeyDown(Keys.Left))
                {
                    X -= speed;
                }
                if (Keyboard.IsKeyDown(Keys.Right))
                {
                    X += speed;
                }

                if (Keyboard.IsKeyDown(Keys.N))
                {
                    Rotation += MathHelper.ToRadians(3);
                }
            }
            else
            {
                if (Keyboard.IsKeyDown(Keys.I))
                {
                    Y -= speed;
                }
                if (Keyboard.IsKeyDown(Keys.K))
                {
                    Y += speed;
                }
                if (Keyboard.IsKeyDown(Keys.J))
                {
                    X -= speed;
                }
                if (Keyboard.IsKeyDown(Keys.L))
                {
                    X += speed;
                }

                if (Keyboard.IsKeyDown(Keys.M))
                {
                    Rotation += MathHelper.ToRadians(3);
                }
            }

            List <GameObject> list;

            if (SuperList.TryGetValue(typeof(EdgeCollision), out list))
            {
                foreach (CollideableGameObject obj in list)
                {
                    if (obj == this)
                    {
                        continue;
                    }

                    Vector2 LineALeft  = new Vector2(X - ScaledWidth / 2, Y);
                    Vector2 LineARight = new Vector2(X + ScaledWidth / 2, Y);
                    Vector2 LineBLeft  = new Vector2(obj.X - obj.ScaledWidth / 2, obj.Y);
                    Vector2 LineBRight = new Vector2(obj.X + obj.ScaledWidth / 2, obj.Y);

                    LineALeft  = Rotate(X, Y, Rotation, LineALeft);
                    LineARight = Rotate(X, Y, Rotation, LineARight);
                    LineBLeft  = Rotate(obj.X, obj.Y, obj.Rotation, LineBLeft);
                    LineBRight = Rotate(obj.X, obj.Y, obj.Rotation, LineBRight);

                    if (LineIntersection(LineALeft, LineARight, LineBLeft, LineBRight))
                    {
                        Color = Color.Red;
                    }
                    else
                    {
                        Color = Color.White;
                    }
                }
            }
            base.Update();
        }