private void Update_Physics_GL_Top(NetNavi_Type navi) { //Top int Top = (int)(navi.Navi_Location().Top / 16); int Left = (int)(navi.Navi_Location().Left / 16); int Right = (int)(navi.Navi_Location().Right / 16); //always does hightmap on tile colleciton for (int x = Left; x <= Right; x++) { RectangleF rct = navi.Navi_Location(); if (stage.CollisionMap.ContainsKey(new Point(x, Top))) { StageCollisionTile tile = stage.CollisionMap[new Point(x, Top)]; tile.Active = true; //set to Top if (rct.Top - (Top * 16 + 16) >= -1) { navi.Set_LocationY(Top * 16 + 16 + navi.Navi_Location().Height); navi.Speed.Y = 0; navi.StepMovement.Y = 0; } } } }
private void Update_Physics_GL_Left(NetNavi_Type navi) { //Top int Top = (int)((navi.Navi_Location().Top + 2) / 16); int Bottom = (int)((navi.Navi_Location().Bottom - 2) / 16); int Left = (int)(navi.Navi_Location().Left / 16); //always does hightmap on tile colleciton for (int y = Top; y <= Bottom; y++) { RectangleF rct = navi.Navi_Location(); if (stage.CollisionMap.ContainsKey(new Point(Left, y))) { StageCollisionTile tile = stage.CollisionMap[new Point(Left, y)]; tile.Active = true; if (rct.Bottom - (y * 16 + 16 - tile.HeightRight) >= 4) { //set to Left if (rct.Left - (Left * 16 + 16) >= -1) { navi.Set_LocationX(Left * 16 + 16); navi.Speed.X = 0; navi.StepMovement.X = 0; } } } } }
private void Update_Physics_GL_Bottom(NetNavi_Type navi, bool OnGround) { //Bottom int Top = (int)(navi.Navi_Location().Top / 16); int Bottom = (int)(navi.Navi_Location().Bottom / 16); int Left = (int)(navi.Navi_Location().Left / 16); int Right = (int)(navi.Navi_Location().Right / 16); //always does hightmap on tile colleciton for (int y = Top; y <= Bottom; y++) { for (int x = Left; x <= Right; x++) { //int x;//, y; //x = Right;// y = Bottom; RectangleF rct = navi.Navi_Location(); if (stage.CollisionMap.ContainsKey(new Point(x, y))) { StageCollisionTile tile = stage.CollisionMap[new Point(x, y)]; tile.Active = true; //Slope collision with a center tile float point, pointL, pointR, ratioL, ratioR; point = 16; if (x != Left && x != Right) { if (tile.HeightLeft > tile.HeightRight) { point = tile.HeightLeft; } else { point = tile.HeightRight; } } else //Slope collision with leftmost or rightmost tile { pointL = 16; pointR = 16; ratioR = (navi.Navi_Location().Right - x * 16) / 16; ratioL = (navi.Navi_Location().Left - x * 16) / 16; if (ratioL >= 0 && ratioL <= 1) { pointL = tile.HeightLeft + (tile.HeightRight - tile.HeightLeft) * ratioL; } if (ratioR >= 0 && ratioR <= 1) { pointR = tile.HeightLeft + (tile.HeightRight - tile.HeightLeft) * ratioR; } if (pointL < pointR) { point = pointL; } else { point = pointR; } } //set to ground if (rct.Bottom > (y * 16) + 16 - point) { if (rct.Bottom - (y * 16) - (16 - point) <= 4) { if (navi.Navi_Location().Top < (y * 16 + (16 - point))) { navi.Set_LocationY(y * 16 + (16 - point)); navi.Speed.Y = 0; navi.StepMovement.Y = 0; OnGround = true; } } } if (navi.Navi_Location().Bottom + 1 >= (y * 16) + 16 - point) { OnGround = true; } } navi.OnGround = OnGround; } } }