home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Trixter's Scene Collection
/
trixter.zip
/
trixter
/
Demos
/
GN_SKP.ZIP
/
SRC
/
GN2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-06-26
|
54KB
|
2,476 lines
#include <alloc.h>
#include <conio.h>
#include <ctype.h>
#include <dos.h>
#include <math.h>
#include <mem.h>
#include <sound.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <wgt4.h>
#include <wgt3d.h>
extern color pal1[256];
extern color pal2[256];
extern color blackpal[256];
extern int i,x,y,j;
extern block virt, virt2, virt3;
extern int sortlist[50];
extern block data;
extern int ctr;
extern int music_on;
typedef struct { /* Used to keep track what portion of the */
int x1,y1,x2,y2; /* screen has been changed, so we can update */
} rect; /* the least amount of video memory */
extern rect lastrect,thisrect;
void draw_land_plasma(void);
/* Landscape Engine - written by Chris Egerter */
#define SCREEN_WIDTH 256
#define HSCREEN_WIDTH 128
#define SCREEN_HEIGHT 30
block gum;
block landscape;
int posx,posy; /* Player's location */
char c;
float hgt;
block texture;
int ox[320];
unsigned char oc[320];
int pspy[50];
long ff[50];
int dxy[50];
int dxx[320];
void gen_plasma(void);
void draw_plasma(void);
extern float teller;
extern int plasmatype;
extern long memleft;
void showmem(void)
{
wsetmode(3);
printf("%lu",farcoreleft());
getch();
vga256();
}
void calc_tables(void)
{
int i;
long x,y,z;
for (i=1; i<SCREEN_HEIGHT; i++)
{
pspy[i] = (long)5900/(SCREEN_HEIGHT-i+15)-20;
ff[i] = (long)20024/(SCREEN_HEIGHT-i+15);
dxy[i] = (int)(i+30);
}
for (i=0; i<SCREEN_WIDTH; i++)
dxx[i] = (long)(i-160) * 1510 / 100;
}
void wvline(int x, int y, int y2, unsigned char col)
{
block temp;
int length;
if (y < ty) y = ty;
else if (y > by) y = by;
if (y2 < ty) y2 = ty;
else if (y2 > by) y2 = by;
temp = abuf + y*320 + x;
length = y2 - y + 1;
asm {
push ds
mov cx,length
lds si, temp
mov al, col
}
vlineloop:
;
asm {
mov [ds:si],al
add si,320
loop vlineloop
pop ds
}
}
void generate_table(void)
{
unsigned int x,y;
unsigned int dsx;
unsigned int dx;
int *gumptr;
int *gumptr2;
int ofs;
/*
ofs = 0;
for (y = 1; y < SCREEN_HEIGHT; y++)
{
for (x = 0; x < SCREEN_WIDTH; x++)
{
dx = dxx[x] / dxy[y] - 55;
dsx = y*320+dx;
memcpy(&gum[ofs], &dsx, 2);
ofs += 2;
}
}
gumptr = &gum[0];
gumptr2= &gum[2];
*gumptr = *gumptr2;
gumptr++;
gumptr2++;
for (y = 1; y < SCREEN_HEIGHT; y++)
for (x = 0; x < SCREEN_WIDTH; x++)
{
*gumptr = *gumptr2 - *gumptr;
gumptr++;
gumptr2++;
}
/* Writes the land data to disk */
landdata = fopen ("gn.004", "wb");
fwrite (gum, SCREEN_WIDTH * SCREEN_HEIGHT * 2, 1, landdata);
fclose (landdata);
*/
/* Reads the land data into memory. */
gum = lib2buf("gn.004");
}
void draw_rays (void)
{
int startx, starty;
int x, y;
long perspy;
long f;
int colr;
int dx;
int nx;
int *gumptr;
block mapptr;
wsetscreen(virt);
for (y = 0; y < 200; y++)
{
wsetcolor(y+128);
wline(0,y,SCREEN_WIDTH,y);
}
for (x = 0; x < SCREEN_WIDTH; x++)
ox[x] = 199;
gumptr = gum;
mapptr = landscape + 4 + posy*320 + posx;
for (y = 1; y < SCREEN_HEIGHT; y++)
{
perspy = pspy[y] - y * hgt;
f = ff[y];
for (x = 0; x < SCREEN_WIDTH; x++)
{
mapptr+= *gumptr++;
colr = *mapptr;
nx = perspy - ((long)colr * f>>10);
if (nx > ox[x])
wvline (x, ox[x], nx, colr);
ox[x] = nx;
}
}
wcopyscreen (0, 0, SCREEN_WIDTH-2, 198, virt, 32, 0, NULL);
}
extern MS *m; /* Music Structure */
void draw_volumebars (void)
{
int curvol;
wsetscreen (landscape);
for(i = 0; i < 8; i++) /* For every channel in song */
{
m = mGetMS (i); /* Get music structure */
curvol = m->DecVolume+5;
wsetcolor (curvol);
wbar (120 + i * 10, 100, 120 + i * 10 + 10, 105);
}
}
void start_landscape(void)
{
int xdir, ydir;
int fadectr;
int ctr;
wnormscreen();
wcls(0);
wloadpalette("lands.pal",pal1);
wsetrgb(0,0,0,0,pal1);
landscape = wloadpak("lands.pak");
calc_tables();
virt = wnewblock (0,0, 319,199);
wtextcolor(1);
posx = 225;
posy = 94;
xdir = -1;
ydir = -1;
fadectr = 0;
ctr = 0;
//gum = farmalloc(SCREEN_WIDTH * SCREEN_HEIGHT * 2);
generate_table();
fadectr = 64;
if (!music_on)
ctr = 200;
do
{
if (music_on)
draw_volumebars ();
if (ctr > 200)
{
posx += xdir;
if (posx > 320)
xdir = -1;
if (posx < 0)
xdir = 1;
posy += ydir;
if (posy > 170)
ydir = -1;
if (posy < 60)
ydir = 1;
}
draw_rays ();
if ((kbhit()) || (ctr == 432))
{
while (kbhit()) getch();
fadectr = -64;
for (i=0; i<256; i++)
wsetrgb(i,0,0,0,blackpal);
wreadpalette(0,255,pal1);
}
if (fadectr > 0)
{
wfade_between_once (0, 255, blackpal, pal1);
wsetpalette(0,255,blackpal);
fadectr--;
}
if (fadectr < 0)
{
wfade_between_once (0, 255, pal1, blackpal);
wsetpalette(0,255,pal1);
fadectr++;
if (fadectr == 0)
ctr = 500;
}
ctr++;
} while (ctr < 500);
posx = 140;
posy = 0;
ctr = 0;
hgt = -2.5;
fadectr = 64;
wloadpalette("ocean.pal",pal1);
wfreeblock (landscape);
landscape = wnewblock(0,0,319,30);
gen_plasma();
if (farcoreleft () < memleft)
memleft = farcoreleft ();
do
{
draw_land_plasma();
draw_rays ();
// wnormscreen();
// wputblock(0,0,landscape,0);
if ((kbhit()) || (ctr == 232))
{
while (kbhit()) getch();
fadectr = -64;
for (i=0; i<256; i++)
wsetrgb(i,0,0,0,blackpal);
wreadpalette(0,255,pal1);
}
if (fadectr > 0)
{
wfade_between_once (0, 255, blackpal, pal1);
wsetpalette(0,255,blackpal);
fadectr--;
}
if (fadectr < 0)
{
wfade_between_once (0, 255, pal1, blackpal);
wsetpalette(0,255,pal1);
fadectr++;
if (fadectr == 0)
ctr = 300;
}
ctr++;
} while (ctr < 300);
while (kbhit()) getch();
wfreeblock (gum);
wfreeblock (virt);
wfreeblock (landscape);
farfree(data);
}
void gen_plasma(void)
{
FILE *plasmadata;
randomize();
/* data = (unsigned char*)farmalloc(65535l);
if (!data)
{
printf("Not enough free memory.\n\n");
exit(1);
}*/
wtextcolor(15);
/*
for (x=1; x<256; x++)
for (y=0; y<256; y++)
data[x+256*y]=(unsigned char)(16*(3+(cos(0.32*sqrt((x-128)*(x-128)+(y-128)*(y-128))))+
cos(x/11.0)+cos(y/26.0)));
/* Writes the plasma data to disk */
plasmadata = fopen ("gn.003", "wb");
fwrite (data, 65535L, 1, plasmadata);
fclose (plasmadata);
*/
/* Reads the plasma data into memory. */
data = lib2buf("gn.003");
}
void draw_land_plasma(void)
{
int pl1, pl2;
teller++;
if (teller > 30000) teller = 0;
pl1=48+cos(teller/37)*47.0+256*(int)(48+47*(sin(teller/31)));
pl2=48+sin(teller/84)*47.0+256*(int)(48+47*(cos(teller/19)))-pl1;
asm .386
asm les di,landscape
asm add di,4
asm push ds
asm lds si,data
asm add si,pl1
asm mov bx,pl2
asm mov cl,30
l1: asm mov dx,160
l2: asm lodsb
asm add al,[si+bx]
asm mov ah, al
asm stosw
asm dec dx
asm jnz l2
asm add si,256-160
asm dec cl
asm jnz l1
asm pop ds
}
int px[4] = {0, 319, 319, 0};
int py[4] = {0, 0, 199, 199};
/* Original source points */
int rx[4], ry[4];
/* Source points after rotation and sin wave warping */
long lsin[360], lcos[360];
void lcalc_sin(void)
{
int i;
for (i = 0; i < 360; i++)
{
lsin[i] = sin(3.1415 * ((double)i / 180.0)) * 1024;
lcos[i] = cos(3.1415 * ((double)i / 180.0)) * 1024;
}
}
void rotatepoly(int centx, int centy, int rot)
/* Rotates the 4 corners of the texture source points, given the center of
rotation and the rotational amount. */
{
int i;
int x, y;
int x2, y2;
for (i = 0; i <= 3; i++)
{
x = px[i] - centx; /* Subtract the centers */
y = py[i] - centy; /* so coordinates are based around (0,0) */
x2 = ((long)x * lcos[rot] - (long)y * lsin[rot]) >> 10;
y2 = ((lo