"Lost treasure of mBedungu" 100 level puzzle game for RETRO
Dependencies: LCD_ST7735 RetroPlatform mbed
main.cpp@1:dcea5500a32d, 2015-03-01 (annotated)
- Committer:
- Architect
- Date:
- Sun Mar 01 05:32:06 2015 +0000
- Revision:
- 1:dcea5500a32d
- Parent:
- 0:f5f961973d01
Initial checkin
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Architect | 1:dcea5500a32d | 1 | /* |
Architect | 1:dcea5500a32d | 2 | * (C) Copyright 2015 Valentin Ivanov. All rights reserved. |
Architect | 1:dcea5500a32d | 3 | * |
Architect | 1:dcea5500a32d | 4 | * This file is part of the "Lost treasure of mBedungu" game application for Retro |
Architect | 1:dcea5500a32d | 5 | * |
Architect | 1:dcea5500a32d | 6 | * The "Lost treasure of mBedungu" application is free software: you can redistribute it and/or modify |
Architect | 1:dcea5500a32d | 7 | * it under the terms of the GNU Lesser General Public License as published by |
Architect | 1:dcea5500a32d | 8 | * the Free Software Foundation, either version 3 of the License, or |
Architect | 1:dcea5500a32d | 9 | * (at your option) any later version. |
Architect | 1:dcea5500a32d | 10 | * |
Architect | 1:dcea5500a32d | 11 | * This program is distributed in the hope that it will be useful, |
Architect | 1:dcea5500a32d | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Architect | 1:dcea5500a32d | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Architect | 1:dcea5500a32d | 14 | * GNU Lesser General Public License for more details. |
Architect | 1:dcea5500a32d | 15 | * |
Architect | 1:dcea5500a32d | 16 | * You should have received a copy of the GNU Lesser General Public License |
Architect | 1:dcea5500a32d | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/> |
Architect | 1:dcea5500a32d | 18 | * |
Architect | 1:dcea5500a32d | 19 | */ |
Architect | 1:dcea5500a32d | 20 | |
Architect | 0:f5f961973d01 | 21 | #include "mbed.h" |
Architect | 0:f5f961973d01 | 22 | #include "Retro.h" |
Architect | 0:f5f961973d01 | 23 | #include "GameScreen.h" |
Architect | 0:f5f961973d01 | 24 | #include "Levels.h" |
Architect | 0:f5f961973d01 | 25 | #include "Sprites.h" |
Architect | 1:dcea5500a32d | 26 | #include "Utils.h" |
Architect | 0:f5f961973d01 | 27 | |
Architect | 0:f5f961973d01 | 28 | #include "IntroScreen.h" |
Architect | 0:f5f961973d01 | 29 | #include "MenuScreen.h" |
Architect | 0:f5f961973d01 | 30 | #include "LevelScreen.h" |
Architect | 0:f5f961973d01 | 31 | |
Architect | 0:f5f961973d01 | 32 | |
Architect | 0:f5f961973d01 | 33 | IntroScreen * pIntroScreen = NULL; |
Architect | 0:f5f961973d01 | 34 | MenuScreen * pMenuScreen = NULL; |
Architect | 0:f5f961973d01 | 35 | GameScreen * pGameScreen = NULL; |
Architect | 0:f5f961973d01 | 36 | LevelScreen * pLevelScreen = NULL; |
Architect | 0:f5f961973d01 | 37 | |
Architect | 0:f5f961973d01 | 38 | Retro retro; |
Architect | 0:f5f961973d01 | 39 | |
Architect | 0:f5f961973d01 | 40 | uint8_t * pRickFont = NULL; |
Architect | 0:f5f961973d01 | 41 | |
Architect | 0:f5f961973d01 | 42 | void unpackFont() |
Architect | 0:f5f961973d01 | 43 | { |
Architect | 0:f5f961973d01 | 44 | pRickFont = (uint8_t *)malloc(376*8); |
Architect | 0:f5f961973d01 | 45 | |
Architect | 0:f5f961973d01 | 46 | if( pRickFont == NULL ) |
Architect | 0:f5f961973d01 | 47 | retro.rightEye = true; |
Architect | 0:f5f961973d01 | 48 | |
Architect | 0:f5f961973d01 | 49 | memset(pRickFont,0,376*8); |
Architect | 0:f5f961973d01 | 50 | //return; |
Architect | 0:f5f961973d01 | 51 | |
Architect | 0:f5f961973d01 | 52 | if( pRickFont != NULL ) |
Architect | 0:f5f961973d01 | 53 | { |
Architect | 0:f5f961973d01 | 54 | for(int i = 0; i < 752; i++) |
Architect | 0:f5f961973d01 | 55 | { |
Architect | 0:f5f961973d01 | 56 | pRickFont[(i<<2)+0] = (rick_font[i]>>6) & 0x03; |
Architect | 0:f5f961973d01 | 57 | pRickFont[(i<<2)+1] = (rick_font[i]>>4) & 0x03; |
Architect | 0:f5f961973d01 | 58 | pRickFont[(i<<2)+2] = (rick_font[i]>>2) & 0x03; |
Architect | 0:f5f961973d01 | 59 | pRickFont[(i<<2)+3] = (rick_font[i]) & 0x03; |
Architect | 0:f5f961973d01 | 60 | } |
Architect | 0:f5f961973d01 | 61 | } |
Architect | 0:f5f961973d01 | 62 | } |
Architect | 0:f5f961973d01 | 63 | |
Architect | 1:dcea5500a32d | 64 | void drawChar(int x, int y, char c, const uint16_t *palette) |
Architect | 0:f5f961973d01 | 65 | { |
Architect | 0:f5f961973d01 | 66 | if( pRickFont == NULL ) |
Architect | 0:f5f961973d01 | 67 | return; |
Architect | 0:f5f961973d01 | 68 | |
Architect | 0:f5f961973d01 | 69 | int index = c-44; |
Architect | 0:f5f961973d01 | 70 | retro.display.drawBitmapIndexed(x,y,376,8,index*8,0,8,8,pRickFont, palette); |
Architect | 0:f5f961973d01 | 71 | } |
Architect | 1:dcea5500a32d | 72 | void drawString(int x, int y, const char *pString, const uint16_t *palette) |
Architect | 0:f5f961973d01 | 73 | { |
Architect | 0:f5f961973d01 | 74 | int i = 0; |
Architect | 0:f5f961973d01 | 75 | char *p = (char*)pString; |
Architect | 0:f5f961973d01 | 76 | while(*p != 0) |
Architect | 0:f5f961973d01 | 77 | { |
Architect | 0:f5f961973d01 | 78 | if( *p == 13 ) |
Architect | 0:f5f961973d01 | 79 | { |
Architect | 0:f5f961973d01 | 80 | i = 0; |
Architect | 0:f5f961973d01 | 81 | p++; |
Architect | 0:f5f961973d01 | 82 | continue; |
Architect | 0:f5f961973d01 | 83 | } |
Architect | 0:f5f961973d01 | 84 | if( *p == 10 ) |
Architect | 0:f5f961973d01 | 85 | { |
Architect | 0:f5f961973d01 | 86 | y += 8; |
Architect | 0:f5f961973d01 | 87 | p++; |
Architect | 0:f5f961973d01 | 88 | continue; |
Architect | 0:f5f961973d01 | 89 | } |
Architect | 0:f5f961973d01 | 90 | |
Architect | 1:dcea5500a32d | 91 | drawChar(x + i*8, y, *p++, palette); |
Architect | 0:f5f961973d01 | 92 | i++; |
Architect | 0:f5f961973d01 | 93 | } |
Architect | 0:f5f961973d01 | 94 | } |
Architect | 0:f5f961973d01 | 95 | |
Architect | 0:f5f961973d01 | 96 | main() |
Architect | 0:f5f961973d01 | 97 | { |
Architect | 1:dcea5500a32d | 98 | |
Architect | 0:f5f961973d01 | 99 | unpackFont(); |
Architect | 0:f5f961973d01 | 100 | |
Architect | 0:f5f961973d01 | 101 | retro.initialize(); |
Architect | 1:dcea5500a32d | 102 | |
Architect | 0:f5f961973d01 | 103 | pGameScreen = new GameScreen(); |
Architect | 1:dcea5500a32d | 104 | pGameScreen->resetLevel(); |
Architect | 0:f5f961973d01 | 105 | |
Architect | 0:f5f961973d01 | 106 | Screen currentScreen = Intro; |
Architect | 0:f5f961973d01 | 107 | |
Architect | 0:f5f961973d01 | 108 | while (true) { |
Architect | 0:f5f961973d01 | 109 | if( retro.update() ) { |
Architect | 0:f5f961973d01 | 110 | |
Architect | 0:f5f961973d01 | 111 | switch( currentScreen ) { |
Architect | 0:f5f961973d01 | 112 | case Intro: |
Architect | 0:f5f961973d01 | 113 | if( pIntroScreen == NULL ) |
Architect | 0:f5f961973d01 | 114 | pIntroScreen = new IntroScreen(); |
Architect | 0:f5f961973d01 | 115 | currentScreen = pIntroScreen->Update(); |
Architect | 0:f5f961973d01 | 116 | break; |
Architect | 0:f5f961973d01 | 117 | case Menu: |
Architect | 0:f5f961973d01 | 118 | if( pMenuScreen == NULL ) |
Architect | 0:f5f961973d01 | 119 | pMenuScreen = new MenuScreen(); |
Architect | 0:f5f961973d01 | 120 | currentScreen = pMenuScreen->Update(); |
Architect | 0:f5f961973d01 | 121 | break; |
Architect | 0:f5f961973d01 | 122 | case Game: |
Architect | 0:f5f961973d01 | 123 | currentScreen = pGameScreen->Update(); |
Architect | 0:f5f961973d01 | 124 | break; |
Architect | 0:f5f961973d01 | 125 | case Level: |
Architect | 0:f5f961973d01 | 126 | if( pLevelScreen == NULL ) |
Architect | 0:f5f961973d01 | 127 | pLevelScreen = new LevelScreen(); |
Architect | 0:f5f961973d01 | 128 | currentScreen = pLevelScreen->Update(); |
Architect | 0:f5f961973d01 | 129 | break; |
Architect | 0:f5f961973d01 | 130 | } |
Architect | 0:f5f961973d01 | 131 | } |
Architect | 0:f5f961973d01 | 132 | } |
Architect | 0:f5f961973d01 | 133 | } |