Guest User

Untitled

a guest
Jan 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. #include "block.h"
  2. #include "Arduino.h"
  3.  
  4. Block::Block(){
  5. orientation = 0;
  6. old_coords = new int[4];
  7. coords = new int[4];
  8. color = 1;
  9. pivot = 213;
  10. }
  11.  
  12. Block::Block(int clr){
  13. orientation = 0;
  14. old_coords = new int[4];
  15. coords = new int[4];
  16. color = clr;
  17. pivot = 213;
  18. }
  19.  
  20. // color = 1: Yellow, Square, no rotations
  21. // color = 2: Blue, Stick, 2 rotations
  22. // color = 3: Red, S, 2 rotations
  23. // color = 4: Green, Z, 2 rotations
  24. // color = 5: Orange, L, 4 rotations
  25. // color = 6: Pink, J, 4 rotations
  26. // color = 7: Purple, T, 4 rotations
  27.  
  28.  
  29. int Block::getColor(){
  30. return color;
  31. }
  32.  
  33. void Block::rotate(){
  34. int clr = getColor();
  35. if (clr == 1){
  36. orientation = 0;
  37. setCoordinates();
  38. } else if (clr == 2 || clr == 3 || clr == 4) {
  39. orientation = (orientation + 1) % 2;
  40. setCoordinates();
  41. } else {
  42. orientation = (orientation + 1) % 4;
  43. setCoordinates();
  44. }
  45. }
  46.  
  47.  
  48. void Block::setCoordinates(){
  49. int clr = getColor();
  50. for (int i = 0; i < 4; i++){
  51. old_coords[i] = coords[i];
  52. }
  53. if (clr == 1){
  54. coords[0] = pivot-9; coords[1] = pivot-8;
  55. coords[2] = pivot+1; coords[3] = pivot+2;
  56. } else if (clr == 2){
  57. if (orientation == 0) {
  58. coords[0] = pivot+10; coords[1] = pivot+11;
  59. coords[2] = pivot+12; coords[3] = pivot+13;
  60. }
  61. else if (orientation == 1) {
  62. coords[0] = pivot+2; coords[1] = pivot+12;
  63. coords[2] = pivot+22; coords[3] = pivot+32;
  64. }
  65. } else if (clr == 3){
  66. if (orientation == 0) {
  67. coords[0] = pivot; coords[1] = pivot+1;
  68. coords[2] = pivot+11; coords[3] = pivot+12;
  69. }
  70. else if (orientation == 1) {
  71. coords[0] = pivot+2; coords[1] = pivot+11;
  72. coords[2] = pivot+12; coords[3] = pivot+21;
  73. }
  74. } else if (clr == 4){
  75. if (orientation == 0) {
  76. coords[0] = pivot+1; coords[1] = pivot+2;
  77. coords[2] = pivot+10; coords[3] = pivot+11;
  78. }
  79. if (orientation == 1) {
  80. coords[0] = pivot+1; coords[1] = pivot+11;
  81. coords[2] = pivot+12; coords[3] = pivot+22;
  82. }
  83. } else if (clr == 5){
  84. if (orientation == 0) {
  85. coords[0] = pivot-11; coords[1] = pivot-1;
  86. coords[2] = pivot; coords[3] = pivot+1;
  87. }
  88. else if (orientation == 1) {
  89. coords[0] = pivot-10; coords[1] = pivot;
  90. coords[2] = pivot+9; coords[3] = pivot+10;
  91. }
  92. else if (orientation == 2) {
  93. coords[0] = pivot-1; coords[1] = pivot;
  94. coords[2] = pivot+1; coords[3] = pivot+11;
  95. }
  96. else if (orientation == 3) {
  97. coords[0] = pivot-10; coords[1] = pivot-9;
  98. coords[2] = pivot; coords[3] = pivot+10;
  99. }
  100. } else if (clr == 6){
  101. if (orientation == 0) {
  102. coords[0] = pivot-9; coords[1] = pivot-1;
  103. coords[2] = pivot; coords[3] = pivot+1;
  104. }
  105. else if (orientation == 1) {
  106. coords[0] = pivot-11; coords[1] = pivot-10;
  107. coords[2] = pivot; coords[3] = pivot+10;
  108. }
  109. else if (orientation == 2) {
  110. coords[0] = pivot-1; coords[1] = pivot;
  111. coords[2] = pivot+1; coords[3] = pivot+9;
  112. }
  113. else if (orientation == 3) {
  114. coords[0] = pivot-10; coords[1] = pivot;
  115. coords[2] = pivot+10; coords[3] = pivot+11;
  116. }
  117. } else {
  118. if (orientation == 0) {
  119. coords[0] = pivot-10; coords[1] = pivot-1;
  120. coords[2] = pivot; coords[3] = pivot+1;
  121. }
  122. else if (orientation == 1) {
  123. coords[0] = pivot-10; coords[1] = pivot-1;
  124. coords[2] = pivot; coords[3] = pivot+10;
  125. }
  126. else if (orientation == 2) {
  127. coords[0] = pivot-1; coords[1] = pivot;
  128. coords[2] = pivot+1; coords[3] = pivot+10;
  129. }
  130. else if (orientation == 3) {
  131. coords[0] = pivot-10; coords[1] = pivot;
  132. coords[2] = pivot+1; coords[3] = pivot+10;
  133. }
  134. }
  135. }
  136.  
  137. int* Block::getCoordinates() {
  138. return coords;
  139. }
  140.  
  141. int* Block::getOldCoordinates() {
  142. return old_coords;
  143. }
Add Comment
Please, Sign In to add comment