So, as a project for funzies, I decided to make a basic game where you run around the screen and get into fights when you encounter skeletons. However, I'm nowhere near the fighting parts yet.
So far, the main character only appears when he moves (no idle animation), erases rocks he passes over, and can escape the grid he's on. Here is the code for his motion. The commented out section makes pictures of the character standing pop up in places of the screen faaaar away from his location.
void movePlayer()
{
tempX = x;
tempY = y;
/* if(!keypressed())
{
if(direction==1)
{draw_sprite( buffer, standBack,y * 20, x * 20);}
if(direction==3)
{draw_sprite( buffer, standfront,y * 20, x * 20);}
if(direction==2)
{draw_sprite( buffer, standright,y * 20, x * 20);}
if(direction==4)
{draw_sprite( buffer, standleft,y * 20, x * 20);}
}
*/
if ( (key[KEY_UP] && !key[KEY_LEFT])&& (key[KEY_UP] && !key[KEY_RIGHT]) && map[y--][x] == 3 &&objMap[y--][x]!=101)
{
objMap[y--][x] = 100;
draw_sprite( buffer, runup, x * 20, y *20);
direction=1;
}
if ( (key[KEY_DOWN] && !key[KEY_LEFT])&& (key[KEY_DOWN] && !key[KEY_RIGHT]) && map[y ++][x] == 3 )
{
objMap[y++][x] = 100;
draw_sprite( buffer, rundown, x * 20, (y) *20);
direction=1;
}
if ( (key[KEY_RIGHT] && !key[KEY_LEFT])&& map[y][x ++] == 3)
{
objMap[y][x ++] = 100;
draw_sprite( buffer, runright, x * 20, y * 20);
direction=2;
}
if ( key[KEY_LEFT] && map[y][x - 1] == 3)
{
objMap[y][x--] = 100;
draw_sprite( buffer, runleft, (x) * 20, y * 20);
direction=4;
}