Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Tetris.h@3:af0a7a4464e5, 2016-04-07 (annotated)
- Committer:
- el14ja
- Date:
- Thu Apr 07 15:42:35 2016 +0000
- Revision:
- 3:af0a7a4464e5
- Parent:
- 2:56dc50270349
- Child:
- 4:e4952be370d3
attempted library integration;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| el14ja | 0:5cfe6c525e0a | 1 | /*Tetris |
| el14ja | 0:5cfe6c525e0a | 2 | |
| el14ja | 0:5cfe6c525e0a | 3 | Library which contains the functions for the game tetris to run on a Nokia N5110 screen |
| el14ja | 0:5cfe6c525e0a | 4 | |
| el14ja | 0:5cfe6c525e0a | 5 | V 1.0 - initial release |
| el14ja | 0:5cfe6c525e0a | 6 | |
| el14ja | 0:5cfe6c525e0a | 7 | Joseph Allison March 2016 |
| el14ja | 0:5cfe6c525e0a | 8 | |
| el14ja | 0:5cfe6c525e0a | 9 | #ifndef TMP102_H |
| el14ja | 0:5cfe6c525e0a | 10 | #define TMP102_H |
| el14ja | 0:5cfe6c525e0a | 11 | |
| el14ja | 0:5cfe6c525e0a | 12 | */ |
| el14ja | 0:5cfe6c525e0a | 13 | |
| el14ja | 0:5cfe6c525e0a | 14 | #ifndef Tetris_H //header guards to stop the library from being included more than once |
| el14ja | 0:5cfe6c525e0a | 15 | #define Tetris_H |
| el14ja | 0:5cfe6c525e0a | 16 | |
| el14ja | 0:5cfe6c525e0a | 17 | #include "mbed.h" |
| el14ja | 2:56dc50270349 | 18 | #include "N5110.h" |
| el14ja | 0:5cfe6c525e0a | 19 | |
| el14ja | 3:af0a7a4464e5 | 20 | //int shapes[7][4] = {{0x00F0,0x4444,0x0F00,0x2222},{0x0071,0x0226,0x0470,0x0322},{0x0074,0x0622,0x0170,0x0223},{0x0033,0x0033,0x0033,0x0033},{0x0072,0x0262,0x0270,0x0232},{0x0036,0x0462,0x0360,0x0231},{0x0063,0x0264,0x0630,0x0132}}; |
| el14ja | 3:af0a7a4464e5 | 21 | |
| el14ja | 3:af0a7a4464e5 | 22 | |
| el14ja | 2:56dc50270349 | 23 | class Tetris |
| el14ja | 2:56dc50270349 | 24 | { |
| el14ja | 2:56dc50270349 | 25 | |
| el14ja | 2:56dc50270349 | 26 | public: |
| el14ja | 2:56dc50270349 | 27 | |
| el14ja | 2:56dc50270349 | 28 | Tetris(); |
| el14ja | 3:af0a7a4464e5 | 29 | void movePieceRight(); |
| el14ja | 3:af0a7a4464e5 | 30 | void movePieceLeft(); |
| el14ja | 3:af0a7a4464e5 | 31 | void spinPiece(); |
| el14ja | 3:af0a7a4464e5 | 32 | void movePieceDown(); |
| el14ja | 3:af0a7a4464e5 | 33 | |
| el14ja | 2:56dc50270349 | 34 | private: |
| el14ja | 2:56dc50270349 | 35 | |
| el14ja | 3:af0a7a4464e5 | 36 | void gameInfo(int score,int level,int next); |
| el14ja | 2:56dc50270349 | 37 | /** |
| el14ja | 2:56dc50270349 | 38 | Sets a 3x3 sets a pixel cell in the game area at position (x,y) |
| el14ja | 2:56dc50270349 | 39 | @param x - cells horizontal position |
| el14ja | 2:56dc50270349 | 40 | @param y - cells vertical position |
| el14ja | 2:56dc50270349 | 41 | */ |
| el14ja | 2:56dc50270349 | 42 | void gamePixel(int x,int y); |
| el14ja | 2:56dc50270349 | 43 | /** |
| el14ja | 2:56dc50270349 | 44 | Sets a 3x3 clears a pixel cell in the game area at position (x,y) |
| el14ja | 2:56dc50270349 | 45 | @param x - cells horizontal position |
| el14ja | 2:56dc50270349 | 46 | @param y - cells vertical position |
| el14ja | 2:56dc50270349 | 47 | */ |
| el14ja | 2:56dc50270349 | 48 | void clearGamePixel(int x, int y); |
| el14ja | 2:56dc50270349 | 49 | /** |
| el14ja | 2:56dc50270349 | 50 | Clears the game area |
| el14ja | 2:56dc50270349 | 51 | */ |
| el14ja | 2:56dc50270349 | 52 | void clearGame(); |
| el14ja | 2:56dc50270349 | 53 | /** |
| el14ja | 2:56dc50270349 | 54 | Places a game piece on the screen |
| el14ja | 2:56dc50270349 | 55 | @param x - cells horizontal position |
| el14ja | 2:56dc50270349 | 56 | @param y - cells vertical position |
| el14ja | 2:56dc50270349 | 57 | @param shape - the shape that is being placed |
| el14ja | 2:56dc50270349 | 58 | */ |
| el14ja | 2:56dc50270349 | 59 | void piecePlace(int x,int y,int shape); |
| el14ja | 2:56dc50270349 | 60 | /** |
| el14ja | 2:56dc50270349 | 61 | Clears a game piece on the screen |
| el14ja | 2:56dc50270349 | 62 | @param x - cells horizontal position |
| el14ja | 2:56dc50270349 | 63 | @param y - cells vertical position |
| el14ja | 2:56dc50270349 | 64 | @param shape - the shape that is being cleared |
| el14ja | 2:56dc50270349 | 65 | */ |
| el14ja | 2:56dc50270349 | 66 | void pieceClear(int x,int y,int shape); |
| el14ja | 3:af0a7a4464e5 | 67 | |
| el14ja | 3:af0a7a4464e5 | 68 | bool movePossible(int xpos, int ypos, int orientation); |
| el14ja | 3:af0a7a4464e5 | 69 | |
| el14ja | 3:af0a7a4464e5 | 70 | void gameSetup(); |
| el14ja | 3:af0a7a4464e5 | 71 | |
| el14ja | 3:af0a7a4464e5 | 72 | void newpiece(); |
| el14ja | 3:af0a7a4464e5 | 73 | |
| el14ja | 3:af0a7a4464e5 | 74 | void newShapeBag(); |
| el14ja | 3:af0a7a4464e5 | 75 | |
| el14ja | 3:af0a7a4464e5 | 76 | void checkCompleteLine(); |
| el14ja | 3:af0a7a4464e5 | 77 | |
| el14ja | 3:af0a7a4464e5 | 78 | void removeCompleteLines(int rowscomplete[4]); |
| el14ja | 3:af0a7a4464e5 | 79 | |
| el14ja | 3:af0a7a4464e5 | 80 | void pieceToGameArray(); |
| el14ja | 3:af0a7a4464e5 | 81 | |
| el14ja | 3:af0a7a4464e5 | 82 | void setGameArea(); |
| el14ja | 3:af0a7a4464e5 | 83 | |
| el14ja | 3:af0a7a4464e5 | 84 | |
| el14ja | 3:af0a7a4464e5 | 85 | |
| el14ja | 3:af0a7a4464e5 | 86 | |
| el14ja | 3:af0a7a4464e5 | 87 | |
| el14ja | 3:af0a7a4464e5 | 88 | void movePiece(int x, int y,int spin); |
| el14ja | 2:56dc50270349 | 89 | public: |
| el14ja | 2:56dc50270349 | 90 | |
| el14ja | 2:56dc50270349 | 91 | int pieceposition[2]; //set position of the current dropping piece *** |
| el14ja | 2:56dc50270349 | 92 | int orientation; |
| el14ja | 3:af0a7a4464e5 | 93 | int gamearea[12][16]; //stores the current states of the game area and is used to check for collisions ***add sides |
| el14ja | 3:af0a7a4464e5 | 94 | int currentshape; |
| el14ja | 3:af0a7a4464e5 | 95 | |
| el14ja | 2:56dc50270349 | 96 | int nextpiece; |
| el14ja | 3:af0a7a4464e5 | 97 | int shapebagcounter; |
| el14ja | 2:56dc50270349 | 98 | int nextshape[7];//stores the next 7 shapes to be used - 7 bag system |
| el14ja | 3:af0a7a4464e5 | 99 | |
| el14ja | 3:af0a7a4464e5 | 100 | int musiccounter; |
| el14ja | 3:af0a7a4464e5 | 101 | |
| el14ja | 3:af0a7a4464e5 | 102 | int score; /*!< */ |
| el14ja | 3:af0a7a4464e5 | 103 | int completedlines; |
| el14ja | 3:af0a7a4464e5 | 104 | int level; |
| el14ja | 3:af0a7a4464e5 | 105 | float gamespeed; //how often a block moves down |
| el14ja | 3:af0a7a4464e5 | 106 | |
| el14ja | 2:56dc50270349 | 107 | private: |
| el14ja | 2:56dc50270349 | 108 | |
| el14ja | 3:af0a7a4464e5 | 109 | |
| el14ja | 2:56dc50270349 | 110 | }; |
| el14ja | 0:5cfe6c525e0a | 111 | |
| el14ja | 0:5cfe6c525e0a | 112 | #endif |