annotate test/testalpha.c @ 1158:ec446adf8cb2

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