GP2X Starting Sdl


reiboul

Peace sells... but who's buying?
Joined
Jul 16, 2006
Messages
587
Age
36
Location
France
Website
Visit site
Hello!!
As the title said, I started SDL some days ago, and I came up with a game I wrote using C++/SDL

It is keyboard only and should be easily ported to GP2X, which from what I know lacks such a game

It's a clone from a PC-game I like, but if you manage to compile it, please do not reveal the game's content. Not that I absolutely want to keep the secret, but if possible I prefer to keep the surprise ;)

Commented source, bitmaps and compile commands I used are here
http://membres.lycos.fr/reiboul/tower.rar

What I need is some advice from better coders, and if anybody is interrested in making new sprites, because I didn't take the time to draw good sprites, so pay no attention to the graphics. Animated sprites would be even better ;)

But what I need most at the moment are good tips on how to make my program better ;)

Thank to everyone that will take time to read my code ;)
 
If anybody know how to write an Uint32 using SDL_ttf, it would help me greatly :(

In fact I want use TTF_RenderFont with the return value of SDL_GetTicks()

SDL_GetTicks() returns an Uint32, and TTF wants a const char* :(
 
Here:

Code:
char * fubar[10];
int nbytes;
Uint32 my_uint32;

nbytes = snprintf( fubar, sizeof(fubar), "%u", my_uint32);
if (nbytes > sizeof(fubar))
   printf(stderr, "target string buffer (%d) is too small by %d\n", sizeof(fubar), nbytes - sizeof(fubar));

Note: Not syntax checked with a compiler.
 
I see you use printf... is your code compatible to C++?
Anyway, thank you, i'll try as soon as I get back to programming!

I've found some sprites and textures, it's beginning to look good, but i'd prefer original sprites that mix good together ;)
 
Here:

Code:
char * fubar[10];
int nbytes;
Uint32 my_uint32;

nbytes = snprintf( fubar, sizeof(fubar), "%u", my_uint32);
if (nbytes > sizeof(fubar))
   printf(stderr, "target string buffer (%d) is too small by %d\n", sizeof(fubar), nbytes - sizeof(fubar));

Note: Not syntax checked with a compiler.

Uhm... you just created an array of 10 char* pointers.

char *fubar; fubar=(char*)malloc(10); snprintf...; free(fubar);

OR

char fubar[10]; memset(fubar,'\0',10); snprintf(fubar, 9, "%u", my_uint32);

otherwise compilation will fail for invalid conversion of char** to char*
 
Last edited by a moderator:
Here:

Code:
char * fubar[10];
int nbytes;
Uint32 my_uint32;

nbytes = snprintf( fubar, sizeof(fubar), "%u", my_uint32);
if (nbytes > sizeof(fubar))
   printf(stderr, "target string buffer (%d) is too small by %d\n", sizeof(fubar), nbytes - sizeof(fubar));

Note: Not syntax checked with a compiler.

Uhm... you just created an array of 10 char* pointers.

char *fubar; fubar=(char*)malloc(10); snprintf...; free(fubar);

OR

char fubar[10]; memset(fubar,'\0',10); snprintf(fubar, 9, "%u", my_uint32);

otherwise compilation will fail for invalid conversion of char** to char*
You are correct is should have been:
Code:
char fubar[10];
int nbytes;
Uint32 my_uint32;

nbytes = snprintf( fubar, sizeof(fubar), "%u", my_uint32);
if (nbytes > sizeof(fubar))
   printf(stderr, "target string buffer (%d) is too small by %d\n", sizeof(fubar), nbytes - sizeof(fubar));

This is why I had the disclaimer about compiler checking ... damn

I see you use printf... is your code compatible to C++?
Anyway, thank you, i'll try as soon as I get back to programming!

I've found some sprites and textures, it's beginning to look good, but i'd prefer original sprites that mix good together ;)

well I did not use printf I used snprintf which takes a format string and puts the output into the string passed and will not exceed the 2nd parameters size. you could try using cout to output the string for the number and use that string.
 
Last edited by a moderator:
yeepee! thanks to you guys, I have a nice score display!

Here is the code I used, slightly modified from yours

char scoreChar[10];
Uint32 scoreInt;

snprintf( scoreChar, sizeof(scoreChar), "%u", SDL_GetTicks());
scoreSprite = TTF_RenderText_Solid(font, scoreChar, textColor);
SDL_BlitSurface(scoreSprite, NULL, screen, NULL);


By the way, did anybody took a look at my code? :unsure: I'd really need some advice, like how to make my scrolling smooth and faster without making the game faster, or simply how to make an afficient scrolling other than my nasty method...
I will update the file in a minute, new one includes some minor modifications, score display, and some better-looking sprites (but they're still ugly :) )
 
Back
Top