#include #include "define.h" #include "pad.h" void InitGameSpecific(void) { int g,h; InitGsLINE(&hline[0], 95, 85, 305, 85, 255, 255, 255); InitGsLINE(&hline[1], 95, 155, 305, 155, 255, 255, 255); InitGsLINE(&vline[0], 165, 15, 165, 225, 255, 255, 255); InitGsLINE(&vline[1], 235, 15, 235, 225, 255, 255, 255); InitGsBOXF(&highlight, 0, 0, 60, 60, 255, 255, 255); highlight.attribute=(1<<28 | 1<<29 | 1<<30); /* (1<<30) is also good semi-transparency: must test for best */ InitGsSPRITE(CROSS_ADD, &playersprite[PLAYER1],0,0); InitGsSPRITE(NOUGHT_ADD, &playersprite[PLAYER2],0,0); InitGsSPRITE(AND_ADD, &and, 0, 0); InitGsLINE(&menuline, 80, 0, 80, 320, 255, 255, 255); InitGsSPRITE(MINITITLE_ADD, &minititle,9,5); /* Title Screen */ and.x=(SCREEN_WIDTH/2)-(and.w/2); and.y=40; playersprite[PLAYER2].x=and.x-playersprite[PLAYER2].w-20; playersprite[PLAYER2].y=40; playersprite[PLAYER1].x=and.x+and.w+20; playersprite[PLAYER1].y=40; FntLoad(960,256); fnt_id[1]=FntOpen(0,25,80,SCREEN_HEIGHT,0,100); fnt_id[2]=FntOpen(0,60,80,SCREEN_HEIGHT,0,100); fnt_id[3]=FntOpen(0,120,80,SCREEN_HEIGHT,0,100); fnt_id[4]=FntOpen(0,180,80,SCREEN_HEIGHT,0,100); for(h=0;h<2;h++) { for(g=0;g<3;g++) { fnt_c[h][g]=9; } } title=FntOpen(80,140,SCREEN_WIDTH-160,SCREEN_HEIGHT,0,200); /* sortr=sortg=sortb=0; */ sortr=255; sortg=sortb=0; GameSetup(); } void DisplayGameSpecific(void) { int spritex,spritey,mark, a; switch(GAMEPOSITION) { case TITLESCREEN : { GsSortFastSprite(&and,&OrderingTable[ActiveBuff],0); GsSortFastSprite(&playersprite[PLAYER2],&OrderingTable[ActiveBuff],0); GsSortFastSprite(&playersprite[PLAYER1],&OrderingTable[ActiveBuff],0); FntPrint(title, " by Rikki Prince\n\n\n\n\n ~c%d%d%dPress Start to\n Continue",title_c[0],title_c[1],title_c[2]); FntFlush(title); break; } case GAMESCREEN : { GsSortLine(&hline[0],&OrderingTable[ActiveBuff],0); GsSortLine(&hline[1],&OrderingTable[ActiveBuff],0); GsSortLine(&vline[0],&OrderingTable[ActiveBuff],0); GsSortLine(&vline[1],&OrderingTable[ActiveBuff],0); GsSortBoxFill(&highlight,&OrderingTable[ActiveBuff],0); for(spritey=0;spritey<3;spritey++) { for(spritex=0;spritex<3;spritex++) { mark=board[spritex][spritey]; if(mark) { playersprite[mark].x=100+(spritex*70); playersprite[mark].y=20+(spritey*70); GsSortFastSprite(&playersprite[mark],&OrderingTable[ActiveBuff],0); } } } GsSortLine(&menuline,&OrderingTable[ActiveBuff],0); GsSortFastSprite(&minititle, &OrderingTable[ActiveBuff],0); FntPrint(title,""); FntPrint(fnt_id[1], " by Rikki\n Prince"); FntPrint(fnt_id[2], " ~c%d%d%dCrosses\n\n ~c999Wins: %d",fnt_c[0][0],fnt_c[0][1],fnt_c[0][2],wins[PLAYER1]); FntPrint(fnt_id[3], " ~c%d%d%dNoughts\n\n ~c999Wins: %d",fnt_c[1][0],fnt_c[1][1],fnt_c[1][2],wins[PLAYER2]); FntPrint(fnt_id[4], " Draws: %d",draws); FntFlush(fnt_id[1]); FntFlush(fnt_id[2]); FntFlush(fnt_id[3]); FntFlush(fnt_id[4]); } default : break; } } void UserManipulation(void) { PAD1=PadRead(); PAD2=PadRead()>>16; switch(GAMEPOSITION) { case TITLESCREEN :if((PAD1&PADR1)&&(PAD1&PADL1)) { GAMEPOSITION=GAMESCREEN; sortr=sortg=0; sortb=255; howmanypads=1; printf("Number of Players: %d\n",howmanypads); } if((PAD1&PADStart)) { GAMEPOSITION=GAMESCREEN; sortr=sortg=0; sortb=255; howmanypads=2; printf("Number of Players: %d\n",howmanypads); } break; case GAMESCREEN : if(currentplayer==PLAYER1) { if(counter>=HIGHMOVEDELAY) { if((PAD1&PADRight)) { highx++; } if((PAD1&PADLeft)) { highx--; } if((PAD1&PADUp)) { highy--; } if((PAD1&PADDown)) { highy++; } if((PAD1&PADCross)) { if(!board[highx][highy]) { board[highx][highy]=PLAYER1; currentplayer=PLAYER2; } } counter=0; } } if(howmanypads==1) { if(currentplayer==PLAYER2) { if(counter>=HIGHMOVEDELAY) { if((PAD1&PADRight)) { highx++; } if((PAD1&PADLeft)) { highx--; } if((PAD1&PADUp)) { highy--; } if((PAD1&PADDown)) { highy++; } if((PAD1&PADCross)) { if(!board[highx][highy]) { board[highx][highy]=PLAYER2; currentplayer=PLAYER1; } } counter=0; } } } if(howmanypads==2) { if(currentplayer==PLAYER2) { if(counter>=HIGHMOVEDELAY) { if((PAD2&PADRight)) { highx++; } if((PAD2&PADLeft)) { highx--; } if((PAD2&PADUp)) { highy--; } if((PAD2&PADDown)) { highy++; } if((PAD2&PADCross)) { if(!board[highx][highy]) { board[highx][highy]=PLAYER2; currentplayer=PLAYER1; } } counter=0; } } } break; default : break; } if((PAD1&PADTriangle)) { printf("Score:\n %d \t %d \t %d \n %d \t %d \t %d \n %d \t %d \t %d \n",board[0][0],board[1][0],board[2][0],board[0][1],board[1][1],board[2][1],board[0][2],board[1][2],board[2][2]); printf("\nPlayer 1 wins: %d\nPlayer 2 Wins: %d\nDraws: %d\n",wins[PLAYER1],wins[PLAYER2],draws); } if((PAD1&PADSquare)) { GameSetup(); } if(((PAD1&PADSelect)&&(PAD1&PADStart))||((PAD2&PADSelect)&&(PAD2&PADStart))) { RUNNING=NO; /* If Start +Select pressed, stop game */ } } void GameUpdate(void) { counter++; colour_cnt++; if(highx<0) highx=0; if(highx>2) highx=2; if(highy<0) highy=0; if(highy>2) highy=2; highlight.x=100+(highx*70); highlight.y=20+(highy*70); /* ComputerMove(); Put back in later if work out how to do decent computer AI! */ if(CheckWin()==PLAYER1) { printf("Player 1 wins!!\n"); wins[PLAYER1]+=1; GameSetup(); } if(CheckWin()==PLAYER2) { printf("Player 2 wins!!\n"); wins[PLAYER2]+=1; GameSetup(); } if(CheckWin()==DRAW) { printf("Draw :(\n"); draws+=1; GameSetup(); } if(GAMEPOSITION==TITLESCREEN) { if(colour_cnt>=FLASHDELAY) { switch(title_c[0]+title_c[1]) { case 18 : title_c[0]=title_c[1]=0; title_c[2]=9; break; case 0 : title_c[0]=title_c[1]=title_c[2]=9; break; } colour_cnt=0; } } if(currentplayer==PLAYER1) { if(colour_cnt>=FLASHDELAY) { switch(fnt_c[0][1]+fnt_c[0][2]) { case 18 : fnt_c[0][1]=fnt_c[0][2]=0; fnt_c[0][0]=9; break; case 0 : fnt_c[0][0]=fnt_c[0][1]=fnt_c[0][2]=9; break; } colour_cnt=0; } fnt_c[1][0]=fnt_c[1][1]=fnt_c[1][2]=9; } if(currentplayer==PLAYER2) { if(colour_cnt>=FLASHDELAY) { switch(fnt_c[1][1]+fnt_c[1][2]) { case 18 : fnt_c[1][1]=fnt_c[1][2]=0; fnt_c[1][0]=9; break; case 0 : fnt_c[1][0]=fnt_c[1][1]=fnt_c[1][2]=9; break; } colour_cnt=0; } fnt_c[0][0]=fnt_c[0][1]=fnt_c[0][2]=9; } } int CheckWin(void) { int p,s,t,check; check=1; p=PLAYER1; if((LINE1(p)) || (LINE2(p)) || (LINE3(p)) || (LINE4(p)) || (LINE5(p)) || (LINE6(p)) || (LINE7(p)) || (LINE8(p))) return PLAYER1; p=PLAYER2; if((LINE1(p)) || (LINE2(p)) || (LINE3(p)) || (LINE4(p)) || (LINE5(p)) || (LINE6(p)) || (LINE7(p)) || (LINE8(p))) return PLAYER2; for(t=0;t<3;t++) { for(s=0;s<3;s++) { if(board[s][t]==0) { check=0; } } } if(check) return DRAW; return 0; } void GameSetup(void) { int p,q; for(q=0;q<3;q++) { for(p=0;p<3;p++) { board[p][q]=0; } } counter=-5; highx=highy=1; currentplayer=PLAYER1; } void ComputerMove(void) { int compx,compy; compx=rand()%3; compy=rand()%3; if(currentplayer==PLAYER2) { while(board[compx][compy]) { compx=rand()%3; compy=rand()%3; } board[compx][compy]=PLAYER2; currentplayer=PLAYER1; } }