Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "block.h"
- #include "Arduino.h"
- Block::Block(){
- orientation = 0;
- old_coords = new int[4];
- coords = new int[4];
- color = 1;
- pivot = 213;
- }
- Block::Block(int clr){
- orientation = 0;
- old_coords = new int[4];
- coords = new int[4];
- color = clr;
- pivot = 213;
- }
- // color = 1: Yellow, Square, no rotations
- // color = 2: Blue, Stick, 2 rotations
- // color = 3: Red, S, 2 rotations
- // color = 4: Green, Z, 2 rotations
- // color = 5: Orange, L, 4 rotations
- // color = 6: Pink, J, 4 rotations
- // color = 7: Purple, T, 4 rotations
- int Block::getColor(){
- return color;
- }
- void Block::rotate(){
- int clr = getColor();
- if (clr == 1){
- orientation = 0;
- setCoordinates();
- } else if (clr == 2 || clr == 3 || clr == 4) {
- orientation = (orientation + 1) % 2;
- setCoordinates();
- } else {
- orientation = (orientation + 1) % 4;
- setCoordinates();
- }
- }
- void Block::setCoordinates(){
- int clr = getColor();
- for (int i = 0; i < 4; i++){
- old_coords[i] = coords[i];
- }
- if (clr == 1){
- coords[0] = pivot-9; coords[1] = pivot-8;
- coords[2] = pivot+1; coords[3] = pivot+2;
- } else if (clr == 2){
- if (orientation == 0) {
- coords[0] = pivot+10; coords[1] = pivot+11;
- coords[2] = pivot+12; coords[3] = pivot+13;
- }
- else if (orientation == 1) {
- coords[0] = pivot+2; coords[1] = pivot+12;
- coords[2] = pivot+22; coords[3] = pivot+32;
- }
- } else if (clr == 3){
- if (orientation == 0) {
- coords[0] = pivot; coords[1] = pivot+1;
- coords[2] = pivot+11; coords[3] = pivot+12;
- }
- else if (orientation == 1) {
- coords[0] = pivot+2; coords[1] = pivot+11;
- coords[2] = pivot+12; coords[3] = pivot+21;
- }
- } else if (clr == 4){
- if (orientation == 0) {
- coords[0] = pivot+1; coords[1] = pivot+2;
- coords[2] = pivot+10; coords[3] = pivot+11;
- }
- if (orientation == 1) {
- coords[0] = pivot+1; coords[1] = pivot+11;
- coords[2] = pivot+12; coords[3] = pivot+22;
- }
- } else if (clr == 5){
- if (orientation == 0) {
- coords[0] = pivot-11; coords[1] = pivot-1;
- coords[2] = pivot; coords[3] = pivot+1;
- }
- else if (orientation == 1) {
- coords[0] = pivot-10; coords[1] = pivot;
- coords[2] = pivot+9; coords[3] = pivot+10;
- }
- else if (orientation == 2) {
- coords[0] = pivot-1; coords[1] = pivot;
- coords[2] = pivot+1; coords[3] = pivot+11;
- }
- else if (orientation == 3) {
- coords[0] = pivot-10; coords[1] = pivot-9;
- coords[2] = pivot; coords[3] = pivot+10;
- }
- } else if (clr == 6){
- if (orientation == 0) {
- coords[0] = pivot-9; coords[1] = pivot-1;
- coords[2] = pivot; coords[3] = pivot+1;
- }
- else if (orientation == 1) {
- coords[0] = pivot-11; coords[1] = pivot-10;
- coords[2] = pivot; coords[3] = pivot+10;
- }
- else if (orientation == 2) {
- coords[0] = pivot-1; coords[1] = pivot;
- coords[2] = pivot+1; coords[3] = pivot+9;
- }
- else if (orientation == 3) {
- coords[0] = pivot-10; coords[1] = pivot;
- coords[2] = pivot+10; coords[3] = pivot+11;
- }
- } else {
- if (orientation == 0) {
- coords[0] = pivot-10; coords[1] = pivot-1;
- coords[2] = pivot; coords[3] = pivot+1;
- }
- else if (orientation == 1) {
- coords[0] = pivot-10; coords[1] = pivot-1;
- coords[2] = pivot; coords[3] = pivot+10;
- }
- else if (orientation == 2) {
- coords[0] = pivot-1; coords[1] = pivot;
- coords[2] = pivot+1; coords[3] = pivot+10;
- }
- else if (orientation == 3) {
- coords[0] = pivot-10; coords[1] = pivot;
- coords[2] = pivot+1; coords[3] = pivot+10;
- }
- }
- }
- int* Block::getCoordinates() {
- return coords;
- }
- int* Block::getOldCoordinates() {
- return old_coords;
- }
Add Comment
Please, Sign In to add comment