Alright, so I got this code I'm trying to write, but the player won't go down the slope, it goes down and up perfectly on the 45 degree slope, but the 315 degree one is a mess. it goes "up" the downward slope, get's stuck and some other stuff. Anyway here's the code:
//you're in a double for loop going through every tile in the map, the int's being used are x, and y
//check if the tile is a slope
if (lv.type[lv.tile[x, y]] == Tiles.SLOPE)
{
//create a rectangle collision box
Rectangle tileCol = new Rectangle(x * lv.tileSize, (y * lv.tileSize), lv.tileSize, lv.tileSize + 1);
//if player collision "col" collides with "tileCol" and you haven't done this before this itteration (only happens once per full double loop)
if (col.Intersects(tileCol) && !onSlope)
{
//get the angle of the tile
float angle = lv.angle[lv.tile[x, y]];
//get the x distance of how far away the player's right is inside the tile
float dist = (col.X + col.Width) - tileCol.X;
//constructs the opposite of a right triangle
float opposite = (float)(Math.Tan(MathHelper.ToRadians(angle)) * (dist));
if (angle < 90)
{
//if player's right is less then or equal to tile's right
if (col.X + col.Width <= tileCol.X + tileCol.Width)
{
//place player on slope. this works properly
pos.Y = tileCol.Y - opposite;
//tell the program we don't wanna go through this again until the next full loop starts.
onSlope = true;
}
}
else if (angle > 90){
if ((col.X + col.Width) >= tileCol.X)
{
//this is where the error is. the player goes "up" a slope that's 315 degrees, instead of down it.
//how do I make the player go down the slope that's 315 degrees!?
pos.Y = tileCol.Y + opposite;
onSlope = true;
}
}
}
}
currently using this code, it makes the player move in a 45 degree angle on the 315 degree blocks.
else if (angle > 90)
{
if (col.X >= tileCol.X)
{
pos.Y = tileCol.Y + lv.tileSize + (dist * -1);
onSlope = true;
}
}