![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
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.
Tetromino/Tetromino.cpp@20:ad685b35a1a4, 2020-06-03 (annotated)
- Committer:
- el18rs
- Date:
- Wed Jun 03 12:47:33 2020 +0000
- Revision:
- 20:ad685b35a1a4
- Parent:
- 19:2ad31dbd5d11
- Child:
- 23:cbfa9d1ee3db
game over function fixed
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el18rs | 3:522c6f850e91 | 1 | #include "Tetromino.h" |
el18rs | 3:522c6f850e91 | 2 | |
el18rs | 3:522c6f850e91 | 3 | Tetromino::Tetromino() |
el18rs | 3:522c6f850e91 | 4 | { |
el18rs | 3:522c6f850e91 | 5 | |
el18rs | 3:522c6f850e91 | 6 | } |
el18rs | 3:522c6f850e91 | 7 | |
el18rs | 3:522c6f850e91 | 8 | Tetromino::~Tetromino() |
el18rs | 3:522c6f850e91 | 9 | { |
el18rs | 3:522c6f850e91 | 10 | |
el18rs | 3:522c6f850e91 | 11 | } |
el18rs | 3:522c6f850e91 | 12 | |
el18rs | 10:7310c9440547 | 13 | void Tetromino::init(int x, int y) |
el18rs | 3:522c6f850e91 | 14 | { |
el18rs | 10:7310c9440547 | 15 | _x = x; |
el18rs | 10:7310c9440547 | 16 | _y = y; |
el18rs | 6:39cbec524483 | 17 | |
el18rs | 10:7310c9440547 | 18 | // _height = height; |
el18rs | 10:7310c9440547 | 19 | // _width = width; |
el18rs | 3:522c6f850e91 | 20 | |
el18rs | 4:7ddd287a5d28 | 21 | _speed = 1; |
el18rs | 6:39cbec524483 | 22 | |
el18rs | 6:39cbec524483 | 23 | } |
el18rs | 6:39cbec524483 | 24 | |
el18rs | 6:39cbec524483 | 25 | void Tetromino::draw(N5110 &lcd) |
el18rs | 6:39cbec524483 | 26 | { |
el18rs | 11:0183a52c1077 | 27 | lcd.drawRect(_x, _y, 4, 4, FILL_BLACK); |
el18rs | 3:522c6f850e91 | 28 | } |
el18rs | 3:522c6f850e91 | 29 | |
el18rs | 3:522c6f850e91 | 30 | void Tetromino::update(Direction d, float mag) |
el18rs | 3:522c6f850e91 | 31 | { |
el18rs | 17:70d45e9e44a8 | 32 | _speed = int(mag*2.5f); |
el18rs | 3:522c6f850e91 | 33 | |
el18rs | 12:965b39a2e049 | 34 | if (d == N) { |
el18rs | 12:965b39a2e049 | 35 | _y-=_speed; |
el18rs | 12:965b39a2e049 | 36 | // printf("d = %i, x = %i, y = %i, speed = %i\n",d,_x,_y,_speed); |
el18rs | 12:965b39a2e049 | 37 | } else if (d == S) { |
el18rs | 8:cebb2aca8e19 | 38 | _y+=_speed; |
el18rs | 3:522c6f850e91 | 39 | } else if (d == E) { |
el18rs | 8:cebb2aca8e19 | 40 | _x+=_speed; |
el18rs | 12:965b39a2e049 | 41 | // printf("d = %i, x = %i, y = %i, speed = %i\n",d,_x,_y,_speed); |
el18rs | 3:522c6f850e91 | 42 | } else if (d == W) { |
el18rs | 8:cebb2aca8e19 | 43 | _x-=_speed; |
el18rs | 12:965b39a2e049 | 44 | // printf("d = %i, x = %i, y = %i, speed = %i\n",d,_x,_y,_speed); |
el18rs | 3:522c6f850e91 | 45 | } |
el18rs | 3:522c6f850e91 | 46 | |
el18rs | 19:2ad31dbd5d11 | 47 | if (_x < 20) { |
el18rs | 19:2ad31dbd5d11 | 48 | _x = 20; |
el18rs | 19:2ad31dbd5d11 | 49 | printf("left wall hit\n"); |
el18rs | 3:522c6f850e91 | 50 | } |
el18rs | 19:2ad31dbd5d11 | 51 | else if (_x > 56) { |
el18rs | 19:2ad31dbd5d11 | 52 | _x = 56; |
el18rs | 19:2ad31dbd5d11 | 53 | printf("right wall hit\n"); |
el18rs | 3:522c6f850e91 | 54 | } |
el18rs | 19:2ad31dbd5d11 | 55 | // printf("back corner of block = (%i,%i)\n",_x,_y); |
el18rs | 19:2ad31dbd5d11 | 56 | // printf("front corner of block = (%i, %i)\n",_x+3,_y+3); |
el18rs | 3:522c6f850e91 | 57 | } |
el18rs | 4:7ddd287a5d28 | 58 | |
el18rs | 6:39cbec524483 | 59 | /*void Tetromino::set_velocity(Vector2D v) |
el18rs | 6:39cbec524483 | 60 | { |
el18rs | 6:39cbec524483 | 61 | _velocity.x = v.x; |
el18rs | 6:39cbec524483 | 62 | _velocity.y = v.y; |
el18rs | 6:39cbec524483 | 63 | }*/ |
el18rs | 6:39cbec524483 | 64 | |
el18rs | 6:39cbec524483 | 65 | Vector2D Tetromino::get_velocity() |
el18rs | 6:39cbec524483 | 66 | { |
el18rs | 6:39cbec524483 | 67 | Vector2D v = {_velocity.x,_velocity.y}; |
el18rs | 6:39cbec524483 | 68 | return v; |
el18rs | 6:39cbec524483 | 69 | } |
el18rs | 4:7ddd287a5d28 | 70 | |
el18rs | 3:522c6f850e91 | 71 | Vector2D Tetromino::get_pos() { |
el18rs | 3:522c6f850e91 | 72 | Vector2D p = {_x,_y}; |
el18rs | 3:522c6f850e91 | 73 | return p; |
el18rs | 3:522c6f850e91 | 74 | } |