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

main.cpp

Committer:
taylorza
Date:
2014-12-27
Revision:
3:a93fe5f207f5
Parent:
2:97d01ba6cd91
Child:
4:45ff7fc8a431

File content as of revision 3:a93fe5f207f5:

#include "GameEngine.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,
};

class MyGame : public Game
{
public:
    MyGame() :
        _player(*this),
        _enemy1(*this, 3, PatrollingEnemy::LeftRight),
        _enemy2(*this, 4)
    {
        _player.setStartPosition(130, 96);
        
        _enemy1.setStartPosition(80, 80);
        _enemy1.setCollisionRect(0, 6, 16, 16);
        
        _enemy2.setStartPosition(8, 8);        
        
        setMap(map, 20, 16, blocks, sprites);
        
        addGameObject(&_player);
        addGameObject(&_enemy1);
        addGameObject(&_enemy2);            
    }
    
private:    
    Player _player;
    PatrollingEnemy _enemy1;
    BouncingEnemy  _enemy2;
    
protected:
    virtual void update()
    {        
        Game::update();
    }
};


MyGame game;  
int main()
{           
    game.run();
    while(true)
    {
        wait(0.5);
    }    
    
}