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

Committer:
taylorza
Date:
Sun Jan 11 02:53:03 2015 +0000
Revision:
9:34008d8b1cdf
Child:
15:5d3f65500736
Final version before optimizations

Who changed what in which revision?

UserRevisionLine numberNew contents of line
taylorza 9:34008d8b1cdf 1 #include "GameEngine.h"
taylorza 9:34008d8b1cdf 2
taylorza 9:34008d8b1cdf 3 #include "SoundBlock.h"
taylorza 9:34008d8b1cdf 4 #include "SoundChannel.h"
taylorza 9:34008d8b1cdf 5 #include "OneBitSound.h"
taylorza 9:34008d8b1cdf 6
taylorza 9:34008d8b1cdf 7 static OneBitSound g_sound(P0_18);
taylorza 9:34008d8b1cdf 8 static Timer g_frameTimer;
taylorza 9:34008d8b1cdf 9
taylorza 9:34008d8b1cdf 10 LCD_ST7735 Game::Surface(
taylorza 9:34008d8b1cdf 11 P0_19,
taylorza 9:34008d8b1cdf 12 P0_20,
taylorza 9:34008d8b1cdf 13 P0_7,
taylorza 9:34008d8b1cdf 14 P0_21,
taylorza 9:34008d8b1cdf 15 P0_22,
taylorza 9:34008d8b1cdf 16 P1_15,
taylorza 9:34008d8b1cdf 17 P0_2,
taylorza 9:34008d8b1cdf 18 LCD_ST7735::RGB);
taylorza 9:34008d8b1cdf 19
taylorza 9:34008d8b1cdf 20 Game *Game::Instance = NULL;
taylorza 9:34008d8b1cdf 21
taylorza 9:34008d8b1cdf 22 void Game::playEffect(uint8_t channel, const SoundBlock *effect, uint8_t count)
taylorza 9:34008d8b1cdf 23 {
taylorza 9:34008d8b1cdf 24 g_sound.play(channel, effect, count);
taylorza 9:34008d8b1cdf 25 }
taylorza 9:34008d8b1cdf 26
taylorza 9:34008d8b1cdf 27 Game::Game() :
taylorza 9:34008d8b1cdf 28 _pScene(NULL),
taylorza 9:34008d8b1cdf 29 _pNextScene(NULL),
taylorza 9:34008d8b1cdf 30 _lives(3),
taylorza 9:34008d8b1cdf 31 _score(0)
taylorza 9:34008d8b1cdf 32 {
taylorza 9:34008d8b1cdf 33 Game::Instance = this;
taylorza 9:34008d8b1cdf 34 }
taylorza 9:34008d8b1cdf 35
taylorza 9:34008d8b1cdf 36 void Game::run()
taylorza 9:34008d8b1cdf 37 {
taylorza 9:34008d8b1cdf 38 g_frameTimer.start();
taylorza 9:34008d8b1cdf 39 int timeAccumulator = 0;
taylorza 9:34008d8b1cdf 40 int lastFrameTime = g_frameTimer.read_us();
taylorza 9:34008d8b1cdf 41
taylorza 9:34008d8b1cdf 42 while(true)
taylorza 9:34008d8b1cdf 43 {
taylorza 9:34008d8b1cdf 44 int timestamp = g_frameTimer.read_us();
taylorza 9:34008d8b1cdf 45 int elapsedTime = timestamp - lastFrameTime;
taylorza 9:34008d8b1cdf 46 lastFrameTime = timestamp;
taylorza 9:34008d8b1cdf 47
taylorza 9:34008d8b1cdf 48 g_sound.update(elapsedTime);
taylorza 9:34008d8b1cdf 49
taylorza 9:34008d8b1cdf 50 timeAccumulator += elapsedTime;
taylorza 9:34008d8b1cdf 51 if (timeAccumulator >= (32000 - _speedAdjust))
taylorza 9:34008d8b1cdf 52 {
taylorza 9:34008d8b1cdf 53 update();
taylorza 9:34008d8b1cdf 54 draw();
taylorza 9:34008d8b1cdf 55 if (_pNextScene != NULL)
taylorza 9:34008d8b1cdf 56 {
taylorza 9:34008d8b1cdf 57 _pScene = _pNextScene;
taylorza 9:34008d8b1cdf 58 _pNextScene = NULL;
taylorza 9:34008d8b1cdf 59 }
taylorza 9:34008d8b1cdf 60 timeAccumulator -= (32000 - _speedAdjust);
taylorza 9:34008d8b1cdf 61 }
taylorza 9:34008d8b1cdf 62 else
taylorza 9:34008d8b1cdf 63 {
taylorza 9:34008d8b1cdf 64 wait_us(1);
taylorza 9:34008d8b1cdf 65 }
taylorza 9:34008d8b1cdf 66 }
taylorza 9:34008d8b1cdf 67 }
taylorza 9:34008d8b1cdf 68
taylorza 9:34008d8b1cdf 69 void Game::die()
taylorza 9:34008d8b1cdf 70 {
taylorza 9:34008d8b1cdf 71 if (_lives > 1)
taylorza 9:34008d8b1cdf 72 {
taylorza 9:34008d8b1cdf 73 --_lives;
taylorza 9:34008d8b1cdf 74 if (_pScene != NULL) _pScene->restartScreen();
taylorza 9:34008d8b1cdf 75 }
taylorza 9:34008d8b1cdf 76 else
taylorza 9:34008d8b1cdf 77 {
taylorza 9:34008d8b1cdf 78 _lives = 0;
taylorza 9:34008d8b1cdf 79 }
taylorza 9:34008d8b1cdf 80 }
taylorza 9:34008d8b1cdf 81
taylorza 9:34008d8b1cdf 82 void Game::update()
taylorza 9:34008d8b1cdf 83 {
taylorza 9:34008d8b1cdf 84 if (_pScene != NULL) _pScene->update();
taylorza 9:34008d8b1cdf 85 }
taylorza 9:34008d8b1cdf 86
taylorza 9:34008d8b1cdf 87 void Game::draw()
taylorza 9:34008d8b1cdf 88 {
taylorza 9:34008d8b1cdf 89 if (_pScene != NULL) _pScene->draw();
taylorza 9:34008d8b1cdf 90 }
taylorza 9:34008d8b1cdf 91
taylorza 9:34008d8b1cdf 92
taylorza 9:34008d8b1cdf 93
taylorza 9:34008d8b1cdf 94