#include #include "nib.dat" const int MAXSHOTS = 25; const int MAXAMMO = 250; // Bitmap holders: bitmap snakecell(4,4); int NUMPLYRS; // OBJECTS: struct coord { float x,y; int direction; coord() {} coord(float xx,float yy) { x = xx; y = yy; } }; struct shot { float x,y,mx,my; int type; shot() {} shot(float xx,float yy,int t) { x = xx; y = yy; type = t; } void move() { x += mx; y += my; } void draw() { switch(type) // type is equivelent to which player part the shot is. { case 0: snakecell.setdata(snake1_body); break; case 1: snakecell.setdata(snake2_body); break; case 2: snakecell.setdata(snake3_body); break; case 3: snakecell.setdata(snake4_body); break; } snakecell.setx(x); snakecell.sety(y); snakecell.draw(); } }; struct snake { float x,y; int length; int direction; int keyset; int ammo; int numshots; int shotdelay; int delaycount; int weapon; int alive; float speed; coord parts[250]; shot shots[MAXSHOTS]; int ammostore[MAXAMMO]; snake () {} snake (float xx,float yy,int l,int d,float s) { x=xx;y=yy;speed=s;direction = d;length = l; ammo = 0; weapon = 1; numshots = 0; shotdelay = 50; delaycount = 0; alive = 1; } void draw(int p); void move(); void fire(); void ctrl(); void updateshots(); void addammo(int num,int t); int getammo(); }; struct fatblob { float x,y,movex,movey; int type; fatblob() { x = 0; y = 0; movex = 0; movey = 0; type = 1; } fatblob(float xx,float yy,float mmx, float mmy,int tt) { x = xx; y = yy; movex = mmx; movey = mmy; type = tt; } void draw() { switch(type) { } } }; // END OBJECTS // ARRAYS snake players[4]; // PROTOTYPES void drawsnakes(); int updatesnakes(); int numalive(); // ========== int lost; int main() { // gamesetup clrscr(); cout << "Battle Snakes. BETA v.0.1" << endl << "Nick Meyer. (c) 2002. Fractal Games." << endl; cout << endl << "How many players? "; cin >> NUMPLYRS; cout << endl << "Thankyou" << endl; // setupgraphics setmode(MODE13H); setupbuf(); clrbuf(); setupkbd(); // setup players for (int n=0;n 1) { clrbuf(); drawsnakes(); lost = updatesnakes(); if (lost) { players[lost-1].alive = 0; lost = 0; } showbuf(); delay(5); } KeyEscape = 0; // /------------------------------/ // /------------------------------/ // /------------------------------/ restorekbd(); disablebuf(); setmode(TEXTMODE); clrscr(); if (!numalive) cout << "It was a tie!!!"; else { for (int n=0;n 0 && numshots= shotdelay) { switch (weapon) { case 1: numshots++; shots[numshots-1].x = parts[0].x; shots[numshots-1].y = parts[0].y; switch (parts[0].direction) { case 1: shots[numshots-1].mx = 0; shots[numshots-1].my = -2; shots[numshots-1].type = getammo(); break; case 2: shots[numshots-1].mx = 2; shots[numshots-1].my = 0; shots[numshots-1].type = getammo(); break; case 3: shots[numshots-1].mx = 0; shots[numshots-1].my = 2; shots[numshots-1].type = getammo(); break; case 4: shots[numshots-1].mx = -2; shots[numshots-1].my = 0; shots[numshots-1].type = getammo(); break; } } delaycount = 0; } } void snake:: updateshots() { for (int n=0;n 318 || shots[n].y < 2 || shots[n].y > 198) { for (int m=n;m316) parts[m].x-=320; if (parts[m].y<0) parts[m].y+=200; else if (parts[m].y>196) parts[m].y-=200; } for (m=length-1;m>0;m--) { switch (parts[m].direction) { case 1: case 3: if (parts[m].y == parts[m-1].y) parts[m].direction = parts[m-1].direction; case 2: case 4: if (parts[m].x == parts[m-1].x) parts[m].direction = parts[m-1].direction; } } } void snake:: draw(int p) { for (int n=0;n