Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************************
- *
- * main.c
- *
- ********************************************************************/
- #include "myLib.h"
- #include "texttile.h"
- #include <stdio.h>
- #define MAXWIDTH 239
- #define MAXHEIGHT 159
- int i;
- int voff = 0;
- int hoff = 0;
- int dice1 =0;
- int bank =100;
- int bet=0;
- int dice2=0;
- int diceTotal=0;
- int diceCounter=0;
- int diceCounter2=0;
- int win=0;
- int lose=0;
- int point=0;
- int pass=0;
- int npass=0;
- char MoneyB[30];
- char MoneyC[30];
- typedef enum { TITLE, BET, ROLL1,POINT,WIN,LOSE} STATE;
- int main(void)
- {
- u16 lastButtons;
- STATE gameState = TITLE;
- unsigned short myScreenMap[1024] = {
- 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
- 16,17,18,19,20,21,22,23,24,25,26,27,28,29,0,0,
- 30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,
- 46,47,48,49,50,51,52,53,54,55,56,57,58,59,0,0,
- 60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,
- 76,77,78,79,80,81,82,83,84,85,86,87,88,89,0,0,
- 90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,
- 106,107,108,109,110,111,112,113,114,115,116,117,118,119,0,0,
- 120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,
- 136,137,138,139,140,141,142,143,144,145,146,147,148,149,0,0,
- 150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,
- 166,167,168,169,170,171,172,173,174,175,176,177,178,179,0,0,
- 180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,
- 196,197,198,199,200,201,202,203,204,205,206,207,208,209,0,0,
- 210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,
- 226,227,228,229,230,231,232,233,234,235,236,237,238,239,0,0,
- 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
- };
- u16 myPalette[] = {BLACK, BLUE, GREEN, RED};
- for(i=0; i<16384/4; i++)
- {
- CHARBLOCKBASE[0].tileimg[i] = fontdata_8x8[i*4] | (fontdata_8x8[i*4+1]<<4) |
- (fontdata_8x8[i*4+2]<<8) | (fontdata_8x8[i*4+3]<<12);
- }
- /* for(i=0; i < 1024; i++)
- {
- SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[i];
- }*/
- for(i=0; i<4; i++)
- {
- PALETTE[i] = myPalette[i];
- }
- PALETTE[16] = BLACK;
- PALETTE[17] = YELLOW;
- PALETTE[32] = GREEN;
- PALETTE[33] = RED;
- REG_DISPCTL = MODE0 | BG0_ENABLE;
- REG_BG0HOFS = 0;
- REG_BG0VOFS = 0;
- REG_BG0CNT = BG_SIZE0 | SBB(31) | CBB(0);
- while(1)
- {
- lastButtons=BUTTONS;
- switch (gameState) {
- case TITLE:
- putText(10,5,"Craps in my pants",1);
- putText(15,5,"Press Start to continue",2);
- if(KEY_DOWN_NOW(BUTTON_START))
- {
- gameState=BET;
- for(i=0; i < 1024; i++)
- {
- SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
- }
- }
- break;
- case BET:
- waitForVblank();
- sprintf(MoneyB, "Balance is $: %d", bank);
- putText(8,1,MoneyB,1);
- putText(12,1,"Press up and down to ",1);
- putText(13,1,"adjust bet money max 9",1);
- putText(15,1,"Press A:Pass B:NoPass",1);
- sprintf(MoneyC, "Bet: $ %d", bet);
- putText (18,1,MoneyC,2);
- //setTile(18,7,myScreenMap[numberC]);
- if(KEY_DOWN_NOW(BUTTON_DOWN)&&(lastButtons & BUTTON_DOWN))
- {
- bet--;
- }
- if(bet<0)
- {
- bet=0;
- }
- if(KEY_DOWN_NOW(BUTTON_UP)&&(lastButtons & BUTTON_UP))
- {
- bet++;
- }
- if(KEY_DOWN_NOW(BUTTON_A)&&(lastButtons & BUTTON_A))
- {
- gameState=ROLL1;
- pass++;
- for(i=0; i < 1024; i++)
- {
- SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
- }
- }
- if(KEY_DOWN_NOW(BUTTON_B)&&(lastButtons & BUTTON_B))
- {
- gameState=ROLL1;
- npass++;
- for(i=0; i < 1024; i++)
- {
- SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
- }
- }
- if(bet>9)bet=9;
- break;
- case ROLL1:
- putText(12,1,"Press A to roll ",1);
- if(KEY_DOWN_NOW(BUTTON_A)&&(lastButtons & BUTTON_A))
- {
- char MoneyB[30];
- dice1=rand()%6 + 1;
- dice2=rand()%6 + 1;
- diceTotal=dice1+dice2;
- if(diceTotal<10)setTile(8,22,myScreenMap[0]);
- setTile(5,7,myScreenMap[dice1]);
- setTile(5,10,myScreenMap[dice2]);
- diceCounter++;
- }
- if(pass>0&&diceCounter>0)
- {
- if(diceTotal==7||diceTotal==11)
- {
- sprintf(MoneyB, "You win! You rolled %d", diceTotal);
- putText(8,1,MoneyB,1);
- putText(10,1,"Press B to continue",2);
- point=diceTotal;
- if(KEY_DOWN_NOW(BUTTON_B)&&(lastButtons & BUTTON_B))
- {
- gameState=WIN;
- for(i=0; i < 1024; i++)
- {
- SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
- }
- }
- }
- if(diceTotal==2||diceTotal==3||diceTotal==12)
- {
- sprintf(MoneyB, "You Lose! You rolled %d", diceTotal);
- putText(8,1,MoneyB,1);
- putText(10,1,"Press A",1);
- point=diceTotal;
- if(KEY_DOWN_NOW(BUTTON_A)&&(lastButtons & BUTTON_A))
- {
- gameState=LOSE;
- for(i=0; i < 1024; i++)
- {
- SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
- }
- }
- }
- if(diceTotal==4||diceTotal==5||diceTotal==6||diceTotal==8||diceTotal==9||diceTotal==10)
- {
- sprintf(MoneyB, "Point is %d roll again", diceTotal);
- putText(8,1,MoneyB,1);
- putText(10,1,"Press B dude",1);
- point=diceTotal;
- if(KEY_DOWN_NOW(BUTTON_B)&&(lastButtons & BUTTON_B))
- {
- for(i=0; i < 1024; i++)
- {
- SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
- }
- diceTotal=0;
- gameState=POINT;
- }
- }
- }
- break;
- case POINT:
- putText(12,1,"Press A to roll ",1);
- if(KEY_DOWN_NOW(BUTTON_A)&&(lastButtons & BUTTON_A)&&diceCounter2==0)
- {
- char MoneyB[30];
- dice1=rand()%6 + 1;
- dice2=rand()%6 + 1;
- diceTotal=dice1+dice2;
- if(diceTotal<10)setTile(8,22,myScreenMap[0]);
- setTile(5,7,myScreenMap[dice1]);
- setTile(5,10,myScreenMap[dice2]);
- }
- if(pass>0&&point==diceTotal)
- {
- sprintf(MoneyB, "You win! %d= Pointer", diceTotal);
- putText(8,1,MoneyB,1);
- putText(9,1,"Press B to continue ",1);
- diceCounter2++;
- if(KEY_DOWN_NOW(BUTTON_B)&&(lastButtons & BUTTON_B))
- {
- gameState=WIN;
- for(i=0; i < 1024; i++)
- {
- SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
- }
- }
- }
- if(pass>0&&point==7)
- {
- sprintf(MoneyB, "You lose! u rolled %d", diceTotal);
- putText(8,1,MoneyB,1);
- diceCounter2++;
- }
- break;
- case WIN:
- putText(10,1,"Good job, money added to bank",1);
- putText(11,1,"Press A to play again",1);
- if(KEY_DOWN_NOW(BUTTON_A)&&(lastButtons & BUTTON_A))
- {
- for(i=0; i < 1024; i++)
- {
- SCREENBLOCKBASE[31].tilemap[i] = myScreenMap[0];
- }
- bank+=bet;
- reset();
- gameState=BET;
- }
- break;
- }
- return 0;
- }
- void reset()
- {
- int bet=0;
- int dice2=0;
- int diceTotal=0;
- int diceCounter=0;
- int win=0;
- int lose=0;
- int point=0;
- }
Add Comment
Please, Sign In to add comment