"Lost treasure of mBedungu" 100 level puzzle game for RETRO
Dependencies: LCD_ST7735 RetroPlatform mbed
main.cpp@0:f5f961973d01, 2015-02-21 (annotated)
- Committer:
- Architect
- Date:
- Sat Feb 21 06:19:29 2015 +0000
- Revision:
- 0:f5f961973d01
- Child:
- 1:dcea5500a32d
Before switching to 16 colors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Architect | 0:f5f961973d01 | 1 | #include "mbed.h" |
Architect | 0:f5f961973d01 | 2 | #include "Retro.h" |
Architect | 0:f5f961973d01 | 3 | #include "GameScreen.h" |
Architect | 0:f5f961973d01 | 4 | #include "Levels.h" |
Architect | 0:f5f961973d01 | 5 | #include "Sprites.h" |
Architect | 0:f5f961973d01 | 6 | |
Architect | 0:f5f961973d01 | 7 | #include "IntroScreen.h" |
Architect | 0:f5f961973d01 | 8 | #include "HelpScreen.h" |
Architect | 0:f5f961973d01 | 9 | #include "MenuScreen.h" |
Architect | 0:f5f961973d01 | 10 | #include "LevelScreen.h" |
Architect | 0:f5f961973d01 | 11 | |
Architect | 0:f5f961973d01 | 12 | |
Architect | 0:f5f961973d01 | 13 | IntroScreen * pIntroScreen = NULL; |
Architect | 0:f5f961973d01 | 14 | HelpScreen * pHelpScreen = NULL; |
Architect | 0:f5f961973d01 | 15 | MenuScreen * pMenuScreen = NULL; |
Architect | 0:f5f961973d01 | 16 | GameScreen * pGameScreen = NULL; |
Architect | 0:f5f961973d01 | 17 | LevelScreen * pLevelScreen = NULL; |
Architect | 0:f5f961973d01 | 18 | |
Architect | 0:f5f961973d01 | 19 | Retro retro; |
Architect | 0:f5f961973d01 | 20 | |
Architect | 0:f5f961973d01 | 21 | bool gameover = false; |
Architect | 0:f5f961973d01 | 22 | |
Architect | 0:f5f961973d01 | 23 | uint8_t * pRickFont = NULL; |
Architect | 0:f5f961973d01 | 24 | |
Architect | 0:f5f961973d01 | 25 | void unpackFont() |
Architect | 0:f5f961973d01 | 26 | { |
Architect | 0:f5f961973d01 | 27 | pRickFont = (uint8_t *)malloc(376*8); |
Architect | 0:f5f961973d01 | 28 | |
Architect | 0:f5f961973d01 | 29 | if( pRickFont == NULL ) |
Architect | 0:f5f961973d01 | 30 | retro.rightEye = true; |
Architect | 0:f5f961973d01 | 31 | |
Architect | 0:f5f961973d01 | 32 | memset(pRickFont,0,376*8); |
Architect | 0:f5f961973d01 | 33 | //return; |
Architect | 0:f5f961973d01 | 34 | |
Architect | 0:f5f961973d01 | 35 | if( pRickFont != NULL ) |
Architect | 0:f5f961973d01 | 36 | { |
Architect | 0:f5f961973d01 | 37 | for(int i = 0; i < 752; i++) |
Architect | 0:f5f961973d01 | 38 | { |
Architect | 0:f5f961973d01 | 39 | pRickFont[(i<<2)+0] = (rick_font[i]>>6) & 0x03; |
Architect | 0:f5f961973d01 | 40 | pRickFont[(i<<2)+1] = (rick_font[i]>>4) & 0x03; |
Architect | 0:f5f961973d01 | 41 | pRickFont[(i<<2)+2] = (rick_font[i]>>2) & 0x03; |
Architect | 0:f5f961973d01 | 42 | pRickFont[(i<<2)+3] = (rick_font[i]) & 0x03; |
Architect | 0:f5f961973d01 | 43 | } |
Architect | 0:f5f961973d01 | 44 | } |
Architect | 0:f5f961973d01 | 45 | } |
Architect | 0:f5f961973d01 | 46 | |
Architect | 0:f5f961973d01 | 47 | void drawChar(int x, int y, char c) |
Architect | 0:f5f961973d01 | 48 | { |
Architect | 0:f5f961973d01 | 49 | if( pRickFont == NULL ) |
Architect | 0:f5f961973d01 | 50 | return; |
Architect | 0:f5f961973d01 | 51 | |
Architect | 0:f5f961973d01 | 52 | int index = c-44; |
Architect | 0:f5f961973d01 | 53 | retro.display.drawBitmapIndexed(x,y,376,8,index*8,0,8,8,pRickFont, palette); |
Architect | 0:f5f961973d01 | 54 | } |
Architect | 0:f5f961973d01 | 55 | void drawString(int x, int y, const char *pString) |
Architect | 0:f5f961973d01 | 56 | { |
Architect | 0:f5f961973d01 | 57 | int i = 0; |
Architect | 0:f5f961973d01 | 58 | char *p = (char*)pString; |
Architect | 0:f5f961973d01 | 59 | while(*p != 0) |
Architect | 0:f5f961973d01 | 60 | { |
Architect | 0:f5f961973d01 | 61 | if( *p == 13 ) |
Architect | 0:f5f961973d01 | 62 | { |
Architect | 0:f5f961973d01 | 63 | i = 0; |
Architect | 0:f5f961973d01 | 64 | p++; |
Architect | 0:f5f961973d01 | 65 | continue; |
Architect | 0:f5f961973d01 | 66 | } |
Architect | 0:f5f961973d01 | 67 | if( *p == 10 ) |
Architect | 0:f5f961973d01 | 68 | { |
Architect | 0:f5f961973d01 | 69 | y += 8; |
Architect | 0:f5f961973d01 | 70 | p++; |
Architect | 0:f5f961973d01 | 71 | continue; |
Architect | 0:f5f961973d01 | 72 | } |
Architect | 0:f5f961973d01 | 73 | |
Architect | 0:f5f961973d01 | 74 | drawChar(x + i*8, y, *p++); |
Architect | 0:f5f961973d01 | 75 | i++; |
Architect | 0:f5f961973d01 | 76 | } |
Architect | 0:f5f961973d01 | 77 | } |
Architect | 0:f5f961973d01 | 78 | |
Architect | 0:f5f961973d01 | 79 | main() |
Architect | 0:f5f961973d01 | 80 | { |
Architect | 0:f5f961973d01 | 81 | unpackFont(); |
Architect | 0:f5f961973d01 | 82 | |
Architect | 0:f5f961973d01 | 83 | //retro.leftEye = true; |
Architect | 0:f5f961973d01 | 84 | |
Architect | 0:f5f961973d01 | 85 | //Seed the randomizer |
Architect | 0:f5f961973d01 | 86 | AnalogIn ain(P0_15); |
Architect | 0:f5f961973d01 | 87 | srand(ain.read_u16()); |
Architect | 0:f5f961973d01 | 88 | |
Architect | 0:f5f961973d01 | 89 | retro.initialize(); |
Architect | 0:f5f961973d01 | 90 | |
Architect | 0:f5f961973d01 | 91 | //retro.display.setPalette(palette); |
Architect | 0:f5f961973d01 | 92 | |
Architect | 0:f5f961973d01 | 93 | int curLevel = 44; |
Architect | 0:f5f961973d01 | 94 | |
Architect | 0:f5f961973d01 | 95 | pGameScreen = new GameScreen(); |
Architect | 0:f5f961973d01 | 96 | pGameScreen->unpackLevel(curLevel); |
Architect | 0:f5f961973d01 | 97 | |
Architect | 0:f5f961973d01 | 98 | Screen currentScreen = Intro; |
Architect | 0:f5f961973d01 | 99 | |
Architect | 0:f5f961973d01 | 100 | while (true) { |
Architect | 0:f5f961973d01 | 101 | if( retro.update() ) { |
Architect | 0:f5f961973d01 | 102 | |
Architect | 0:f5f961973d01 | 103 | switch( currentScreen ) { |
Architect | 0:f5f961973d01 | 104 | case Intro: |
Architect | 0:f5f961973d01 | 105 | if( pIntroScreen == NULL ) |
Architect | 0:f5f961973d01 | 106 | pIntroScreen = new IntroScreen(); |
Architect | 0:f5f961973d01 | 107 | currentScreen = pIntroScreen->Update(); |
Architect | 0:f5f961973d01 | 108 | break; |
Architect | 0:f5f961973d01 | 109 | case Menu: |
Architect | 0:f5f961973d01 | 110 | if( pMenuScreen == NULL ) |
Architect | 0:f5f961973d01 | 111 | pMenuScreen = new MenuScreen(); |
Architect | 0:f5f961973d01 | 112 | currentScreen = pMenuScreen->Update(); |
Architect | 0:f5f961973d01 | 113 | break; |
Architect | 0:f5f961973d01 | 114 | case Game: |
Architect | 0:f5f961973d01 | 115 | currentScreen = pGameScreen->Update(); |
Architect | 0:f5f961973d01 | 116 | break; |
Architect | 0:f5f961973d01 | 117 | case Level: |
Architect | 0:f5f961973d01 | 118 | if( pLevelScreen == NULL ) |
Architect | 0:f5f961973d01 | 119 | pLevelScreen = new LevelScreen(); |
Architect | 0:f5f961973d01 | 120 | currentScreen = pLevelScreen->Update(); |
Architect | 0:f5f961973d01 | 121 | break; |
Architect | 0:f5f961973d01 | 122 | } |
Architect | 0:f5f961973d01 | 123 | } |
Architect | 0:f5f961973d01 | 124 | } |
Architect | 0:f5f961973d01 | 125 | } |