I was developing a game based on a grid system, and the player could only move 25 pixels per click, and when the player held the key for too long, it would simply move one tile, and then stay in the same place, instead of moving more tiles. It's a maze game, so I'm not sure of how to proceed.
I would like the player to be able to move freely, since it always looks better and enhances gameplay, but I'm not sure of how to combine a grid map (with things on the floor, doors, etc.) and a free movement. In fact, I'm not even sure if it's possible.
Here's some of my code (possibly impossible to run on its own)
int main(int argc, char *argv[])
{
/* Initialize SDL */
SDL_Surface *screen;
SDL_Init(SDL_INIT_VIDEO);
screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, SDL_SWSURFACE);
SDL_WM_SetCaption("test", "test");
int map[MAP_HEIGHT][MAP_WIDTH];
SDL_Event event;
load_map();
while (true)
{
while (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT)
{
SDL_Quit();
return 0;
}
if (event.type == SDL_KEYDOWN)
{
/* This is where I get key input, no acceleration, just
"player_y = player_y - TILE_SIZE"
*/
}
(...)
On the one hand, I would like a way of moving freely like in a first person shooter game, or Animal Crossing (most commercial games with a moving player actually), but on the other hand, can I still have a map grid? I'm not sure and I need help both with deciding what to use in a maze game, and with the code (continuous key pressing).
Actually and ideally, how to move one tile at a time, but when he keeps pressing the key for longer, the player will keep moving more tiles? Thanks.