![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
All there but errors need fixing
TetrisGame/TetrisGame.cpp@4:7ddd287a5d28, 2020-05-31 (annotated)
- Committer:
- el18rs
- Date:
- Sun May 31 17:01:53 2020 +0000
- Revision:
- 4:7ddd287a5d28
- Parent:
- 3:522c6f850e91
- Child:
- 5:53e021832adc
Includes most parts but still has errors that need fixing
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el18rs | 3:522c6f850e91 | 1 | #include "TetrisGame.h" |
el18rs | 3:522c6f850e91 | 2 | |
el18rs | 3:522c6f850e91 | 3 | TetrisGame::TetrisGame() |
el18rs | 3:522c6f850e91 | 4 | { |
el18rs | 3:522c6f850e91 | 5 | |
el18rs | 3:522c6f850e91 | 6 | } |
el18rs | 3:522c6f850e91 | 7 | |
el18rs | 3:522c6f850e91 | 8 | TetrisGame::~TetrisGame() |
el18rs | 3:522c6f850e91 | 9 | { |
el18rs | 3:522c6f850e91 | 10 | |
el18rs | 3:522c6f850e91 | 11 | } |
el18rs | 3:522c6f850e91 | 12 | |
el18rs | 4:7ddd287a5d28 | 13 | void TetrisGame::init(int number, int x, int y, int speed) |
el18rs | 3:522c6f850e91 | 14 | { |
el18rs | 4:7ddd287a5d28 | 15 | // initialise game parameters |
el18rs | 4:7ddd287a5d28 | 16 | _number = blockArray[blocknumber]; |
el18rs | 4:7ddd287a5d28 | 17 | _x = x; |
el18rs | 4:7ddd287a5d28 | 18 | _y = y; |
el18rs | 3:522c6f850e91 | 19 | _speed = speed; |
el18rs | 3:522c6f850e91 | 20 | |
el18rs | 4:7ddd287a5d28 | 21 | _tetromino.init(_number, WIDTH/2 - 2, HEIGHT, _speed); // puts tetromino in middle SHOULD THIS INCLUDE ARRAY???? |
el18rs | 4:7ddd287a5d28 | 22 | |
el18rs | 3:522c6f850e91 | 23 | } |
el18rs | 3:522c6f850e91 | 24 | |
el18rs | 4:7ddd287a5d28 | 25 | |
el18rs | 3:522c6f850e91 | 26 | void TetrisGame::read_input(Gamepad &pad) |
el18rs | 3:522c6f850e91 | 27 | { |
el18rs | 3:522c6f850e91 | 28 | _d = pad.get_direction(); |
el18rs | 4:7ddd287a5d28 | 29 | _mag = pad.get_mag(); |
el18rs | 3:522c6f850e91 | 30 | } |
el18rs | 3:522c6f850e91 | 31 | |
el18rs | 3:522c6f850e91 | 32 | void TetrisGame::draw(N5110 &lcd) |
el18rs | 3:522c6f850e91 | 33 | { |
el18rs | 4:7ddd287a5d28 | 34 | // draw elements in lcd buffer |
el18rs | 3:522c6f850e91 | 35 | |
el18rs | 4:7ddd287a5d28 | 36 | // board |
el18rs | 3:522c6f850e91 | 37 | lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); |
el18rs | 3:522c6f850e91 | 38 | |
el18rs | 4:7ddd287a5d28 | 39 | _tetromino.draw(lcd, _number); |
el18rs | 3:522c6f850e91 | 40 | |
el18rs | 3:522c6f850e91 | 41 | |
el18rs | 3:522c6f850e91 | 42 | } |
el18rs | 3:522c6f850e91 | 43 | |
el18rs | 4:7ddd287a5d28 | 44 | void TetrisGame::update(Gamepad &pad) |
el18rs | 3:522c6f850e91 | 45 | { |
el18rs | 4:7ddd287a5d28 | 46 | // check_score(pad); |
el18rs | 4:7ddd287a5d28 | 47 | |
el18rs | 4:7ddd287a5d28 | 48 | // _p1.update(_d,_mag); |
el18rs | 4:7ddd287a5d28 | 49 | _tetromino.update(_d,_mag); |
el18rs | 3:522c6f850e91 | 50 | |
el18rs | 4:7ddd287a5d28 | 51 | check_wall_collision(pad); |
el18rs | 4:7ddd287a5d28 | 52 | check_tetromino_collisions(); |
el18rs | 3:522c6f850e91 | 53 | } |
el18rs | 4:7ddd287a5d28 | 54 | |
el18rs | 4:7ddd287a5d28 | 55 | |
el18rs | 4:7ddd287a5d28 | 56 | void TetrisGame::check_wall_collision(Gamepad &pad) |
el18rs | 3:522c6f850e91 | 57 | { |
el18rs | 3:522c6f850e91 | 58 | Vector2D tetromino_pos = _tetromino.get_pos(); |
el18rs | 3:522c6f850e91 | 59 | Vector2D tetromino_velocity = _tetromino.get_velocity(); |
el18rs | 3:522c6f850e91 | 60 | |
el18rs | 4:7ddd287a5d28 | 61 | // check if hit floor |
el18rs | 4:7ddd287a5d28 | 62 | if (tetromino_pos.y + 4 >= (HEIGHT-1) ) { |
el18rs | 4:7ddd287a5d28 | 63 | |
el18rs | 4:7ddd287a5d28 | 64 | tetromino_pos.y = (HEIGHT-1) - 4; |
el18rs | 4:7ddd287a5d28 | 65 | tetromino_velocity.y = 0; |
el18rs | 4:7ddd287a5d28 | 66 | |
el18rs | 4:7ddd287a5d28 | 67 | pad.tone(750.0,0.1); |
el18rs | 3:522c6f850e91 | 68 | |
el18rs | 4:7ddd287a5d28 | 69 | cancel_line(); // check if line full and cancel + drop down if it is |
el18rs | 4:7ddd287a5d28 | 70 | |
el18rs | 4:7ddd287a5d28 | 71 | _tetromino.init(_number, WIDTH/2 - 2, HEIGHT, _speed); // drop new shame |
el18rs | 4:7ddd287a5d28 | 72 | |
el18rs | 4:7ddd287a5d28 | 73 | blocknumber ++; |
el18rs | 4:7ddd287a5d28 | 74 | if (blocknumber > 4) { |
el18rs | 4:7ddd287a5d28 | 75 | blocknumber = 0; |
el18rs | 4:7ddd287a5d28 | 76 | } |
el18rs | 4:7ddd287a5d28 | 77 | } |
el18rs | 4:7ddd287a5d28 | 78 | // check if hit roof |
el18rs | 4:7ddd287a5d28 | 79 | else if (tetromino_pos.y <= 1) { |
el18rs | 4:7ddd287a5d28 | 80 | |
el18rs | 4:7ddd287a5d28 | 81 | exit_game(); |
el18rs | 4:7ddd287a5d28 | 82 | |
el18rs | 3:522c6f850e91 | 83 | } |
el18rs | 3:522c6f850e91 | 84 | |
el18rs | 4:7ddd287a5d28 | 85 | // SAVE OLD SCREEN AND DROP NEW TETROMINO???? // |
el18rs | 4:7ddd287a5d28 | 86 | // update tetromino parameters?? |
el18rs | 4:7ddd287a5d28 | 87 | } |
el18rs | 4:7ddd287a5d28 | 88 |