Beispiel #1
0
        public static void SplitUpParticle(Particle p, Rectangle collisionObject)
        {
            p.alive = false;
            Vector2 lastPartPos = p.position;

            Vector2 move = p.force;

            int k = 100;

            while (!MapStuff.Instance.map.Walkable(p.position) && k > 0)
            {
                if (!MapStuff.Instance.map.CheckPosition(p))
                    return;
                --k;
                p.position.Y -= 1;
            }


            while (move.X == p.force.X && move.Y == p.force.Y && !(move.X == 0 && move.Y == 0))
            {
                lastPartPos -= p.force;

                if (lastPartPos.X < collisionObject.X || lastPartPos.X > collisionObject.X + collisionObject.Width)
                    move.X *= -1;

                if (lastPartPos.Y < collisionObject.Y || lastPartPos.Y > collisionObject.Y + collisionObject.Height)
                    move.Y *= -1;

            }

            int numberOfSnow = (int)p.mass;

            if (numberOfSnow <= 5)
                return;

            p.mass = 1;

            for (int i = 0; i < numberOfSnow; ++i)
            {
                move = MyRectangle.rotate(move, MathHelper.ToRadians(MapStuff.Instance.rnd.Next(-30, 30)));

                Rectangle particleRect = new Rectangle(p.position.ToPoint(), new Point(2, 2));

                move = Vector2.Normalize(move);
                move *= MapStuff.Instance.rnd.Next(100, 300) / 100f;

                /*
                while (particleRect.Intersects(collisionObject))
                {
                    p.position += move;
                    particleRect = new Rectangle(p.position.ToPoint(), new Point(2, 2));
                }
                */

                MapStuff.Instance.partCollHandler.AddParticle(p.position + 3 * move, 1, 6, move, false, false);
            }
        }
Beispiel #2
0
        public static void SplitUpParticle(Particle p)
        {
            Vector2 move = p.force;
            Vector2 position = p.position;

            int k = 10;
            while (!MapStuff.Instance.map.Walkable(position - p.force))
            {
                position -= p.force;

                k--;
                if (k < 0)
                    return;
            }

            k = 10;
            while (MapStuff.Instance.map.Walkable(position))
            {
                position += p.force;

                k--;
                if (k < 0)
                    return;
            }

            Vector2 reflect = Vector2.Zero;

            if (MapStuff.Instance.map.Walkable(position - new Vector2(p.force.X, 0)))
                reflect.X = -1 * Math.Sign(p.force.X);

            if (MapStuff.Instance.map.Walkable(position - new Vector2(0, p.force.Y)))
                reflect.Y = -1 * Math.Sign(p.force.Y);


            int numberOfSnow = (int)p.mass;

            if (numberOfSnow <= 5)
                return;

            p.mass = 1;

            



            for (int i = 0; i < numberOfSnow; ++i)
            {
                move = Vector2.Reflect(p.force, reflect);
                if (move.Y > 0)
                    move.Y *= -1;
                move.Normalize();
                move *= MapStuff.Instance.rnd.Next(100, 300) / 100f;
                move = MyRectangle.rotate(move, MathHelper.ToRadians(MapStuff.Instance.rnd.Next(-30, 30)));

                MapStuff.Instance.partCollHandler.AddParticle(p.position + move, 1, 6, move, false, false);
            }
        }
Beispiel #3
0
 public bool intersect(MyRectangle other)
 {
     if (!rect.Intersects(other.rect))
     {
         return(false);
     }
     else
     {
         return(intersect(other.bounds, triangles, rect) || intersect(bounds, other.triangles, other.rect));
     }
 }