@@ -40,6 +40,7 @@ | |||||
static int XSIZ, YSIZ; | static int XSIZ, YSIZ; | ||||
static struct caca_bitmap *caca_bitmap; | static struct caca_bitmap *caca_bitmap; | ||||
static char *bitmap; | static char *bitmap; | ||||
static int pause = 0; | |||||
#else | #else | ||||
static aa_context *context; | static aa_context *context; | ||||
static aa_renderparams *params; | static aa_renderparams *params; | ||||
@@ -193,6 +194,9 @@ drawfire (void) | |||||
register unsigned char *p; | register unsigned char *p; | ||||
#ifndef LIBCACA | #ifndef LIBCACA | ||||
char *bitmap = aa_image (context); | char *bitmap = aa_image (context); | ||||
#else | |||||
if(pause) | |||||
goto paused; | |||||
#endif | #endif | ||||
height++; | height++; | ||||
@@ -216,6 +220,7 @@ drawfire (void) | |||||
i = 0; | i = 0; | ||||
firemain (); | firemain (); | ||||
#ifdef LIBCACA | #ifdef LIBCACA | ||||
paused: | |||||
caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1, | caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1, | ||||
caca_bitmap, bitmap); | caca_bitmap, bitmap); | ||||
caca_refresh(); | caca_refresh(); | ||||
@@ -230,14 +235,24 @@ drawfire (void) | |||||
static void | static void | ||||
game (void) | game (void) | ||||
{ | { | ||||
#ifndef LIBCACA | |||||
int event; | int event; | ||||
#endif | |||||
gentable (); | gentable (); | ||||
#ifdef LIBCACA | #ifdef LIBCACA | ||||
while (!(event = caca_get_event(CACA_EVENT_KEY_PRESS))) | |||||
for(;;) | |||||
#else | #else | ||||
while (!(event = aa_getevent (context, 0)) || event == AA_RESIZE) | while (!(event = aa_getevent (context, 0)) || event == AA_RESIZE) | ||||
#endif | #endif | ||||
{ | { | ||||
#ifdef LIBCACA | |||||
switch (caca_get_event(CACA_EVENT_KEY_PRESS)) | |||||
{ | |||||
case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: return; | |||||
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause; | |||||
} | |||||
#endif | |||||
drawfire (); | drawfire (); | ||||
} | } | ||||
} | } | ||||
@@ -57,7 +57,7 @@ int main(int argc, char **argv) | |||||
unsigned int x[METABALLS], y[METABALLS]; | unsigned int x[METABALLS], y[METABALLS]; | ||||
struct caca_bitmap *caca_bitmap; | struct caca_bitmap *caca_bitmap; | ||||
float i = 10.0, j = 17.0, k = 11.0; | float i = 10.0, j = 17.0, k = 11.0; | ||||
int p, frame = 0; | |||||
int p, frame = 0, pause = 0; | |||||
if(caca_init()) | if(caca_init()) | ||||
return 1; | return 1; | ||||
@@ -86,8 +86,17 @@ int main(int argc, char **argv) | |||||
} | } | ||||
/* Go ! */ | /* Go ! */ | ||||
while(!caca_get_event(CACA_EVENT_KEY_PRESS)) | |||||
for(;;) | |||||
{ | { | ||||
switch(caca_get_event(CACA_EVENT_KEY_PRESS)) | |||||
{ | |||||
case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: goto end; | |||||
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause; | |||||
} | |||||
if(pause) | |||||
goto paused; | |||||
frame++; | frame++; | ||||
/* Crop the palette */ | /* Crop the palette */ | ||||
@@ -134,6 +143,7 @@ int main(int argc, char **argv) | |||||
for(p = 0; p < METABALLS; p++) | for(p = 0; p < METABALLS; p++) | ||||
draw_ball(x[p], y[p]); | draw_ball(x[p], y[p]); | ||||
paused: | |||||
/* Draw our virtual buffer to screen, letting libcaca resize it */ | /* Draw our virtual buffer to screen, letting libcaca resize it */ | ||||
caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1, | caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1, | ||||
caca_bitmap, pixels + (METASIZE / 2) * (1 + XSIZ)); | caca_bitmap, pixels + (METASIZE / 2) * (1 + XSIZ)); | ||||
@@ -141,6 +151,8 @@ int main(int argc, char **argv) | |||||
} | } | ||||
/* End, bye folks */ | /* End, bye folks */ | ||||
end: | |||||
caca_free_bitmap(caca_bitmap); | |||||
caca_end(); | caca_end(); | ||||
return 0; | return 0; | ||||
@@ -46,7 +46,7 @@ int main (int argc, char **argv) | |||||
{ | { | ||||
int red[256], green[256], blue[256], alpha[256]; | int red[256], green[256], blue[256], alpha[256]; | ||||
struct caca_bitmap *bitmap; | struct caca_bitmap *bitmap; | ||||
int i, x, y, frame; | |||||
int i, x, y, frame = 0, pause = 0; | |||||
if(caca_init() < 0) | if(caca_init() < 0) | ||||
return 1; | return 1; | ||||
@@ -68,8 +68,17 @@ int main (int argc, char **argv) | |||||
bitmap = caca_create_bitmap(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0); | bitmap = caca_create_bitmap(8, XSIZ, YSIZ, XSIZ, 0, 0, 0, 0); | ||||
/* Main loop */ | /* Main loop */ | ||||
for(frame = 0; !caca_get_event(CACA_EVENT_KEY_PRESS); frame++) | |||||
for(;;) | |||||
{ | { | ||||
switch(caca_get_event(CACA_EVENT_KEY_PRESS)) | |||||
{ | |||||
case CACA_EVENT_KEY_PRESS | CACA_KEY_ESCAPE: goto end; | |||||
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause; | |||||
} | |||||
if(pause) | |||||
goto paused; | |||||
memset(screen, 0, XSIZ * YSIZ); | memset(screen, 0, XSIZ * YSIZ); | ||||
/* Set the palette */ | /* Set the palette */ | ||||
@@ -92,11 +101,15 @@ int main (int argc, char **argv) | |||||
y = sin(0.09 * frame + 1.0) * 64.0 + (YSIZ / 2); | y = sin(0.09 * frame + 1.0) * 64.0 + (YSIZ / 2); | ||||
put_disc(x, y); | put_disc(x, y); | ||||
frame++; | |||||
paused: | |||||
caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1, | caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1, | ||||
bitmap, screen); | bitmap, screen); | ||||
caca_refresh(); | caca_refresh(); | ||||
} | } | ||||
end: | |||||
caca_free_bitmap(bitmap); | caca_free_bitmap(bitmap); | ||||
caca_end(); | caca_end(); | ||||
@@ -89,6 +89,9 @@ int main (int argc, char **argv) | |||||
case CACA_EVENT_KEY_PRESS | ' ': pause = !pause; | case CACA_EVENT_KEY_PRESS | ' ': pause = !pause; | ||||
} | } | ||||
if(pause) | |||||
goto paused; | |||||
for(i = 0 ; i < 256; i++) | for(i = 0 ; i < 256; i++) | ||||
{ | { | ||||
double z = ((double)i) / 256 * 6 * M_PI; | double z = ((double)i) / 256 * 6 * M_PI; | ||||
@@ -101,18 +104,16 @@ int main (int argc, char **argv) | |||||
/* Set the palette */ | /* Set the palette */ | ||||
caca_set_bitmap_palette(bitmap, red, green, blue, alpha); | caca_set_bitmap_palette(bitmap, red, green, blue, alpha); | ||||
if(!pause) | |||||
{ | |||||
do_plasma(screen, | |||||
(1.0 + sin(((double)frame) * R[0])) / 2, | |||||
(1.0 + sin(((double)frame) * R[1])) / 2, | |||||
(1.0 + sin(((double)frame) * R[2])) / 2, | |||||
(1.0 + sin(((double)frame) * R[3])) / 2, | |||||
(1.0 + sin(((double)frame) * R[4])) / 2, | |||||
(1.0 + sin(((double)frame) * R[5])) / 2); | |||||
frame++; | |||||
} | |||||
do_plasma(screen, | |||||
(1.0 + sin(((double)frame) * R[0])) / 2, | |||||
(1.0 + sin(((double)frame) * R[1])) / 2, | |||||
(1.0 + sin(((double)frame) * R[2])) / 2, | |||||
(1.0 + sin(((double)frame) * R[3])) / 2, | |||||
(1.0 + sin(((double)frame) * R[4])) / 2, | |||||
(1.0 + sin(((double)frame) * R[5])) / 2); | |||||
frame++; | |||||
paused: | |||||
caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1, | caca_draw_bitmap(0, 0, caca_get_width() - 1, caca_get_height() - 1, | ||||
bitmap, screen); | bitmap, screen); | ||||
caca_refresh(); | caca_refresh(); | ||||