test/testsprite2.c
changeset 1985 8055185ae4ed
parent 1965 a788656ca29a
child 2222 926294b2bb4e
     1.1 --- a/test/testsprite2.c	Thu Aug 24 12:49:59 2006 +0000
     1.2 +++ b/test/testsprite2.c	Mon Aug 28 03:17:39 2006 +0000
     1.3 @@ -8,11 +8,15 @@
     1.4  
     1.5  #define NUM_SPRITES	100
     1.6  #define MAX_SPEED 	1
     1.7 -#define BACKGROUND  0x00A0A0A0
     1.8  
     1.9  static CommonState *state;
    1.10  static int num_sprites;
    1.11  static SDL_TextureID *sprites;
    1.12 +static SDL_bool cycle_color;
    1.13 +static SDL_bool cycle_alpha;
    1.14 +static int cycle_direction = 1;
    1.15 +static int current_alpha = 0;
    1.16 +static int current_color = 0;
    1.17  static SDL_Rect *positions;
    1.18  static SDL_Rect *velocities;
    1.19  static int sprite_w, sprite_h;
    1.20 @@ -66,6 +70,8 @@
    1.21              SDL_FreeSurface(temp);
    1.22              return (-1);
    1.23          }
    1.24 +        SDL_SetTextureBlendMode(sprites[i], blendMode);
    1.25 +        SDL_SetTextureScaleMode(sprites[i], scaleMode);
    1.26      }
    1.27      SDL_FreeSurface(temp);
    1.28  
    1.29 @@ -85,9 +91,36 @@
    1.30      /* Query the sizes */
    1.31      SDL_GetWindowSize(window, &window_w, &window_h);
    1.32  
    1.33 +    /* Cycle the color and alpha, if desired */
    1.34 +    if (cycle_color) {
    1.35 +        current_color += cycle_direction;
    1.36 +        if (current_color < 0) {
    1.37 +            current_color = 0;
    1.38 +            cycle_direction = -cycle_direction;
    1.39 +        }
    1.40 +        if (current_color > 255) {
    1.41 +            current_color = 255;
    1.42 +            cycle_direction = -cycle_direction;
    1.43 +        }
    1.44 +        SDL_SetTextureColorMod(sprite, 255, (Uint8) current_color,
    1.45 +                               (Uint8) current_color);
    1.46 +    }
    1.47 +    if (cycle_alpha) {
    1.48 +        current_alpha += cycle_direction;
    1.49 +        if (current_alpha < 0) {
    1.50 +            current_alpha = 0;
    1.51 +            cycle_direction = -cycle_direction;
    1.52 +        }
    1.53 +        if (current_alpha > 255) {
    1.54 +            current_alpha = 255;
    1.55 +            cycle_direction = -cycle_direction;
    1.56 +        }
    1.57 +        SDL_SetTextureAlphaMod(sprite, (Uint8) current_alpha);
    1.58 +    }
    1.59 +
    1.60      /* Move the sprite, bounce at the wall, and draw */
    1.61      n = 0;
    1.62 -    SDL_RenderFill(NULL, BACKGROUND);
    1.63 +    SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
    1.64      for (i = 0; i < num_sprites; ++i) {
    1.65          position = &positions[i];
    1.66          velocity = &velocities[i];
    1.67 @@ -103,7 +136,7 @@
    1.68          }
    1.69  
    1.70          /* Blit the sprite onto the screen */
    1.71 -        SDL_RenderCopy(sprite, NULL, position, blendMode, scaleMode);
    1.72 +        SDL_RenderCopy(sprite, NULL, position);
    1.73      }
    1.74  
    1.75      /* Update the screen! */
    1.76 @@ -166,6 +199,12 @@
    1.77                          consumed = 2;
    1.78                      }
    1.79                  }
    1.80 +            } else if (SDL_strcasecmp(argv[i], "--cyclecolor") == 0) {
    1.81 +                cycle_color = SDL_TRUE;
    1.82 +                consumed = 1;
    1.83 +            } else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
    1.84 +                cycle_alpha = SDL_TRUE;
    1.85 +                consumed = 1;
    1.86              } else if (SDL_isdigit(*argv[i])) {
    1.87                  num_sprites = SDL_atoi(argv[i]);
    1.88                  consumed = 1;
    1.89 @@ -173,7 +212,7 @@
    1.90          }
    1.91          if (consumed < 0) {
    1.92              fprintf(stderr,
    1.93 -                    "Usage: %s %s [--blend none|mask|blend|add|mod] [--scale none|fast|slow|best]",
    1.94 +                    "Usage: %s %s [--blend none|mask|blend|add|mod] [--scale none|fast|slow|best] [--cyclecolor] [--cyclealpha]\n",
    1.95                      argv[0], CommonUsage(state));
    1.96              quit(1);
    1.97          }
    1.98 @@ -192,7 +231,7 @@
    1.99      }
   1.100      for (i = 0; i < state->num_windows; ++i) {
   1.101          SDL_SelectRenderer(state->windows[i]);
   1.102 -        SDL_RenderFill(NULL, BACKGROUND);
   1.103 +        SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
   1.104      }
   1.105      if (LoadSprite("icon.bmp") < 0) {
   1.106          quit(2);
   1.107 @@ -237,7 +276,7 @@
   1.108                  switch (event.window.event) {
   1.109                  case SDL_WINDOWEVENT_EXPOSED:
   1.110                      SDL_SelectRenderer(event.window.windowID);
   1.111 -                    SDL_RenderFill(NULL, BACKGROUND);
   1.112 +                    SDL_RenderFill(0xA0, 0xA0, 0xA0, 0xFF, NULL);
   1.113                      break;
   1.114                  }
   1.115                  break;