home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Hack-Phreak Scene Programs
/
cleanhpvac.zip
/
cleanhpvac
/
FGDEMO40.ZIP
/
SOURCE.COM
/
TGSDEMO.CPP
< prev
next >
Wrap
Text File
|
1995-02-12
|
7KB
|
261 lines
/* **********************************************************
** **
** MOVING SKY WITH SCALING LOGO DEMO **
** **
** programmer: Michael Miller (516) 825-6735 **
** last updated : 2/10/95 **
** **
**********************************************************
** **
** tools: Fastgraph 4.0 and Fastgraph/Image 2.0 **
** Compiles with either Borland C++, Turbo C++, **
** Microsoft C/C++, Visual C++, or Watcom C/C++ **
** **
** specs: Uses mode 20 and resizes video memory to a **
** single 640x400 page **
** **
** The sky is displayed directly to the screen **
** **
** An IMAGE class object loads the logo an is **
** responsible for scaling and displaying it **
** **
**********************************************************
*/
#include <fastgraf.h>
#include <fgimage.h>
#include <iostream.h>
// constants
#define VIDEO_MODE 20
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 200
#define VISUAL_WIDTH 320
#define VISUAL_HEIGHT 200
//-------------------------- CLASS DEFINITIONS
int handle;
/* /\/\/\/\/\/\/\/\/\/\/\/\/
\/\/\/ CLASS IMAGE /\/\/\
/\/\/\/\/\/\/\/\/\/\/\/\/ */
class IMAGE
{
protected :
char *imagedata, *scaledata;
int image_width, image_height, center_x, center_y;
public :
// By passing the width and height I can place a full screen
// PCX file into the image file and only use the part I want
IMAGE(char *pcxfile,int width,int height)
{
// assign image_width & image_height
image_width = width;
image_height = height;
// find page center coordinates
center_x = (VISUAL_WIDTH - image_width)/2;
center_y = ((VISUAL_HEIGHT - image_height)/2)+image_height;
// dynamically allocate memory for imagedata and backround
imagedata = new char[(image_width+1) * (image_height+1)];
scaledata = new char[(image_width+1) * (image_height+1)];
// load the actual image from the pcxfile, populate imagedata
fg_move(0,0);
fgi_showpcx(pcxfile,0,handle);
fg_move(0,image_height-1);
fg_getimage(imagedata,image_width,image_height);
}
~IMAGE() { delete imagedata; }
int GET_WIDTH() { return image_width; }
int GET_HEIGHT() { return image_height; }
int CENTER_X() { return center_x; }
int CENTER_Y() { return center_y; }
// draws the object at the current position
void show()
{
fg_drwimage(imagedata,image_width,image_height);
}
// draws a scaled object,
// x,y are the current offscreen coordinates they allow the
// image to be centered as the sky pans
void show(double scale,int x,int y)
{
if (scale < 0.0) return;
// Image is scaled down , calculate the center based on its size
if (scale < 1.0)
{
int dwidth = int (image_width * scale );
int dheight = int (image_height * scale );
int xloc = x+(320-dwidth)/2;
int yloc = y+((200-dheight)/2)+dheight;
fg_move(xloc,yloc);
fg_scale(imagedata,scaledata,image_width,image_height,dwidth,dheight);
fg_drwimage(scaledata,dwidth,dheight);
return;
}
else
{
fg_move(center_x+x,center_y+y);
fg_drwimage(imagedata,image_width,image_height);
return;
}
}
};
//-------------------------- GLOBAL VARIABLE DEFINITIONS
IMAGE *logo;
//-------------------------- FUNCTION DEFINITIONS
void move_backround()
{
// initialization
int visual_offset = 200;
int work_offset = 0;
int work_page = 0;
int image_x = logo->CENTER_X();
int image_y = logo->CENTER_Y();
int image_width = logo->GET_WIDTH();
int image_height = logo->GET_HEIGHT();
char *buffer[2];
buffer[0] = new char[image_width*image_height];
buffer[1] = new char[image_width*image_height];
fg_pan(0,visual_offset);
// get buffer[0] from page 0
fg_move(image_x+2,image_y+work_offset);
fg_getimage(buffer[0],image_width,image_height);
visual_offset = 0;
work_offset = 200;
work_page = 1;
// get buffer[1] from page 1
fg_move(image_x+1,image_y+work_offset);
fg_getimage(buffer[1],image_width,image_height);
// setup keyboard handler
fg_kbinit(1);
int counter = 0;
for (int t = 1; t < 320; t++)
{
if (work_offset == 0)
work_page = 0;
else
work_page = 1;
// repaint backround on work_page
fg_move(image_x+t,image_y+work_offset);
fg_drwimage(buffer[work_page],image_width,image_height);
// get backround on work_page
fg_move(image_x+t+2,image_y+work_offset);
fg_getimage(buffer[work_page],image_width,image_height);
// check for pan < 309 and no key pressed
if (t < 309 && counter == 0)
logo->show(t*0.06,t+2,work_offset);
else if (counter > 0)
{
counter++;
logo->show((11-counter)*0.1,t+2,work_offset);
if (counter == 10)
{
fg_pan(0,work_offset);
fg_move(image_x+t,image_y+visual_offset);
fg_drwimage(buffer[1-work_page],image_width,image_height);
fg_pan(0,visual_offset);
return;
}
}
else
logo->show((320-t)*0.1,t+2,work_offset);
// test for key pressed
if (fg_kblast() != 0 && counter == 0)
{
fg_kbinit(0);
counter = 1;
}
visual_offset = 200 - visual_offset;
work_offset = 200 - work_offset;
// pan screen to t and change display memory to visual_offset
fg_pan(t,visual_offset);
}
}
//-------------------------- MAIN FUNCTION DEFINITION
void main()
{
// make sure the image library file is present
handle = fgi_open("TGSDEMO.FGI");
if (handle == 0)
{
cout << "Unable to open TGSDEMO.FGI image library." << endl;
return;
}
// initialize variables
int old_mode;
unsigned char key, aux;
// establish the video mode
old_mode = fg_getmode();
if (fg_testmode(VIDEO_MODE,4) == 0)
{
fgi_close(handle);
return;
}
fg_setmode(VIDEO_MODE);
//resize the video screen to one large page
fg_resize(640,400);
//display the offpage prt of screen memory
fg_pan(0,200);
// initialize the graphic objects
logo = new IMAGE("LOGO.PCX",263,39);
// copy 0-199 to 200-399
fgi_showpcx("SKY.PCX",0,handle);
// move to screen displaying the sky
fg_pan(0,0);
// copy the sky to the offscreen
fg_transfer(0,639,0,199,0,399,0,0);
// action!
move_backround();
// clean up and exit to DOS
fg_kbinit(0);
delete logo;
fg_setmode(old_mode);
fg_reset();
fgi_close(handle);
}