Race around the city collecting the flags while avoiding those that stand in the way of your mission. Make no mistake you will need to be quick to outwit your opponents, they are smart and will try to box you in. I wrote this game to prove that writing a game with scrolling scenery is possible even with the limited 6kB of RAM available. I had to compromise sound effects for features, I wanted multiple opponents, I wanted to be able to drop smoke bombs to trap the opponents but all this required memory so the sound effects had to take a back seat.
GameScreen.h
- Committer:
- taylorza
- Date:
- 2015-01-28
- Revision:
- 0:d85c449aca6d
- Child:
- 1:1b8125937f28
File content as of revision 0:d85c449aca6d:
#include "Constants.h" #include "GameEngine.h" #include "Map.h" #include "Assets.h" #include "Flag.h" #include "Enemy.h" #include "Player.h" #ifndef __GAMESCREEN_H__ #define __GAMESCREEN_H__ class GameScreen; GameScreen* GameScreenInstance; class GameScreen : public TileViewer { public: GameScreen() : TileViewer(13, 16), _player(Point(184, 400)), _enemy1(Point(64, 464), Point(16, -32), Point(8, 8), _player), _enemy2(Point(88, 464), Point(1024, -32), Point(32, 32), _player), _enemy3(Point(112, 464), Point(16, 1024), Point(-32, -32), _player), _radarBitmap(48, 64), _radarCanvas(&_radarBitmap), _updateCounter(0) { Game::Surface.setForegroundColor(Color565::White); Game::Surface.setBackgroundColor(HUD_BACKGROUND); setMap(map, 48, 64, blocks, sprites); _radarCanvas.clear(); _cars[0] = &_player; _cars[1] = &_enemy1; _cars[2] = &_enemy2; _cars[3] = &_enemy3; for(int i = 0; i < MAX_FLAGS; ++i) { int x = 0; int y = 0; for(;;) { x = rand() % getMapTilesX(); y = rand() % getMapTilesY(); const Block &block1 = getBlock(x * 8, y * 8); if (&block1 == &blocks[0]) break; } _flags[i].setPosition(Point(x * 8, y * 8)); addGameObject(&_flags[i]); } _player.setPosition(Point(64, 400)); _player.setCars(_cars); _player.setFlags(_flags); addGameObject(&_enemy1); addGameObject(&_enemy2); addGameObject(&_enemy3); addGameObject(&_player); track(&_player); } virtual void update() { if (_player.getLives() > 0) { TileViewer::update(); } else { // Game Over } } virtual void draw() { TileViewer::draw(); if (_updateCounter++ % 8 == 0) { Game::Surface.drawBitmap(108, 16, getRadarBitmap(), 0, 0, 48, 64); } //char buffer[10]; //sprintf(buffer, "%d", _player.getScore()); //Game::Surface.drawString(font_ibm, 108, 4, buffer); //sprintf(buffer, "%d", _player.getLives()); //Game::Surface.drawString(font_ibm, 108, 100, buffer); // Render fuel uint8_t limit = (uint8_t)(((float)_player.getFuel() / 100) * 48); //sprintf(buffer, "%d", limit); //Game::Surface.drawString(font_ibm, 108, 100, buffer); uint16_t fuelColor = limit < 15 ? Color565::Red : Color565::Yellow; Game::Surface.fillRect(108, 90, 108, 94, fuelColor, fuelColor); Game::Surface.fillRect(108, 84, 108 + limit, 90, fuelColor); Game::Surface.fillRect(108 + limit + 1, 84, 160, 90, HUD_BACKGROUND); } inline RallyCar** getCars() { return _cars; } Bitmap2bpp& getRadarBitmap() { _radarCanvas.clear(); for (int i = 0; i < MAX_FLAGS; ++i) { Flag &flag = _flags[i]; if (flag.getActive()) { _radarCanvas.setPixel(flag.getPosition().X / 8, flag.getPosition().Y / 8, 3); } } _radarCanvas.setPixel(_enemy1.getPosition().X / 8, _enemy1.getPosition().Y / 8, 2); _radarCanvas.setPixel(_enemy2.getPosition().X / 8, _enemy2.getPosition().Y / 8, 2); _radarCanvas.setPixel(_enemy3.getPosition().X / 8, _enemy3.getPosition().Y / 8, 2); _radarCanvas.setPixel(_player.getPosition().X / 8, _player.getPosition().Y / 8, 1); return _radarBitmap; } private: Player _player; Enemy _enemy1; Enemy _enemy2; Enemy _enemy3; RallyCar *_cars[MAX_CARS]; Flag _flags[MAX_FLAGS]; Bitmap2bpp _radarBitmap; Canvas<Bitmap2bpp> _radarCanvas; uint8_t _updateCounter; }; #endif //__GAMESCREEN_H__