![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
All there but errors need fixing
Diff: Tetromino/Tetromino.cpp
- Revision:
- 4:7ddd287a5d28
- Parent:
- 3:522c6f850e91
--- a/Tetromino/Tetromino.cpp Sun May 24 11:18:33 2020 +0000 +++ b/Tetromino/Tetromino.cpp Sun May 31 17:01:53 2020 +0000 @@ -1,52 +1,22 @@ #include "Tetromino.h" -const int ISprite[4][4] = { - {0,0,1,0,}, - {0,0,1,0,}, - {0,0,1,0,}, - {0,0,1,0,}, -}; - -const int L0Sprite[4][4] = { - {0,1,0,0,}, - {0,1,0,0,}, - {0,1,1,0,}, - {0,0,0,0,}, -}; - -const int Z0Sprite[4][4] = { - {0,1,0,0,}, - {0,1,1,0,}, - {0,0,1,0,}, - {0,0,0,0,}, -}; - -const int OSprite[4][4] = { - {0,0,0,0,}, - {0,1,1,0,}, - {0,1,1,0,}, - {0,0,0,0,}, -}; - -const int TSprite[4][4] = { - {0,1,0,0,}, - {0,1,1,0,}, - {0,1,0,0,}, - {0,0,0,0,}, -}; - -const int L1Sprite[4][4] = { - {0,0,1,0,}, - {0,0,1,0,}, - {0,1,1,0,}, - {0,0,0,0,}, -}; - -const int Z1Sprite[4][4] = { - {0,0,1,0,}, - {0,1,1,0,}, - {0,1,0,0,}, - {0,0,0,0,}, +int tetromino[3][4][4] = { +{ + {1,1,1,1}, + {1,1,1,1}, + {1,1,1,1}, + {1,1,1,1} +}, { + {1,1,1,1}, + {1,1,1,1}, + {1,1,1,1}, + {1,1,1,1} +}, { + {1,1,1,1}, + {1,1,1,1}, + {1,1,1,1}, + {1,1,1,1} +} }; Tetromino::Tetromino() @@ -59,43 +29,21 @@ } -void Tetromino::init(int x, int height, int width) +void Tetromino::init(int number, int x, int y, int speed) { _x = x; - _y = HEIGHT/2 - height/2; - _height = height; - _width = width; - _speed = 1; - -} + _y = y; + _speed = speed; + _number = blockArray[blocknumber]; - - -void Tetromino::draw(N5110 &lcd, int x) -{ - int shape = rand() % 6; - if (shape == 0) { - lcd.drawSprite(_x, _y, 4, 4, (int*)ISprite); /*_shape_type = 0;*/ - } else if (shape == 1) { - lcd.drawSprite(_x, _y, 4, 4, (int*)L0Sprite); /*_shape_type = 1;*/ - } else if (shape == 2) { - lcd.drawSprite(_x, _y, 4, 4, (int*)Z0Sprite); /*_shape_type = 2;*/ - } else if (shape == 3) { - lcd.drawSprite(_x, _y, 4, 4, (int*)OSprite); /*_shape_type = 3;*/ - } else if (shape == 4) { - lcd.drawSprite(_x, _y, 4, 4, (int*)TSprite); /*_shape_type = 4;*/ - } else if (shape == 5) { - lcd.drawSprite(_x, _y, 4, 4, (int*)L1Sprite); /*_shape_type = 5;*/ - } else if (shape == 6) { - lcd.drawSprite(_x, _y, 4, 4, (int*)Z1Sprite); /*_shape_type = 6;*/ - } -// return _shape_type; + _speed = 1; + _x = WIDTH/2 - 2; + _y = HEIGHT; + + _velocity.x = speed; + _velocity.y = speed; } - - - - void Tetromino::update(Direction d, float mag) { @@ -114,10 +62,12 @@ if (_x < 1) { _x = 1; } - if (_x > WIDTH - _width - 1) { - _x = WIDTH - _width - 1; + if (_x > WIDTH - 3) { + _x = WIDTH - 3; } } + + Vector2D Tetromino::get_pos() { Vector2D p = {_x,_y}; return p;