Mercurial > sdl-ios-xcode
annotate test/testalpha.c @ 4426:1bceff8f008f
Fixed bug #943
Ozkan Sezer 2010-02-06 12:31:06 PST
Hi:
Here are some small fixes for compiling SDL against mingw-w64.
(see http://mingw-w64.sourceforge.net/ . Despite the name, it
supports both win32 and win64.)
src/audio/windx5/directx.h and src/video/windx5/directx.h (both
SDL-1.2 and SDL-1.3.) I get compilation errors about some union
not having a member named u1 and alike, because of other system
headers being included before this one and them already defining
DUMMYUNIONNAME and stuff. This header probably assumes that those
stuff are defined in windef.h, but mingw-w64 headers define them
in _mingw.h. Easily fixed by moving NONAMELESSUNION definition to
the top of the file.
src/thread/win32/SDL_systhread.c (both SDL-1.2 and SDL-1.3.) :
The __GNUC__ case for pfnSDL_CurrentBeginThread is 32-bit centric
because _beginthreadex returns uintptr_t, not unsigned long which
is 32 bits in win64. Changing the return type to uintptr_t fixes
it.
video/SDL_blit.h (and configure.in) (SDL-1.3-only) : MinGW-w64
uses msvcrt version of _aligned_malloc and _aligned_free and
they are defined in intrin.h (similar to VC). Adding proper
ifdefs fixes it. (Notes about macros to check: __MINGW32__ is
defined for both mingw.org and for mingw-w64 for both win32 and
win64, __MINGW64__ is only defined for _WIN64, so __MINGW64__
can't be used to detect mingw-w64: including _mingw.h and then
checking for __MINGW64_VERSION_MAJOR does the trick.)
SDL_win32video.h (SDL-1.3-only) : Tweaked the VINWER definition
and location in order to avoid multiple redefinition warnings.
Hope these are useful. Thanks.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 10 Mar 2010 15:02:58 +0000 |
parents | f8816ffa210b |
children |
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 |
3585
f8816ffa210b
Initial band-aids on SDL_GetMouseState() API breakage. More work to come.
Ryan C. Gordon <icculus@icculus.org>
parents:
2822
diff
changeset
|
294 SDL_GetMouseState(&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 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
|
332 main(int argc, char *argv[]) |
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 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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 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
|
343 Uint32 ticks, lastticks; |
691
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
344 |
0 | 345 |
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
|
346 /* 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
|
347 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
|
348 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
|
349 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
|
350 } |
0 | 351 |
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
|
352 /* 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
|
353 #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
|
354 /* 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
|
355 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
|
356 h = 320; |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1293
diff
changeset
|
357 #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
|
358 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
|
359 h = 480; |
1465
8dfa9a6d69a5
Updated WinCE support by Dmitry (with some tweaks)
Sam Lantinga <slouken@libsdl.org>
parents:
1293
diff
changeset
|
360 #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
|
361 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
|
362 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
|
363 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
|
364 } 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
|
365 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
|
366 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
|
367 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
368 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 video_bpp = 16; |
691
609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
0
diff
changeset
|
374 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
|
375 } |
c121d94672cb
SDL 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 } 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
|
377 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
|
378 } 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
|
379 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
|
380 } 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
|
381 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
|
382 } 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
|
383 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
|
384 } 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
|
385 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
|
386 } 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
|
387 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
|
388 } 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
|
389 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
|
390 } 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
|
391 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
|
392 "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
|
393 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
|
394 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
|
395 } |
c121d94672cb
SDL 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 } |
c121d94672cb
SDL 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 |
c121d94672cb
SDL 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 /* 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
|
399 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
|
400 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
|
401 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
|
402 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
|
403 } |
c121d94672cb
SDL 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 FillBackground(screen); |
0 | 405 |
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
|
406 /* 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
|
407 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
|
408 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
|
409 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
|
410 } |
0 | 411 |
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
|
412 /* 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
|
413 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
|
414 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
|
415 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
|
416 } |
0 | 417 |
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
|
418 /* 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
|
419 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
|
420 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
|
421 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
|
422 } 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
|
423 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
|
424 } |
c121d94672cb
SDL 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 ((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
|
426 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
|
427 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
428 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
|
429 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
|
430 } 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
|
431 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
|
432 } |
0 | 433 |
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
|
434 /* 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
|
435 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
|
436 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
|
437 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
|
438 } 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
|
439 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
|
440 } |
886
05c551e5bc64
Date: Sat, 24 Apr 2004 15:13:32 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
691
diff
changeset
|
441 |
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
|
442 /* 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
|
443 { |
c121d94672cb
SDL 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 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
|
445 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
|
446 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
|
447 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
|
448 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
|
449 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
|
450 } |
0 | 451 |
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
|
452 /* 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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 /* 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
|
458 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
|
459 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
|
460 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
|
461 } 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
|
462 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
|
463 } |
0 | 464 |
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
|
465 /* 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
|
466 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
|
467 if ((ticks - lastticks) < FRAME_TICKS) { |
0 | 468 #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
|
469 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
|
470 FRAME_TICKS - (ticks - lastticks)); |
0 | 471 #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
|
472 SDL_Delay(FRAME_TICKS - (ticks - lastticks)); |
0 | 473 #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
|
474 fprintf(stderr, "Slept %d ticks\n", (SDL_GetTicks() - ticks)); |
0 | 475 #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
|
476 } |
c121d94672cb
SDL 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 lastticks = ticks; |
0 | 478 |
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
|
479 /* 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
|
480 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
|
481 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
|
482 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
|
483 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
|
484 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
|
485 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
|
486 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
|
487 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
|
488 } |
c121d94672cb
SDL 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 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
|
490 /* 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
|
491 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
|
492 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
|
493 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
|
494 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
|
495 } |
c121d94672cb
SDL 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 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
|
497 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
|
498 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
|
499 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
|
500 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
|
501 } 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
|
502 SDL_Rect area; |
0 | 503 |
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
|
504 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
|
505 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
|
506 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
|
507 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
|
508 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
|
509 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
|
510 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
|
511 } |
c121d94672cb
SDL 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 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
|
513 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
|
514 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
|
515 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
|
516 } |
c121d94672cb
SDL 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 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
|
518 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
|
519 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
|
520 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
|
521 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
|
522 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
|
523 } |
c121d94672cb
SDL 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 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
525 } |
c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
1779
diff
changeset
|
526 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
|
527 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
|
528 SDL_FreeSurface(backing); |
0 | 529 |
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
|
530 /* 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
|
531 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
|
532 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
|
533 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
|
534 } |
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
|
535 |
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
|
536 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
|
537 return (0); |
0 | 538 } |