Jump to content
  • Advertisement
Sign in to follow this  
feliperuiz

Align to grid

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!