/* Used to collision detection, the sweep aspect just means it will check various points along the movement based on x and y velocity in the case of throwing an item, the velocity is to great to avoid "sweeping" the collision as the item will simply pass through and avoid all collision detection since i have capped the velocity of the throw to a given amount, creating three sweep points at 1/4, 1/2, full velocity works (for now). */ public bool ItemSweepCollision(ItemTile itemCheck) { int checkX = itemCheck.Box.X + (int)itemCheck.XVelocity; int checkY = itemCheck.Box.Y + (int)itemCheck.YVelocity; ItemTile checkItemSweep = new ItemTile(0, new Rectangle(checkX - (int) itemCheck.XVelocity / 4, checkY -(int) itemCheck.YVelocity / 4, 20, 20), genMaps[ACTIVELEVEL].GetMap.Item1, gameObj); ItemTile checkItemSweep2 = new ItemTile(0, new Rectangle(checkX - (int)itemCheck.XVelocity / 2, checkY - (int)itemCheck.YVelocity / 2, 20, 20), genMaps[ACTIVELEVEL].GetMap.Item1, gameObj); ItemTile checkItemSweep3 = new ItemTile(0, new Rectangle(checkX - (int)itemCheck.XVelocity / 1, checkY - (int)itemCheck.YVelocity / 1, 20, 20), genMaps[ACTIVELEVEL].GetMap.Item1, gameObj); //Need to implement sweeping detection to fix collision graph offsets if (ItemCollisionDetection(checkItemSweep)) { itemCheck.MotionState = false; return true; } if (ItemCollisionDetection(checkItemSweep2)) { itemCheck.MotionState = false; return true; } if (ItemCollisionDetection(checkItemSweep3)) { itemCheck.MotionState = false; return true; } return false; }
int CompareTo(ItemTile check) { if (this.itemKey > check.itemKey) { return -1; } return 1; }
public bool ItemCollisionDetection(ItemTile itemCheck) { Rectangle newBox; //Collision for platform tiles require movement from top collisions foreach (PlatFormTile tile in genMaps[ACTIVELEVEL].PlatFormTile) { //Top if (itemCheck.Box.Bottom >= tile.Box.Top && itemCheck.Box.Bottom <= tile.Box.Top && itemCheck.Box.Right >= tile.Box.Left && itemCheck.Box.Left <= tile.Box.Right ) { newBox = new Rectangle(itemCheck.Box.X, tile.Box.Top - 1, 40, 40); itemCheck.Box = newBox; return true; } //Bottom if (itemCheck.Box.Top <= tile.Box.Bottom - yOffset && itemCheck.Box.Top >= tile.Box.Bottom && itemCheck.Box.Right >= tile.Box.Left&& itemCheck.Box.Left <= tile.Box.Right) { newBox = new Rectangle(itemCheck.Box.X, tile.Box.Bottom + itemCheck.Box.Height, 40, 40); itemCheck.Box = newBox; return true; } if (itemCheck.Box.Left >= tile.Box.Left && itemCheck.Box.Left <= tile.Box.Right && itemCheck.Box.Top <= tile.Box.Bottom && itemCheck.Box.Bottom >= tile.Box.Top) { newBox = new Rectangle(tile.Box.Right + 2, itemCheck.Box.Y, 40, 40); itemCheck.Box = newBox; return true; } //Left side collisions with offsets if (itemCheck.Box.Right <= tile.Box.Right && itemCheck.Box.Right >= tile.Box.Left && itemCheck.Box.Top <= tile.Box.Bottom && itemCheck.Box.Bottom >= tile.Box.Top) { newBox = new Rectangle(tile.Box.Left - 2 - tile.Box.Width, itemCheck.Box.Y, 40, 40); itemCheck.Box = newBox; return true; } } return false; }