Example #1
0
 public LevelObj(Rect position, float depth, int id, string parentName = "none")
 {
     texture              = null;
     this.position        = new ObjRect(0, 0, 0, 0);
     this.position.left   = (int)position.xMin;
     this.position.top    = (int)position.yMin;
     this.position.width  = (int)position.width;
     this.position.height = (int)position.height;
     this.position.depth  = depth;
     this.id              = id;
     this.isCloneOf       = parentName;
 }
Example #2
0
        public void CollidingWith(Rectangle blockRec)
        {
            if (ObjRect.Intersects(blockRec))
            {
                blockPos = new Vector2(ObjRect.X, ObjRect.Y);
                ObjRect  = new Rectangle((int)blockPos.X, (int)blockPos.Y, ObjRect.Width, ObjRect.Height);

                if (blockRec.Top - ObjRect.Bottom >= -10 && blockRec.Top - ObjRect.Bottom < 0 && blockRec.Left + 10 <= ObjRect.Right && blockRec.Right - 10 >= ObjRect.X)
                {
                    ObjRect = new Rectangle((int)blockPos.X, blockRec.Top - ObjRect.Height, ObjRect.Width, ObjRect.Height);

                    isFalling  = false;
                    blockPos  += velocity;
                    velocity.Y = 0f;
                    blockPos   = new Vector2(ObjRect.X, ObjRect.Y);
                }
                //Checks under side of block
                if (ObjRect.Top - blockRec.Bottom >= -10 && ObjRect.Top - blockRec.Bottom < 0)
                {
                    ObjRect    = new Rectangle((int)blockPos.X, blockRec.Bottom, ObjRect.Width, ObjRect.Height);
                    blockPos  += velocity;
                    velocity.Y = 0f;
                    blockPos   = new Vector2(ObjRect.X, ObjRect.Y);
                }
                //Checks left side of block
                if ((blockRec.Left - ObjRect.Right) >= -10 && (blockRec.Left - ObjRect.Right) < 0)
                {
                    ObjRect  = new Rectangle(blockRec.Left - ObjRect.Width, ObjRect.Y, ObjRect.Width, ObjRect.Height);
                    blockPos = new Vector2(ObjRect.X, ObjRect.Y);
                    canMove  = false;
                }
                //Checks right side of block
                if ((ObjRect.Left - blockRec.Right) >= -10 && (ObjRect.Left - blockRec.Right) < 0)
                {
                    ObjRect  = new Rectangle(blockRec.Right, ObjRect.Y, ObjRect.Width, ObjRect.Height);
                    blockPos = new Vector2(ObjRect.X, ObjRect.Y);
                    canMove  = false;
                }


                //if(isFalling == true)
                //{
                //   isFalling = true;
                //   velocity.Y += 0.23f * 1;
                //  blockPos += velocity;
                //  ObjRect = new Rectangle((int)blockPos.X, (int)blockPos.Y, ObjRect.Width, ObjRect.Height);
                //     blockPos = new Vector2(ObjRect.X, ObjRect.Y);
                //
                blockPos = new Vector2(ObjRect.X, ObjRect.Y);
                ObjRect  = new Rectangle((int)blockPos.X, (int)blockPos.Y, ObjRect.Width, ObjRect.Height);
            }
        }
Example #3
0
 public Chunk(string name, Rect position, int id, int depth, List <LevelObj> objects, string parentName = "none") :
     base(position, depth, id, parentName)
 {
     isSaved       = false;
     Name          = name;
     idAccumulator = 0;
     layerNumber   = depth;
     if (objects == null)
     {
         this.objects = new List <LevelObj>();
     }
     else
     {
         this.objects = objects;
     }
     if (this.objects.Count > 0)
     {
         Vector2 min = new Vector2(this.objects[0].position.left, this.objects[0].position.top);
         Vector2 max = new Vector2(this.objects[0].position.left + this.objects[0].position.width,
                                   this.objects[0].position.top + this.objects[0].position.height);
         foreach (var item in this.objects)
         {
             Vector2 tempMin = new Vector2(item.position.left, item.position.top);
             if (tempMin.magnitude < min.magnitude)
             {
                 min = tempMin;
             }
             Vector2 tempMax = new Vector2(item.position.left + item.position.width,
                                           item.position.top + item.position.height);
             if (tempMax.magnitude > max.magnitude)
             {
                 max = tempMax;
             }
             idAccumulator = 0;
         }
         centerOfChunk = new ObjRect((int)(max.x - min.x), (int)(max.y - min.y), 50, 50);
     }
     else
     {
         centerOfChunk = new ObjRect(0, 0, 0, 0);
     }
 }
 public static Rect ChangeType(ObjRect objRect)
 {
     return(new Rect(objRect.left, objRect.top, objRect.width, objRect.height));
 }