Tetris game for mbed.
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
Fork of HelloWorld by
tetris.h@2:36cda8980746, 2016-11-07 (annotated)
- Committer:
- greiner218
- Date:
- Mon Nov 07 00:43:45 2016 +0000
- Revision:
- 2:36cda8980746
V1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
greiner218 | 2:36cda8980746 | 1 | #ifndef TETRIS_H |
greiner218 | 2:36cda8980746 | 2 | #define TETRIS_H |
greiner218 | 2:36cda8980746 | 3 | |
greiner218 | 2:36cda8980746 | 4 | #define DIMX 8 //10 |
greiner218 | 2:36cda8980746 | 5 | #define DIMY 4 |
greiner218 | 2:36cda8980746 | 6 | #define DIMZ 22 |
greiner218 | 2:36cda8980746 | 7 | #define DIMLOSE 18 |
greiner218 | 2:36cda8980746 | 8 | #define LINE0 0x000F000F000F000FULL |
greiner218 | 2:36cda8980746 | 9 | #define LINE1 0x00F000F000F000F0ULL |
greiner218 | 2:36cda8980746 | 10 | #define LINE2 0x0F000F000F000F00ULL |
greiner218 | 2:36cda8980746 | 11 | #define LINE3 0xF000F000F000F000ULL |
greiner218 | 2:36cda8980746 | 12 | #define FACE0 0x000000000000FFFFULL |
greiner218 | 2:36cda8980746 | 13 | #define FACE1 0x00000000FFFF0000ULL |
greiner218 | 2:36cda8980746 | 14 | #define FACE2 0x0000FFFF00000000ULL |
greiner218 | 2:36cda8980746 | 15 | #define FACE3 0xFFFF000000000000ULL |
greiner218 | 2:36cda8980746 | 16 | #define SET_SIZE 7 |
greiner218 | 2:36cda8980746 | 17 | |
greiner218 | 2:36cda8980746 | 18 | static unsigned long long block_list[] = {0x0033003300330033ULL, 0x000000000000000FULL, 0x0000000000000017ULL, |
greiner218 | 2:36cda8980746 | 19 | 0x000000000000008EULL, 0x00000000000000C6ULL, 0x0000000000000036ULL, |
greiner218 | 2:36cda8980746 | 20 | 0X000100010001111FULL}; |
greiner218 | 2:36cda8980746 | 21 | //51, 15, 23, 142, 198, 54, 281479271747871 |
greiner218 | 2:36cda8980746 | 22 | |
greiner218 | 2:36cda8980746 | 23 | class Block { |
greiner218 | 2:36cda8980746 | 24 | public: |
greiner218 | 2:36cda8980746 | 25 | unsigned long long block; |
greiner218 | 2:36cda8980746 | 26 | int offset; |
greiner218 | 2:36cda8980746 | 27 | int height; |
greiner218 | 2:36cda8980746 | 28 | |
greiner218 | 2:36cda8980746 | 29 | Block(); |
greiner218 | 2:36cda8980746 | 30 | Block(short); |
greiner218 | 2:36cda8980746 | 31 | Block(short, short, short); |
greiner218 | 2:36cda8980746 | 32 | unsigned long long getFace(int); |
greiner218 | 2:36cda8980746 | 33 | unsigned long long getLine(int); |
greiner218 | 2:36cda8980746 | 34 | unsigned long long getFaceLine(int,int); |
greiner218 | 2:36cda8980746 | 35 | void rotY(); |
greiner218 | 2:36cda8980746 | 36 | void rotZ(); |
greiner218 | 2:36cda8980746 | 37 | void rotX(); |
greiner218 | 2:36cda8980746 | 38 | void movR(); |
greiner218 | 2:36cda8980746 | 39 | void movL(); |
greiner218 | 2:36cda8980746 | 40 | void movB(); |
greiner218 | 2:36cda8980746 | 41 | void movF(); |
greiner218 | 2:36cda8980746 | 42 | void movU(); |
greiner218 | 2:36cda8980746 | 43 | void movD(); |
greiner218 | 2:36cda8980746 | 44 | }; |
greiner218 | 2:36cda8980746 | 45 | |
greiner218 | 2:36cda8980746 | 46 | class Board{ |
greiner218 | 2:36cda8980746 | 47 | |
greiner218 | 2:36cda8980746 | 48 | public: |
greiner218 | 2:36cda8980746 | 49 | Board(); |
greiner218 | 2:36cda8980746 | 50 | void setBlock(); |
greiner218 | 2:36cda8980746 | 51 | void setBlockFaceLine(int,int); |
greiner218 | 2:36cda8980746 | 52 | void setBlockFaceLineVal(int,int,unsigned long long); |
greiner218 | 2:36cda8980746 | 53 | int check(); |
greiner218 | 2:36cda8980746 | 54 | int checkFaceLine(int,int); |
greiner218 | 2:36cda8980746 | 55 | void updateBlock(); |
greiner218 | 2:36cda8980746 | 56 | void checkAndUpdate(); |
greiner218 | 2:36cda8980746 | 57 | void drawGrid(); |
greiner218 | 2:36cda8980746 | 58 | void drawBlock(Block); |
greiner218 | 2:36cda8980746 | 59 | void eraseBlock(Block); |
greiner218 | 2:36cda8980746 | 60 | unsigned long long line[DIMZ+4]; |
greiner218 | 2:36cda8980746 | 61 | Block activeBlock; |
greiner218 | 2:36cda8980746 | 62 | Block nextBlock; |
greiner218 | 2:36cda8980746 | 63 | void drawPix(int,int,int); |
greiner218 | 2:36cda8980746 | 64 | void erasePix(int,int,int); |
greiner218 | 2:36cda8980746 | 65 | void getNewBlock(); |
greiner218 | 2:36cda8980746 | 66 | unsigned long long getFaceLine(int,int); |
greiner218 | 2:36cda8980746 | 67 | void checkForClear(int); |
greiner218 | 2:36cda8980746 | 68 | void clearLine(int); |
greiner218 | 2:36cda8980746 | 69 | int score; |
greiner218 | 2:36cda8980746 | 70 | void redrawBoardLine(int, int, unsigned long long); |
greiner218 | 2:36cda8980746 | 71 | void drawScore(); |
greiner218 | 2:36cda8980746 | 72 | void blockFall(); |
greiner218 | 2:36cda8980746 | 73 | int lost; |
greiner218 | 2:36cda8980746 | 74 | void checkLose(); |
greiner218 | 2:36cda8980746 | 75 | }; |
greiner218 | 2:36cda8980746 | 76 | |
greiner218 | 2:36cda8980746 | 77 | unsigned long long shift(unsigned long long,int); |
greiner218 | 2:36cda8980746 | 78 | |
greiner218 | 2:36cda8980746 | 79 | |
greiner218 | 2:36cda8980746 | 80 | |
greiner218 | 2:36cda8980746 | 81 | #endif |