test/testsprite.c
changeset 288 2f5a6062db86
parent 107 01fcac5d146e
child 529 21409a7a5fee
     1.1 --- a/test/testsprite.c	Wed Feb 27 16:15:34 2002 +0000
     1.2 +++ b/test/testsprite.c	Thu Feb 28 00:28:26 2002 +0000
     1.3 @@ -1,4 +1,3 @@
     1.4 -
     1.5  /* Simple program:  Move N sprites around on the screen as fast as possible */
     1.6  
     1.7  #include <stdio.h>
     1.8 @@ -18,6 +17,7 @@
     1.9  SDL_Rect *positions;
    1.10  SDL_Rect *velocities;
    1.11  int sprites_visible;
    1.12 +Uint16 sprite_w, sprite_h;
    1.13  
    1.14  int LoadSprite(SDL_Surface *screen, char *file)
    1.15  {
    1.16 @@ -66,12 +66,12 @@
    1.17  		position = &positions[i];
    1.18  		velocity = &velocities[i];
    1.19  		position->x += velocity->x;
    1.20 -		if ( (position->x < 0) || (position->x >= screen->w) ) {
    1.21 +		if ( (position->x < 0) || (position->x >= (screen->w - sprite_w)) ) {
    1.22  			velocity->x = -velocity->x;
    1.23  			position->x += velocity->x;
    1.24  		}
    1.25  		position->y += velocity->y;
    1.26 -		if ( (position->y < 0) || (position->y >= screen->h) ) {
    1.27 +		if ( (position->y < 0) || (position->y >= (screen->h - sprite_w)) ) {
    1.28  			velocity->y = -velocity->y;
    1.29  			position->y += velocity->y;
    1.30  		}
    1.31 @@ -209,10 +209,12 @@
    1.32  	sprite_rects += numsprites;
    1.33  	velocities = sprite_rects;
    1.34  	sprite_rects += numsprites;
    1.35 +	sprite_w = sprite->w;
    1.36 +	sprite_h = sprite->h;
    1.37  	srand(time(NULL));
    1.38  	for ( i=0; i<numsprites; ++i ) {
    1.39 -		positions[i].x = rand()%screen->w;
    1.40 -		positions[i].y = rand()%screen->h;
    1.41 +		positions[i].x = rand()%(screen->w - sprite_w);
    1.42 +		positions[i].y = rand()%(screen->h - sprite_h);
    1.43  		positions[i].w = sprite->w;
    1.44  		positions[i].h = sprite->h;
    1.45  		velocities[i].x = 0;
    1.46 @@ -285,5 +287,6 @@
    1.47  		printf("%2.2f frames per second\n",
    1.48  					((double)frames*1000)/(now-then));
    1.49  	}
    1.50 +	SDL_Quit();
    1.51  	return(0);
    1.52  }