/* PROGRAM : SWAR.C AUTHOR : Jay Vaughan DATE : 4 November 1991 DESCRIPTION : Simple graphics game for the Atari Portfolio, using the GRLIB functions I developed for my Portfolio. NOTE : See README.DOC for more information. Copyright (C) 1991, 1992 Jay Vaughan */ #include #include #include #include #include #define ARROWAIT 250 #define CGAMODE 6 #define ON 1 #define OFF 0 #define RSHIFT 1 #define LSHIFT 2 #define FIRE 8 #define QUIT 1028 #define BG 0 #define YOU 1 #define NUMBALLS 8 #define DOWN 1 #define UP -1 #define RESTING 0 #define STOPPED 0xff #define LOOPTIME 5 struct balldef { int xpos, ypos; int oypos; int bdir; int velocity; }; struct balldef ball[NUMBALLS]; int color=1, currpos, oldpos; int done=0, instog, cnt=0; int oldbgpos, bgpos, bgdir; int whofired; int szone=10; int homein=0; int cballn; int indanger=0; int score, bgscore=0; int arrowup=0; int arrowcnt=0; int arrowx=0; int lives; int round=1; videomode(int mode) { union REGS inr,outr; inr.h.ah=0; inr.h.al=mode; int86(16,&inr,&outr); } videodot(int x, int y) { union REGS inr,outr; inr.h.ah = 12; /* write pixel */ inr.h.al = color; inr.x.cx = x; inr.x.dx = y; int86(16,&inr,&outr); /* call video intr */ } setballpos() { ball[0].xpos=10; ball[0].ypos=30; ball[0].oypos=20; ball[0].bdir=RESTING; ball[0].velocity=1; ball[1].xpos=20; ball[1].ypos=30; ball[1].oypos=20; ball[1].bdir=RESTING; ball[1].velocity=1; ball[2].xpos=30; ball[2].ypos=30; ball[2].oypos=20; ball[2].bdir=RESTING; ball[2].velocity=1; ball[3].xpos=40; ball[3].ypos=30; ball[3].oypos=20; ball[3].bdir=RESTING; ball[3].velocity=1; ball[4].xpos=50; ball[4].ypos=30; ball[4].oypos=20; ball[4].bdir=RESTING; ball[4].velocity=1; ball[5].xpos=60; ball[5].ypos=30; ball[5].oypos=20; ball[5].bdir=RESTING; ball[5].velocity=1; ball[6].xpos=70; ball[6].ypos=30; ball[6].oypos=20; ball[6].bdir=RESTING; ball[6].velocity=1; ball[7].xpos=80; ball[7].ypos=30; ball[7].oypos=20; ball[7].bdir=RESTING; ball[7].velocity=1; } /* Draws a line on the screen from (x1, y1) to (x2, y2) */ line(int x1, int y1, int x2, int y2) { register int xdelta; /* The change in x coordinates */ register int ydelta; /* The change in y coordinates */ register int xstep; /* The change to make in the x coordinate in each step */ register int ystep; /* The change to make in the y coordinate in each step */ register int change; /* The amount that the x or y coordinate has changed */ xdelta = x2 - x1; /* Calculate the change in x coordinates */ ydelta = y2 - y1; /* Calculate the change in y coordinates */ if (xdelta < 0) { /* The line will be drawn from right to left */ xdelta = -xdelta; xstep = -1; } else /* The line will be drawn from left to right */ xstep = 1; if (ydelta < 0) { /* The line will be drawn from bottom to top */ ydelta = -ydelta; ystep = -1; } else /* The line will be drawn from top to bottom */ ystep = 1; if (xdelta > ydelta) /* x changes quicker than y */ { change = xdelta >> 1; /* change set to twice the value of xdelta */ while (x1 != x2) /* Draw until the terminating dot is reached */ { videodot(x1, y1); /* Draw a dot on the screen */ x1 += xstep; /* Update x coordinate */ change += ydelta; /* Update change */ if (change > xdelta) { y1 += ystep; /* Update the y coordinate */ change -= xdelta; /* Reset change */ } } } else /* y changes quicker than x */ { change = ydelta >> 1; /* change set to twice the value of ydelta */ while (y1 != y2) /* Draw until the terminating dot is reached */ { videodot(x1, y1); /* Draw a dot on the screen */ y1 += ystep; /* Update y coordinate */ change += xdelta; /* Update change */ if (change > ydelta) /* If change is large enough to update the x coordinate */ { x1 += xstep; /* Update the x coordinate */ change -= ydelta; /* Reset change */ } } } } /* line */ plotzapper(int zapper, int *xpos, int state) { int ybase, yb1, yb2, yb3; if (*xpos<=4) *xpos=4; else if (*xpos>=95) *xpos=95; if (zapper==1) { yb1=0; yb2=1; yb3=2; ybase=57; } else { yb1=0; yb2=-1; yb3=-2; ybase=4; } color=state; videodot(*xpos+1, ybase+yb1); videodot(*xpos, ybase+yb2); videodot(*xpos+1, ybase+yb2); videodot(*xpos+2, ybase+yb2); videodot(*xpos-1, ybase+yb3); videodot(*xpos, ybase+yb3); videodot(*xpos+2, ybase+yb3); videodot(*xpos+3, ybase+yb3); } plotzapper2(int *xpos, int state) { if (*xpos<=4) *xpos=4; else if (*xpos>=140) *xpos=140; color=state; videodot(*xpos+1, 5); videodot(*xpos, 4); videodot(*xpos+1, 4); videodot(*xpos+2, 4); videodot(*xpos-1, 3); videodot(*xpos, 3); videodot(*xpos+2, 3); videodot(*xpos+3, 3); } int shiftstate() { union REGS inr, outr; inr.h.ah=02; int86(0x16, &inr, &outr); return(outr.h.al); } long keystate() { union REGS inr, outr; inr.h.ah=02; int86(0x16, &inr, &outr); if (kbhit()) getch(); return(outr.x.ax); } idelay(long time) { register int n; for (n=0;narrowx-2) && (currposball[i].xpos-3)&& (currposarrowx-2) && (bgposball[i].xpos-3)&& (bgpos54) { ball[bn].bdir=STOPPED; bgscore++; ball[bn].ypos=55; } } } placearrow() { videodot(arrowx, 30); videodot(arrowx-1, 31); videodot(arrowx, 31); videodot(arrowx+1, 31); videodot(arrowx, 32); videodot(arrowx, 33); } putarrowup(int arwcol) { if (arwcol==ON) arrowx=srand(2)?3:95; color=arwcol; placearrow(); } main(argc, argv) int argc; char *argv[]; { char *c; register int i; i=argc; /* I hate warning messages ... */ c=argv[1]; switch (*c) { case 'h' : case 'H' : szone=15; homein=1; break; case 'm' : case 'M' : szone=10; break; case 'e' : case 'E' : szone=5; break; case '?' : { printf("Space War Usage:\n"); printf("SWAR [h,m,e]\n"); printf(" [H]ard [M]edium [E]asy\n"); printf("Shift keys move left and right. Alt key\n"); printf("fires. The rest is very simple ...\n"); printf("(c) ChimeTime Software\n"); exit(1); } } instog=keystate()&FIRE; lives=3; setballpos(); while (lives>0) { videomode(3); printf("Round : %d - Lives : %d\n", round, lives); printf("Score - Me : %d You : %d\n", bgscore, score); idelay(30000); color=ON; videomode(CGAMODE); line(0, 0, 100, 0); line(100, 0, 100, 63); line(0, 63, 100, 63); line(0, 0, 0, 63); for (i=0;i(bgpos-2)) && (currpos<(bgpos+2))) if (srand(2)) bgdir=-bgdir; /* Add some srand motion if player is close */ if (cnt==LOOPTIME) /* Only move position after LOOPTIME loops */ { cnt=0; /* Reset our loop counter */ if (homein) /* If its hard, then home in on the player */ bgdir=currpos(currpos-szone)) && (bgpos<(currpos+szone))) if (srand(2)) bgf(); /* Fire at the player now and then */ } } /* Zap a ball endangering the computers zapper if it is close enough */ if ((indanger)&&(bgpos>ball[cballn].xpos-3)&& (bgposscore) printf("I win. You were contaminated.\n"); else printf("You win. I was wasted with nukes.\n"); }