home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Hack-Phreak Scene Programs
/
cleanhpvac.zip
/
cleanhpvac
/
FGDEMO40.ZIP
/
SOURCE.COM
/
MISC.C
< prev
next >
Wrap
Text File
|
1995-02-12
|
24KB
|
1,007 lines
/**********************************************************************\
* *
* misc.c -- bird, mouse, keyboard handler, things on the Misc. menu. *
* *
\**********************************************************************/
#include "defs.h"
/* include bitmap data so the images are compiled into the EXE file */
#include "birds.h"
#include "fgtitle.h"
#include "fighter.h"
/**********************************************************************\
* *
* do_bird -- make a bitmapped bird fly across the screen *
* *
\**********************************************************************/
int do_bird()
{
int x;
int frame;
if (!exists("MOUNTAIN.PCX"))
abort_program("File missing: MOUNTAIN.PCX.\n");
/* load the background on the hidden page */
fg_mousevis(OFF);
fg_setpage(hidden);
fg_showpcx("MOUNTAIN.PCX",0);
fg_setpage(visual);
fg_copypage(hidden,visual);
fg_waitfor(8);
fg_mousevis(OFF);
fg_transfer(0,xlimit,70,100,0,30,visual,hidden);
/* the bird flies behind two trees -- store this image where we can
get it later */
fg_transfer(0,119,70,100,0,61,visual,hidden);
fg_tcmask(0x8002);
/* first pass -- the bird flies to the right */
frame = 0;
for (x = 0; x < 640; x+=16)
{
fg_transfer(0,xlimit,0,30,0,100,hidden,hidden);
fg_setpage(hidden);
frame = !frame;
if (frame == 0)
{
fg_move(x,100);
fg_clpimage(bird1,20,20);
}
else
{
fg_move(x,89);
fg_clpimage(bird2,24,20);
}
/* redraw the trees on top of the bird */
fg_tcxfer(0,119,31,61,0,100,hidden,hidden);
fg_setpage(visual);
fg_restore(0,xlimit,70,100);
fg_waitfor(2);
}
fg_transfer(0,639,0,30,0,100,hidden,visual);
/* put the Fastgraph title bitmap, with shadows */
fg_waitfor(8);
fg_move(187,75);
fg_setcolor(9);
fg_drawmap(fgtitle,36,53);
fg_move(194,81);
fg_setcolor(0);
fg_drawmap(fgtitle,36,53);
fg_move(195,82);
fg_setcolor(15);
fg_drawmap(fgtitle,36,53);
fg_waitfor(8);
/* second pass -- fly to the left -- flip the bird <g> */
fg_transfer(0,xlimit,230,260,0,30,visual,hidden);
for (x = 624; x >-40; x-=16)
{
fg_transfer(0,xlimit,0,30,0,260,hidden,hidden);
fg_setpage(hidden);
frame = !frame;
if (frame == 0)
{
fg_move(x,260);
fg_flpimage(bird1,20,20);
}
else
{
fg_move(x,249);
fg_flpimage(bird2,24,20);
}
fg_setpage(visual);
fg_restore(0,xlimit,230,260);
fg_waitfor(1);
}
fg_transfer(0,639,0,30,0,260,hidden,visual);
/* restore the hidden page */
fg_setpage(hidden);
draw_screen(4);
/* wait for a keystroke */
fg_mousevis(ON);
wait_for_keystroke();
/* copy menu screen from hidden to visual */
fg_mousevis(OFF);
fg_copypage(hidden,visual);
fg_mousevis(ON);
/* fix the colors */
fg_palettes(default_colors);
/* restore the screen and return to the menu */
redraw = TRUE;
return(OK);
}
/**********************************************************************\
* *
* do_borland -- display the Borland logo (we obtained a license from *
* Borland to do this!) *
* *
\**********************************************************************/
int do_borland()
{
if (!exists("BORLAND.PCX"))
abort_program("File missing: BORLAND.PCX.\n");
fg_mousevis(OFF);
fg_setpage(hidden);
fg_showpcx("BORLAND.PCX",0);
fg_tcmask(0x7FEE);
fg_tcxfer(32,295,7,191,136,300,hidden,visual);
/* copy the visual page to the hidden page */
fg_setpage(visual);
fg_copypage(visual,hidden);
fg_setpage(hidden);
fg_setcolor(15);
fg_rect(136,287,40,300);
fg_rect(288,433,122,300);
fg_setcolor(11);
fg_drect(136,287,40,300,matrix2);
fg_drect(288,433,122,300,matrix2);
/* wait for a keystroke */
fg_mousevis(ON);
wait_for_keystroke();
/* copy menu screen from hidden to visual */
fg_mousevis(OFF);
fg_fadein(0);
fg_mousevis(ON);
/* restore the screen and return to the menu */
redraw = TRUE;
return(OK);
}
/**********************************************************************\
* *
* do_dub -- wavering Fastgraph logo courtesy of Dub Media *
* Dub Media does renderings and sprite animation for *
* game programmers. Call Mike or Alfred at (617)647-1101 *
* *
\**********************************************************************/
int do_dub()
{
int i,j,x,y;
int x1,y2;
int stall_time;
if (!exists("DUB.PCX"))
abort_program("File missing: DUB.PCX.\n");
stall_time = clockspeed/4;
fg_mousevis(OFF);
fg_setpage(hidden);
fg_showpcx("DUB.PCX",0);
/* clear the visual screen below the menu */
fg_setpage(visual);
fg_setcolor(0);
fg_rect(4,635,39,346);
/* redraw the menu with no options highlighted */
horizontal_menu(main_menu,-ITEMS,-3);
fg_mousevis(OFF);
/* put the first image on the screen */
fg_transfer(32,137,235,297,520,336,hidden,visual);
/* draw the other images on the screen in sequence */
x1 = 56;
y2 = 100;
fg_setcolor(0);
for (j = 0; j < 2; j++)
{
for (i = 1; i < 4; i++)
{
for (x = 0; x < 640; x+=160)
{
for (y = 56; y <= 224; y+= 56)
{
fg_rect(x1-8,x1-1,y2-56,y2);
fg_transfer(x,x+159,y-56,y,x1,y2,hidden,visual);
fg_stall(stall_time);
y2++;
x1+= 8;
}
}
}
for (i = 1; i < 4; i++)
{
for (x = 0; x < 640; x+=160)
{
for (y = 56; y <= 224; y+= 56)
{
fg_rect(x1-8,x1-1,y2-56,y2);
fg_transfer(x,x+159,y-56,y,x1,y2,hidden,visual);
fg_stall(stall_time);
y2++;
x1-= 8;
}
}
}
}
for (i = 1; i < 3; i++)
{
for (x = 0; x < 640; x+=160)
{
for (y = 56; y <= 224; y+= 56)
{
fg_rect(x1-8,x1-1,y2-56,y2);
fg_transfer(x,x+159,y-56,y,x1,y2,hidden,visual);
fg_stall(stall_time);
y2++;
x1+= 8;
}
}
}
/* redraw the menu on the hidden page */
fg_setpage(hidden);
draw_screen(3);
/* wait for a keystroke */
fg_mousevis(ON);
wait_for_keystroke();
fg_mousevis(OFF);
/* restore the screen and return */
fg_copypage(hidden,visual);
redraw = TRUE;
fg_fadein(0);
fg_palettes(default_colors);
fg_mousevis(ON);
return(OK);
}
/**********************************************************************\
* *
* do_histogram -- create a histogram *
* *
\**********************************************************************/
int do_histogram()
{
register int i;
int x1,x2,y1,y2;
static char label[] = "Productivity";
static char title[] = "See profits soar with Fastgraph!";
static int x[] = {130, 180, 230, 280, 330, 380, 430, 480};
static int y[] = {290, 275, 270, 265, 200, 170, 130, 100};
/* clear the bottom of the screen */
fg_mousevis(OFF);
fg_restore(0,xlimit,menu_bottom,ylimit);
fg_setpage(visual);
fg_setcolor(0);
y1 = 100;
y2 = 300;
/* axes */
fg_rect(120,520,y2,y2);
fg_rect(120,120,y1,y2);
for (i = 100; i < 300; i+=20)
{
y1 = i;
fg_rect(120,126,y1,y1);
}
/* boxes */
for (i = 0; i < 8; i++)
{
x1 = x[i];
x2 = x1 + 30;
y1 = y[i];
fg_setcolor(11);
fg_rect(x1,x2,y1,y2);
fg_setcolor(0);
fg_box(x1,x2,y1,y2);
}
/* label the x axis */
x1 = 320 - length_pstring(label)/2 - 2;
x2 = 320 + length_pstring(label)/2 + 2;
y2 = 320;
y1 = y2 - PTSIZE - 1;
fg_setcolor(0);
center_pstring(label,x1,x2,y2);
/* Profits soar with Fastgraph */
x1 = 320 - length_pstring(title)/2 - 2;
x2 = 320 + length_pstring(title)/2 + 2;
y2 = 90;
y1 = y2 - PTSIZE - 1;
fg_setcolor(0);
center_pstring(title,x1,x2,y2);
/* wait for a keystroke or mouse button */
fg_mousevis(ON);
wait_for_keystroke();
/* restore the screen and return to the menu */
fg_mousevis(OFF);
fg_restore(0,xlimit,menu_bottom,ylimit);
redraw = TRUE;
return(OK);
}
/**********************************************************************\
* *
* do_joystick -- demo some joystick functions *
* *
\**********************************************************************/
int do_joystick()
{
static char *string1[] = {
"Joystick",
"Joysticks found on Port 1 and Port 2."
};
static char *string2[] = {
"Joystick",
"Joystick found on Port 1."
};
static char *string3[] = {
"Joystick",
"Joystick found on Port 2."
};
static char *string4[] = {
"Joystick",
"Joystick not found."
};
static int joy1_x[] = {140,200,260,140,200,260,140,200,260};
static int joy2_x[] = {360,420,480,360,420,480,360,420,480};
static int joy_y[] = {110,110,110,140,140,140,170,170,170};
char key,aux;
unsigned char key1,aux1;
int x,y;
int count,mousex,mousey;
int pos1,pos2,new_pos1,new_pos2;
int joystick[2];
/* initialize joysticks, if possible */
if (fg_initjoy(1) == 0)
joystick[0] = TRUE;
else
joystick[0] = FALSE;
if (fg_initjoy(2) == 0)
joystick[1] = TRUE;
else
joystick[1] = FALSE;
fg_mousevis(OFF);
fg_restore(0,xlimit,menu_bottom,ylimit);
/* report status of joysticks */
if (joystick[0] && joystick[1])
info_window(120,520,220,string1,2);
else if (joystick[0])
info_window(120,520,220,string2,2);
else if (joystick[1])
info_window(120,520,220,string3,2);
else
info_window(120,520,220,string4,2);
/* draw a grid to illustrate joystick positions */
fg_mousevis(OFF);
if (joystick[0])
{
fg_setcolor(15);
fg_rect(120,300,100,190);
fg_setcolor(0);
fg_box(120,300,100,190);
fg_box(180,240,100,190);
fg_box(120,300,130,160);
}
if (joystick[1])
{
fg_setcolor(15);
fg_rect(340,520,100,190);
fg_setcolor(0);
fg_box(340,520,100,190);
fg_box(400,460,100,190);
fg_box(340,520,130,160);
}
pos1 = 4; new_pos1 = pos1;
pos2 = 4; new_pos2 = pos2;
/* draw red boxes to represent joystick straight up position */
fg_setcolor(4);
if (joystick[0])
{
x = joy1_x[pos1];
y = joy_y[pos1];
fg_rect(x,x+20,y,y+10);
}
if (joystick[1])
{
x = joy2_x[pos2];
y = joy_y[pos2];
fg_rect(x,x+20,y,y+10);
}
fg_mousevis(ON);
for(;;)
{
fg_waitfor(3);
/* handle first joystick */
if (joystick[0])
{
fg_intjoy(1,&key,&aux);
if (key == CR)
break;
if (aux == 0)
new_pos1 = 4;
else if (aux >= 71 && aux <= 73)
new_pos1 = aux - 71;
else if (aux >= 75 && aux <= 77)
new_pos1 = aux - 72;
else if (aux >= 79 && aux <= 81)
new_pos1 = aux - 73;
if (new_pos1 != pos1)
{
fg_setcolor(15);
x = joy1_x[pos1];
y = joy_y[pos1];
fg_mousevis(OFF);
fg_rect(x,x+20,y,y+10);
pos1 = new_pos1;
fg_setcolor(4);
x = joy1_x[pos1];
y = joy_y[pos1];
fg_rect(x,x+20,y,y+10);
fg_mousevis(ON);
}
}
/* handle second joystick */
if (joystick[1])
{
fg_intjoy(2,&key,&aux);
if (key == CR)
break;
if (aux == 0)
new_pos2 = 4;
else if (aux >= 71 && aux <= 73)
new_pos2 = aux - 71;
else if (aux >= 75 && aux <= 77)
new_pos2 = aux - 72;
else if (aux >= 79 && aux <= 81)
new_pos2 = aux - 73;
if (new_pos2 != pos2)
{
fg_setcolor(15);
x = joy2_x[pos2];
y = joy_y[pos2];
fg_mousevis(OFF);
fg_rect(x,x+20,y,y+10);
pos2 = new_pos2;
fg_setcolor(4);
x = joy2_x[pos2];
y = joy_y[pos2];
fg_rect(x,x+20,y,y+10);
fg_mousevis(ON);
}
}
/* exit loop if key or mouse button pressed */
fg_intkey(&key1,&aux1);
if (key1+aux1 > 0)
break;
fg_mousebut(1,&count,&mousex,&mousey);
if (count > 0)
break;
}
/* restore the screen and return to the menu */
fg_mousevis(OFF);
fg_restore(0,xlimit,menu_bottom,ylimit);
redraw = TRUE;
return(OK);
}
/**********************************************************************\
* *
* do_mouse -- nice animated mouse from Tom Guthery *
* *
\**********************************************************************/
int do_mouse()
{
register int i,j;
int stalltime;
if (!exists("MOUSE.PCX"))
abort_program("File missing: MOUSE.PCX.\n");
stalltime = (int)(clockspeed/8);
/* display the frames on the hidden page */
fg_mousevis(OFF);
fg_setpage(hidden);
fg_showpcx("MOUSE.PCX",0);
fg_setpage(visual);
/* redraw the menu bar, unhighlighted */
fg_setcolor(0);
fg_rect(4,635,39,346);
horizontal_menu(main_menu,-ITEMS,-4);
fg_setcolor(0);
/* run the mouse around 4 times */
for (j = 0; j < 4; j++)
{
for (i = 0; i < 36; i++)
{
mouserun(i);
if (j <= 1)
fg_waitfor(1);
else
fg_stall(stalltime);
}
}
fg_rect(4,635,39,346);
mouserun(36);
fg_waitfor(1);
/* "Flix" */
fg_transfer(0,271,291,349,192,227,hidden,visual);
/* panting mouse */
for (j = 0; j < 12; j++)
{
for (i = 37; i < 40; i++)
{
mouserun(i);
fg_waitfor(2);
}
}
for (j = 0; j < 2; j++)
{
for (i = 1; i < 37; i++)
{
mouserun(i);
if (j < 1)
fg_waitfor(1);
else
fg_stall(stalltime);
}
}
fg_waitfor(1);
/* panting mouse */
for (j = 0; j < 6; j++)
{
for (i = 37; i < 40; i++)
{
mouserun(i);
fg_waitfor(2);
}
}
/* restore the hidden page */
fg_setpage(hidden);
draw_screen(4);
/* wait for a keystroke */
/* copy menu screen from hidden to visual */
fg_mousevis(OFF);
fg_fadein(0);
fg_mousevis(ON);
/* restore the screen and return to the menu */
redraw = TRUE;
return(OK);
}
/**********************************************************************\
* *
* mouserun -- run the mousey around the screen *
* *
\**********************************************************************/
int mouserun(int i)
{
int j;
int difx,dify;
/* location of each mouse frame on the hidden page */
typedef struct rodent
{
int x1;
int x2;
int y1;
int y2;
} RODENT;
static RODENT mousey[] =
{
{0,119,0,49},
{120,247,0,46},
{248,359,0,57},
{360,479,0,64},
{248,303,64,180},
{304,359,64,186},
{360,423,72,178},
{424,495,72,188},
{0,119,184,233},
{120,247,176,222},
{248,359,192,250},
{360,479,192,257},
{0,55,56,170},
{56,103,56,178},
{104,167,56,162},
{168,239,56,172},
{496,623,0,56},
{496,623,64,122},
{496,623,128,183}
};
/* where we want the mouse to go on the visual page, and which frame */
typedef struct path
{
int x;
int y;
int image;
} PATH;
static PATH mousepath[] =
{
{8,343,0},
{72,327,1},
{144,343,2},
{152,343,3},
{176,343,0},
{240,327,1},
{312,343,2},
{320,343,3},
{344,343,0},
{408,327,1},
{480,343,2},
{488,343,3},
{512,343,0},
{576,346,4},
{560,287,5},
{568,218,6},
{560,199,7},
{576,169,4},
{512,93,8},
{448,106,9},
{392,100,10},
{376,110,11},
{344,93,8},
{280,106,9},
{224,100,10},
{208,110,11},
{176,93,8},
{112,106,9},
{56,100,10},
{40,110,11},
{8,93,8},
{8,161,12},
{32,229,13},
{8,278,14},
{8,313,15},
{8,343,12},
{8,343,0},
{56,343,16},
{56,343,17},
{56,343,18}
};
/* draw the mouse */
j = mousepath[i].image;
dify = mousey[j].y2 - mousey[j].y1;
difx = mousey[j].x2 - mousey[j].x1;
/* erase the previous mouse-this is complicated to avoid flicker */
if (j >= 0 && j < 4) /* bottom mouse */
{
fg_rect(8,mousepath[i].x-1,278,343); /* erase to left */
fg_rect(8,631,mousepath[i].y+1,347); /* erase below */
fg_rect(8,631,228,mousepath[i].y-dify); /* erase above */
}
else if (j >= 4 && j < 8) /* right mouse */
{
fg_rect(512,632,mousepath[i].y+1,347); /* erase below */
fg_rect(512,mousepath[i].x-1,mousepath[i].y-dify,mousepath[i].y);
fg_rect(mousepath[i].x+difx+1,633,mousepath[i].y-dify,mousepath[i].y);
}
else if (j >= 8 && j < 12) /* top mouse */
{
fg_rect(mousepath[i].x + difx,633,40,110); /* erase right */
fg_rect(mousepath[i].x,633,mousepath[i].y,169); /* erase below */
fg_rect(mousepath[i].x,633,39,mousepath[i].y-dify); /* erase above */
}
else if (j >= 12 && j < 16) /* left mouse */
{
fg_rect(8,79,40,mousepath[i].y - dify); /* erase above */
fg_rect(7,mousepath[i].x-1,40,mousepath[i].y); /* erase left */
fg_rect(mousepath[i].x+difx,128,40,mousepath[i].y);/* erase right */
}
else if (j >= 16) /* panting mouse */
{
fg_rect(56,180,280,mousepath[i].y-dify-1);
fg_rect(8,55,226,343);
}
fg_transfer(mousey[j].x1,mousey[j].x2,mousey[j].y1,mousey[j].y2,
mousepath[i].x,mousepath[i].y,hidden,visual);
return(OK);
}
/**********************************************************************\
* *
* do_keyboard -- simple game to show the keyboard handler *
* *
\**********************************************************************/
/* define keyboard keys */
#define kb_esc 1
#define kb_alt 56
#define kb_ctrl 29
#define kb_left 75
#define kb_right 77
#define kb_up 72
#define kb_down 80
int do_keyboard()
{
int fighter_x,fighter_y;
int bullet_x[20],bullet_y[20];
int nbullets;
register int i;
static char *string[] = {
"low level keyboard handler enabled",
"Use the arrow keys to move the plane around, CTRL to shoot, ESC to quit."
};
fg_mousevis(OFF);
fg_restore(0,xlimit,menu_bottom,ylimit);
horizontal_menu(main_menu,-ITEMS,-4);
/* post instructions at bottom of screen */
info_window(20,620,308,string,2);
/* set palette 13 to non-transparent black */
fg_palette(13,0);
fighter_x = 340;
fighter_y = 276;
nbullets = 0;
/* put the fighter plane on the screen at the original positions */
fg_move(fighter_x,fighter_y);
fg_drwimage(fighter,15,64);
/* prepare background workspace area */
fg_transfer (8,55,40,108,0,378,hidden,hidden);
/* enable the keyboard handler */
fg_kbinit(1);
/* main loop -- loop until escape is pressed */
while (!fg_kbtest(kb_esc))
{
/* check the arrow keys */
if (fighter_x > 16 && fg_kbtest(kb_left))
fighter_x -= 2;
if (fighter_x < 592 && fg_kbtest(kb_right))
fighter_x += 2;
if (fighter_y > 108 && fg_kbtest(kb_up))
fighter_y -= 2;
if (fighter_y < 300 && fg_kbtest(kb_down))
fighter_y += 2;
/* move the plane around */
fg_transfer (0,47,310,378,fighter_x-8,fighter_y+2,hidden,hidden);
fg_move(fighter_x,fighter_y);
fg_setpage(hidden);
fg_drwimage(fighter,15,64);
fg_setpage(visual);
fg_restore(fighter_x-8,fighter_x+39,fighter_y-68,fighter_y+2);
/* fire bullets, if any */
for (i = 0; i < nbullets; i++)
{
if (bullet_y[i] < fighter_y - 64 || bullet_x[i] <= fighter_x-8)
fg_transfer(0,8,311,312,bullet_x[i],bullet_y[i],hidden,visual);
if (bullet_y[i] < fighter_y - 64)
fg_transfer(0,8,311,312,bullet_x[i]+24,bullet_y[i],hidden,visual);
bullet_y[i] -= 8;
fg_setcolor(4);
fg_setpage(visual);
fg_rect(bullet_x[i],bullet_x[i]+1,bullet_y[i]-1,bullet_y[i]);
fg_rect(bullet_x[i]+25,bullet_x[i]+26,bullet_y[i]-1,bullet_y[i]);
}
/* new bullets? */
if (nbullets < 20 && fg_kbtest(kb_ctrl))
{
i = nbullets;
bullet_x[i] = fighter_x+1;
bullet_y[i] = fighter_y-40;
fg_setcolor(4);
fg_setpage(visual);
fg_rect(bullet_x[i],bullet_x[i]+1,bullet_y[i]-1,bullet_y[i]);
fg_rect(bullet_x[i]+25,bullet_x[i]+26,bullet_y[i]-1,bullet_y[i]);
nbullets++;
}
/* kill bullet at top of screen */
for(;;)
{
if (nbullets > 0 && bullet_y[0] <= 48)
{
fg_transfer(0,8,311,312,bullet_x[0],bullet_y[0],hidden,visual);
fg_transfer(0,8,311,312,bullet_x[0]+25,bullet_y[0],hidden,visual);
for (i = 0; i< nbullets-1; i++)
{
bullet_x[i] = bullet_x[i+1];
bullet_y[i] = bullet_y[i+1];
}
nbullets--;
}
else
break;
}
}
/* disable the keyboard handler */
fg_kbinit(0);
/* restore the hidden page */
fg_setpage(hidden);
draw_screen(4);
/* restore the screen and return to the menu */
fg_mousevis(OFF);
fg_copypage(hidden,visual);
redraw = TRUE;
/* fix the palette */
fg_palette(13,61);
return(OK);
}