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:
Sat Nov 29 08:36:45 2014 +0000
Revision:
1:ecf7bbccddc1
Parent:
0:2ee0812e2615
Child:
2:97d01ba6cd91
No with bouncing enemies

Who changed what in which revision?

UserRevisionLine numberNew contents of line
taylorza 0:2ee0812e2615 1 #include "GameEngine.h"
taylorza 0:2ee0812e2615 2 #include "SpriteSheet.h"
taylorza 0:2ee0812e2615 3 #include "Player.h"
taylorza 1:ecf7bbccddc1 4 #include "PatrollingEnemy.h"
taylorza 0:2ee0812e2615 5 #include "font_IBM.h"
taylorza 0:2ee0812e2615 6
taylorza 0:2ee0812e2615 7 // Block images
taylorza 0:2ee0812e2615 8 static const ImageFrame emptyBlock(bmp, 0, 0, 8, 8);
taylorza 1:ecf7bbccddc1 9 static const ImageFrame brickBlock(bmp, 0, 64, 8, 8);
taylorza 1:ecf7bbccddc1 10 static const ImageFrame meshFenceTopBlock(bmp, 8, 64, 8, 8);
taylorza 1:ecf7bbccddc1 11 static const ImageFrame meshFenceBlock(bmp, 16, 64, 8, 8);
taylorza 1:ecf7bbccddc1 12 static const ImageFrame platformBlock(bmp, 24, 64, 8, 8);
taylorza 1:ecf7bbccddc1 13 static const ImageFrame brickTrimBlock(bmp, 32, 64, 8, 8);
taylorza 0:2ee0812e2615 14
taylorza 0:2ee0812e2615 15 // Sprite images
taylorza 0:2ee0812e2615 16 static const ImageFrame playerWalk1(bmp, 0, 0, 16, 16);
taylorza 0:2ee0812e2615 17 static const ImageFrame playerWalk2(bmp, 16, 0, 16, 16);
taylorza 0:2ee0812e2615 18 static const ImageFrame playerWalk3(bmp, 32, 0, 16, 16);
taylorza 0:2ee0812e2615 19 static const ImageFrame playerWalk4(bmp, 48, 0, 16, 16);
taylorza 0:2ee0812e2615 20
taylorza 0:2ee0812e2615 21 static const ImageFrame angryBird1(bmp, 0, 16, 16, 16);
taylorza 0:2ee0812e2615 22 static const ImageFrame angryBird2(bmp, 16, 16, 16, 16);
taylorza 0:2ee0812e2615 23 static const ImageFrame angryBird3(bmp, 32, 16, 16, 16);
taylorza 0:2ee0812e2615 24 static const ImageFrame angryBird4(bmp, 48, 16, 16, 16);
taylorza 0:2ee0812e2615 25
taylorza 1:ecf7bbccddc1 26 static const ImageFrame mineCart1(bmp, 0, 32, 16, 16);
taylorza 1:ecf7bbccddc1 27 static const ImageFrame mineCart2(bmp, 16, 32, 16, 16);
taylorza 1:ecf7bbccddc1 28 static const ImageFrame mineCart3(bmp, 32, 32, 16, 16);
taylorza 1:ecf7bbccddc1 29 static const ImageFrame mineCart4(bmp, 48, 32, 16, 16);
taylorza 1:ecf7bbccddc1 30
taylorza 1:ecf7bbccddc1 31 static const ImageFrame bubble1(bmp, 0, 48, 16, 16);
taylorza 1:ecf7bbccddc1 32
taylorza 0:2ee0812e2615 33 // Blocks
taylorza 0:2ee0812e2615 34 const Block blocks[] =
taylorza 0:2ee0812e2615 35 {
taylorza 0:2ee0812e2615 36 Block(&emptyBlock, Block::Background, 0, 0), // 0 - Empty block
taylorza 0:2ee0812e2615 37 Block(&brickBlock, Block::Solid, 2, 0), // 1 - Brick - Red on black
taylorza 0:2ee0812e2615 38 Block(&meshFenceTopBlock, Block::Background, 1, 0), // 2 - Mesh fence top - Blue on black
taylorza 0:2ee0812e2615 39 Block(&meshFenceBlock, Block::Background, 1, 0), // 3 - Mesh fence - Blue on black
taylorza 0:2ee0812e2615 40 Block(&platformBlock, Block::Platform, 5, 0), // 4 - Platform - Cyan on black
taylorza 0:2ee0812e2615 41 Block(&brickTrimBlock, Block::Background, 2, 0), // 5 - Brick trim - Red on black
taylorza 0:2ee0812e2615 42 };
taylorza 0:2ee0812e2615 43
taylorza 0:2ee0812e2615 44 // Sprite animation sequences
taylorza 0:2ee0812e2615 45 const ImageFrame *playerWalking[] = { &playerWalk1, &playerWalk2, &playerWalk3, &playerWalk4, NULL };
taylorza 0:2ee0812e2615 46 const ImageFrame *angryBird[] = { &angryBird1, &angryBird2, &angryBird3, &angryBird4, NULL };
taylorza 1:ecf7bbccddc1 47 const ImageFrame *mineCart[] = { &mineCart1, &mineCart2, &mineCart3, &mineCart4, NULL };
taylorza 1:ecf7bbccddc1 48 const ImageFrame *bubble[] = { &bubble1, NULL };
taylorza 0:2ee0812e2615 49
taylorza 0:2ee0812e2615 50 // Sprites
taylorza 0:2ee0812e2615 51 Sprite sprites[] =
taylorza 0:2ee0812e2615 52 {
taylorza 0:2ee0812e2615 53 Sprite(playerWalking, 7), // 0 - Player walking
taylorza 1:ecf7bbccddc1 54 Sprite(angryBird, 6), // 1 - Angry bird
taylorza 1:ecf7bbccddc1 55 Sprite(mineCart, 6), // 2 - Mine cart
taylorza 1:ecf7bbccddc1 56 Sprite(bubble, 1) // 3 - Bubble
taylorza 0:2ee0812e2615 57 };
taylorza 0:2ee0812e2615 58
taylorza 0:2ee0812e2615 59 static const uint8_t map[] = {
taylorza 0:2ee0812e2615 60 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
taylorza 0:2ee0812e2615 61 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
taylorza 0:2ee0812e2615 62 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
taylorza 0:2ee0812e2615 63 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
taylorza 0:2ee0812e2615 64 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
taylorza 0:2ee0812e2615 65 1,4,4,0,1,1,1,1,0,0,0,1,1,0,0,1,1,0,0,1,
taylorza 0:2ee0812e2615 66 1,0,0,0,5,1,1,1,0,0,0,1,1,2,2,1,1,0,0,1,
taylorza 0:2ee0812e2615 67 1,4,4,0,0,0,5,1,0,0,0,1,1,3,3,1,1,0,0,1,
taylorza 0:2ee0812e2615 68 1,0,0,0,0,0,0,0,0,0,0,5,1,1,1,1,5,0,0,1,
taylorza 0:2ee0812e2615 69 1,4,4,0,0,0,0,0,0,0,0,0,5,5,5,5,0,0,0,1,
taylorza 0:2ee0812e2615 70 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
taylorza 0:2ee0812e2615 71 1,1,1,1,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
taylorza 0:2ee0812e2615 72 1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,5,1,1,1,1,
taylorza 1:ecf7bbccddc1 73 1,1,1,1,4,4,0,0,0,0,0,0,0,0,0,0,0,5,1,1,
taylorza 0:2ee0812e2615 74 1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,
taylorza 0:2ee0812e2615 75 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
taylorza 0:2ee0812e2615 76 };
taylorza 0:2ee0812e2615 77
taylorza 1:ecf7bbccddc1 78 class BouncingEnemy : public GameObject
taylorza 0:2ee0812e2615 79 {
taylorza 0:2ee0812e2615 80 public:
taylorza 1:ecf7bbccddc1 81 BouncingEnemy(Game &game, uint8_t spriteId) :
taylorza 1:ecf7bbccddc1 82 GameObject(game),
taylorza 1:ecf7bbccddc1 83 _dx(1),
taylorza 1:ecf7bbccddc1 84 _dy(1)
taylorza 0:2ee0812e2615 85 {
taylorza 1:ecf7bbccddc1 86 setSpriteId(spriteId);
taylorza 0:2ee0812e2615 87 }
taylorza 0:2ee0812e2615 88
taylorza 0:2ee0812e2615 89 virtual void update()
taylorza 0:2ee0812e2615 90 {
taylorza 1:ecf7bbccddc1 91 if (_dx > 0)
taylorza 0:2ee0812e2615 92 {
taylorza 1:ecf7bbccddc1 93 if (!moveRight()) _dx = -1;
taylorza 1:ecf7bbccddc1 94 }
taylorza 1:ecf7bbccddc1 95 else if (_dx < 0)
taylorza 1:ecf7bbccddc1 96 {
taylorza 1:ecf7bbccddc1 97 if (!moveLeft()) _dx = 1;
taylorza 0:2ee0812e2615 98 }
taylorza 1:ecf7bbccddc1 99
taylorza 1:ecf7bbccddc1 100 if (_dy > 0)
taylorza 0:2ee0812e2615 101 {
taylorza 1:ecf7bbccddc1 102 if (!moveDown()) _dy = -1;
taylorza 0:2ee0812e2615 103 }
taylorza 1:ecf7bbccddc1 104 else if (_dy < 0)
taylorza 1:ecf7bbccddc1 105 {
taylorza 1:ecf7bbccddc1 106 if (!moveUp()) _dy = 1;
taylorza 1:ecf7bbccddc1 107 }
taylorza 1:ecf7bbccddc1 108
taylorza 0:2ee0812e2615 109 animate();
taylorza 0:2ee0812e2615 110 }
taylorza 0:2ee0812e2615 111
taylorza 1:ecf7bbccddc1 112 private:
taylorza 1:ecf7bbccddc1 113 int8_t _dx;
taylorza 1:ecf7bbccddc1 114 int8_t _dy;
taylorza 0:2ee0812e2615 115 };
taylorza 0:2ee0812e2615 116
taylorza 0:2ee0812e2615 117 class MyGame : public Game
taylorza 0:2ee0812e2615 118 {
taylorza 0:2ee0812e2615 119 public:
taylorza 0:2ee0812e2615 120 MyGame() :
taylorza 0:2ee0812e2615 121 _player(*this),
taylorza 1:ecf7bbccddc1 122 _enemy1(*this, 1, PatrollingEnemy::UpDown),
taylorza 1:ecf7bbccddc1 123 _enemy2(*this, 2, PatrollingEnemy::LeftRight),
taylorza 1:ecf7bbccddc1 124 _enemy3(*this, 3)
taylorza 0:2ee0812e2615 125 {
taylorza 0:2ee0812e2615 126 _player.setStartPosition(100, 96);
taylorza 0:2ee0812e2615 127 _enemy1.setStartPosition(104, 16);
taylorza 1:ecf7bbccddc1 128 _enemy2.setStartPosition(48, 24);
taylorza 1:ecf7bbccddc1 129 _enemy3.setStartPosition(80, 96);
taylorza 0:2ee0812e2615 130 setMap(map, 20, 16, blocks, sprites);
taylorza 0:2ee0812e2615 131 }
taylorza 0:2ee0812e2615 132
taylorza 0:2ee0812e2615 133 private:
taylorza 0:2ee0812e2615 134 Player _player;
taylorza 0:2ee0812e2615 135 PatrollingEnemy _enemy1;
taylorza 1:ecf7bbccddc1 136 PatrollingEnemy _enemy2;
taylorza 1:ecf7bbccddc1 137 BouncingEnemy _enemy3;
taylorza 0:2ee0812e2615 138
taylorza 0:2ee0812e2615 139 protected:
taylorza 0:2ee0812e2615 140 virtual void update(float elapsedTime)
taylorza 0:2ee0812e2615 141 {
taylorza 0:2ee0812e2615 142 _player.update();
taylorza 0:2ee0812e2615 143 _enemy1.update();
taylorza 1:ecf7bbccddc1 144 _enemy2.update();
taylorza 1:ecf7bbccddc1 145 _enemy3.update();
taylorza 0:2ee0812e2615 146 wait_ms(32);
taylorza 0:2ee0812e2615 147 }
taylorza 0:2ee0812e2615 148
taylorza 0:2ee0812e2615 149 virtual void draw(float elapsedTime)
taylorza 0:2ee0812e2615 150 {
taylorza 0:2ee0812e2615 151 _player.draw();
taylorza 0:2ee0812e2615 152 _enemy1.draw();
taylorza 1:ecf7bbccddc1 153 _enemy2.draw();
taylorza 1:ecf7bbccddc1 154 _enemy3.draw();
taylorza 0:2ee0812e2615 155 }
taylorza 0:2ee0812e2615 156 };
taylorza 0:2ee0812e2615 157
taylorza 0:2ee0812e2615 158 int main()
taylorza 0:2ee0812e2615 159 {
taylorza 0:2ee0812e2615 160 DigitalOut led1(P0_9);
taylorza 0:2ee0812e2615 161 led1 = 1;
taylorza 0:2ee0812e2615 162
taylorza 0:2ee0812e2615 163 MyGame game;
taylorza 0:2ee0812e2615 164 game.run();
taylorza 0:2ee0812e2615 165 }
taylorza 0:2ee0812e2615 166 /*
taylorza 0:2ee0812e2615 167 void draw(Block &block, int x, int y)
taylorza 0:2ee0812e2615 168 {
taylorza 0:2ee0812e2615 169 uint8_t fc = block.getForegroundColor();
taylorza 0:2ee0812e2615 170 uint8_t fch = (fc << 4) & 0xf0;
taylorza 0:2ee0812e2615 171 uint8_t fcl = fc & 0x0f;
taylorza 0:2ee0812e2615 172
taylorza 0:2ee0812e2615 173 uint8_t bc = block.getBackgroundColor();
taylorza 0:2ee0812e2615 174 uint8_t bch = (bc << 4) & 0xf0;
taylorza 0:2ee0812e2615 175 uint8_t bcl = bc & 0x0f;
taylorza 0:2ee0812e2615 176
taylorza 0:2ee0812e2615 177 uint8_t *bitmap = _bmp8x8.getBitmapData();
taylorza 0:2ee0812e2615 178 int offset = 0;
taylorza 0:2ee0812e2615 179 for (int iy = 0; iy < 8; ++iy)
taylorza 0:2ee0812e2615 180 {
taylorza 0:2ee0812e2615 181 uint8_t b = *block.getBits(iy);
taylorza 0:2ee0812e2615 182 bitmap[offset] = b & 0x80 ? ((bitmap[offset] & 0x0f) | fch) : ((bitmap[offset] & 0x0f) | bch);
taylorza 0:2ee0812e2615 183 bitmap[offset] = b & 0x40 ? ((bitmap[offset] & 0xf0) | fcl) : ((bitmap[offset] & 0xf0) | bcl);
taylorza 0:2ee0812e2615 184 ++offset;
taylorza 0:2ee0812e2615 185
taylorza 0:2ee0812e2615 186 bitmap[offset] = b & 0x20 ? ((bitmap[offset] & 0x0f) | fch) : ((bitmap[offset] & 0x0f) | bch);
taylorza 0:2ee0812e2615 187 bitmap[offset] = b & 0x10 ? ((bitmap[offset] & 0xf0) | fcl) : ((bitmap[offset] & 0xf0) | bcl);
taylorza 0:2ee0812e2615 188 ++offset;
taylorza 0:2ee0812e2615 189
taylorza 0:2ee0812e2615 190 bitmap[offset] = b & 0x08 ? ((bitmap[offset] & 0x0f) | fch) : ((bitmap[offset] & 0x0f) | bch);
taylorza 0:2ee0812e2615 191 bitmap[offset] = b & 0x04 ? ((bitmap[offset] & 0xf0) | fcl) : ((bitmap[offset] & 0xf0) | bcl);
taylorza 0:2ee0812e2615 192 ++offset;
taylorza 0:2ee0812e2615 193
taylorza 0:2ee0812e2615 194 bitmap[offset] = b & 0x02 ? ((bitmap[offset] & 0x0f) | fch) : ((bitmap[offset] & 0x0f) | bch);
taylorza 0:2ee0812e2615 195 bitmap[offset] = b & 0x01 ? ((bitmap[offset] & 0xf0) | fcl) : ((bitmap[offset] & 0xf0) | bcl);
taylorza 0:2ee0812e2615 196 ++offset;
taylorza 0:2ee0812e2615 197 }
taylorza 0:2ee0812e2615 198 lcd.drawBitmap(x, y, _bmp8x8, 0, 0, 8, 8);
taylorza 0:2ee0812e2615 199 }
taylorza 0:2ee0812e2615 200
taylorza 0:2ee0812e2615 201 void compose(Block &block, int x, int y)
taylorza 0:2ee0812e2615 202 {
taylorza 0:2ee0812e2615 203 uint8_t *bitmap = _composedBitmap.getBitmapData();
taylorza 0:2ee0812e2615 204 int offsetRow = (y * _composedBitmap.getStride()) + (x >> 1);
taylorza 0:2ee0812e2615 205
taylorza 0:2ee0812e2615 206 uint8_t fc = block.getForegroundColor();
taylorza 0:2ee0812e2615 207 uint8_t fch = (fc << 4) & 0xf0;
taylorza 0:2ee0812e2615 208 uint8_t fcl = fc & 0x0f;
taylorza 0:2ee0812e2615 209
taylorza 0:2ee0812e2615 210 uint8_t bc = block.getBackgroundColor();
taylorza 0:2ee0812e2615 211 uint8_t bch = (bc << 4) & 0xf0;
taylorza 0:2ee0812e2615 212 uint8_t bcl = bc & 0x0f;
taylorza 0:2ee0812e2615 213
taylorza 0:2ee0812e2615 214 for (int iy = 0; iy < 8; ++iy, offsetRow += _composedBitmap.getStride())
taylorza 0:2ee0812e2615 215 {
taylorza 0:2ee0812e2615 216 int offset = offsetRow;
taylorza 0:2ee0812e2615 217 uint8_t b = *block.getBits(iy);
taylorza 0:2ee0812e2615 218 bool highNibble = ((x & 0x01) == 0);
taylorza 0:2ee0812e2615 219 for(int c = 0; c < 8; ++c, b <<= 1)
taylorza 0:2ee0812e2615 220 {
taylorza 0:2ee0812e2615 221 if (b & 0x80)
taylorza 0:2ee0812e2615 222 {
taylorza 0:2ee0812e2615 223 if (highNibble) bitmap[offset] = ((bitmap[offset] & 0x0f) | fch);
taylorza 0:2ee0812e2615 224 else
taylorza 0:2ee0812e2615 225 {
taylorza 0:2ee0812e2615 226 bitmap[offset] = ((bitmap[offset] & 0xf0) | fcl);
taylorza 0:2ee0812e2615 227 ++offset;
taylorza 0:2ee0812e2615 228 }
taylorza 0:2ee0812e2615 229 }
taylorza 0:2ee0812e2615 230 else
taylorza 0:2ee0812e2615 231 {
taylorza 0:2ee0812e2615 232 if (highNibble) bitmap[offset] = ((bitmap[offset] & 0x0f) | bch);
taylorza 0:2ee0812e2615 233 else
taylorza 0:2ee0812e2615 234 {
taylorza 0:2ee0812e2615 235 bitmap[offset] = ((bitmap[offset] & 0xf0) | bcl);
taylorza 0:2ee0812e2615 236 ++offset;
taylorza 0:2ee0812e2615 237 }
taylorza 0:2ee0812e2615 238 }
taylorza 0:2ee0812e2615 239 highNibble = !highNibble;
taylorza 0:2ee0812e2615 240 }
taylorza 0:2ee0812e2615 241 }
taylorza 0:2ee0812e2615 242 }
taylorza 0:2ee0812e2615 243
taylorza 0:2ee0812e2615 244
taylorza 0:2ee0812e2615 245 void compose(Sprite &sprite, int x, int y, bool flip)
taylorza 0:2ee0812e2615 246 {
taylorza 0:2ee0812e2615 247 uint8_t *bitmap = _composedBitmap.getBitmapData();
taylorza 0:2ee0812e2615 248
taylorza 0:2ee0812e2615 249 int offsetRow = (y * _composedBitmap.getStride()) + (x >> 1);
taylorza 0:2ee0812e2615 250
taylorza 0:2ee0812e2615 251 uint8_t fc = sprite.getForegroundColor();
taylorza 0:2ee0812e2615 252 uint8_t fch = (fc << 4) & 0xf0;
taylorza 0:2ee0812e2615 253 uint8_t fcl = fc & 0x0f;
taylorza 0:2ee0812e2615 254
taylorza 0:2ee0812e2615 255 if (!flip)
taylorza 0:2ee0812e2615 256 {
taylorza 0:2ee0812e2615 257 for (int iy = 0; iy < 16; ++iy, offsetRow += _composedBitmap.getStride())
taylorza 0:2ee0812e2615 258 {
taylorza 0:2ee0812e2615 259 int offset = offsetRow;
taylorza 0:2ee0812e2615 260 uint8_t *p = sprite.getBits(iy);
taylorza 0:2ee0812e2615 261 bool highNibble = ((x & 0x01) == 0);
taylorza 0:2ee0812e2615 262 for (int ix = 0; ix < 2; ++ix)
taylorza 0:2ee0812e2615 263 {
taylorza 0:2ee0812e2615 264 uint8_t b = *p++;
taylorza 0:2ee0812e2615 265 for(int c = 0; c < 8; ++c, b <<= 1)
taylorza 0:2ee0812e2615 266 {
taylorza 0:2ee0812e2615 267 if (b & 0x80)
taylorza 0:2ee0812e2615 268 {
taylorza 0:2ee0812e2615 269 if (highNibble) bitmap[offset] = ((bitmap[offset] & 0x0f) | fch);
taylorza 0:2ee0812e2615 270 else
taylorza 0:2ee0812e2615 271 {
taylorza 0:2ee0812e2615 272 bitmap[offset] = ((bitmap[offset] & 0xf0) | fcl);
taylorza 0:2ee0812e2615 273 offset++;
taylorza 0:2ee0812e2615 274 }
taylorza 0:2ee0812e2615 275 }
taylorza 0:2ee0812e2615 276 else if (!highNibble)
taylorza 0:2ee0812e2615 277 {
taylorza 0:2ee0812e2615 278 offset++;
taylorza 0:2ee0812e2615 279 }
taylorza 0:2ee0812e2615 280 highNibble = !highNibble;
taylorza 0:2ee0812e2615 281 }
taylorza 0:2ee0812e2615 282 }
taylorza 0:2ee0812e2615 283 }
taylorza 0:2ee0812e2615 284 }
taylorza 0:2ee0812e2615 285 else
taylorza 0:2ee0812e2615 286 {
taylorza 0:2ee0812e2615 287 for (int iy = 0; iy < 16; ++iy, offsetRow += _composedBitmap.getStride())
taylorza 0:2ee0812e2615 288 {
taylorza 0:2ee0812e2615 289 int offset = offsetRow;
taylorza 0:2ee0812e2615 290 uint8_t *p = sprite.getBits(iy) + 1;
taylorza 0:2ee0812e2615 291 bool highNibble = ((x & 0x01) == 0);
taylorza 0:2ee0812e2615 292 for (int ix = 0; ix < 2; ++ix)
taylorza 0:2ee0812e2615 293 {
taylorza 0:2ee0812e2615 294 uint8_t b = *p--;
taylorza 0:2ee0812e2615 295 for(int c = 0; c < 8; ++c, b >>= 1)
taylorza 0:2ee0812e2615 296 {
taylorza 0:2ee0812e2615 297 if (b & 0x01)
taylorza 0:2ee0812e2615 298 {
taylorza 0:2ee0812e2615 299 if (highNibble) bitmap[offset] = ((bitmap[offset] & 0x0f) | fch);
taylorza 0:2ee0812e2615 300 else
taylorza 0:2ee0812e2615 301 {
taylorza 0:2ee0812e2615 302 bitmap[offset] = ((bitmap[offset] & 0xf0) | fcl);
taylorza 0:2ee0812e2615 303 offset++;
taylorza 0:2ee0812e2615 304 }
taylorza 0:2ee0812e2615 305 }
taylorza 0:2ee0812e2615 306 else if (!highNibble)
taylorza 0:2ee0812e2615 307 {
taylorza 0:2ee0812e2615 308 offset++;
taylorza 0:2ee0812e2615 309 }
taylorza 0:2ee0812e2615 310 highNibble = !highNibble;
taylorza 0:2ee0812e2615 311 }
taylorza 0:2ee0812e2615 312 }
taylorza 0:2ee0812e2615 313 }
taylorza 0:2ee0812e2615 314 }
taylorza 0:2ee0812e2615 315 }
taylorza 0:2ee0812e2615 316
taylorza 0:2ee0812e2615 317 void drawScreen(uint8_t *screen)
taylorza 0:2ee0812e2615 318 {
taylorza 0:2ee0812e2615 319 int yOffset = 0;
taylorza 0:2ee0812e2615 320 for(int y = 0; y < 16; ++y, yOffset += 20)
taylorza 0:2ee0812e2615 321 {
taylorza 0:2ee0812e2615 322 for (int x = 0; x < 20; ++x)
taylorza 0:2ee0812e2615 323 {
taylorza 0:2ee0812e2615 324 uint8_t blockId = screen[yOffset + x];
taylorza 0:2ee0812e2615 325 if (blockId != 0)
taylorza 0:2ee0812e2615 326 {
taylorza 0:2ee0812e2615 327 Block &block = blocks[blockId];
taylorza 0:2ee0812e2615 328 draw(block, x * 8, y * 8);
taylorza 0:2ee0812e2615 329 }
taylorza 0:2ee0812e2615 330 }
taylorza 0:2ee0812e2615 331 }
taylorza 0:2ee0812e2615 332 }
taylorza 0:2ee0812e2615 333
taylorza 0:2ee0812e2615 334 void drawSprite(uint8_t *screen, Sprite &sprite, int x, int y, int dx, int dy, bool flip)
taylorza 0:2ee0812e2615 335 {
taylorza 0:2ee0812e2615 336 int cellX = x / 8;
taylorza 0:2ee0812e2615 337 int cellY = y / 8;
taylorza 0:2ee0812e2615 338 int rx = x % 8;
taylorza 0:2ee0812e2615 339 int ry = y % 8;
taylorza 0:2ee0812e2615 340
taylorza 0:2ee0812e2615 341 if (rx == 0 && dx == 1 && cellX > 0) { --cellX; rx += 8; }
taylorza 0:2ee0812e2615 342 if (ry == 0 && dy == 1 && cellY > 0) { --cellY; ry += 8; }
taylorza 0:2ee0812e2615 343
taylorza 0:2ee0812e2615 344 _composedBitmap.clear();
taylorza 0:2ee0812e2615 345 // Compose blocks
taylorza 0:2ee0812e2615 346 for (int cy = 0; cy < 3; ++cy)
taylorza 0:2ee0812e2615 347 {
taylorza 0:2ee0812e2615 348 int yOffset = (cellY + cy) * 20;
taylorza 0:2ee0812e2615 349 for (int cx = 0; cx < 3; ++cx)
taylorza 0:2ee0812e2615 350 {
taylorza 0:2ee0812e2615 351 uint8_t blockId = screen[yOffset + cellX + cx];
taylorza 0:2ee0812e2615 352 if (blockId != 0)
taylorza 0:2ee0812e2615 353 {
taylorza 0:2ee0812e2615 354 Block &block = blocks[blockId];
taylorza 0:2ee0812e2615 355 compose(block, cx * 8, cy * 8);
taylorza 0:2ee0812e2615 356 }
taylorza 0:2ee0812e2615 357 }
taylorza 0:2ee0812e2615 358 }
taylorza 0:2ee0812e2615 359
taylorza 0:2ee0812e2615 360 // Compose sprite
taylorza 0:2ee0812e2615 361 compose(sprite, rx, ry, flip);
taylorza 0:2ee0812e2615 362
taylorza 0:2ee0812e2615 363 // Render the composed image
taylorza 0:2ee0812e2615 364 lcd.drawBitmap(cellX * 8, cellY * 8, _composedBitmap, 0, 0, 24, 24);
taylorza 0:2ee0812e2615 365 }
taylorza 0:2ee0812e2615 366
taylorza 0:2ee0812e2615 367 int main()
taylorza 0:2ee0812e2615 368 {
taylorza 0:2ee0812e2615 369 DigitalOut led1(P0_9);
taylorza 0:2ee0812e2615 370 led1 = 1;
taylorza 0:2ee0812e2615 371
taylorza 0:2ee0812e2615 372 lcd.setOrientation(LCD_ST7735::Rotate270, false);
taylorza 0:2ee0812e2615 373
taylorza 0:2ee0812e2615 374 drawScreen(screen0);
taylorza 0:2ee0812e2615 375
taylorza 0:2ee0812e2615 376 int px = 80;
taylorza 0:2ee0812e2615 377 int py = 15;
taylorza 0:2ee0812e2615 378 int dx = 0;
taylorza 0:2ee0812e2615 379 int dy = 0;
taylorza 0:2ee0812e2615 380 bool flip = false;
taylorza 0:2ee0812e2615 381 char buffer[50];
taylorza 0:2ee0812e2615 382 while (true)
taylorza 0:2ee0812e2615 383 {
taylorza 0:2ee0812e2615 384 if (GameInput::isLeftPressed() && px > 8) { dx = -1; px--; flip = false; wait_ms(16); sprites[0].animate(); }
taylorza 0:2ee0812e2615 385 if (GameInput::isRightPressed() && px < 136) { dx = 1; px++; flip = true; wait_ms(16); sprites[0].animate();}
taylorza 0:2ee0812e2615 386 if (GameInput::isUpPressed() && py > 8) { dy = -1; py--; wait_ms(16); sprites[0].animate();}
taylorza 0:2ee0812e2615 387 if (GameInput::isDownPressed() && py < 104) { dy = 1; py++; wait_ms(16); sprites[0].animate();}
taylorza 0:2ee0812e2615 388
taylorza 0:2ee0812e2615 389 drawSprite(screen0, sprites[0], px, py, dx, dy, flip);
taylorza 0:2ee0812e2615 390 drawSprite(screen0, sprites[0], 50, 50, 0, 0, flip);
taylorza 0:2ee0812e2615 391
taylorza 0:2ee0812e2615 392 sprintf(buffer, "%d, %d ", px, py);
taylorza 0:2ee0812e2615 393 lcd.drawString(font_ibm, 0, 0, buffer);
taylorza 0:2ee0812e2615 394 }
taylorza 0:2ee0812e2615 395 */
taylorza 0:2ee0812e2615 396 /*
taylorza 0:2ee0812e2615 397 lcd.drawCircle(50, 50, 35, Color565::Red);
taylorza 0:2ee0812e2615 398 char buffer[100];
taylorza 0:2ee0812e2615 399 Timer timer;
taylorza 0:2ee0812e2615 400 timer.start();
taylorza 0:2ee0812e2615 401 while(true)
taylorza 0:2ee0812e2615 402 {
taylorza 0:2ee0812e2615 403 timer.reset();
taylorza 0:2ee0812e2615 404 for (int sy = 0; sy < 5; sy++)
taylorza 0:2ee0812e2615 405 {
taylorza 0:2ee0812e2615 406 for (int sx = 0; sx < 6; sx++)
taylorza 0:2ee0812e2615 407 {
taylorza 0:2ee0812e2615 408 for (int y = 0; y < 3; y++)
taylorza 0:2ee0812e2615 409 {
taylorza 0:2ee0812e2615 410 for (int x = 0; x < 3; x++)
taylorza 0:2ee0812e2615 411 {
taylorza 0:2ee0812e2615 412 draw(blocks[0], x * 8, y * 8);
taylorza 0:2ee0812e2615 413 }
taylorza 0:2ee0812e2615 414 }
taylorza 0:2ee0812e2615 415
taylorza 0:2ee0812e2615 416 draw(sprite, 5, 5, false);
taylorza 0:2ee0812e2615 417 lcd.drawBitmap(8 + (sx * 24), (sy * 24), _composedBitmap, 0, 0, 24, 24);
taylorza 0:2ee0812e2615 418 }
taylorza 0:2ee0812e2615 419 }
taylorza 0:2ee0812e2615 420 sprite.animate();
taylorza 0:2ee0812e2615 421 float seconds = timer.read_ms();
taylorza 0:2ee0812e2615 422 sprintf(buffer, "%f", seconds);
taylorza 0:2ee0812e2615 423 lcd.drawString(font_ibm, 0, 120, buffer);
taylorza 0:2ee0812e2615 424 //wait_ms(250);
taylorza 0:2ee0812e2615 425 }
taylorza 0:2ee0812e2615 426
taylorza 0:2ee0812e2615 427 */
taylorza 0:2ee0812e2615 428
taylorza 0:2ee0812e2615 429 /*
taylorza 0:2ee0812e2615 430 Bitmap4bpp image(8, 8);
taylorza 0:2ee0812e2615 431
taylorza 0:2ee0812e2615 432 int x = 5;
taylorza 0:2ee0812e2615 433 int y = 5;
taylorza 0:2ee0812e2615 434 int dx = 1;
taylorza 0:2ee0812e2615 435 int dy = 1;
taylorza 0:2ee0812e2615 436 while (true)
taylorza 0:2ee0812e2615 437 {
taylorza 0:2ee0812e2615 438 lcd.drawBitmap(x, y, image, 0, 0, 8, 8);
taylorza 0:2ee0812e2615 439 lcd.drawBitmap(x, y + 12, image, 1, 0, 7, 8);
taylorza 0:2ee0812e2615 440 lcd.drawBitmap(x, y + 24, image, 0, 0, 7, 8);
taylorza 0:2ee0812e2615 441 lcd.drawBitmap(x, y + 36, image, 1, 0, 6, 8);
taylorza 0:2ee0812e2615 442
taylorza 0:2ee0812e2615 443 if (x > 151) dx = -1; else if (x < 1) dx = 1;
taylorza 0:2ee0812e2615 444 if (y > 83) dy = -1; else if (y < 1) dy = 1;
taylorza 0:2ee0812e2615 445 x += dx;
taylorza 0:2ee0812e2615 446 y += dy;
taylorza 0:2ee0812e2615 447 }
taylorza 0:2ee0812e2615 448 */
taylorza 0:2ee0812e2615 449
taylorza 0:2ee0812e2615 450 /*
taylorza 0:2ee0812e2615 451 _composedBitmap[0] = 24;
taylorza 0:2ee0812e2615 452 _composedBitmap[1] = 24;
taylorza 0:2ee0812e2615 453 for (int i = 0; i < 24*24; ++i)
taylorza 0:2ee0812e2615 454 {
taylorza 0:2ee0812e2615 455 _composedBitmap[2+i] = Color565::Green;
taylorza 0:2ee0812e2615 456 }
taylorza 0:2ee0812e2615 457
taylorza 0:2ee0812e2615 458 SpaceGame game;
taylorza 0:2ee0812e2615 459
taylorza 0:2ee0812e2615 460 draw(blocks[0], 0, 0);
taylorza 0:2ee0812e2615 461 draw(blocks[0], 8, 0);
taylorza 0:2ee0812e2615 462 draw(blocks[0], 16, 0);
taylorza 0:2ee0812e2615 463
taylorza 0:2ee0812e2615 464 draw(blocks[0], 0, 8);
taylorza 0:2ee0812e2615 465 draw(blocks[0], 8, 8);
taylorza 0:2ee0812e2615 466 draw(blocks[0], 16, 8);
taylorza 0:2ee0812e2615 467
taylorza 0:2ee0812e2615 468 draw(blocks[0], 0, 16);
taylorza 0:2ee0812e2615 469 draw(blocks[0], 8, 16);
taylorza 0:2ee0812e2615 470 draw(blocks[0], 16, 16);
taylorza 0:2ee0812e2615 471
taylorza 0:2ee0812e2615 472 draw(sprite, 0, 0);
taylorza 0:2ee0812e2615 473
taylorza 0:2ee0812e2615 474 Game::Screen.drawCircle(50, 50, 25, Color565::Blue);
taylorza 0:2ee0812e2615 475 Game::Screen.drawBitmap(50, 50, (const uint16_t*)_composedBitmap);
taylorza 0:2ee0812e2615 476
taylorza 0:2ee0812e2615 477 game.run();
taylorza 0:2ee0812e2615 478
taylorza 0:2ee0812e2615 479 while(true){}
taylorza 0:2ee0812e2615 480 }
taylorza 0:2ee0812e2615 481 */
taylorza 0:2ee0812e2615 482
taylorza 0:2ee0812e2615 483 /*
taylorza 0:2ee0812e2615 484 #include "Color565.h"
taylorza 0:2ee0812e2615 485 #include "font_IBM.h"
taylorza 0:2ee0812e2615 486 #include "SpriteSheet.h"
taylorza 0:2ee0812e2615 487
taylorza 0:2ee0812e2615 488 enum PlayerState
taylorza 0:2ee0812e2615 489 {
taylorza 0:2ee0812e2615 490 Stopped,
taylorza 0:2ee0812e2615 491 Walking,
taylorza 0:2ee0812e2615 492 Falling,
taylorza 0:2ee0812e2615 493 Flying,
taylorza 0:2ee0812e2615 494 };
taylorza 0:2ee0812e2615 495
taylorza 0:2ee0812e2615 496 void drawEnvironment(LCD_ST7735 lcd);
taylorza 0:2ee0812e2615 497 void drawPlatform(LCD_ST7735 lcd, int x, int y, int width, uint16_t color);
taylorza 0:2ee0812e2615 498
taylorza 0:2ee0812e2615 499 int main()
taylorza 0:2ee0812e2615 500 {
taylorza 0:2ee0812e2615 501 LCD_ST7735 lcd(
taylorza 0:2ee0812e2615 502 P0_19,
taylorza 0:2ee0812e2615 503 P0_4, // Reset
taylorza 0:2ee0812e2615 504 P0_5, // DS
taylorza 0:2ee0812e2615 505 P0_21,
taylorza 0:2ee0812e2615 506 P0_22,
taylorza 0:2ee0812e2615 507 P1_15,
taylorza 0:2ee0812e2615 508 P0_2, // CS
taylorza 0:2ee0812e2615 509 LCD_ST7735::RGB);
taylorza 0:2ee0812e2615 510
taylorza 0:2ee0812e2615 511 lcd.setOrientation(LCD_ST7735::Rotate270, false);
taylorza 0:2ee0812e2615 512 lcd.clearScreen();
taylorza 0:2ee0812e2615 513
taylorza 0:2ee0812e2615 514 DigitalOut led1(P0_9);
taylorza 0:2ee0812e2615 515 DigitalOut led2(P0_8);
taylorza 0:2ee0812e2615 516
taylorza 0:2ee0812e2615 517 DigitalIn up(P0_13, PullUp);
taylorza 0:2ee0812e2615 518 DigitalIn down(P0_12, PullUp);
taylorza 0:2ee0812e2615 519 DigitalIn left(P0_14, PullUp);
taylorza 0:2ee0812e2615 520 DigitalIn right(P0_11, PullUp);
taylorza 0:2ee0812e2615 521 DigitalIn square(P0_16, PullUp);
taylorza 0:2ee0812e2615 522 DigitalIn circle(P0_1, PullUp);
taylorza 0:2ee0812e2615 523
taylorza 0:2ee0812e2615 524 PwmOut sound(P0_18);
taylorza 0:2ee0812e2615 525 sound = 0;
taylorza 0:2ee0812e2615 526 sound.period(0.0);
taylorza 0:2ee0812e2615 527
taylorza 0:2ee0812e2615 528 int x = 100;
taylorza 0:2ee0812e2615 529 int y = 5;
taylorza 0:2ee0812e2615 530 bool flip = false;
taylorza 0:2ee0812e2615 531
taylorza 0:2ee0812e2615 532 int frame = 0;
taylorza 0:2ee0812e2615 533
taylorza 0:2ee0812e2615 534 PlayerState state = Walking;
taylorza 0:2ee0812e2615 535 int walkSpeed = 24;
taylorza 0:2ee0812e2615 536 int flySpeed = 6;
taylorza 0:2ee0812e2615 537 int fallSpeed = 10;
taylorza 0:2ee0812e2615 538 int speed = 0;
taylorza 0:2ee0812e2615 539 int speedCounter = 0;
taylorza 0:2ee0812e2615 540
taylorza 0:2ee0812e2615 541 while (true)
taylorza 0:2ee0812e2615 542 {
taylorza 0:2ee0812e2615 543 wait_ms(1);
taylorza 0:2ee0812e2615 544
taylorza 0:2ee0812e2615 545 if (--speedCounter <= 0)
taylorza 0:2ee0812e2615 546 {
taylorza 0:2ee0812e2615 547 if (x < 0) x = 0;
taylorza 0:2ee0812e2615 548 if (x > 160 - 16) x = 160 - 16;
taylorza 0:2ee0812e2615 549 if (y < 0) y = 0;
taylorza 0:2ee0812e2615 550 if (y > 128 - 24) y = 128 - 24;
taylorza 0:2ee0812e2615 551
taylorza 0:2ee0812e2615 552 if (state == Stopped)
taylorza 0:2ee0812e2615 553 {
taylorza 0:2ee0812e2615 554 lcd.drawGlyph(x, y, Color565::White, Color565::Black, bmp, 0, 0, 16, 16, flip);
taylorza 0:2ee0812e2615 555 }
taylorza 0:2ee0812e2615 556 else if (state == Flying || state == Falling)
taylorza 0:2ee0812e2615 557 {
taylorza 0:2ee0812e2615 558 switch(frame)
taylorza 0:2ee0812e2615 559 {
taylorza 0:2ee0812e2615 560 case 0 : lcd.drawGlyph(x, y, Color565::White, Color565::Black, bmp, 0, 16, 16, 16, flip); break;
taylorza 0:2ee0812e2615 561 case 1 : lcd.drawGlyph(x, y, Color565::White, Color565::Black, bmp, 16, 16, 16, 16, flip); break;
taylorza 0:2ee0812e2615 562 case 2 : lcd.drawGlyph(x, y, Color565::White, Color565::Black, bmp, 32, 16, 16, 16, flip); break;
taylorza 0:2ee0812e2615 563 case 3 : lcd.drawGlyph(x, y, Color565::White, Color565::Black, bmp, 48, 16, 16, 16, flip); break;
taylorza 0:2ee0812e2615 564 }
taylorza 0:2ee0812e2615 565 frame = (frame + 1) % 4;
taylorza 0:2ee0812e2615 566 }
taylorza 0:2ee0812e2615 567 else if (state == Walking)
taylorza 0:2ee0812e2615 568 {
taylorza 0:2ee0812e2615 569 switch(frame)
taylorza 0:2ee0812e2615 570 {
taylorza 0:2ee0812e2615 571 case 0 : lcd.drawGlyph(x, y, Color565::White, Color565::Black, bmp, 0, 0, 16, 16, flip); break;
taylorza 0:2ee0812e2615 572 case 1 : lcd.drawGlyph(x, y, Color565::White, Color565::Black, bmp, 16, 0, 16, 16, flip); break;
taylorza 0:2ee0812e2615 573 case 2 : lcd.drawGlyph(x, y, Color565::White, Color565::Black, bmp, 32, 0, 16, 16, flip); break;
taylorza 0:2ee0812e2615 574 case 3 : lcd.drawGlyph(x, y, Color565::White, Color565::Black, bmp, 48, 0, 16, 16, flip); break;
taylorza 0:2ee0812e2615 575 }
taylorza 0:2ee0812e2615 576 frame = (frame + 1) % 4;
taylorza 0:2ee0812e2615 577 }
taylorza 0:2ee0812e2615 578
taylorza 0:2ee0812e2615 579 if (!up)
taylorza 0:2ee0812e2615 580 {
taylorza 0:2ee0812e2615 581 if (state != Flying)
taylorza 0:2ee0812e2615 582 {
taylorza 0:2ee0812e2615 583 state = Flying;
taylorza 0:2ee0812e2615 584 speed = flySpeed;
taylorza 0:2ee0812e2615 585 frame = 0;
taylorza 0:2ee0812e2615 586 }
taylorza 0:2ee0812e2615 587 else if (y > 2)
taylorza 0:2ee0812e2615 588 {
taylorza 0:2ee0812e2615 589 y--;
taylorza 0:2ee0812e2615 590 }
taylorza 0:2ee0812e2615 591 }
taylorza 0:2ee0812e2615 592 else if (y < 128 - 24)
taylorza 0:2ee0812e2615 593 {
taylorza 0:2ee0812e2615 594 if (state != Falling)
taylorza 0:2ee0812e2615 595 {
taylorza 0:2ee0812e2615 596 state = Falling;
taylorza 0:2ee0812e2615 597 speed = fallSpeed;
taylorza 0:2ee0812e2615 598 frame = 0;
taylorza 0:2ee0812e2615 599 }
taylorza 0:2ee0812e2615 600 y++;
taylorza 0:2ee0812e2615 601 }
taylorza 0:2ee0812e2615 602 else
taylorza 0:2ee0812e2615 603 {
taylorza 0:2ee0812e2615 604 if (state != Stopped && state != Walking)
taylorza 0:2ee0812e2615 605 {
taylorza 0:2ee0812e2615 606 state = Stopped;
taylorza 0:2ee0812e2615 607 frame = 0;
taylorza 0:2ee0812e2615 608 }
taylorza 0:2ee0812e2615 609 }
taylorza 0:2ee0812e2615 610
taylorza 0:2ee0812e2615 611 if (!left || (!flip && state == Walking))
taylorza 0:2ee0812e2615 612 {
taylorza 0:2ee0812e2615 613 if (flip)
taylorza 0:2ee0812e2615 614 {
taylorza 0:2ee0812e2615 615 flip = false;
taylorza 0:2ee0812e2615 616 frame = 0;
taylorza 0:2ee0812e2615 617 }
taylorza 0:2ee0812e2615 618 else
taylorza 0:2ee0812e2615 619 {
taylorza 0:2ee0812e2615 620 if (state == Stopped)
taylorza 0:2ee0812e2615 621 {
taylorza 0:2ee0812e2615 622 state = Walking;
taylorza 0:2ee0812e2615 623 speed = walkSpeed;
taylorza 0:2ee0812e2615 624 frame = 1;
taylorza 0:2ee0812e2615 625 }
taylorza 0:2ee0812e2615 626 else if (state == Walking)
taylorza 0:2ee0812e2615 627 {
taylorza 0:2ee0812e2615 628 if (frame == 0) state = Stopped;
taylorza 0:2ee0812e2615 629 x -= 1;
taylorza 0:2ee0812e2615 630 }
taylorza 0:2ee0812e2615 631 else if (state == Flying || state == Falling)
taylorza 0:2ee0812e2615 632 {
taylorza 0:2ee0812e2615 633 x -= 1;
taylorza 0:2ee0812e2615 634 }
taylorza 0:2ee0812e2615 635 }
taylorza 0:2ee0812e2615 636 }
taylorza 0:2ee0812e2615 637
taylorza 0:2ee0812e2615 638 if (!right || (flip && state == Walking))
taylorza 0:2ee0812e2615 639 {
taylorza 0:2ee0812e2615 640 if (!flip)
taylorza 0:2ee0812e2615 641 {
taylorza 0:2ee0812e2615 642 flip = true;
taylorza 0:2ee0812e2615 643 frame = 0;
taylorza 0:2ee0812e2615 644 }
taylorza 0:2ee0812e2615 645 else
taylorza 0:2ee0812e2615 646 {
taylorza 0:2ee0812e2615 647 if (state == Stopped)
taylorza 0:2ee0812e2615 648 {
taylorza 0:2ee0812e2615 649 state = Walking;
taylorza 0:2ee0812e2615 650 speed = walkSpeed;
taylorza 0:2ee0812e2615 651 frame = 1;
taylorza 0:2ee0812e2615 652 }
taylorza 0:2ee0812e2615 653 else if (state == Walking)
taylorza 0:2ee0812e2615 654 {
taylorza 0:2ee0812e2615 655 if (frame == 0) state = Stopped;
taylorza 0:2ee0812e2615 656 x += 1;
taylorza 0:2ee0812e2615 657 }
taylorza 0:2ee0812e2615 658 else if (state == Flying || state == Falling)
taylorza 0:2ee0812e2615 659 {
taylorza 0:2ee0812e2615 660 x += 1;
taylorza 0:2ee0812e2615 661 }
taylorza 0:2ee0812e2615 662 }
taylorza 0:2ee0812e2615 663 }
taylorza 0:2ee0812e2615 664 speedCounter = speed;
taylorza 0:2ee0812e2615 665 }
taylorza 0:2ee0812e2615 666 }
taylorza 0:2ee0812e2615 667 }
taylorza 0:2ee0812e2615 668
taylorza 0:2ee0812e2615 669 void drawEnvironment(LCD_ST7735 lcd)
taylorza 0:2ee0812e2615 670 {
taylorza 0:2ee0812e2615 671 for (int y = 0; y < 16; ++y)
taylorza 0:2ee0812e2615 672 {
taylorza 0:2ee0812e2615 673 for (int x = 0; x < 20; ++x)
taylorza 0:2ee0812e2615 674 {
taylorza 0:2ee0812e2615 675 int i= y * 20 + x;
taylorza 0:2ee0812e2615 676 switch(environment[i])
taylorza 0:2ee0812e2615 677 {
taylorza 0:2ee0812e2615 678 case 1: lcd.drawGlyph(x * 8, y * 8, Color565::Green, Color565::Black, bmp, 0, 81, 8, 8, false); break;
taylorza 0:2ee0812e2615 679 case 2: lcd.drawGlyph(x * 8, y * 8, Color565::Green, Color565::Black, bmp, 8, 81, 8, 8, false); break;
taylorza 0:2ee0812e2615 680 case 3: lcd.drawGlyph(x * 8, y * 8, Color565::Green, Color565::Black, bmp, 16, 81, 8, 8, false); break;
taylorza 0:2ee0812e2615 681 }
taylorza 0:2ee0812e2615 682 }
taylorza 0:2ee0812e2615 683 }
taylorza 0:2ee0812e2615 684 }
taylorza 0:2ee0812e2615 685
taylorza 0:2ee0812e2615 686 void drawPlatform(LCD_ST7735 lcd, int x, int y, int width, uint16_t color)
taylorza 0:2ee0812e2615 687 {
taylorza 0:2ee0812e2615 688 lcd.drawGlyph(x, y, color, Color565::Black, bmp, 0, 81, 8, 8, false);
taylorza 0:2ee0812e2615 689 lcd.drawGlyph(x + (width - 1) * 8, y, color, Color565::Black, bmp, 16, 81, 8, 8, false);
taylorza 0:2ee0812e2615 690
taylorza 0:2ee0812e2615 691 for(int i = 1; i < width - 1; ++i)
taylorza 0:2ee0812e2615 692 {
taylorza 0:2ee0812e2615 693 lcd.drawGlyph(x + (i * 8), y, color, Color565::Black, bmp, 8, 81, 8, 8, false);
taylorza 0:2ee0812e2615 694 }
taylorza 0:2ee0812e2615 695
taylorza 0:2ee0812e2615 696 }
taylorza 0:2ee0812e2615 697 */