Exemple #1
0
 public virtual RectBox GetRectBox()
 {
     if (_rotation != 0)
     {
         int[] result = MathUtils.GetLimit(_position.GetX(),
                                           _position.GetY(), GetWidth(), GetHeight(),
                                           MathUtils.ToDegrees(_rotation));
         if (temp_rect == null)
         {
             temp_rect = new RectBox(result[0], result[1], result[2],
                                     result[3]);
         }
         else
         {
             temp_rect.SetBounds(result[0], result[1], result[2], result[3]);
         }
     }
     else
     {
         if (temp_rect == null)
         {
             temp_rect = new RectBox(_position.GetX(), _position.GetY(),
                                     GetWidth(), GetHeight());
         }
         else
         {
             temp_rect.SetBounds(_position.GetX(), _position.GetY(),
                                 GetWidth(), GetHeight());
         }
     }
     return(temp_rect);
 }
Exemple #2
0
 protected virtual void SetSize(int w, int h)
 {
     if (boundingRect != null)
     {
         boundingRect.SetBounds(location.x, location.y, w, h);
     }
     else
     {
         boundingRect = new RectBox(location.x, location.y, w, h);
     }
 }
Exemple #3
0
 protected internal RectBox GetRect(float x, float y, float w, float h)
 {
     if (rect == null)
     {
         rect = new RectBox(x, y, w, h);
     }
     else
     {
         rect.SetBounds(x, y, w, h);
     }
     return(rect);
 }
Exemple #4
0
 public RectBox GetRect()
 {
     if (rect == null)
     {
         rect = new RectBox(0, 0, width, height);
     }
     else
     {
         rect.SetBounds(0, 0, width, height);
     }
     return(rect);
 }
Exemple #5
0
 public void UpdateCamera()
 {
     if (follow != null &&
         !moveRect.Contains(follow.GetX() + follow.GetWidth() / 2,
                            follow.GetY() + follow.GetHeight() / 2))
     {
         float targetCX = follow.GetX() - (this.renderWidth / 2);
         float targetCY = follow.GetY() - (this.renderHeight / 2);
         if (maxSpeed != null)
         {
             if (MathUtils.Abs(targetCX - cameraX) > maxSpeed.x)
             {
                 if (targetCX > cameraX)
                 {
                     cameraX += maxSpeed.x * 2;
                 }
                 else
                 {
                     cameraX -= maxSpeed.x * 2;
                 }
             }
             else
             {
                 cameraX = targetCX;
             }
             if (MathUtils.Abs(targetCY - cameraY) > maxSpeed.y)
             {
                 if (targetCY > cameraY)
                 {
                     cameraY += maxSpeed.y * 2;
                 }
                 else
                 {
                     cameraY -= maxSpeed.y * 2;
                 }
             }
             else
             {
                 cameraY = targetCY;
             }
         }
         else
         {
             cameraX = targetCX;
             cameraY = targetCY;
         }
     }
     if (cameraX < 0)
     {
         cameraX = 0;
     }
     if (cameraX + renderWidth > cameraRect.GetWidth())
     {
         cameraX = cameraRect.GetWidth() - renderWidth + 1;
     }
     if (cameraY < 0)
     {
         cameraY = 0;
     }
     if (cameraY + renderHeight > cameraRect.GetHeight())
     {
         cameraY = cameraRect.GetHeight() - renderHeight + 1;
     }
     visibleRect.SetBounds(cameraX - horBorderPixel, cameraY
                           - vertBorderPixel, renderWidth + horBorderPixel, renderHeight
                           + vertBorderPixel);
     moveRect.SetBounds(cameraX + horBorderPixel / 2 - speedX, cameraY
                        + vertBorderPixel / 2, renderWidth - horBorderPixel + speedY,
                        renderHeight - vertBorderPixel);
 }