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:
1:ecf7bbccddc1
Parent:
0:2ee0812e2615
Child:
2:97d01ba6cd91
--- a/main.cpp	Sat Nov 29 06:40:50 2014 +0000
+++ b/main.cpp	Sat Nov 29 08:36:45 2014 +0000
@@ -1,15 +1,16 @@
 #include "GameEngine.h"
 #include "SpriteSheet.h"
 #include "Player.h"
+#include "PatrollingEnemy.h"
 #include "font_IBM.h"
 
 // Block images
 static const ImageFrame emptyBlock(bmp, 0, 0, 8, 8);
-static const ImageFrame brickBlock(bmp, 0, 32, 8, 8);
-static const ImageFrame meshFenceTopBlock(bmp, 8, 32, 8, 8);
-static const ImageFrame meshFenceBlock(bmp, 16, 32, 8, 8);
-static const ImageFrame platformBlock(bmp, 24, 32, 8, 8);
-static const ImageFrame brickTrimBlock(bmp, 32, 32, 8, 8);
+static const ImageFrame brickBlock(bmp, 0, 64, 8, 8);
+static const ImageFrame meshFenceTopBlock(bmp, 8, 64, 8, 8);
+static const ImageFrame meshFenceBlock(bmp, 16, 64, 8, 8);
+static const ImageFrame platformBlock(bmp, 24, 64, 8, 8);
+static const ImageFrame brickTrimBlock(bmp, 32, 64, 8, 8);
 
 // Sprite images
 static const ImageFrame playerWalk1(bmp, 0, 0, 16, 16);
@@ -22,6 +23,13 @@
 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[] =
 {
@@ -36,12 +44,16 @@
 // Sprite animation sequences
 const ImageFrame *playerWalking[] = { &playerWalk1, &playerWalk2, &playerWalk3, &playerWalk4, 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(angryBird, 6)        // 1 - Angry bird
+    Sprite(angryBird, 6),       // 1 - Angry bird
+    Sprite(mineCart, 6),        // 2 - Mine cart
+    Sprite(bubble, 1)           // 3 - Bubble
 };
 
 static const uint8_t map[] = {
@@ -58,36 +70,48 @@
     1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
     1,1,1,1,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
     1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,5,1,1,1,1,
-    1,1,1,1,4,4,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
+    1,1,1,1,4,4,0,0,0,0,0,0,0,0,0,0,0,5,1,1,
     1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
     1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 };
 
-class PatrollingEnemy : public GameObject
+class BouncingEnemy : public GameObject
 {
     public:
-        PatrollingEnemy(Game &game) :
-            GameObject(game),
-            _movingUp(false)
+        BouncingEnemy(Game &game, uint8_t spriteId) :
+            GameObject(game),        
+            _dx(1),
+            _dy(1)
         {
-            setSpriteId(1);            
+            setSpriteId(spriteId);            
         }
         
         virtual void update()
         {
-            if (_movingUp)
+            if (_dx > 0) 
             {
-                _movingUp = moveUp();
+                if (!moveRight()) _dx = -1;
+            }
+            else if (_dx < 0)
+            {
+                if (!moveLeft()) _dx = 1;
             }
-            else
+            
+            if (_dy > 0) 
             {
-                _movingUp = !moveDown();
+                if (!moveDown()) _dy = -1;
             }
+            else if (_dy < 0)
+            {
+                if (!moveUp()) _dy = 1;
+            }
+            
             animate();
         }
         
-    private:
-        bool _movingUp;
+    private:        
+        int8_t _dx;
+        int8_t _dy;
 };
 
 class MyGame : public Game
@@ -95,22 +119,30 @@
 public:
     MyGame() :
         _player(*this),
-        _enemy1(*this)
+        _enemy1(*this, 1, PatrollingEnemy::UpDown),
+        _enemy2(*this, 2, PatrollingEnemy::LeftRight),
+        _enemy3(*this, 3)
     {
         _player.setStartPosition(100, 96);
         _enemy1.setStartPosition(104, 16);
+        _enemy2.setStartPosition(48, 24);
+        _enemy3.setStartPosition(80, 96);
         setMap(map, 20, 16, blocks, sprites);
     }
     
 private:    
     Player _player;
     PatrollingEnemy _enemy1;
+    PatrollingEnemy _enemy2;
+    BouncingEnemy _enemy3;
     
 protected:
     virtual void update(float elapsedTime)
     {
         _player.update();  
         _enemy1.update();
+        _enemy2.update();
+        _enemy3.update();
         wait_ms(32);
     }
     
@@ -118,6 +150,8 @@
     {
         _player.draw();
         _enemy1.draw();
+        _enemy2.draw();
+        _enemy3.draw();
     }
 };