home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
No Fragments Archive 10: Diskmags
/
nf_archive_10.iso
/
MAGS
/
AT_WORLD
/
ATRIW1.MSA
/
OTHER_MODULES_POLLYMOD_POLLYMOD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-23
|
12KB
|
258 lines
/************************************************************************************************************************************************************/
/* */
/* Pollymod.c Dark Lord Module written By Bill Self */
/* 23 Apr 94 */
/************************************************************************************************************************************************************/
#include "vdi.h"
#include "stdlib.h"
#include "mod_head.h"
#include "osbind.h"
#define BLACK 0
#ifndef TRUE
#define TRUE 1
#define FALSE 0
#endif
int calc_num(int, int);
int main(DKL_INFO *dark_pars)
{
short handle, xres, yres;
short pxy[4];
int *exit_flag;
int max_colours;
short x,coloura,colourb,totala,totalb,colour_changea,colour_changeb;
int no_recs,col_change,poly_speed,speed,def_sides,count;
int num_recs[2];
short num[2][10];
short coords1[17][10]; /* Coordinates for 1st rectangle */
short direction[2][10]; /* Direction individual coordinates are moving */
short coords2[17][10]; /* Coordinates for second rectangles */
int sides[2][22];
xres=dark_pars->dk_xres; /* Screen size x axis */
yres=dark_pars->dk_yres; /* Screen size y axis */
handle=dark_pars->dk_handle; /* Workstation handle */
exit_flag=dark_pars->dklord_flag; /* Watch for it to become TRUE */
max_colours=dark_pars->dk_pens; /* Max no of colours (screen res) */
num_recs[0]=dark_pars->dk_start1; /* No of trailing rectangles 1st rectangle set */
num_recs[1]=dark_pars->dk_start2; /* No of trailing rectangles 2nd rectangle set */
col_change=dark_pars->dk_start3; /* Speed of colour change */
no_recs=dark_pars->dk_flag1; /* Draw one or both sets, delete old etc */
poly_speed=dark_pars->dk_flag2; /* Rate of progres for rectangles, */
def_sides=dark_pars->dk_flag3; /* No of sides of rectangles to draw */
pxy[0]=0;
pxy[1]=0;
pxy[2]=xres;
pxy[3]=yres;
vs_clip(handle, TRUE, pxy); /* set clip rectangle */
for (x=0;x<8;x=x+2){
coords1[0][x]=(short)calc_num(1,xres); /* Initialize coordinates with random numbers */
coords2[0][x]=(short)calc_num(1,xres); /* x axis first */
}
for (x=1;x<8;x=x+2){
coords1[0][x]=(short)calc_num(1,yres); /* Then the y axis */
coords2[0][x]=(short)calc_num(1,yres);
}
coords1[0][8]=coords1[0][0]; /* Ensure the rectangles fourth edge */
coords1[0][9]=coords1[0][1]; /* joins the first corner */
coords2[0][8]=coords2[0][0];
coords2[0][9]=coords2[0][1];
for (x=0;x<17;++x){ /* Initialize all elements in coordinate */
copy_coords(coords1); /* arrays with coords above */
copy_coords(coords2);
}
for (x=0;x<10;++x){
direction[0][x]=0; /* Initialize other variables and arrays */
direction[1][x]=1;
}
switch (poly_speed){ /* Find which speed selected by user */
case 1 :speed=50; /* and set the speed variable accordingly */
break;
case 2 :speed=35; /* Poly_speed = DarkLord flag2 */
break;
case 3 :speed=20;
break;
case 4 :speed=15;
break;
case 5 :speed=10;
break;
case 6 :speed=03;
break;
default:speed=10;
}
for(x=0;x<10;++x){
num[0][x] = (short)calc_num(1,speed); /* Initialize num array with random numbers between */
num[1][x] = (short)calc_num(1,speed); /* 1 and the max speed chosen above from flag 2 */
}
for (x=0;x<21;++x){
keep_sides(sides);
}
totala=0; /* Initialize more variables, */
totalb=0; /* totala & b = speed of colour change */
count=0; /* count = how long before clearing screen, */
coloura=(short)calc_num(1,max_colours); /* Get colour for first polygon */
colourb=(short)calc_num(1,max_colours); /* Get colour for second polygon */
colour_changea = calc_num(1,col_change); /* Initial time to change colour a */
colour_changeb = calc_num(1,col_change); /* Initial time to change colour b */
while(*exit_flag) {
if ((no_recs==5 || no_recs==6) && count==5000){
v_clrwk(handle); /* If option selected, flag1, and count reached */
count=0; /* threshold, clear the screen and */
} /* reset count variables */
keep_sides(sides); /* Keep record of num sides drawn for each rectangle*/
if (def_sides==6)sides[0][0]=calc_num(1,6); /* If random no of sides selected choose no of */
else sides[0][0]=def_sides; /* sides to draw, else use flag as is. */
vsl_color(handle,coloura); /* Set colour to draw with. */
v_pline (handle,sides[0][0],coords1[0]); /* Draw rectangle with first set of coords */
vsl_color(handle,BLACK); /* Select colour Black to erase trail */
if (no_recs==1 || no_recs==2) v_pline (handle,sides[0][num_recs[0]+1],coords1[num_recs[0]+1]);
/* if selected flag1 erase last polygon according */
/* to length of trail selected coords[num_recs[0]+1]*/
vsl_color(handle,colourb); /* select colour to draw second rectangle with */
if (no_recs==2 || no_recs==4 || no_recs==6){
v_pline (handle,sides[0][0],coords2[0]); /* do second rectangle if flag set */
vsl_color(handle,BLACK); /* Colour to Black to erase last rectangle in trail */
if (no_recs==2) v_pline (handle,sides[0][num_recs[1]+1],coords2[num_recs[1]+1]);/* as above for second set */
}
if (totala == colour_changea){ /* is it time to change colour for the first set */
coloura=(short)calc_num(1,max_colours); /* if so choose random colour <= max_colours */
colour_changea = calc_num(1,col_change); /* reset time to change colour (random number */
totala = 0; /* between 1 and col_change(DarkLord variable3) */
}
if (totalb == colour_changeb){ /* as above but for second set of rectangles */
colourb=(short)calc_num(1,max_colours);
colour_changeb = calc_num(1,col_change);
totalb = 0;
}
copy_coords(coords1); /* Back up coordinates for both sets of rectangles */
copy_coords(coords2);
for (x=0;x<8;x=x+2){ /* Get the new coorditates for the x axis */
do_coord(coords1,&direction[0],x,xres,&num[0],&speed);
}
for (x=1;x<8;x=x+2){ /* Get the new coordinates for the y axis */
do_coord(coords1,&direction[0],x,yres,&num[0],&speed);
}
coords1[0][8]=coords1[0][0]; /* Join up the rectangle */
coords1[0][9]=coords1[0][1];
for (x=0;x<8;x=x+2){ /* as above but for the second rectangle set */
do_coord(coords2,&direction[1],x,xres,&num[1],&speed);
}
for (x=1;x<8;x=x+2){
do_coord(coords2,&direction[1],x,yres,&num[1],&speed);
}
coords2[0][8]=coords2[0][0];
coords2[0][9]=coords2[0][1];
totala++;
totalb++; /* Increment counters */
count++;
}
return 0;
}
/* -------------------------------------------------------------------- */
int calc_num(int min, int max)
{
int diff; /* Function to return a random */
/* number between min and max */
diff=max-min;
if(!diff) diff=1; /* avoid divide-by-zero exception */
return ((Random()%diff)+min);
}
/* -------------------------------------------------------------------- */
do_coord(coord,direct,point,screen_max,n,speed) /* This is the important bit, deals with one coord */
short coord[17][10]; /* at a time, checks which direction it is going in */
short direct[]; /* and if it's not at the edge of the screen, */
short n[]; /* sends it on it's merry way. */
short screen_max;
short point;
int *speed;
{
if (coord[0][point] <= (screen_max-(*speed+1)) && direct[point]==1){ /* Is coord at the screen boundry */
coord[0][point] = coord[0][point] + n[point]; /* If not continue in that direction */
direct[point]=1;
}
else {
if (direct[point] == 1) { /* If direction about to change */
n[point] = (short)calc_num(1,*speed); /* set new speed for this coord */
}
coord[0][point] = coord[0][point] - n[point]; /* Change direction of coord */
direct[point]=0;
}
if (coord[0][point] >= (*speed+1) && direct[point]==0){ /* is coord at left (x axis) or top (y axis) of */
coord[0][point] = coord[0][point] - n[point]; /* screen if not continue in that direction */
direct[point]=0;
}
else {
if (direct[point] == 0) {
n[point] = (short)calc_num(1,*speed); /* If about to change direction get new speed value */
}
coord[0][point] = coord[0][point] + n[point]; /* if the coordinate has reached the boundry change */
direct[point]=1;
}
return 0;
}
copy_coords(coords)
short coords[17][10];
{
short x,y;
for (x=16;x>0;--x){ /* Function to copy coords to next down the line in the coords array. */
for (y=0;y<10;y++){ /* Backs up previous coords in array. */
coords[x][y]=coords[x-1][y];
}
}
return 0;
}
keep_sides(sides) /* Function to retain the number of sides drawn for each rectangle */
int sides[2][22]; /* necessary when random sides chosen, it's be a strange choice but still */
{
short x;
for (x=22;x>0;--x){
sides[0][x]=sides[0][x-1];
}
return 0;
}