Mercurial > sdl-ios-xcode
annotate test/testalpha.c @ 2809:7e257c3a3bf0
Temporary fix for Mac OS X crash in textoverlay
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 29 Nov 2008 21:48:14 +0000 |
parents | 938aa47f903a |
children | cf271ff76061 |
rev | line source |
---|---|
0 | 1 |
2 /* Simple program: Fill a colormap with gray and stripe it down the screen, | |
3 Then move an alpha valued sprite around the screen. | |
4 */ | |
5 | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <string.h> | |
9 #include <math.h> | |
10 | |
11 #include "SDL.h" | |
12 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
13 #define FRAME_TICKS (1000/30) /* 30 frames/second */ |
0 | 14 |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
886
diff
changeset
|
15 /* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
16 static void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
17 quit(int rc) |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
886
diff
changeset
|
18 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
19 SDL_Quit(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
20 exit(rc); |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
886
diff
changeset
|
21 } |
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
886
diff
changeset
|
22 |
1293
23b1ef7d003b
Added some useful command line arguments for testing
Sam Lantinga <slouken@libsdl.org>
parents:
1152
diff
changeset
|
23 /* Fill the screen with a gradient */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
24 static void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
25 FillBackground(SDL_Surface * screen) |
1293
23b1ef7d003b
Added some useful command line arguments for testing
Sam Lantinga <slouken@libsdl.org>
parents:
1152
diff
changeset
|
26 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
27 Uint8 *buffer; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
28 Uint8 gradient; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
29 int i, k; |
1293
23b1ef7d003b
Added some useful command line arguments for testing
Sam Lantinga <slouken@libsdl.org>
parents:
1152
diff
changeset
|
30 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
31 /* Set the surface pixels and refresh! */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
32 if (SDL_LockSurface(screen) < 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
33 fprintf(stderr, "Couldn't lock the display surface: %s\n", |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
34 SDL_GetError()); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
35 quit(2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
36 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
37 buffer = (Uint8 *) screen->pixels; |
2799
bbf3aac2672a
Again, map the color with the alpha channel filled in.
Sam Lantinga <slouken@libsdl.org>
parents:
2797
diff
changeset
|
38 switch (screen->format->BytesPerPixel) { |
2806
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
39 case 1: |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
40 case 3: |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
41 for (i = 0; i < screen->h; ++i) { |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
42 memset(buffer, (i * 255) / screen->h, |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
43 screen->w * screen->format->BytesPerPixel); |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
44 buffer += screen->pitch; |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
45 } |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
46 break; |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
47 case 2: |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
48 for (i = 0; i < screen->h; ++i) { |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
49 Uint16 *buffer16; |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
50 Uint16 color; |
2799
bbf3aac2672a
Again, map the color with the alpha channel filled in.
Sam Lantinga <slouken@libsdl.org>
parents:
2797
diff
changeset
|
51 |
2806
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
52 gradient = ((i * 255) / screen->h); |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
53 color = (Uint16) SDL_MapRGB(screen->format, |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
54 gradient, gradient, gradient); |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
55 buffer16 = (Uint16 *) buffer; |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
56 for (k = 0; k < screen->w; k++) { |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
57 *buffer16++ = color; |
2799
bbf3aac2672a
Again, map the color with the alpha channel filled in.
Sam Lantinga <slouken@libsdl.org>
parents:
2797
diff
changeset
|
58 } |
2806
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
59 buffer += screen->pitch; |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
60 } |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
61 break; |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
62 case 4: |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
63 for (i = 0; i < screen->h; ++i) { |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
64 Uint32 *buffer32; |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
65 Uint32 color; |
2799
bbf3aac2672a
Again, map the color with the alpha channel filled in.
Sam Lantinga <slouken@libsdl.org>
parents:
2797
diff
changeset
|
66 |
2806
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
67 gradient = ((i * 255) / screen->h); |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
68 color = SDL_MapRGB(screen->format, gradient, gradient, gradient); |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
69 buffer32 = (Uint32 *) buffer; |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
70 for (k = 0; k < screen->w; k++) { |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
71 *buffer32++ = color; |
2799
bbf3aac2672a
Again, map the color with the alpha channel filled in.
Sam Lantinga <slouken@libsdl.org>
parents:
2797
diff
changeset
|
72 } |
2806
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
73 buffer += screen->pitch; |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
74 } |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
75 break; |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
76 } |
1293
23b1ef7d003b
Added some useful command line arguments for testing
Sam Lantinga <slouken@libsdl.org>
parents:
1152
diff
changeset
|
77 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
78 SDL_UnlockSurface(screen); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
79 SDL_UpdateRect(screen, 0, 0, 0, 0); |
1293
23b1ef7d003b
Added some useful command line arguments for testing
Sam Lantinga <slouken@libsdl.org>
parents:
1152
diff
changeset
|
80 } |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
886
diff
changeset
|
81 |
0 | 82 /* Create a "light" -- a yellowish surface with variable alpha */ |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
83 SDL_Surface * |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
84 CreateLight(int radius) |
0 | 85 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
86 Uint8 trans, alphamask; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
87 int range, addition; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
88 int xdist, ydist; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
89 Uint16 x, y; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
90 Uint16 skip; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
91 Uint32 pixel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
92 SDL_Surface *light; |
0 | 93 |
94 #ifdef LIGHT_16BIT | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
95 Uint16 *buf; |
0 | 96 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
97 /* Create a 16 (4/4/4/4) bpp square with a full 4-bit alpha channel */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
98 /* Note: this isn't any faster than a 32 bit alpha surface */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
99 alphamask = 0x0000000F; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
100 light = SDL_CreateRGBSurface(SDL_SWSURFACE, 2 * radius, 2 * radius, 16, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
101 0x0000F000, 0x00000F00, 0x000000F0, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
102 alphamask); |
0 | 103 #else |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
104 Uint32 *buf; |
0 | 105 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
106 /* Create a 32 (8/8/8/8) bpp square with a full 8-bit alpha channel */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
107 alphamask = 0x000000FF; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
108 light = SDL_CreateRGBSurface(SDL_SWSURFACE, 2 * radius, 2 * radius, 32, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
109 0xFF000000, 0x00FF0000, 0x0000FF00, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
110 alphamask); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
111 if (light == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
112 fprintf(stderr, "Couldn't create light: %s\n", SDL_GetError()); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
113 return (NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
114 } |
0 | 115 #endif |
116 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
117 /* Fill with a light yellow-orange color */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
118 skip = light->pitch - (light->w * light->format->BytesPerPixel); |
0 | 119 #ifdef LIGHT_16BIT |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
120 buf = (Uint16 *) light->pixels; |
0 | 121 #else |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
122 buf = (Uint32 *) light->pixels; |
0 | 123 #endif |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
124 /* Get a tranparent pixel value - we'll add alpha later */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
125 pixel = SDL_MapRGBA(light->format, 0xFF, 0xDD, 0x88, 0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
126 for (y = 0; y < light->h; ++y) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
127 for (x = 0; x < light->w; ++x) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
128 *buf++ = pixel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
129 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
130 buf += skip; /* Almost always 0, but just in case... */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
131 } |
0 | 132 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
133 /* Calculate alpha values for the surface. */ |
0 | 134 #ifdef LIGHT_16BIT |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
135 buf = (Uint16 *) light->pixels; |
0 | 136 #else |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
137 buf = (Uint32 *) light->pixels; |
0 | 138 #endif |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
139 for (y = 0; y < light->h; ++y) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
140 for (x = 0; x < light->w; ++x) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
141 /* Slow distance formula (from center of light) */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
142 xdist = x - (light->w / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
143 ydist = y - (light->h / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
144 range = (int) sqrt(xdist * xdist + ydist * ydist); |
0 | 145 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
146 /* Scale distance to range of transparency (0-255) */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
147 if (range > radius) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
148 trans = alphamask; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
149 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
150 /* Increasing transparency with distance */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
151 trans = (Uint8) ((range * alphamask) / radius); |
0 | 152 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
153 /* Lights are very transparent */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
154 addition = (alphamask + 1) / 8; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
155 if ((int) trans + addition > alphamask) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
156 trans = alphamask; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
157 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
158 trans += addition; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
159 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
160 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
161 /* We set the alpha component as the right N bits */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
162 *buf++ |= (255 - trans); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
163 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
164 buf += skip; /* Almost always 0, but just in case... */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
165 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
166 /* Enable RLE acceleration of this alpha surface */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
167 SDL_SetAlpha(light, SDL_SRCALPHA | SDL_RLEACCEL, 0); |
0 | 168 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
169 /* We're done! */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
170 return (light); |
0 | 171 } |
172 | |
173 static Uint32 flashes = 0; | |
174 static Uint32 flashtime = 0; | |
175 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
176 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
177 FlashLight(SDL_Surface * screen, SDL_Surface * light, int x, int y) |
0 | 178 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
179 SDL_Rect position; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
180 Uint32 ticks1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
181 Uint32 ticks2; |
0 | 182 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
183 /* Easy, center light */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
184 position.x = x - (light->w / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
185 position.y = y - (light->h / 2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
186 position.w = light->w; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
187 position.h = light->h; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
188 ticks1 = SDL_GetTicks(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
189 SDL_BlitSurface(light, NULL, screen, &position); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
190 ticks2 = SDL_GetTicks(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
191 SDL_UpdateRects(screen, 1, &position); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
192 ++flashes; |
0 | 193 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
194 /* Update time spend doing alpha blitting */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
195 flashtime += (ticks2 - ticks1); |
0 | 196 } |
197 | |
198 static int sprite_visible = 0; | |
199 static SDL_Surface *sprite; | |
200 static SDL_Surface *backing; | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
201 static SDL_Rect position; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
202 static int x_vel, y_vel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
203 static int alpha_vel; |
0 | 204 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
205 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
206 LoadSprite(SDL_Surface * screen, char *file) |
0 | 207 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
208 SDL_Surface *converted; |
0 | 209 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
210 /* Load the sprite image */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
211 sprite = SDL_LoadBMP(file); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
212 if (sprite == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
213 fprintf(stderr, "Couldn't load %s: %s", file, SDL_GetError()); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
214 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
215 } |
0 | 216 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
217 /* Set transparent pixel as the pixel at (0,0) */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
218 if (sprite->format->palette) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
219 SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, *(Uint8 *) sprite->pixels); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
220 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
221 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
222 /* Convert sprite to video format */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
223 converted = SDL_DisplayFormat(sprite); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
224 SDL_FreeSurface(sprite); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
225 if (converted == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
226 fprintf(stderr, "Couldn't convert background: %s\n", SDL_GetError()); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
227 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
228 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
229 sprite = converted; |
0 | 230 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
231 /* Create the background */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
232 backing = SDL_CreateRGBSurface(SDL_SWSURFACE, sprite->w, sprite->h, 8, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
233 0, 0, 0, 0); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
234 if (backing == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
235 fprintf(stderr, "Couldn't create background: %s\n", SDL_GetError()); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
236 SDL_FreeSurface(sprite); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
237 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
238 } |
0 | 239 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
240 /* Convert background to video format */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
241 converted = SDL_DisplayFormat(backing); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
242 SDL_FreeSurface(backing); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
243 if (converted == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
244 fprintf(stderr, "Couldn't convert background: %s\n", SDL_GetError()); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
245 SDL_FreeSurface(sprite); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
246 return (-1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
247 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
248 backing = converted; |
0 | 249 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
250 /* Set the initial position of the sprite */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
251 position.x = (screen->w - sprite->w) / 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
252 position.y = (screen->h - sprite->h) / 2; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
253 position.w = sprite->w; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
254 position.h = sprite->h; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
255 x_vel = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
256 y_vel = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
257 alpha_vel = 1; |
0 | 258 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
259 /* We're ready to roll. :) */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
260 return (0); |
0 | 261 } |
262 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
263 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
264 AttractSprite(Uint16 x, Uint16 y) |
0 | 265 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
266 x_vel = ((int) x - position.x) / 10; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
267 y_vel = ((int) y - position.y) / 10; |
0 | 268 } |
269 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
270 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
271 MoveSprite(SDL_Surface * screen, SDL_Surface * light) |
0 | 272 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
273 SDL_Rect updates[2]; |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
274 Uint8 alpha; |
0 | 275 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
276 /* Erase the sprite if it was visible */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
277 if (sprite_visible) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
278 updates[0] = position; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
279 SDL_BlitSurface(backing, NULL, screen, &updates[0]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
280 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
281 updates[0].x = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
282 updates[0].y = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
283 updates[0].w = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
284 updates[0].h = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
285 sprite_visible = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
286 } |
0 | 287 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
288 /* Since the sprite is off the screen, we can do other drawing |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
289 without being overwritten by the saved area behind the sprite. |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
290 */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
291 if (light != NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
292 int x, y; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
293 |
2710
44e49d3fa6cf
Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents:
2267
diff
changeset
|
294 SDL_GetMouseState(0, &x, &y); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
295 FlashLight(screen, light, x, y); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
296 } |
0 | 297 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
298 /* Move the sprite, bounce at the wall */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
299 position.x += x_vel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
300 if ((position.x < 0) || (position.x >= screen->w)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
301 x_vel = -x_vel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
302 position.x += x_vel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
303 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
304 position.y += y_vel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
305 if ((position.y < 0) || (position.y >= screen->h)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
306 y_vel = -y_vel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
307 position.y += y_vel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
308 } |
0 | 309 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
310 /* Update transparency (fade in and out) */ |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
311 SDL_GetSurfaceAlphaMod(sprite, &alpha); |
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
312 if (((int) alpha + alpha_vel) < 0) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
313 alpha_vel = -alpha_vel; |
2267
c785543d1843
Okay, still some bugs, but everything builds again...
Sam Lantinga <slouken@libsdl.org>
parents:
1895
diff
changeset
|
314 } else if (((int) alpha + alpha_vel) > 255) { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
315 alpha_vel = -alpha_vel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
316 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
317 SDL_SetAlpha(sprite, SDL_SRCALPHA, (Uint8) (alpha + alpha_vel)); |
0 | 318 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
319 /* Save the area behind the sprite */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
320 updates[1] = position; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
321 SDL_BlitSurface(screen, &updates[1], backing, NULL); |
0 | 322 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
323 /* Blit the sprite onto the screen */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
324 updates[1] = position; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
325 SDL_BlitSurface(sprite, NULL, screen, &updates[1]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
326 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
327 /* Make it so! */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
328 SDL_UpdateRects(screen, 2, updates); |
0 | 329 } |
330 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
331 void |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
332 WarpSprite(SDL_Surface * screen, int x, int y) |
0 | 333 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
334 SDL_Rect updates[2]; |
0 | 335 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
336 /* Erase, move, Draw, update */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
337 updates[0] = position; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
338 SDL_BlitSurface(backing, NULL, screen, &updates[0]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
339 position.x = x - sprite->w / 2; /* Center about X */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
340 position.y = y - sprite->h / 2; /* Center about Y */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
341 updates[1] = position; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
342 SDL_BlitSurface(screen, &updates[1], backing, NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
343 updates[1] = position; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
344 SDL_BlitSurface(sprite, NULL, screen, &updates[1]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
345 SDL_UpdateRects(screen, 2, updates); |
0 | 346 } |
347 | |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
348 int |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
349 main(int argc, char *argv[]) |
0 | 350 { |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
351 const SDL_VideoInfo *info; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
352 SDL_Surface *screen; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
353 int w, h; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
354 Uint8 video_bpp; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
355 Uint32 videoflags; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
356 int i, done; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
357 SDL_Event event; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
358 SDL_Surface *light; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
359 int mouse_pressed; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
360 Uint32 ticks, lastticks; |
691
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
361 |
0 | 362 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
363 /* Initialize SDL */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
364 if (SDL_Init(SDL_INIT_VIDEO) < 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
365 fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
366 return (1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
367 } |
0 | 368 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
369 /* Alpha blending doesn't work well at 8-bit color */ |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1293
diff
changeset
|
370 #ifdef _WIN32_WCE |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
371 /* Pocket PC */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
372 w = 240; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
373 h = 320; |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1293
diff
changeset
|
374 #else |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
375 w = 640; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
376 h = 480; |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1293
diff
changeset
|
377 #endif |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
378 info = SDL_GetVideoInfo(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
379 if (info->vfmt->BitsPerPixel > 8) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
380 video_bpp = info->vfmt->BitsPerPixel; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
381 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
382 video_bpp = 16; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
383 fprintf(stderr, "forced 16 bpp mode\n"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
384 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
385 videoflags = SDL_SWSURFACE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
386 for (i = 1; argv[i]; ++i) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
387 if (strcmp(argv[i], "-bpp") == 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
388 video_bpp = atoi(argv[++i]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
389 if (video_bpp <= 8) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
390 video_bpp = 16; |
691
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
391 fprintf(stderr, "forced 16 bpp mode\n"); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
392 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
393 } else if (strcmp(argv[i], "-hw") == 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
394 videoflags |= SDL_HWSURFACE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
395 } else if (strcmp(argv[i], "-warp") == 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
396 videoflags |= SDL_HWPALETTE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
397 } else if (strcmp(argv[i], "-width") == 0 && argv[i + 1]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
398 w = atoi(argv[++i]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
399 } else if (strcmp(argv[i], "-height") == 0 && argv[i + 1]) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
400 h = atoi(argv[++i]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
401 } else if (strcmp(argv[i], "-resize") == 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
402 videoflags |= SDL_RESIZABLE; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
403 } else if (strcmp(argv[i], "-noframe") == 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
404 videoflags |= SDL_NOFRAME; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
405 } else if (strcmp(argv[i], "-fullscreen") == 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
406 videoflags |= SDL_FULLSCREEN; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
407 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
408 fprintf(stderr, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
409 "Usage: %s [-width N] [-height N] [-bpp N] [-warp] [-hw] [-fullscreen]\n", |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
410 argv[0]); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
411 quit(1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
412 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
413 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
414 |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
415 /* Set video mode */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
416 if ((screen = SDL_SetVideoMode(w, h, video_bpp, videoflags)) == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
417 fprintf(stderr, "Couldn't set %dx%dx%d video mode: %s\n", |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
418 w, h, video_bpp, SDL_GetError()); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
419 quit(2); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
420 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
421 FillBackground(screen); |
0 | 422 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
423 /* Create the light */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
424 light = CreateLight(82); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
425 if (light == NULL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
426 quit(1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
427 } |
0 | 428 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
429 /* Load the sprite */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
430 if (LoadSprite(screen, "icon.bmp") < 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
431 SDL_FreeSurface(light); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
432 quit(1); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
433 } |
0 | 434 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
435 /* Print out information about our surfaces */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
436 printf("Screen is at %d bits per pixel\n", screen->format->BitsPerPixel); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
437 if ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
438 printf("Screen is in video memory\n"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
439 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
440 printf("Screen is in system memory\n"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
441 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
442 if ((screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
443 printf("Screen has double-buffering enabled\n"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
444 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
445 if ((sprite->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
446 printf("Sprite is in video memory\n"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
447 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
448 printf("Sprite is in system memory\n"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
449 } |
0 | 450 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
451 /* Run a sample blit to trigger blit acceleration */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
452 MoveSprite(screen, NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
453 if ((sprite->flags & SDL_HWACCEL) == SDL_HWACCEL) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
454 printf("Sprite blit uses hardware alpha acceleration\n"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
455 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
456 printf("Sprite blit dosn't uses hardware alpha acceleration\n"); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
457 } |
886
05c551e5bc64
Date: Sat, 24 Apr 2004 15:13:32 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
458 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
459 /* Set a clipping rectangle to clip the outside edge of the screen */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
460 { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
461 SDL_Rect clip; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
462 clip.x = 32; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
463 clip.y = 32; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
464 clip.w = screen->w - (2 * 32); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
465 clip.h = screen->h - (2 * 32); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
466 SDL_SetClipRect(screen, &clip); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
467 } |
0 | 468 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
469 /* Wait for a keystroke */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
470 lastticks = SDL_GetTicks(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
471 done = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
472 mouse_pressed = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
473 while (!done) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
474 /* Update the frame -- move the sprite */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
475 if (mouse_pressed) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
476 MoveSprite(screen, light); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
477 mouse_pressed = 0; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
478 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
479 MoveSprite(screen, NULL); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
480 } |
0 | 481 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
482 /* Slow down the loop to 30 frames/second */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
483 ticks = SDL_GetTicks(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
484 if ((ticks - lastticks) < FRAME_TICKS) { |
0 | 485 #ifdef CHECK_SLEEP_GRANULARITY |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
486 fprintf(stderr, "Sleeping %d ticks\n", |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
487 FRAME_TICKS - (ticks - lastticks)); |
0 | 488 #endif |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
489 SDL_Delay(FRAME_TICKS - (ticks - lastticks)); |
0 | 490 #ifdef CHECK_SLEEP_GRANULARITY |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
491 fprintf(stderr, "Slept %d ticks\n", (SDL_GetTicks() - ticks)); |
0 | 492 #endif |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
493 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
494 lastticks = ticks; |
0 | 495 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
496 /* Check for events */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
497 while (SDL_PollEvent(&event)) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
498 switch (event.type) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
499 case SDL_VIDEORESIZE: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
500 screen = |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
501 SDL_SetVideoMode(event.resize.w, event.resize.h, |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
502 video_bpp, videoflags); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
503 if (screen) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
504 FillBackground(screen); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
505 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
506 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
507 /* Attract sprite while mouse is held down */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
508 case SDL_MOUSEMOTION: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
509 if (event.motion.state != 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
510 AttractSprite(event.motion.x, event.motion.y); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
511 mouse_pressed = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
512 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
513 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
514 case SDL_MOUSEBUTTONDOWN: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
515 if (event.button.button == 1) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
516 AttractSprite(event.button.x, event.button.y); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
517 mouse_pressed = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
518 } else { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
519 SDL_Rect area; |
0 | 520 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
521 area.x = event.button.x - 16; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
522 area.y = event.button.y - 16; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
523 area.w = 32; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
524 area.h = 32; |
2806
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
525 SDL_FillRect(screen, &area, |
938aa47f903a
Fixed testalpha screen clear for screen formats with an alpha channel
Sam Lantinga <slouken@libsdl.org>
parents:
2799
diff
changeset
|
526 SDL_MapRGB(screen->format, 0, 0, 0)); |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
527 SDL_UpdateRects(screen, 1, &area); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
528 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
529 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
530 case SDL_KEYDOWN: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
531 if (event.key.keysym.sym == SDLK_ESCAPE) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
532 done = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
533 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
534 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
535 case SDL_QUIT: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
536 done = 1; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
537 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
538 default: |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
539 break; |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
540 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
541 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
542 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
543 SDL_FreeSurface(light); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
544 SDL_FreeSurface(sprite); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
545 SDL_FreeSurface(backing); |
0 | 546 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
547 /* Print out some timing information */ |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
548 if (flashes > 0) { |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
549 printf("%d alpha blits, ~%4.4f ms per blit\n", |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
550 flashes, (float) flashtime / flashes); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
551 } |
1151
be9c9c8f6d53
Removed atexit() from most of the test programs; atexit(SDL_Quit) isn't safe
Ryan C. Gordon <icculus@icculus.org>
parents:
886
diff
changeset
|
552 |
1895
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
553 SDL_Quit(); |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
554 return (0); |
0 | 555 } |