home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
x
/
volume6
/
xplumb
/
part01
/
flow.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-04-11
|
5KB
|
185 lines
/*
* Copyright 1990 Digital Equipment Corporation
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted,
* provided that the above copyright notice appear in all copies and that
* both that copyright notice and this permission notice appear in
* supporting documentation, and that the name of Digital Equipment
* Corporation not be used in advertising or publicity pertaining to
* distribution of the software without specific, written prior
* permission. Digital Equipment Corporation makes no representations
* about the suitability of this software for any purpose. It is
* provided "as is" without express or implied warranty.
*
* DIGITAL EQUIPMENT CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS, IN NO EVENT SHALL DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR
* ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* Author: Terry Weissman
* weissman@wsl.dec.com
*/
#include "plumbing.h"
static int fx, fy;
static Direction indir, outdir;
static int perc; // Percentage through * 100.
static int deltaperc;
static int deltatime;
static int DirX[4] = {0, -1, 1, 0};
static int DirY[4] = {-1, 0, 0, 1};
static void Paint(int fx, int fy, Direction indir, Direction outdir,
int perc) {
Scrn scrn;
Display *dpy;
Window window;
int i, ssize, flowwidth, lssize, hssize, numpix, ipix, opix, x0, y0;
GC gc;
for (i=0 ; i<numscreens ; i++) {
scrn = screen[i];
dpy = scrn->GetDpy();
window = scrn->GetWindow();
ssize = scrn->GetSSize();
flowwidth = scrn->GetFlowWidth();
x0 = scrn->GetBoardX() + ssize * fx;
y0 = scrn->GetBoardY() + ssize * fy;
lssize = (ssize - flowwidth) / 2;
hssize = (ssize + flowwidth) / 2;
gc = scrn->GetFlowGC();
numpix = perc * ssize / 10000;
if (numpix <= 0) continue;
ipix = Min(numpix, hssize);
if (fx != startx || fy != starty) {
switch (indir) {
case Up:
XFillRectangle(dpy, window, gc, x0 + lssize, y0 + 0,
flowwidth, ipix);
break;
case Down:
XFillRectangle(dpy, window, gc, x0 + lssize, y0 + ssize - ipix,
flowwidth, ipix);
break;
case Left:
XFillRectangle(dpy, window, gc, x0 + 0, y0 + lssize,
ipix, flowwidth);
break;
case Right:
XFillRectangle(dpy, window, gc, x0 + ssize - ipix, y0 + lssize,
ipix, flowwidth);
break;
case BadDir:
Punt("Bad in direction in Paint!");
}
}
opix = numpix - ipix;
if (opix <= 0) continue;
switch(outdir) {
case Up:
XFillRectangle(dpy, window, gc, x0 + lssize, y0 + lssize - opix,
flowwidth, opix);
break;
case Down:
XFillRectangle(dpy, window, gc, x0 + lssize, y0 + hssize,
flowwidth, opix);
break;
case Left:
XFillRectangle(dpy, window, gc, x0 + lssize - opix, y0 + lssize,
opix, flowwidth);
break;
case Right:
XFillRectangle(dpy, window, gc, x0 + hssize, y0 + lssize,
opix, flowwidth);
break;
case BadDir:
Punt("Bad out direction in Paint!");
}
}
}
static void TripFlow(void *) {
TimerAddTimeout(deltatime, TripFlow, NULL);
perc += deltaperc;
if (perc >= 10000) {
Paint(fx, fy, indir, outdir, 10000);
perc -= 10000;
fx += DirX[outdir];
fy += DirY[outdir];
if (fx < 0 || fx >= HSQUARES || fy < 0 || fy >= VSQUARES) {
GameOver();
return;
}
indir = OppositeDirection(outdir);
outdir = board[fx][fy].GetPiece()->GetOutDir(indir);
if (outdir == BadDir) {
GameOver();
return;
}
if (numtoget > 0) numtoget--;
score->AddScore(LevelFlowScore());
if (!board[fx][fy].GetRemovable()) {
score->AddScore(LevelCrossOverScore());
}
board[fx][fy].ClearRemovable();
}
Paint(fx, fy, indir, outdir, perc);
}
void FlowRefigureDeltas() {
int i;
int ssize = MINSSIZE ;
for (i=0 ; i<numscreens ; i++) {
if (ssize < screen[i]->GetSSize())
ssize = screen[i]->GetSSize();
}
deltaperc = 10000 / ssize;
deltatime = (fastflow ? 250 : LevelTimePerPiece()) / ssize;
}
void FlowRepaint() {
int x = startx;
int y = starty;
Direction in = startdir;
Direction out = startdir;
while (x != fx || y != fy || in != indir || out != outdir) {
Paint(x, y, in, out, 10000);
x += DirX[out];
y += DirY[out];
if (x < 0 || y < 0 || x >= HSQUARES || y >= VSQUARES) return;
in = OppositeDirection(out);
out = board[x][y].GetPiece()->GetOutDir(in);
}
Paint(fx, fy, indir, outdir, perc);
}
void FlowFast() {
if (score->GetCountDown() > 0) {
score->SetCountDown(0);
}
fastflow = True;
FlowRefigureDeltas();
}
void FlowStart() {
fx = startx;
fy = starty;
indir = outdir = startdir;
perc = 5000;
fastflow = False;
FlowRefigureDeltas();
TripFlow(NULL);
}