test/testsprite2.c
changeset 9922 b066d5fd5fa7
parent 9619 b94b6d0bff0f
child 9998 f67cf37e9cd4
equal deleted inserted replaced
9921:8865d17947de 9922:b066d5fd5fa7
   201         for (i = 0; i < num_sprites; ++i) {
   201         for (i = 0; i < num_sprites; ++i) {
   202             position = &positions[i];
   202             position = &positions[i];
   203             velocity = &velocities[i];
   203             velocity = &velocities[i];
   204             position->x += velocity->x;
   204             position->x += velocity->x;
   205             if ((position->x < 0) || (position->x >= (viewport.w - sprite_w))) {
   205             if ((position->x < 0) || (position->x >= (viewport.w - sprite_w))) {
   206             	velocity->x = -velocity->x;
   206                 velocity->x = -velocity->x;
   207             	position->x += velocity->x;
   207                 position->x += velocity->x;
   208             }
   208             }
   209             position->y += velocity->y;
   209             position->y += velocity->y;
   210             if ((position->y < 0) || (position->y >= (viewport.h - sprite_h))) {
   210             if ((position->y < 0) || (position->y >= (viewport.h - sprite_h))) {
   211             	velocity->y = -velocity->y;
   211                 velocity->y = -velocity->y;
   212             	position->y += velocity->y;
   212                 position->y += velocity->y;
   213             }
   213             }
   214 
   214 
   215         }
   215         }
   216         
   216         
   217         /* Countdown sprite-move iterations and disable color changes at iteration end - used for visual tests. */
   217         /* Countdown sprite-move iterations and disable color changes at iteration end - used for visual tests. */
   225     }
   225     }
   226 
   226 
   227     /* Draw sprites */
   227     /* Draw sprites */
   228     for (i = 0; i < num_sprites; ++i) {
   228     for (i = 0; i < num_sprites; ++i) {
   229         position = &positions[i];
   229         position = &positions[i];
   230 		
   230 
   231         /* Blit the sprite onto the screen */
   231         /* Blit the sprite onto the screen */
   232         SDL_RenderCopy(renderer, sprite, NULL, position);
   232         SDL_RenderCopy(renderer, sprite, NULL, position);
   233     }
   233     }
   234 
   234 
   235     /* Update the screen! */
   235     /* Update the screen! */
   261 int
   261 int
   262 main(int argc, char *argv[])
   262 main(int argc, char *argv[])
   263 {
   263 {
   264     int i;
   264     int i;
   265     Uint32 then, now, frames;
   265     Uint32 then, now, frames;
   266 	Uint64 seed;
   266     Uint64 seed;
   267     const char *icon = "icon.bmp";
   267     const char *icon = "icon.bmp";
   268 
   268 
   269     /* Initialize parameters */
   269     /* Initialize parameters */
   270     num_sprites = NUM_SPRITES;
   270     num_sprites = NUM_SPRITES;
   271 
   271