# Align to grid

This topic is 3755 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey, I'm developing a game like bomber man in the C language using the SDL and I need to align my character to the grid. I thought of a way of doing it, but it feels too much work-around programming. The code for this is: #define GRID 32 ... case SDLK_LEFT: for(i=0;i<GRID/speed;i++) { walk('l',speed,screen); SDL_BlitSurface(background,NULL,screen,NULL); SDL_Delay(50); SDL_BlitSurface(Kenny.image,&(Kenny.src),screen,&(Kenny.dst)); } ... //here is the same procedure for the other keys void walk (char direction, int speed, SDL_Surface *screen) { switch(direction) { case 'u': Kenny.step.up++; Kenny.step.left=0; Kenny.step.right=0; Kenny.step.down=1; if(Kenny.dst.y<=0) { Kenny.dst.y-=0; } else { Kenny.dst.y-=speed; } Kenny.src.y=0; //here I change Kenny.src.x=((Kenny.step.up+1)%4)*32; //the sprites break; ... //here is the same procedure for the other directions default: break; } } I have some urgency on this 'cause this game needs to be ready by tuesday. Thanks. [Edited by - feliperuiz on July 5, 2008 5:57:06 AM]

##### Share on other sites
Not sure if this is what you had in mind, but something along these lines:
#include <stdio.h>int AlignToGrid (int n, int gridsize){	return (n / gridsize) * gridsize;}int main (){	int i=0;	for (i=0; i < 120; ++i)	{		printf ("Characters position is %i, aligned to grid %i.\n", i, AlignToGrid (i, 32));	}	return 0;}

##### Share on other sites
I didn't see how I could use that code. I need a way to make a character walk the grid size once per keypress, but changing its legs.

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5

• 9
• 14
• 9
• 9
• 9
• ### Forum Statistics

• Total Topics
632922
• Total Posts
3009216
• ### Who's Online (See full list)

There are no registered users currently online

×