All there but errors need fixing

Dependencies:   mbed

Overview:

Rookie Tetris is a jigsaw style game based on the classic Tetris.

A block will appear at the top of the screen, you must move it (your options for movement are left, right and down - you cannot move up the board). The block will stop when it if placed either on the floor of the board or on-top of another block.

Your goal is to fill a complete row of the board with the blocks; when you do so the row will delete and the pattern above it will drop down. The game is over when your pattern is tall enough to reach to the top of the board!

Controls:

Use the joystick to move your block! Your block cannot move out of the parameters of the board.

Pot 2 controls the contrast of the screen.

Committer:
el18rs
Date:
Sun May 31 17:35:30 2020 +0000
Revision:
5:53e021832adc
Parent:
4:7ddd287a5d28
Child:
6:39cbec524483
changes made

Who changed what in which revision?

UserRevisionLine numberNew 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
el18rs 5:53e021832adc 89 void check_tetromino_collisions(Tetromino tetromino)
el18rs 5:53e021832adc 90 {
el18rs 5:53e021832adc 91 Vector2D tetromino_pos = _tetromino.get_pos();
el18rs 5:53e021832adc 92 Vector2D tetromino_velocity = _tetromino.get_velocity();
el18rs 5:53e021832adc 93
el18rs 5:53e021832adc 94 if (
el18rs 5:53e021832adc 95 (lcd.get_pixel(tetromino_pos.y + 4, tetromino_pos.x) = 1) || // not sure if it should be 4 or 5 ???
el18rs 5:53e021832adc 96 (lcd.get_pixel(tetromino_pos.y + 4, tetromino_pos.x + 1) = 1) ||
el18rs 5:53e021832adc 97 (lcd.get_pixel(tetromino_pos.y + 4, tetromino_pos.x + 2) = 1) ||
el18rs 5:53e021832adc 98 (lcd.get_pixel(tetromino_pos.y + 4, tetromino_pos.x + 3) = 1)
el18rs 5:53e021832adc 99 ) {
el18rs 5:53e021832adc 100 tetromino_velocity.x = 0;
el18rs 5:53e021832adc 101
el18rs 5:53e021832adc 102 pad.tone(1000.0,0.1);
el18rs 5:53e021832adc 103 cancel_line();
el18rs 5:53e021832adc 104
el18rs 5:53e021832adc 105 blocknumber ++
el18rs 5:53e021832adc 106 if (blocknumber > 4) { blocknumber = 0; }
el18rs 5:53e021832adc 107
el18rs 5:53e021832adc 108 _tetromino.init(_number, WIDTH/2 - 2, HEIGHT, _speed); // break to loop back or keep this ??
el18rs 5:53e021832adc 109
el18rs 5:53e021832adc 110 }