I have a sdl project. It is very fun. It doesn't work. The picture leaves a trail. Here is my Main(). I am leaving out the function prototypes to conserve space.
Code:
int main(int argc, char * argv[]) {
char keyCode;
Uint8 *keys;
keys = SDL_GetKeyState(NULL);
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) {
printf("Cannot initialize Audio and/or Video%\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF|SDL_HWSURFACE); //HWwhat?
if(screen == NULL) {
printf("Unable to set 640 by 480 resolution%\n", SDL_GetError());
exit(1);
}
InitImages();
DrawBG();
bool done = false;
int xslope = 2;
int yslope = 2;
int speed = 1;
while(done == false)
{{{{{
if( kbhit() ) {
keyCode = getch();
if(keyCode = 27)
exit(1);
}
//90 degree counter clockwise: (x,y) -> (-y, x)
//90 degree clockwise: (x, y) -> (y, -x)
int xopp = xslope * 2;
int yopp = yslope * 2;
//for vertical movement need to turn yslope into opposite reciprocal
//(speed % 5 == 0)? (xpos = (xslope += (speed / 5))): xpos + xslope;
//(speed % 5 == 0)? (ypos = (yslope += (speed / 5))): ypos + yslope;
//xpos += (speed % 5 == 0)? (xslope + (speed / 5)) : xslope;
//ypos += (speed % 5 == 0)? (yslope + (speed / 5)) : yslope;
ypos += yslope;
xpos +=xslope;
if(ypos < 0) {
ypos = 0;
yslope = ( yslope - yopp );
yslope < 0? yslope-- : yslope++;
}
if(ypos >= (480 - 66)) {
ypos = (480 - 66);
yslope = ( yslope - yopp );
yslope < 0? xslope-- : xslope++;
}
if(xpos < 0) {
xpos = 0;
xslope = ( xslope - xopp );
xslope < 0? xslope-- : xslope++;
}
if(xpos >= 581) {
xpos = 581;
xslope = (xslope - xopp );
xslope < 0? xslope-- : xslope++;
}
DrawScene();
}}}}}
return 0;
}
seriously though, if you can see anything wrong PLEASE tell me.
I will be greatly indebted