Example #1
0
        private static bool IsPollygonsIntersecting(PollygonCollider object1, PollygonCollider object2)
        {
            foreach (PollygonCollider collider in new PollygonCollider[] { object1, object2 })
            {
                for (int i1 = 0; i1 < collider.Points.Length; i1++)
                {
                    int     i2 = (i1 + 1) % collider.Points.Length;
                    Vector2 p1 = collider.GetActualPointPosition(i1);
                    Vector2 p2 = collider.GetActualPointPosition(i2);

                    Vector2 normal = new Vector2(p2.Y - p1.Y, p1.X - p2.X);

                    double minA = double.MaxValue, maxA = double.MinValue;
                    for (int index = 0; index < object1.Points.Length; index++)
                    {
                        var projected = normal.X * object1.GetActualPointPosition(index).X + normal.Y * object1.GetActualPointPosition(index).Y;
                        if (projected < minA)
                        {
                            minA = projected;
                        }
                        if (projected > maxA)
                        {
                            maxA = projected;
                        }
                    }

                    double minB = double.MaxValue, maxB = double.MinValue;
                    for (int index = 0; index < object2.Points.Length; index++)
                    {
                        var projected = normal.X * object2.GetActualPointPosition(index).X + normal.Y * object2.GetActualPointPosition(index).Y;
                        if (projected < minB)
                        {
                            minB = projected;
                        }
                        if (projected > maxB)
                        {
                            maxB = projected;
                        }
                    }

                    if (maxA < minB || maxB < minA)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Example #2
0
        public void Draw(GameTime gameTime)
        {
            Scenes.Level currLevel = GameplayManager.self.CurrLevel;

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

            foreach (object item in currLevel.items)
            {
                if (item is Room)
                {
                    spriteBatch.Draw(((Room)item).texture, mainFrame, Color.White);
                }
                else if (item is Player)
                {
                    spriteBatch.Draw(TextureManager.spriteSheet, ((Player)item).position, ((Player)item).spriteSource, Color.White, 0f, new Vector2(0, 0), 1f, (((Player)item).dir == -1) ? SpriteEffects.FlipHorizontally: SpriteEffects.None, 0.6f);
                }
                else if (item is Enemy)
                {
                    spriteBatch.Draw(TextureManager.spriteSheet, ((Enemy)item).position, ((Enemy)item).spriteSource, ((Enemy)item).color, 0f, new Vector2(0, 0), 1f, (((Enemy)item).dir == -1) ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0.6f);
                }
                else if (item is Weapon)
                {
                    spriteBatch.Draw(TextureManager.spriteSheet,
                                     ((Weapon)item).getRenderPosition(),
                                     ((Weapon)item).spriteSource,
                                     Color.White,
                                     (((Weapon)item).playerInstance.dir == 1) ? -((Weapon)item).rotation : ((Weapon)item).rotation,
                                     new Vector2(0, ((Weapon)item).spriteSource.Height),
                                     1f,
                                     ((Weapon)item).playerInstance.dir == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally,
                                     0.6f);
                }
                else if (item is Food)
                {
                    spriteBatch.Draw(((Food)item).texture, ((Food)item).position, ((Food)item).spriteSource, Color.White);
                }
                else if (item is WaterFountain)
                {
                    spriteBatch.Draw(TextureManager.spriteSheet, ((WaterFountain)item).position, ((WaterFountain)item).spriteSource, Color.White);
                }

                if (DRAW_COLLIDER && item is Physics.BoxCollider)
                {
                    Rectangle box = ((Physics.BoxCollider)item).area;
                    int       bw  = 2;
                    spriteBatch.Draw(t, new Rectangle(box.Left, box.Top, bw, box.Height), Color.LightGreen);   // Left
                    spriteBatch.Draw(t, new Rectangle(box.Right, box.Top, bw, box.Height), Color.LightGreen);  // Right
                    spriteBatch.Draw(t, new Rectangle(box.Left, box.Top, box.Width, bw), Color.LightGreen);    // Top
                    spriteBatch.Draw(t, new Rectangle(box.Left, box.Bottom, box.Width, bw), Color.LightGreen); // Bottom
                }
                else if (DRAW_COLLIDER && item is Physics.PollygonCollider)
                {
                    Physics.PollygonCollider collider = (Physics.PollygonCollider)item;
                    for (int i = 1; i < collider.Points.Length; i++)
                    {
                        DrawLine(collider.GetActualPointPosition(i - 1), collider.GetActualPointPosition(i));

                        if (i == collider.Points.Length - 1)
                        {
                            DrawLine(collider.GetActualPointPosition(i), collider.GetActualPointPosition(0));
                        }
                    }
                }
            }

            // Draw blood particles
            Game1.self.bloodParticleEngine.Draw(spriteBatch);

            if (currLevel.UIContainers.Count > 0)
            {
                currLevel.UIContainers.Peek().Draw(spriteBatch);
            }


            spriteBatch.Draw(TextureManager.cursorTexture, new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Color.White);
            spriteBatch.End();
        }