Beispiel #1
0
 public Consumable(Vector2 position)
 {
     pos = position;
     rect = new BoundingRectangle(position, 10);
     int randNum = Game1.random.Next(3);
     switch (randNum)
     {
         case 0:
             cType = ConsumableType.MASS;
             draw = new DrawOscillate(SpriteDatabase.GetAnimation("pwr_mass"), .4f);
             break;
         case 1:
             cType = ConsumableType.SLIP;
             draw = new DrawOscillate(SpriteDatabase.GetAnimation("pwr_slick"), .4f);
             break;
         case 2:
             cType = ConsumableType.SPEED;
             draw = new DrawOscillate(SpriteDatabase.GetAnimation("pwr_speed"), .4f);
             break;
         case 3:
             cType = ConsumableType.TURN;
             draw = new DrawOscillate(SpriteDatabase.GetAnimation("pwr_turn"), .4f);
             break;
     }
 }
Beispiel #2
0
 public Trigger(int x, int y, int w, int h, int id)
 {
     triggered = false;
     rect = new BoundingRectangle(x, y, w, h);
     this.id = id;
     if (count < id)
         count = id + 1;
 }
Beispiel #3
0
 public Consumable(Vector2 position, ConsumableType type)
 {
     pos = position;
     rect = new BoundingRectangle(position, 10);
     cType = type;
     switch (type)
     {
         case ConsumableType.MASS:
             draw = new DrawOscillate(SpriteDatabase.GetAnimation("pwr_mass"), .4f);
             break;
         case ConsumableType.SLIP:
             draw = new DrawOscillate(SpriteDatabase.GetAnimation("pwr_slick"), .4f);
             break;
         case ConsumableType.SPEED:
             draw = new DrawOscillate(SpriteDatabase.GetAnimation("pwr_speed"), .4f);
             break;
         case ConsumableType.TURN:
             draw = new DrawOscillate(SpriteDatabase.GetAnimation("pwr_turn"), .4f);
             break;
     }
 }
Beispiel #4
0
        public float? intersectionDistance(BoundingRectangle rect)
        {
            LineSegment[] side = new LineSegment[4]; 
            side[0] = new LineSegment(rect.Bounds.Left, rect.Bounds.Top, rect.Bounds.Right, rect.Bounds.Top);
            side[1] = new LineSegment(rect.Bounds.Left, rect.Bounds.Bottom, rect.Bounds.Right, rect.Bounds.Bottom);
            side[2] = new LineSegment(rect.Bounds.Left, rect.Bounds.Top, rect.Bounds.Left, rect.Bounds.Bottom);
            side[3] = new LineSegment(rect.Bounds.Right, rect.Bounds.Top, rect.Bounds.Right, rect.Bounds.Bottom);

            Vector2 intersectPt = Vector2.Zero;
            float? shortestDist = null;
            float currDist;
            for (int i = 0; i < 4; i++)
            {
                intersectPt = intersection(side[i]);
                currDist = distance(intersectPt);
                if (!intersectPt.Equals(Vector2.Zero) && (shortestDist == null || currDist < shortestDist))
                {
                    shortestDist = currDist;
                }
            }

            return shortestDist;
        }
Beispiel #5
0
 public void getEntities(BoundingRectangle bounds, ref List<Wall> ret)
 {
     ret.AddRange(objects);
     Rectanglef box = bounds.Bounds;
     if (maxDepth > 0)
     {
         if (box.Left < halfW)
         {
             if (box.Top < halfH)
                 cells[TOP_LEFT].getEntities(bounds, ref ret);
             if (box.Bottom >= halfH)
                 cells[BOTTOM_LEFT].getEntities(bounds, ref ret);
         }
         if (box.Right >= halfW)
         {
             if (box.Top < halfH)
                 cells[TOP_RIGHT].getEntities(bounds, ref ret);
             if (box.Bottom >= halfH)
                 cells[BOTTOM_RIGHT].getEntities(bounds, ref ret);
         }
     }
 }
Beispiel #6
0
        private void createMapGrid()
        {
            // Add walls to the grid
            BoundingRectangle test = new BoundingRectangle(Vector2.Zero, gridLength / 2);

            grid = new List<Wall>[(int)Math.Ceiling((Map.HEIGHT + 100) / gridLength), (int)Math.Ceiling((Map.WIDTH + 100) / gridLength)];

            int y = grid.GetLength(0);
            int x = grid.GetLength(1);

            for (int i = 0; i != y; ++i)
            {
                for (int j = 0; j != x; ++j)
                {
                    test.Update(new Vector2(j * test.Bounds.Height, i * test.Bounds.Width));

                    grid[i, j] = new List<Wall>();

                    // Check collision
                    for (int k = 0; k != map.walls.Count; ++k)
                    {
                        if (test.Collides(map.walls[k].BoundingRectangle))
                        {
                            grid[i, j].Add(map.walls[k]);
                        }
                    }
                }
            }
        }
Beispiel #7
0
 public Wall(Vector2 pos, BoundingRectangle boundRect, bool seeThrough = false)
 {
     this.pos = pos;
     this.rect = boundRect;
     this.seeThrough = seeThrough;
 }
 /// <summary>
 /// Checks for collision with other bounding rectangle
 /// </summary>
 /// <param name="rectangle">Bounding rectangle to check collision with</param>
 /// <returns>True if there is a collision</returns>
 public bool Collides(BoundingRectangle rectangle)
 {
     return boundingRectangle.Intersects(rectangle.boundingRectangle);
 }
Beispiel #9
0
 public Trigger(int x, int y, int w, int h)
 {
     triggered = false;
     rect = new BoundingRectangle(x, y, w, h);
     id = ++count;
 }
Beispiel #10
0
        /// <summary>
        ///  Check collision with a box
        /// </summary>
        /// <param name="rect">Bounding rectangle</param>
        /// <returns>True if there is a collision</returns>
        public bool IntersectsBox(BoundingRectangle box)
        {
            float left = box.Bounds.Left;
            float right = box.Bounds.Right;
            float top = box.Bounds.Top;
            float bottom = box.Bounds.Bottom;

            // if the line's endpoints are on the same side of the rectangle, there can't be an intersection
            if ((left > start.X && left > end.X) ||
                (right< start.X && right < end.X) ||
                (top > start.Y && top > end.Y) ||
                (bottom < start.Y && bottom < end.Y))
                return false;

            // Find the line's X and Y positions at the box's edges
            float xTop = getXfromY(top);
            float xBottom = getXfromY(bottom);
            float yLeft = getYfromX(left);
            float yRight = getYfromX(right);

            // If all of the points are outside the rectangle, there is no intersection
            if (
                (xTop < left || xTop > right) &&
                (xBottom < left || xBottom > right) &&
                (yLeft < top || yLeft > bottom) &&
                (yRight < top || yRight > bottom)
                )
            {
                return false;
            }

            return true;
        }