Original Post
Hi guys, and ladies! I'm working on a 2D platformer game and been coding on it back and forth, but need to shape things up a bit better, especially my slope code. Download here: http://aliengame.xieke.com/Downloads/New_Project_0.3.0.rar This used to be my metroid clone project, which now is heading in the direction of becoming it's own game with unique graphics, since I found a talented gfx artist.
My current slope function (pseudo code):
Tiles are 32x32 in size.
At the moment I'm using arrays to define slopes:
//a simple 45 degree slope to the right
//Each number represents how many pixels to move the player up on the y axis.
int Slope_Right[32] = {
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,
};
then in the code I compute how many pixels into the tile I am by:
//get the current tile the player is standing on.
player_x_calc = ( (player->worldx)/32)*32;
//worldx - player_x_calc, which gives how many pixels the player is in on the tile.
player->WhereOnTilex = player->worldx - player_x_calc;
//get players tile x & y position
tilex = player->worldx/32;
tiley = player->worldy/32;
//get the current tile
tile = SR387_Map[tile_y][tile_x][1];
//check the current tile against a slope index, if we found that player SLOPE RIGHT
if(SlopeIndex[test_tile] == SLOPE_RIGHT)
{
//set the new player y position to the current tile, and move him/her up the
//pixels pre defined in the slop array.
player->worldy = (tiley*32) - Slope_Right[player->WhereOnTilex];
}
My question is: Is there a more efficent way to do this on? I have found very little examples on the internet about slope walking, I did find som more advanced algebra on the issue, but not a "down-to-earth" example, So I came up with this solution.