Platform game written for the GHI/OutrageousCircuits RETRO game device. Navigate the caves collecting all the pickups and avoiding the creatures and haunted mine carts that patrol the caves. Oh and remember to watch out for the poisonous plants... This game demonstrates the ability to have multiple animated sprites where the sprites can overlap the background environment. See how the player moves past the fence and climbs the wall in the 3rd screen.

Dependencies:   mbed

Revision:
4:45ff7fc8a431
Parent:
3:a93fe5f207f5
Child:
8:ad5164d57f0d
--- a/main.cpp	Sat Dec 27 23:24:30 2014 +0000
+++ b/main.cpp	Fri Jan 02 00:58:50 2015 +0000
@@ -1,139 +1,105 @@
 #include "GameEngine.h"
+#include "SoundEffects.h"
 #include "SpriteSheet.h"
 #include "Player.h"
 #include "PatrollingEnemy.h"
 #include "BouncingEnemy.h"
-#include "font_IBM.h"
-
-// Block images
-static const ImageFrame emptyBlock(bmp, 0, 0, 8, 8);
-static const ImageFrame brickBlock(bmp, 16, 48, 8, 8);
-static const ImageFrame meshFenceTopBlock(bmp, 24, 48, 8, 8);
-static const ImageFrame meshFenceBlock(bmp, 32, 48, 8, 8);
-static const ImageFrame platformBlock(bmp, 40, 48, 8, 8);
-static const ImageFrame brickTrimBlock(bmp, 48, 48, 8, 8);
-static const ImageFrame leftLadderBlock(bmp, 16, 56, 8, 8);
-static const ImageFrame rightLadderBlock(bmp, 24, 56, 8, 8);
-static const ImageFrame wallBlock(bmp, 56, 48, 8, 8);
-static const ImageFrame spikeyPlantBlock(bmp, 32, 56, 8, 8);
-
-// Sprite images
-static const ImageFrame playerWalk1(bmp, 0, 0, 16, 16);
-static const ImageFrame playerWalk2(bmp, 16, 0, 16, 16);
-static const ImageFrame playerWalk3(bmp, 32, 0, 16, 16);
-static const ImageFrame playerWalk4(bmp, 48, 0, 16, 16);
-
-static const ImageFrame playerClimb1(bmp, 0, 64, 16, 16);
-static const ImageFrame playerClimb2(bmp, 16, 64, 16, 16);
-static const ImageFrame playerClimb3(bmp, 32, 64, 16, 16);
-static const ImageFrame playerClimb4(bmp, 48, 64, 16, 16);
-
-static const ImageFrame angryBird1(bmp, 0, 16, 16, 16);
-static const ImageFrame angryBird2(bmp, 16, 16, 16, 16);
-static const ImageFrame angryBird3(bmp, 32, 16, 16, 16);
-static const ImageFrame angryBird4(bmp, 48, 16, 16, 16);
-
-static const ImageFrame mineCart1(bmp, 0, 32, 16, 16);
-static const ImageFrame mineCart2(bmp, 16, 32, 16, 16);
-static const ImageFrame mineCart3(bmp, 32, 32, 16, 16);
-static const ImageFrame mineCart4(bmp, 48, 32, 16, 16);
-
-static const ImageFrame bubble1(bmp, 0, 48, 16, 16);
-
-// Blocks
-const Block blocks[] =
-{
-    Block(&emptyBlock, Block::Background, 0, 0),        // 0 - Empty block
-    Block(&brickBlock, Block::Solid, 2, 0),             // 1 - Brick - Red on black
-    Block(&meshFenceTopBlock, Block::Background, 1, 0), // 2 - Mesh fence top - Blue on black
-    Block(&meshFenceBlock, Block::Background, 1, 0),    // 3 - Mesh fence - Blue on black
-    Block(&platformBlock, Block::Platform, 5, 0),       // 4 - Platform - Cyan on black
-    Block(&brickTrimBlock, Block::Background, 2, 0),    // 5 - Brick trim - Red on black
-    Block(&leftLadderBlock, Block::Ladder, 6, 0),       // 6 - Left ladder half - Yellow on black
-    Block(&rightLadderBlock, Block::Ladder, 6, 0),      // 7 - Right ladder half - Yellow on black
-    Block(&wallBlock, Block::Ladder, 5, 0),             // 8 - Wall - Cyan on black
-    Block(&spikeyPlantBlock, Block::Deadly, 4, 0)       // 9 - Deadly spikey plant block - Green on black
-}; 
-
-// Sprite animation sequences
-const ImageFrame *playerWalking[] = { &playerWalk1, &playerWalk2, &playerWalk3, &playerWalk4, NULL };
-const ImageFrame *playerClimbing[] = { &playerClimb1, &playerClimb2, &playerClimb3, &playerClimb4, NULL };
-const ImageFrame *angryBird[] = { &angryBird1, &angryBird2, &angryBird3, &angryBird4, NULL };
-const ImageFrame *mineCart[] = { &mineCart1, &mineCart2, &mineCart3, &mineCart4, NULL };
-const ImageFrame *bubble[] = { &bubble1, NULL };
-
-// Sprites
-Sprite sprites[] =
-{
-    Sprite(playerWalking, 7),   // 0 - Player walking
-    Sprite(playerClimbing, 7),  // 1 - Player climbing
-    Sprite(angryBird, 6),       // 2 - Angry bird
-    Sprite(mineCart, 6),        // 3 - Mine cart
-    Sprite(bubble, 1)           // 4 - Bubble
-};
-
-static const uint8_t map[] = {
-    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-    1,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,1,
-    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
-    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
-    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
-    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
-    1,4,6,7,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,1,
-    1,0,6,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
-    1,0,6,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
-    1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,6,7,4,1,
-    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,7,0,1,
-    1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,6,7,0,1,
-    1,4,6,7,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,1,
-    1,2,6,7,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,
-    1,3,6,7,3,3,9,3,3,3,3,9,3,3,3,3,3,3,3,1,    
-    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
-};
+#include "Assets.h"
+#include "Maps.h"
+#include "ScreenIntro.h"
+#include "Screen1.h"
+#include "Screen2.h"
+#include "Screen3.h"
 
 class MyGame : public Game
 {
-public:
-    MyGame() :
-        _player(*this),
-        _enemy1(*this, 3, PatrollingEnemy::LeftRight),
-        _enemy2(*this, 4)
-    {
-        _player.setStartPosition(130, 96);
+    public:
+        MyGame() :
+            _screen(-1),
+            _intro(true)
+        {
+            setScene(new ScreenIntro);             
+        }
+        
+    private:
+        int _screen;
         
-        _enemy1.setStartPosition(80, 80);
-        _enemy1.setCollisionRect(0, 6, 16, 16);
-        
-        _enemy2.setStartPosition(8, 8);        
-        
-        setMap(map, 20, 16, blocks, sprites);
+        virtual void completeScreen()
+        {
+            _intro = false;
+            if (_screen == 2) 
+            {
+                increaseSpeed(10);
+                addLives(1);
+            }
+            
+            _screen = (_screen + 1) % 3;
+            
+            Scene *pCur = getScene();
+            if (pCur != NULL) delete pCur;
+            
+            switch(_screen)
+            {
+                case 0 : setScene(new Screen1); break;
+                case 1 : setScene(new Screen2); break;
+                case 2 : setScene(new Screen3); break;
+            }
+        };
         
-        addGameObject(&_player);
-        addGameObject(&_enemy1);
-        addGameObject(&_enemy2);            
-    }
+        virtual void update()
+        {
+            static bool died = false;
+            
+            if (getLives() > 0)
+            {
+                Game::update();
+            }                       
+            else 
+            {
+                if (died == false)
+                {
+                    died = true;
+                    PLAY_EFFECT(2, Sound_GameOver);
+                }
+            }            
+        }
+        
+        virtual void draw()
+        {            
+            Game::draw();
+            
+            if (!_intro)
+            {
+                if (getLives() == 0) Surface.drawBitmap(52, 60, bmpText, 0, 0, 56, 8, Color565::White, Color565::Black);            
+                
+                Surface.drawBitmap(0, 0, bmpText, 0, 16, 32, 8, Color565::White, Color565::Black);                        
+                drawNumber(34, 0, getLives());
+                
+                Surface.drawBitmap(72, 0, bmpText, 32, 16, 34, 8, Color565::White, Color565::Black);                        
+                drawNumber(110, 0, getScore());
+            }            
+        }
+        
+    private:
+        void drawNumber(int x, int y, int number)
+        {
+            sprintf(_textBuffer, "%d", number);
+            for (char *p = _textBuffer; *p != 0; ++p, x += 8)
+            {
+                int sx = (*p - 48) * 8;                
+                Surface.drawBitmap(x, y, bmpText, sx, 8, 8, 8, Color565::White, Color565::Black);                    
+            }
+        }        
     
-private:    
-    Player _player;
-    PatrollingEnemy _enemy1;
-    BouncingEnemy  _enemy2;
-    
-protected:
-    virtual void update()
-    {        
-        Game::update();
-    }
+    private:        
+        char _textBuffer[15];
+        bool _intro;
 };
 
+MyGame game;
 
-MyGame game;  
 int main()
-{           
+{               
     game.run();
-    while(true)
-    {
-        wait(0.5);
-    }    
-    
 }