1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539
|
/***********************************************************
* K O U L E S *
*----------------------------------------------------------*
* C1995 JAHUSOFT *
* Jan Hubicka *
* Dukelskych Bojovniku 1944 *
* 390 03 Tabor *
* Czech Republic *
* Phone: 0041-361-32613 *
* eMail: hubicka@limax.paru.cas.cz *
*----------------------------------------------------------*
* Copyright(c)1995,1996 by Jan Hubicka.See README for *
* licence details. *
*----------------------------------------------------------*
* framebuffer.c fast 8 bit framebuffer bitmap creation *
* routines *
***********************************************************/
#include "koules.h"
#define NCOLORS 32
#define HOLE_XCENTER (2*HOLE_RADIUS-3*HOLE_RADIUS/4)
#define HOLE_YCENTER (2*HOLE_RADIUS-HOLE_RADIUS/4)
#define HOLE_MAX_RADIUS (HOLE_RADIUS/DIV+0.5*HOLE_RADIUS/DIV)
#define HOLE_SIZE_MAX (radius*radius)
#ifndef NODIRECT
/*
* hardcoded bitmap drawing routines
*/
static char *
draw_ball_bitmap (int radius, CONST int color)
{
char *bitmap = NULL, *point;
int x, y, r;
radius /= DIV;
if ((bitmap = alloca ((radius * 2) * (radius * 2) + 2)) == NULL)
perror ("create_ball_bitmap"), exit (-1);
point = bitmap;
for (y = 0; y < radius * 2; y++)
for (x = 0; x < radius * 2; x++, point++)
{
if ((x - radius) * (x - radius) + (y - radius) * (y - radius)
< (radius - 0.5) * (radius - 0.5))
{
r = (x - 3 * radius / 4) * (x - 3 * radius / 4) +
(y - radius / 4) * (y - radius / 4);
r = r * 32 / (1.5 * radius) / (1.5 * radius);
if (r > 31)
r = 31;
*point = color + r;
}
else
*point = 0;
}
return (CompileBitmap (radius * 2, radius * 2, (char *) bitmap));
}
static char *
draw_reversed_ball_bitmap (int radius, CONST int color)
{
char *bitmap = NULL, *point;
int x, y, r;
radius /= DIV;
if ((bitmap = alloca ((radius * 2) * (radius * 2) + 2)) == NULL)
perror ("create_ball_bitmap"), exit (-1);
point = bitmap;
for (y = 0; y < radius * 2; y++)
for (x = 0; x < radius * 2; x++, point++)
{
if ((x - radius) * (x - radius) + (y - radius) * (y - radius)
< (radius - 0.5) * (radius - 0.5))
{
r = (x - 3 * radius / 4) * (x - 3 * radius / 4) +
(y - radius / 4) * (y - radius / 4);
r = r * 32 / (1.5 * radius) / (1.5 * radius);
if (r > 31)
r = 31;
*point = color + 16 + r / 2;
}
else
*point = 0;
}
return (CompileBitmap (radius * 2, radius * 2, (char *) bitmap));
}
static char *
draw_apple_bitmap (int radius, CONST int color)
{
char *bitmap = NULL, *point;
int x, y, r;
int radius1;
radius /= DIV;
if ((bitmap = alloca ((radius * 2) * (radius * 2) + 2)) == NULL)
perror ("create_ball_bitmap"), exit (-1);
point = bitmap;
for (y = 0; y < radius * 2; y++)
for (x = 0; x < radius * 2; x++, point++)
{
if (DIV == 2)
radius1 = radius * (abs (x - radius) / 2 + 25) / 30;
else
radius1 = radius * (abs (x - radius) / 2 + 50) / 60;
if (radius1 > radius)
radius1 = radius;
if ((x - radius) * (x - radius) + (y - radius) * (y - radius)
< ((radius1) * (radius1)))
{
r = (x - 3 * radius / 4) * (x - 3 * radius / 4) +
(y - radius / 4) * (y - radius / 4);
r = 3 + r * 22 / (1.5 * radius1) / (1.5 * radius1);
if (r > 31)
r = 31;
*point = color + r;
}
else
*point = 0;
}
return (CompileBitmap (radius * 2, radius * 2, (char *) bitmap));
}
#else
static float err = 0.0;
#ifdef XSUPPORT
static INLINE int
errdist (int c)
{
float sat, merr;
int i;
int p;
c &= 0xff;
sat = opixels[c] + err;
merr = sat - spixels[c];
p = c;
if (sat < spixels[c])
{
int max = c / 32;
max = (max + 1) * 32;
for (i = c; i < max && i < 255; i++)
{
if (fabs (merr) > fabs (spixels[i] - sat))
{
p = i;
merr = sat - spixels[i];
}
}
}
if (sat > spixels[c])
{
int min = c / 32;
min *= 32;
for (i = c; i > min && i > 0; i--)
{
if (fabs (merr) > fabs (spixels[i] - sat))
{
p = i;
merr = sat - spixels[i];
}
}
}
if (fabs (merr) > fabs (64 - sat))
{
p = 255;
merr = sat - 64;
}
if (fabs (merr) > fabs (sat))
{
p = 32;
merr = sat;
}
err = merr;
return (p);
}
#else
#define errdist(c) c
#endif
static BitmapType
draw_ball_bitmap (int radius, CONST int color)
{
RawBitmapType bbitmap;
int x, y, r, c;
radius /= DIV;
err = 0.0;
bbitmap = CreateBitmap ((radius * 2), (radius * 2));
for (y = 0; y < radius * 2; y++)
for (x = 0; x < radius * 2; x++)
{
if ((x - radius) * (x - radius) + (y - radius) * (y - radius)
< (radius - 0.5) * (radius - 0.5))
{
r = (x - 3 * radius / 4) * (x - 3 * radius / 4) +
(y - radius / 4) * (y - radius / 4);
r = r * 32 / (1.5 * radius) / (1.5 * radius);
if (r > 31)
r = 31;
c = errdist (color + r);
BSetPixel (bbitmap, x, y, c);
}
else
{
err = 0.0;
BSetPixel (bbitmap, x, y, 0);
}
}
return (CompileBitmap (radius * 2, radius * 2, bbitmap));
}
static BitmapType
draw_reversed_ball_bitmap (int radius, CONST int color)
{
RawBitmapType bbitmap;
int x, y, r, c;
radius /= DIV;
err = 0.0;
bbitmap = CreateBitmap ((radius * 2), (radius * 2));
for (y = 0; y < radius * 2; y++)
for (x = 0; x < radius * 2; x++)
{
if ((x - radius) * (x - radius) + (y - radius) * (y - radius)
< (radius - 0.5) * (radius - 0.5))
{
r = (x - 3 * radius / 4) * (x - 3 * radius / 4) +
(y - radius / 4) * (y - radius / 4);
r = r * 32 / (1.5 * radius) / (1.5 * radius);
if (r > 31)
r = 31;
c = errdist (color + 16 + r / 2);
BSetPixel (bbitmap, x, y, c);
}
else
{
err = 0.0;
BSetPixel (bbitmap, x, y, 0);
}
}
return (CompileBitmap (radius * 2, radius * 2, bbitmap));
}
static BitmapType
draw_apple_bitmap (int radius, CONST int color)
{
RawBitmapType bitmap;
int x, y, r, c;
int radius1;
radius /= DIV;
bitmap = CreateBitmap ((radius * 2), (radius * 2));
err = 0;
for (y = 0; y < radius * 2; y++)
for (x = 0; x < radius * 2; x++)
{
if (DIV == 2)
radius1 = radius * (abs (x - radius) / 2 + 25) / 30;
else
radius1 = radius * (abs (x - radius) / 2 + 50) / 60;
if (radius1 > radius)
radius1 = radius;
if ((x - radius) * (x - radius) + (y - radius) * (y - radius)
< ((radius1) * (radius1)))
{
r = (x - 3 * radius / 4) * (x - 3 * radius / 4) +
(y - radius / 4) * (y - radius / 4);
r = 3 + r * 22 / (1.5 * radius1) / (1.5 * radius1);
if (r > 31)
r = 31;
c = errdist (color + r);
BSetPixel (bitmap, x, y, c);
}
else
{
BSetPixel (bitmap, x, y, 0);
}
}
return (CompileBitmap (radius * 2, radius * 2, bitmap));
}
#endif
void
create_bitmap ()
{
int x, y, r, po, radius;
#ifndef NODIRECT
char hole_data[HOLE_RADIUS * 2][HOLE_RADIUS * 2];
char ehole_data[HOLE_RADIUS * 2][HOLE_RADIUS * 2];
#else
int c;
RawBitmapType hole_data, ehole_data;
#endif
printf ("creating bitmaps...\n");
#ifndef NODIRECT
for (x = 0; x < HOLE_RADIUS * 2; x++)
for (y = 0; y < HOLE_RADIUS * 2; y++)
{
if (DIV == 1)
radius = HOLE_RADIUS / 2 + (int) (atan (fabs (x - HOLE_RADIUS + 0.5) / fabs (y - HOLE_RADIUS + 0.5)) * HOLE_RADIUS / 2) % (HOLE_RADIUS / 2);
else
radius = HOLE_RADIUS / 4;
if ((x - HOLE_RADIUS / DIV) * (x - HOLE_RADIUS / DIV) + (y - HOLE_RADIUS / DIV) * (y - HOLE_RADIUS / DIV)
< radius * radius)
{
r = (x - HOLE_RADIUS / DIV) * (x - HOLE_RADIUS / DIV) +
(y - HOLE_RADIUS / DIV) * (y - HOLE_RADIUS / DIV);
r = r * 24 / HOLE_SIZE_MAX;
if (r > 23)
r = 23;
hole_data[x][y] = 64 + r + 1;
ehole_data[x][y] = 128 + r + 1;
}
else
hole_data[x][y] = 0,
ehole_data[x][y] = 0;
}
hole_bitmap = (CompileBitmap (HOLE_RADIUS * 2, HOLE_RADIUS * 2, (char *) hole_data));
ehole_bitmap = (CompileBitmap (HOLE_RADIUS * 2, HOLE_RADIUS * 2, (char *) ehole_data));
#else
ehole_data = CreateBitmap ((HOLE_RADIUS * 2), (HOLE_RADIUS * 2));
hole_data = CreateBitmap ((HOLE_RADIUS * 2), (HOLE_RADIUS * 2));
err = 0;
for (x = 0; x < HOLE_RADIUS * 2; x++)
for (y = 0; y < HOLE_RADIUS * 2; y++)
{
if (DIV == 1)
radius = HOLE_RADIUS / 2 + (int) (atan (fabs (x - HOLE_RADIUS + 0.5) / fabs (y - HOLE_RADIUS + 0.5)) * HOLE_RADIUS / 2) % (HOLE_RADIUS / 2);
else
radius = HOLE_RADIUS / 4;
if ((x - HOLE_RADIUS / DIV) * (x - HOLE_RADIUS / DIV) + (y - HOLE_RADIUS / DIV) * (y - HOLE_RADIUS / DIV)
< radius * radius)
{
r = (x - HOLE_RADIUS / DIV) * (x - HOLE_RADIUS / DIV) +
(y - HOLE_RADIUS / DIV) * (y - HOLE_RADIUS / DIV);
r = r * 24 / HOLE_SIZE_MAX;
if (r > 23)
r = 23;
c = errdist (64 + r + 1);
BSetPixel (hole_data, x, y, c);
c = errdist (128 + r + 1);
BSetPixel (ehole_data, x, y, c);
}
else
{
BSetPixel (hole_data, x, y, 0);
BSetPixel (ehole_data, x, y, 0);
}
}
ehole_bitmap = (CompileBitmap ((HOLE_RADIUS * 2), (HOLE_RADIUS * 2), ehole_data));
hole_bitmap = (CompileBitmap (HOLE_RADIUS * 2, HOLE_RADIUS * 2, hole_data));
#endif
for (po = 0; po < MAXROCKETS; po++)
{
eye_bitmap[po] = draw_ball_bitmap (EYE_RADIUS, 32 + 32 * po);
}
ball_bitmap = draw_ball_bitmap (BALL_RADIUS, ball (0));
mouse_bitmap = draw_ball_bitmap (MOUSE_RADIUS * DIV, 32 + 32 * 2);
bball_bitmap = draw_ball_bitmap (BBALL_RADIUS, 4 * 32);
apple_bitmap = draw_apple_bitmap (APPLE_RADIUS, ball (0));
inspector_bitmap = draw_ball_bitmap (INSPECTOR_RADIUS, 160);
lunatic_bitmap = draw_reversed_ball_bitmap (LUNATIC_RADIUS, 192);
lball_bitmap[0] = draw_ball_bitmap (BALL_RADIUS, 4 * 32);
lball_bitmap[1] = draw_ball_bitmap (BALL_RADIUS, 5 * 32);
lball_bitmap[2] = draw_reversed_ball_bitmap (BALL_RADIUS, 192);
lball_bitmap[3] = draw_reversed_ball_bitmap (BALL_RADIUS, 0);
lball_bitmap[4] = draw_reversed_ball_bitmap (BALL_RADIUS, 3 * 32 - 5);
/* lball_bitmap[5] = draw_reversed_ball_bitmap (BALL_RADIUS, 4 * 32 - 5);*/
for (x = 0; x < 5; x++)
rocket_bitmap[x] = draw_ball_bitmap (ROCKET_RADIUS, rocketcolor[x]);
}
#ifndef XSUPPORT
static void
createbackground ()
{
/* Create fancy dark red background */
int x, y;
#ifndef NODIRECT
char *pixel = background->vbuf;
#endif
for (y = 0; y < MAPHEIGHT + 20; y++)
for (x = 0; x < MAPWIDTH; x++)
{
int i = 0;
int n = 0;
int c;
if (x > 0)
{
#ifndef NODIRECT
i += *(pixel - 1) - back (0);
#else
i += SGetPixel (x - 1, y);
#endif
n++;
}
if (y > 0)
{
#ifndef NODIRECT
i += *(pixel - MAPWIDTH) - back (0);
#else
i += SGetPixel (x, y - 1);
#endif
n++;
}
c = (i + (rand () % 16)) / (n + 1);
if (c > 9)
c = 9;
#ifndef NODIRECT
*pixel = back (0) + c;
pixel++;
#else
SPutPixel (x, y, back (0) + c);
#endif
}
}
#else
#ifdef MITSHM
static void
Shmcreatebackground ()
{
/* Create fancy dark red background */
int x, y;
unsigned char *pixel = (unsigned char *) background.vbuff;
for (y = 0; y < MAPHEIGHT + 20; y++)
for (x = 0; x < MAPWIDTH; x++)
{
int i = 0;
int n = 0;
int c;
if (x > 0)
{
i += *(pixel - 1) - back (0);
n++;
}
if (y > 0)
{
i += *(pixel - MAPWIDTH) - back (0);
n++;
}
c = (i + (rand () % 16)) / (n + 1);
if (c > 9)
c = 9;
*pixel = back (0) + c;
pixel++;
}
pixel = (unsigned char *) background.vbuff;
for (y = 0; y < MAPHEIGHT + 20; y++)
for (x = 0; x < MAPWIDTH; x++)
*pixel = (unsigned char) pixels[*pixel],
pixel++;
}
#endif
static void
createbackground ()
{
/* Create fancy dark red background */
int x, y;
XImage *img;
char *data;
#ifdef MITSHM
if (shm)
{
Shmcreatebackground ();
return;
}
#endif
if ((data = (char *) calloc ((MAPWIDTH + BitmapPad (dp)) * (MAPHEIGHT + 20) * 4, 1)) == NULL)
perror ("Memory Error"), exit (2);
img = XCreateImage (dp, DefaultVisual (dp, screen), DefaultDepth (dp, screen),
ZPixmap, 0, data, MAPWIDTH, MAPHEIGHT + 20,
BitmapPad (dp), 0);
for (y = 0; y < MAPHEIGHT + 20; y++)
for (x = 0; x < MAPWIDTH; x++)
{
int i = 0;
int n = 0;
int c;
if (x > 0)
{
i += XGetPixel (img, x - 1, y);
n++;
}
if (y > 0)
{
i += XGetPixel (img, x, y - 1);
n++;
}
c = (i + (rand () % 16)) / (n + 1);
if (c > 9)
c = 9;
/*gl_setpixel (x, y, back (0) + c); */
XPutPixel (img, x, y, c & 0xff);
}
for (y = 0; y < MAPHEIGHT + 20; y++)
for (x = 0; x < MAPWIDTH; x++)
XPutPixel (img, x, y, pixels[back (0) + XGetPixel (img, x, y)]);
XPutImage (dp, current.pixmap, gc, img, 0, 0, 0, 0, MAPWIDTH, MAPHEIGHT + 20);
XSync (dp, 1);
XDestroyImage (img);
}
#endif
void
drawstarbackground ()
{
/* Create fancy dark red background */
int x;
int x1, y1, c1;
SetScreen (starbackground);
ClearScreen ();
for (x = 0; x < 700 / DIV / DIV; x++)
{
x1 = rand () % MAPWIDTH;
y1 = rand () % (MAPHEIGHT + 20);
c1 = rand () % 32 + 192;
SSetPixel (x1, y1, c1);
}
}
void
drawbackground ()
{ /*int i; */
/* Build up background from map data */
SetScreen (background);
ClearScreen ();
createbackground ();
EnableClipping ();
#ifdef MITSHM
if (shm)
HLine (0, MAPHEIGHT, MAPWIDTH - 1, back (16));
else
#endif
Line (0, MAPHEIGHT, MAPWIDTH - 1, MAPHEIGHT, back (16));
DisableClipping ();
}
|