Map editor |
Map editor |
Ricardo Cruz
Guest
|
Hi Thiago,
Start by structuring the damn code into functions and stuff. Also, if you're using gcc, feed it with the -Wall flag and fix all warnings. You're making logic tests instead of assignments. Here is a better structured code: #define MAP_WIDTH 10 #define MAP_HEIGHT 10 char map[MAP_WIDTH][MAP_HEIGHT]; /* It might be a good idea to make wrapper access functions to your array to avoid crashes resulting of reading/writting outside of its boundries, and to make thins more readable. As a bonus, it makes it easily extandable to support more than one map. */ char get_tile(int x, int y) { if(x < 0 || x >= MAP_WIDTH) return 0; // printf return map[x][y]; } void put_tile(int x, int y, char t) { if(x < 0 || x >= MAP_WIDTH) return; // printf map[x][y] = c; } /* Toggling of the tiles. */ #define MAX_TILES 3 void toggle_tile(int x, int y) { char t = get_tile(x,y) + 1; if(t >= MAX_TILES) t = 0; put_tile(x,y,t); } (...) /* A value to the tile that the mouse cursor is pointing to. Just used so we know in mouse motion if we're hover a new tile or still the same. */ int mouse_hover_tile = -1; (...) case SDL_MOUSEBUTTONDOWN: { int x = event.button.x / MAP_WIDTH, y = event.button.y / MAP_HEIGHT; mouse_hover_tile = x + (y * MAP_WIDTH); toggle_tile(x,y); break; } case SDL_MOUSEMOTION: { if(!(event.motion.state & SDL_BUTTON(1))) break; int x = event.motion.x / MAP_WIDTH, y = event.motion.y / MAP_HEIGHT; int hover_tile = x + (y * MAP_WIDTH); if(hover_tile != mouse_hover_tile) { mouse_hover_tile = hover_tile; toggle_tile(x,y); } break; } (...) Espero que tenha ajudado. Mas esta lista n?o deve ser usada para estes problemas... Se quiseres, envia-me o c?digo do teu programa que eu tenho todo o prazer em te corrigir os erros. Cheers, Ricardo Em Quinta, 19 de Janeiro de 2006 15:39, o Thiago Nunes Leite escreveu:
-- It's always darkest just before it gets pitch black. |
|||||||||||||||
|