diff test/testsprite.c @ 288:2f5a6062db86

Updated for Watcom C++ and LCC compilers
author Sam Lantinga <slouken@libsdl.org>
date Thu, 28 Feb 2002 00:28:26 +0000
parents 01fcac5d146e
children 21409a7a5fee
line wrap: on
line diff
--- a/test/testsprite.c	Wed Feb 27 16:15:34 2002 +0000
+++ b/test/testsprite.c	Thu Feb 28 00:28:26 2002 +0000
@@ -1,4 +1,3 @@
-
 /* Simple program:  Move N sprites around on the screen as fast as possible */
 
 #include <stdio.h>
@@ -18,6 +17,7 @@
 SDL_Rect *positions;
 SDL_Rect *velocities;
 int sprites_visible;
+Uint16 sprite_w, sprite_h;
 
 int LoadSprite(SDL_Surface *screen, char *file)
 {
@@ -66,12 +66,12 @@
 		position = &positions[i];
 		velocity = &velocities[i];
 		position->x += velocity->x;
-		if ( (position->x < 0) || (position->x >= screen->w) ) {
+		if ( (position->x < 0) || (position->x >= (screen->w - sprite_w)) ) {
 			velocity->x = -velocity->x;
 			position->x += velocity->x;
 		}
 		position->y += velocity->y;
-		if ( (position->y < 0) || (position->y >= screen->h) ) {
+		if ( (position->y < 0) || (position->y >= (screen->h - sprite_w)) ) {
 			velocity->y = -velocity->y;
 			position->y += velocity->y;
 		}
@@ -209,10 +209,12 @@
 	sprite_rects += numsprites;
 	velocities = sprite_rects;
 	sprite_rects += numsprites;
+	sprite_w = sprite->w;
+	sprite_h = sprite->h;
 	srand(time(NULL));
 	for ( i=0; i<numsprites; ++i ) {
-		positions[i].x = rand()%screen->w;
-		positions[i].y = rand()%screen->h;
+		positions[i].x = rand()%(screen->w - sprite_w);
+		positions[i].y = rand()%(screen->h - sprite_h);
 		positions[i].w = sprite->w;
 		positions[i].h = sprite->h;
 		velocities[i].x = 0;
@@ -285,5 +287,6 @@
 		printf("%2.2f frames per second\n",
 					((double)frames*1000)/(now-then));
 	}
+	SDL_Quit();
 	return(0);
 }