![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
All there but errors need fixing
Tetromino/Tetromino.cpp
- Committer:
- el18rs
- Date:
- 2020-05-24
- Revision:
- 3:522c6f850e91
- Child:
- 4:7ddd287a5d28
File content as of revision 3:522c6f850e91:
#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,}, }; Tetromino::Tetromino() { } Tetromino::~Tetromino() { } void Tetromino::init(int x, int height, int width) { _x = x; _y = HEIGHT/2 - height/2; _height = height; _width = width; _speed = 1; } 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; } void Tetromino::update(Direction d, float mag) { _speed = int(mag*10.0f); if (d == CENTRE) { _y+=_speed; } else if (d == S) { _y+=_speed*2; } else if (d == E) { _x+=_speed; } else if (d == W) { _x-=_speed; } if (_x < 1) { _x = 1; } if (_x > WIDTH - _width - 1) { _x = WIDTH - _width - 1; } } Vector2D Tetromino::get_pos() { Vector2D p = {_x,_y}; return p; }