Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <plib.h>
- #include "PmodOLED.h"
- #include "OledChar.h"
- #include "OledGrph.h"
- #include "delay.h"
- #pragma config ICESEL = ICS_PGx1 // ICE/ICD Comm Channel Select
- #pragma config FNOSC = PRIPLL // Oscillator selection
- #pragma config POSCMOD = XT // Primary oscillator mode
- #pragma config FPLLIDIV = DIV_2 // PLL input divider
- #pragma config FPLLMUL = MUL_20 // PLL multiplier
- #pragma config FPLLODIV = DIV_1 // PLL output divider
- #pragma config FPBDIV = DIV_8 // Peripheral bus clock divider
- #pragma config FSOSCEN = OFF // Secondary oscillator enable
- // Global variable to pass the ADC reading to main
- volatile int ADC_reading1;
- volatile int ADC_reading2;
- volatile int ADC_conv;
- int buttonstate = 0;
- int topScore = 0;
- int midScore = 0;
- int botScore = 0;
- int score = 0;
- //avatar position
- int cx = 0;
- int cy = 0;
- //prize position
- int px = 0;
- int py = 0;
- int pv = 0;
- //trap position
- int tx = 0;
- int ty = 0;
- int tv = 0;
- //collision detection
- int k = 0;
- int paused = 0;
- //bitmaps
- unsigned char bitmap[] = {0x3C, 0x7E, 0xFF, 0xFF, 0xE7, 0xE7, 0x42, 0x00};
- unsigned char prizemap[] = {0x3c, 0x42, 0xA9, 0x85, 0x85, 0xA9, 0x42, 0x3C};
- unsigned char trapmap[] = {0x3C, 0x7E, 0xFF, 0xFF, 0xE7, 0xE7, 0x42, 0x00};
- int lose = 0;
- int win = 0;
- #define BUFLEN 64
- char buf[BUFLEN];
- int diffLevel = 0;
- #define OBJECTS 8
- #define OBJECTSM 10
- #define OBJECTSH 12
- #define HITSIZE 2
- int objx[OBJECTS] = {0, 0, 0, 0, 0, 0, 0, 0}; //x co-ordinate of objects
- int objy[OBJECTS] = {0, 0, 0, 0, 0, 0, 0, 0}; //y co-ordinate of objects
- int objt[OBJECTS] = {0, 0, 0, 0, 0, 0, 0, 0}; //type of object: trap = 1, prize = 2, object exists = 0
- int objxm[OBJECTSM] = {0,0,0,0,0,0,0,0,0,0};
- int objym[OBJECTSM] = {0,0,0,0,0,0,0,0,0,0};
- int objtm[OBJECTSM] = {0,0,0,0,0,0,0,0,0,0};
- int objxh[OBJECTSH] = {0,0,0,0,0,0,0,0,0,0,0,0};
- int objyh[OBJECTSH] = {0,0,0,0,0,0,0,0,0,0,0,0};
- int objth[OBJECTSH] = {0,0,0,0,0,0,0,0,0,0,0,0};
- // The interrupt handler for the ADC
- // IPL7 highest interrupt priority
- void __ISR(_ADC_VECTOR, IPL7SRS) _ADCHandler(void) {
- ADC_conv++;
- ADC_reading1 = ReadADC10(0);
- ADC_reading2 = ReadADC10(1);
- INTClearFlag(INT_AD1);
- }
- void ADCInit() {
- SetChanADC10(ADC_CH0_POS_SAMPLEA_AN2 |
- ADC_CH0_NEG_SAMPLEA_NVREF);
- OpenADC10( // config1
- ADC_FORMAT_INTG32 |
- ADC_CLK_AUTO |
- ADC_AUTO_SAMPLING_ON ,
- // config2
- ADC_VREF_AVDD_AVSS |
- ADC_SCAN_ON |
- ADC_SAMPLES_PER_INT_2 ,
- // config3
- ADC_SAMPLE_TIME_8 |
- ADC_CONV_CLK_20Tcy ,
- // configport
- ENABLE_AN2_ANA |
- ENABLE_AN3_ANA ,
- // configscan
- ~(SKIP_SCAN_AN2 |
- SKIP_SCAN_AN3)
- );
- EnableADC10();
- // Set up, clear, and enable ADC interrupts
- INTSetVectorPriority(INT_ADC_VECTOR, INT_PRIORITY_LEVEL_7);
- INTClearFlag(INT_AD1);
- INTEnable(INT_AD1, INT_ENABLED);
- }
- void __ISR(_CHANGE_NOTICE_VECTOR, IPL3AUTO) CNInterruptHandler(void)
- {
- //button 2 is pressed
- if (INTGetFlag(INT_CN))
- {
- if (PORTReadBits(IOPORT_G, BIT_6) == BIT_6)
- {
- buttonstate = 1;
- paused = 1;
- }
- else if (PORTReadBits(IOPORT_G, BIT_7) == BIT_7)
- {
- buttonstate = 0;
- }
- INTClearFlag(INT_CN);
- }
- }
- void initChangeNotice()
- {
- mCNOpen(CN_ON, CN8_ENABLE | CN9_ENABLE, 0); //unsure of this
- PORTRead(IOPORT_G);
- INTSetPriority(INT_CN, 3);
- INTClearFlag(INT_CN);
- INTEnable(INT_CN, 1);
- }
- void SystemInit()
- {
- PORTSetPinsDigitalIn(IOPORT_G, BIT_6 | BIT_7);
- initChangeNotice();
- PORTSetPinsAnalogIn (IOPORT_B, BIT_2);
- PORTSetPinsAnalogIn (IOPORT_B, BIT_3);
- PORTSetPinsDigitalOut(IOPORT_B, BIT_6);
- PORTSetBits (IOPORT_B, BIT_6);
- ADCInit();
- DelayInit();
- OledInit();
- INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);
- INTEnableInterrupts();
- INTEnableSystemMultiVectoredInt();
- }
- void movePlayer()
- {
- if (ADC_reading1 > 520 && ADC_reading2 >490 && ADC_reading2 < 520) //UD neutral, right
- {
- if (cx != 119)
- {
- OledMoveTo(cx++, cy);
- OledPutBmp(8, 8, bitmap);
- OledUpdate(); // look at it
- DelayMs(5); // short delay
- OledMoveTo(cx, cy);
- OledPutBmp(8, 8, bitmap);
- OledUpdate();
- }
- //if reached right edge, remain there
- else
- {
- cx = 119;
- }
- }
- //move left
- if (ADC_reading1 < 490 && ADC_reading2 >490 && ADC_reading2 < 520) //UD neutral, Left
- {
- if (cx != 0)
- {
- OledMoveTo(cx--, cy);
- OledPutBmp(8, 8, bitmap);
- OledUpdate(); // look at it
- DelayMs(5); // short delay
- OledMoveTo(cx, cy);
- OledPutBmp(8, 8, bitmap);
- OledUpdate();
- }
- //if reached left edge, remain there
- else
- {
- cx = 0;
- }
- }
- //move down
- if (ADC_reading2 < 490 && ADC_reading1 >490 && ADC_reading1 < 520) //down
- {
- if (cy != 23)
- {
- OledMoveTo(cx, cy++);
- OledPutBmp(8, 8, bitmap);
- OledUpdate(); // look at it
- DelayMs(5); // short delay
- OledMoveTo(cx, cy);
- OledPutBmp(8, 8, bitmap);
- OledUpdate();
- }
- //if reached down edge, remain there
- else
- {
- cy = 23;
- }
- }
- //move up
- if (ADC_reading2 > 520 && ADC_reading1 >490 && ADC_reading1 < 520) //up
- {
- if (cy != 0)
- {
- OledMoveTo(cx, cy--);
- OledPutBmp(8, 8, bitmap);
- OledUpdate(); // look at it
- DelayMs(5); // short delay
- OledMoveTo(cx, cy);
- OledPutBmp(8, 8, bitmap);
- OledUpdate();
- }
- //if reached up edge, remain there
- else
- {
- cy = 0;
- }
- }
- //move up-right
- if (ADC_reading1 > 520 && ADC_reading2 > 520) //up and right
- {
- if (cx != 119 && cy != 0)
- {
- OledMoveTo(cx++, cy--);
- OledPutBmp(8, 8, bitmap);
- OledUpdate(); // look at it
- DelayMs(5); // short delay
- OledMoveTo(cx, cy);
- OledPutBmp(8, 8, bitmap);
- OledUpdate();
- }
- //if reached any edge, remain there
- else if (cx == 119)
- {
- cx = 119;
- }
- else if (cy == 0)
- {
- cy = 0;
- }
- }
- //move up-left
- if (ADC_reading1 < 490 && ADC_reading2 > 520) //up and left
- {
- if (cx != 0 && cy != 0)
- {
- OledMoveTo(cx--, cy--);
- OledPutBmp(8, 8, bitmap);
- OledUpdate(); // look at it
- DelayMs(5); // short delay
- OledMoveTo(cx, cy);
- OledPutBmp(8, 8, bitmap);
- OledUpdate();
- }
- else if (cx == 0)
- {
- cx = 0;
- }
- else if (cy == 0)
- {
- cy = 0;
- }
- }
- //move down-right
- if (ADC_reading1 > 520 && ADC_reading2 < 490) //down and right
- {
- if (cx != 119 && cy != 23)
- {
- OledMoveTo(cx++, cy++);
- OledPutBmp(8, 8, bitmap);
- OledUpdate(); // look at it
- DelayMs(5); // short delay
- OledMoveTo(cx, cy);
- OledPutBmp(8, 8, bitmap);
- OledUpdate();
- }
- //if reached any edge, remain there
- else if (cx == 119)
- {
- cx = 119;
- }
- else if (cy == 23)
- {
- cy = 23;
- }
- }
- //move down-left
- if (ADC_reading1 < 490 && ADC_reading2 < 490) //down and left
- {
- if (cx != 0 && cy != 23)
- {
- OledMoveTo(cx--, cy++);
- OledPutBmp(8, 8, bitmap);
- OledUpdate(); // look at it
- DelayMs(5); // short delay
- OledMoveTo(cx, cy);
- OledPutBmp(8, 8, bitmap);
- OledUpdate();
- }
- //if reached any edge, remain there
- else if (cx == 0)
- {
- cx = 0;
- }
- else if (cy == 23)
- {
- cy = 23;
- }
- }
- }
- int detectcollisionsingle(int ax, int ay, int vx, int vy)
- {
- int collx = ax - vx;
- int colly = ay - vy;
- collx = (collx < 0) ? -collx : collx;
- colly = (colly < 0) ? -colly : colly;
- if ((collx <= HITSIZE) && (colly <= HITSIZE))
- return 1;
- else
- return 0;
- }
- int detectcollision(int ax, int ay) {
- int i;
- if(diffLevel == 0)
- {
- for (i=0; i<OBJECTS; i++)
- if (detectcollisionsingle(ax, ay, objx[i], objy[i]))
- if (objt[i] > 0) // object exists
- return i;
- return -1;
- }
- else if(diffLevel == 1)
- {
- for (i=0; i<OBJECTSM; i++)
- if (detectcollisionsingle(ax, ay, objxm[i], objym[i]))
- if (objtm[i] > 0) // object exists
- return i;
- return -1;
- }
- else if (diffLevel == 2)
- {
- for (i=0; i<OBJECTSH; i++)
- if (detectcollisionsingle(ax, ay, objxh[i], objyh[i]))
- if (objth[i] > 0) // object exists
- return i;
- return -1;
- }
- return -1;
- }
- //code for prizes
- void prizePut() {
- OledSetDrawColor(1);
- OledSetDrawMode(modOledXor);
- OledMoveTo(px, py);
- OledPutBmp(8, 8, prizemap);
- OledUpdate();
- }
- //starts with invisible
- void prizeShow(int n) {
- // make prize visible (n=1) or invisible (n=0)
- if (pv =! n) {
- pv = n;
- prizePut();
- }
- }
- //code for traps
- void trapPut() {
- OledSetDrawColor(1);
- OledSetDrawMode(modOledXor);
- OledMoveTo(tx, ty);
- OledPutBmp(8, 8, trapmap);
- OledUpdate();
- }
- //starts with invisible
- void trapShow(int n) {
- // make trap visible (n=1) or invisible (n=0)
- if (tv =! n) {
- tv = n;
- trapPut();
- }
- }
- int youWin()
- {
- int i;
- if (diffLevel == 0)
- {
- for (i = 0; i < OBJECTS; i++)
- {
- //check if obj is a prize
- if (objt[i] == 2)
- {
- //prize exists so have not won yet
- return 0;
- }
- }
- }
- else if (diffLevel == 1)
- {
- for (i = 0; i < OBJECTSM; i++)
- {
- //check if obj is a prize
- if (objtm[i] == 2)
- {
- //prize exists so have not won yet
- return 0;
- }
- }
- }
- else if (diffLevel == 2)
- {
- for (i = 0; i < OBJECTSH; i++)
- {
- //check if obj is a prize
- if (objth[i] == 2)
- {
- //prize exists so have not won yet
- return 0;
- }
- }
- }
- //no prize was found. All prizes have been claimed
- return 1;
- }
- void theGameisOn()
- {
- snprintf(buf, 16, "%d", score); //updates in the background as timer2 continues
- OledSetCursor(111, 0);
- OledPutString(buf);
- movePlayer();
- k = detectcollision(cx, cy); //use avatar's co-ordinates
- if (k != -1)
- {
- if (diffLevel == 0)
- {
- if (objt[k] == 1)
- {
- //trap
- tx = objx[k];
- ty = objy[k];
- trapShow(0);
- score--;
- }
- else if (objt[k] == 2)
- {
- //prize
- px = objx[k];
- py = objy[k];
- prizeShow(0);
- score++;
- }
- //erase obj
- objt[k] = 0;
- }
- else if (diffLevel == 1)
- {
- if (objtm[k] == 1)
- {
- //trap
- tx = objxm[k];
- ty = objym[k];
- trapShow(0);
- score--;
- }
- else if (objtm[k] == 2)
- {
- //prize
- px = objxm[k];
- py = objym[k];
- prizeShow(0);
- score++;
- }
- objtm[k] = 0;
- }
- else if (diffLevel == 2)
- {
- if (objth[k] == 1)
- {
- //trap
- tx = objxh[k];
- ty = objyh[k];
- trapShow(0);
- score--;
- }
- else if (objth[k] == 2)
- {
- //prize
- px = objxh[k];
- py = objyh[k];
- prizeShow(0);
- score++;
- }
- objth[k] = 0;
- }
- }
- if (score < 0)
- {
- lose = 1;
- }
- else if (youWin()==1)
- {
- win = 1;
- }
- }
- int main() {
- SystemInit();
- int random;
- //main menu joystick position
- int mx = 0;
- int my = 0;
- //difficulty menu joystick position
- int dx = 0;
- int dy = 0;
- win = 0;
- lose = 0;
- diffLevel = 0;
- OledClearBuffer();
- OledSetDrawColor(1);
- OledSetDrawMode(modOledXor);
- while (1) {
- enum tState {main, difficulty, howToPlay, scoreboard, play, pause};
- static enum tState menu = main;
- switch (menu)
- {
- case main:
- OledSetCursor(0, 0);
- OledPutString("Difficulty ");
- OledSetCursor(0, 1);
- OledPutString("How to play ");
- OledSetCursor(0, 2);
- OledPutString("Scoreboard ");
- OledSetCursor(0, 3);
- OledPutString("Play ");
- win = 0;
- lose = 0;
- score = 0;
- srand(ReadTimer1());
- //safety check
- if (my < 0)
- {
- my = 0;
- }
- else if (my > 3)
- {
- my = 3;
- }
- //make that line blink
- OledSetCursor(0, my);
- OledPutString(" ");
- DelayMs(25);
- //Up, made less sensitive
- if (ADC_reading2 > 900 && ADC_reading1 > 200 && ADC_reading1 < 700)
- {
- if (my != 0)
- {
- my--; //move up one position
- }
- else
- {
- my = 0;
- }
- }
- //Down
- if (ADC_reading2 < 100 && ADC_reading1 > 200 && ADC_reading1 < 700)
- {
- //safety checking second time
- if (my != 3)
- {
- my++;
- }
- else
- {
- my = 3;
- }
- }
- //Pressed either left or right
- if (ADC_reading1 > 700 | ADC_reading1 < 200 && ADC_reading2 > 100 && ADC_reading2 < 900)
- {
- if (my == 0)
- {
- OledClear();
- menu = difficulty;
- }
- else if (my == 1)
- {
- //how to play
- OledClear();
- OledMoveTo(48,23);
- OledPutBmp(8, 8, prizemap);
- OledUpdate();
- OledMoveTo(111,23);
- OledPutBmp(8, 8, trapmap);
- OledUpdate();
- menu = howToPlay;
- }
- else if (my == 2)
- {
- OledClear();
- menu = scoreboard;
- }
- else if (my == 3)
- {
- OledClear();
- cx = 0;
- cy = 0;
- OledMoveTo(cx,cy);
- OledPutBmp(8, 8, bitmap);
- OledUpdate();
- int i;
- int j;
- if (diffLevel == 0)
- {
- int i;
- for (i = 0; i < OBJECTS; i++)
- {
- random = rand() % 119;
- if(random < 8)
- objx[i] = random + 8;
- else
- objx[i] = random;
- random = rand() % 23;
- if (random < 8)
- objy[i] = random + 8;
- else
- objy[i] = random;
- //check that no traps and prizes spawn in the same location
- for (j = 0; j < i; j++)
- {
- if (objx[j] == objx[i])
- objx[i] = rand() % 119;
- if (objy[j] == objy[i])
- objy[i] = rand() % 23;
- }
- for (j = 0; j < i; j++)
- {
- if (objx[j] == objx[i])
- objx[i] = rand() % 119;
- if (objy[j] == objy[i])
- objy[i] = rand() % 23;
- }
- //i is current position
- //j is looping through menu
- for (j = 0; j < i; j++)
- {
- //if difference is less than 8
- //int diff = abs(objx[i]-objx[j]);
- if (abs(objx[i]-objx[j]) < 8 && abs(objy[i]-objy[j]) < 8 )
- {
- //call r
- //objx[i] = objx[i] + (objx[i]-objx[j]);
- //objy[i] = objy[i] + (objx[i]-objx[j]);
- i--;
- }
- }
- //px = objx[i];
- //py = objy[i];
- }
- //number of prizes = 6
- //number of traps = 2
- for (i = 0; i < OBJECTS; i++)
- {
- if (i < 4)
- {
- objt[i] = 2;
- px = objx[i];
- py = objy[i];
- prizePut();
- }
- else
- {
- objt[i] = 1;
- tx = objx[i];
- ty = objy[i];
- trapPut();
- }
- }
- }
- else if (diffLevel == 1)
- {
- //number of prizes = 5
- //number of traps = 5
- for (i = 0; i < OBJECTSM; i++)
- {
- random = rand() % 119;
- if(random < 8)
- objxm[i] = random + 8;
- else
- objxm[i] = random;
- random = rand() % 23;
- if (random < 8)
- objym[i] = random + 8;
- else
- objym[i] = random;
- //check that no traps and prizes spawn in the same location
- for (j = 0; j < i; j++)
- {
- if (objxm[j] == objxm[i])
- objxm[i] = rand() % 119;
- if (objym[j] == objym[i])
- objym[i] = rand() % 23;
- }
- for (j = 0; j < i; j++)
- {
- if (objxm[j] == objxm[i])
- objxm[i] = rand() % 119;
- if (objym[j] == objym[i])
- objym[i] = rand() % 23;
- }
- //i is current position
- //j is looping through menu
- for (j = 0; j < i; j++)
- {
- //if difference is less than 8
- if (abs(objxm[i]-objxm[j]) < 8 && abs(objym[i]-objym[j]) < 8 )
- {
- i--;
- }
- }
- }
- //number of prizes = 6
- //number of traps = 2
- for (i = 0; i < OBJECTSM; i++)
- {
- if (i < 5)
- {
- objtm[i] = 2;
- px = objxm[i];
- py = objym[i];
- prizePut();
- }
- else
- {
- objtm[i] = 1;
- tx = objxm[i];
- ty = objym[i];
- trapPut();
- }
- }
- }
- else if (diffLevel == 2)
- {
- //number of prizes = 2
- //number of traps = 6
- for (i = 0; i < OBJECTSH; i++)
- {
- random = rand() % 119;
- if(random < 8)
- objxh[i] = random + 8;
- else
- objxh[i] = random;
- random = rand() % 23;
- if (random < 8)
- objyh[i] = random + 8;
- else
- objyh[i] = random;
- //check that no traps and prizes spawn in the same location
- for (j = 0; j < i; j++)
- {
- if (objxh[j] == objxh[i])
- objxh[i] = rand() % 119;
- if (objyh[j] == objyh[i])
- objyh[i] = rand() % 23;
- }
- for (j = 0; j < i; j++)
- {
- if (objxh[j] == objxh[i])
- objxh[i] = rand() % 119;
- if (objyh[j] == objyh[i])
- objyh[i] = rand() % 23;
- }
- //i is current position
- //j is looping through array
- for (j = 0; j < i; j++)
- {
- if (abs(objxh[i]-objxh[j]) < 8 && abs(objyh[i]-objyh[j]) < 8 )
- {
- //call r
- //objx[i] = objx[i] + (objx[i]-objx[j]);
- //objy[i] = objy[i] + (objx[i]-objx[j]);
- i--;
- }
- }
- }
- for (i = 0; i < OBJECTSH; i++)
- {
- if (i < 6)
- {
- objth[i] = 2;
- px = objxh[i];
- py = objyh[i];
- prizePut();
- }
- else
- {
- objth[i] = 1;
- tx = objxh[i];
- ty = objyh[i];
- trapPut();
- }
- }
- }
- menu = play;
- //spawn the bitmap
- }
- //reset my before changing state
- my = 0;
- }
- break;
- case difficulty:
- OledSetCursor(0, 0);
- OledPutString("Easy ");
- OledSetCursor(0, 1);
- OledPutString("Medium ");
- OledSetCursor(0, 2);
- OledPutString("Hard ");
- if (dy < 0)
- {
- dy = 0;
- }
- else if (dy > 2)
- {
- dy = 2;
- }
- //make that line blink
- OledSetCursor(0, dy);
- OledPutString(" ");
- DelayMs(25);
- if (ADC_reading2 > 950 && ADC_reading1 > 200 && ADC_reading1 < 900)
- {
- if (dy != 0)
- {
- dy--; //move up one position
- }
- else
- {
- dy = 0;
- }
- }
- //Down
- if (ADC_reading2 < 50 && ADC_reading1 > 200 && ADC_reading1 < 900)
- {
- //safety checking second time
- if (dy != 2)
- {
- dy++;
- }
- else
- {
- dy = 2;
- }
- }
- //Pressed either left or right
- if (PORTReadBits(IOPORT_G, BIT_7) == BIT_7)//ADC_reading1 > 900 | ADC_reading1 < 200 && ADC_reading2 > 50 && ADC_reading2 < 950)
- {
- if (dy == 0)
- {
- diffLevel = 0;
- }
- else if (dy == 1)
- {
- diffLevel = 1;
- }
- else if (dy == 2)
- {
- diffLevel = 2;
- }
- menu = main;
- //don't reset dy
- }
- /*
- if (PORTReadBits(IOPORT_G, BIT_7) == BIT_7)
- {
- menu = main;
- }
- */
- break;
- case howToPlay:
- //display how to play game here
- //with bitmap of trap and prize
- OledSetCursor(0, 0);
- OledPutString("Gather candles");
- OledSetCursor(0, 1);
- OledPutString("avoid skulls to");
- OledSetCursor(0, 2);
- OledPutString("make ghost happy.");
- OledSetCursor(0,3);
- OledPutString("Prize:");
- OledSetCursor(8,3);
- OledPutString("Trap:");
- //display bitmaps
- if (PORTReadBits(IOPORT_G, BIT_7) == BIT_7)
- {
- menu = main;
- }
- break;
- case scoreboard:
- snprintf(buf, BUFLEN, "1: %3d ", topScore); //updates in the background as timer2 continues
- OledSetCursor(0,0);
- OledPutString(buf);
- snprintf(buf, BUFLEN, "2: %3d ", midScore); //updates in the background as timer2 continues
- OledSetCursor(0,1);
- OledPutString(buf);
- snprintf(buf, BUFLEN, "3: %3d ", botScore); //updates in the background as timer2 continues
- OledSetCursor(0,2);
- OledPutString(buf);
- if (PORTReadBits(IOPORT_G, BIT_7) == BIT_7)
- {
- menu = main;
- }
- break;
- case play:
- theGameisOn();
- if (win == 1)
- {
- OledClear();
- OledSetCursor(0, 1);
- OledPutString("You win!");
- DelayMs(3000);
- //update score
- if (score > topScore)
- {
- topScore = score;
- }
- else if (score > midScore)
- {
- midScore = score;
- }
- else if (score > botScore)
- {
- botScore = score;
- }
- menu = main;
- }
- else if (lose == 1)
- {
- OledClear();
- OledSetCursor(0, 1);
- OledPutString("You lose.");
- DelayMs(3000);
- //update score
- if (score > topScore)
- {
- topScore = score;
- }
- else if (score > midScore)
- {
- midScore = score;
- }
- else if (score > botScore)
- {
- botScore = score;
- }
- menu = main;
- }
- else if (PORTReadBits(IOPORT_G, BIT_7) == BIT_7)
- {
- OledClear();
- menu = main;
- }
- else if (paused == 1)
- {
- menu = pause;
- }
- break;
- case pause:
- //so I guess do nothing here
- if (PORTReadBits(IOPORT_G, BIT_7) == BIT_7)
- {
- OledClear();
- menu = main;
- }
- else if (PORTReadBits(IOPORT_G, BIT_6) == BIT_6)
- {
- paused = 0;
- menu = play;
- }
- break;
- }
- }
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement