![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
All there but errors need fixing
Diff: Tetromino/Tetromino.cpp
- Revision:
- 3:522c6f850e91
- Child:
- 4:7ddd287a5d28
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tetromino/Tetromino.cpp Sun May 24 11:18:33 2020 +0000 @@ -0,0 +1,124 @@ +#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; +} \ No newline at end of file