"Lost treasure of mBedungu" 100 level puzzle game for RETRO
Dependencies: LCD_ST7735 RetroPlatform mbed
Diff: main.cpp
- Revision:
- 0:f5f961973d01
- Child:
- 1:dcea5500a32d
diff -r 000000000000 -r f5f961973d01 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Feb 21 06:19:29 2015 +0000 @@ -0,0 +1,125 @@ +#include "mbed.h" +#include "Retro.h" +#include "GameScreen.h" +#include "Levels.h" +#include "Sprites.h" + +#include "IntroScreen.h" +#include "HelpScreen.h" +#include "MenuScreen.h" +#include "LevelScreen.h" + + +IntroScreen * pIntroScreen = NULL; +HelpScreen * pHelpScreen = NULL; +MenuScreen * pMenuScreen = NULL; +GameScreen * pGameScreen = NULL; +LevelScreen * pLevelScreen = NULL; + +Retro retro; + +bool gameover = false; + +uint8_t * pRickFont = NULL; + +void unpackFont() +{ + pRickFont = (uint8_t *)malloc(376*8); + + if( pRickFont == NULL ) + retro.rightEye = true; + + memset(pRickFont,0,376*8); + //return; + + if( pRickFont != NULL ) + { + for(int i = 0; i < 752; i++) + { + pRickFont[(i<<2)+0] = (rick_font[i]>>6) & 0x03; + pRickFont[(i<<2)+1] = (rick_font[i]>>4) & 0x03; + pRickFont[(i<<2)+2] = (rick_font[i]>>2) & 0x03; + pRickFont[(i<<2)+3] = (rick_font[i]) & 0x03; + } + } +} + +void drawChar(int x, int y, char c) +{ + if( pRickFont == NULL ) + return; + + int index = c-44; + retro.display.drawBitmapIndexed(x,y,376,8,index*8,0,8,8,pRickFont, palette); +} +void drawString(int x, int y, const char *pString) +{ + int i = 0; + char *p = (char*)pString; + while(*p != 0) + { + if( *p == 13 ) + { + i = 0; + p++; + continue; + } + if( *p == 10 ) + { + y += 8; + p++; + continue; + } + + drawChar(x + i*8, y, *p++); + i++; + } +} + +main() +{ + unpackFont(); + + //retro.leftEye = true; + + //Seed the randomizer + AnalogIn ain(P0_15); + srand(ain.read_u16()); + + retro.initialize(); + + //retro.display.setPalette(palette); + + int curLevel = 44; + + pGameScreen = new GameScreen(); + pGameScreen->unpackLevel(curLevel); + + Screen currentScreen = Intro; + + while (true) { + if( retro.update() ) { + + switch( currentScreen ) { + case Intro: + if( pIntroScreen == NULL ) + pIntroScreen = new IntroScreen(); + currentScreen = pIntroScreen->Update(); + break; + case Menu: + if( pMenuScreen == NULL ) + pMenuScreen = new MenuScreen(); + currentScreen = pMenuScreen->Update(); + break; + case Game: + currentScreen = pGameScreen->Update(); + break; + case Level: + if( pLevelScreen == NULL ) + pLevelScreen = new LevelScreen(); + currentScreen = pLevelScreen->Update(); + break; + } + } + } +}