Advertisement
Suby

block.cpp

Apr 27th, 2012
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.34 KB | None | 0 0
  1. #include "SDL.h"
  2. #include "SDL_image.h"
  3. #include <string>
  4. #include "constants.h"
  5. #include "classes.h"
  6. #include "functions.h"
  7. #include "globals.h"
  8.  
  9. Block::Block()
  10. {
  11. y = -1;
  12. x = -1;
  13. ShowBlock = 0;
  14. ShapeColor = 1;
  15. }
  16.  
  17. int Block::Getx()
  18. {
  19. return x;
  20. }
  21.  
  22. int Block::Gety()
  23. {
  24. return y;
  25. }
  26.  
  27. void Block::Setx(int xvalue)
  28. {
  29. x = xvalue;
  30. }
  31.  
  32. void Block::Sety(int yvalue)
  33. {
  34. y = yvalue;
  35. }
  36.  
  37. void Block::DisplayBlocks()
  38. {
  39. if (ShowBlock == 1)
  40. {
  41. if (ShapeColor == 1)
  42. apply_surface(x, y, skyrider, screen);
  43.  
  44. if (ShapeColor == 2)
  45. apply_surface(x, y, JShapeBlock, screen);
  46.  
  47. if (ShapeColor == 3)
  48. apply_surface(x, y, LShapeBlock, screen);
  49.  
  50. if (ShapeColor == 4)
  51. apply_surface(x, y, OShapeBlock, screen);
  52.  
  53. if (ShapeColor == 5)
  54. apply_surface(x, y, ZShapeBlock, screen);
  55.  
  56. if (ShapeColor == 6)
  57. apply_surface(x, y, TShapeBlock, screen);
  58.  
  59. if (ShapeColor == 7)
  60. apply_surface(x, y, SShapeBlock, screen);
  61. }
  62. }
  63.  
  64. void Block::SetShowBlock(bool OnOff)
  65. {
  66. ShowBlock = OnOff;
  67. }
  68.  
  69. bool Block::GetShowBlock()
  70. {
  71. return ShowBlock;
  72. }
  73.  
  74. void Block::SetShapeColor(int shapecolorvalue)
  75. {
  76. ShapeColor = shapecolorvalue;
  77. }
  78.  
  79.  
  80.  
  81.  
  82. Shape::Shape()
  83. {
  84. shape = 0;
  85. RxVel = 0;
  86. LxVel = 0;
  87. yVel = 0;
  88. yVelFast = 0;
  89. LxVelFast = 0;
  90. RxVelFast = 0;
  91. FlipShape = 0;
  92. orientation = 1;
  93. Fast = 0;
  94. pause = false;
  95. restart = false;
  96. }
  97.  
  98. void Shape::SetRestart(bool restartvalue)
  99. {
  100. restart = restartvalue;
  101. }
  102.  
  103. void Shape::Rotate(Block* aBlock, Shape aShape, int maxsize)
  104. {
  105. int counter = 0;
  106. int CurrentxPosition[4] = {0};
  107. int CurrentyPosition[4] = {0};
  108. while (counter < 4)
  109. {
  110. CurrentxPosition[counter] = aBlock[aShape.GetBlockMarker(counter)].Getx();
  111. CurrentyPosition[counter] = aBlock[aShape.GetBlockMarker(counter)].Gety();
  112. counter++;
  113. }
  114.  
  115. while (FlipShape == true)
  116. {
  117. //I shape
  118. if (shape == 1)
  119. {
  120. if (orientation == 1 || orientation == 3)
  121. {
  122. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  123. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  124. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + (BLOCK_WIDTH * 2));
  125.  
  126. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  127. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  128. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  129. }
  130.  
  131. if (orientation == 2 || orientation == 4)
  132. {
  133. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  134. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  135. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  136.  
  137. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
  138. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  139. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + (BLOCK_HEIGHT * 2));
  140. }
  141.  
  142. }
  143.  
  144. //JShape
  145. if (shape == 2)
  146. {
  147. if (orientation == 1)
  148. {
  149. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  150. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  151. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  152.  
  153. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
  154. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  155. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  156. }
  157.  
  158. if (orientation == 2)
  159. {
  160. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  161. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  162. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  163.  
  164. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
  165. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
  166. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  167. }
  168.  
  169. if (orientation == 3)
  170. {
  171. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  172. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  173. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  174.  
  175. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  176. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  177. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  178. }
  179.  
  180. if (orientation == 4)
  181. {
  182. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  183. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  184. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  185.  
  186. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  187. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  188. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
  189. }
  190. }
  191.  
  192. //LShape
  193. if (shape == 3)
  194. {
  195. if (orientation == 1)
  196. {
  197. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  198. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  199. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  200.  
  201. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  202. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  203. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  204. }
  205.  
  206. if (orientation == 2)
  207. {
  208. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  209. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  210. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  211.  
  212. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
  213. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
  214. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  215. }
  216.  
  217. if (orientation == 3)
  218. {
  219. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  220. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  221. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  222.  
  223. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
  224. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  225. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  226. }
  227.  
  228. if (orientation == 4)
  229. {
  230. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  231. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  232. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  233.  
  234. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  235. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  236. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
  237. }
  238. }
  239. //skip 4 because 4 is the square with the same position every time
  240.  
  241. //ZShape
  242. if (shape == 5)
  243. {
  244. if (orientation == 1)
  245. {
  246. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  247. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  248. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  249.  
  250. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  251. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
  252. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  253. }
  254.  
  255. if (orientation == 2)
  256. {
  257. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  258. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  259. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  260.  
  261. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  262. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  263. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  264.  
  265. }
  266. if (orientation == 3)
  267. {
  268. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  269. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  270. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  271.  
  272. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  273. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
  274. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  275. }
  276.  
  277. if (orientation == 4)
  278. {
  279. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  280. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  281. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  282.  
  283. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  284. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  285. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  286.  
  287. }
  288. }
  289.  
  290. //TShape
  291. if (shape == 6)
  292. {
  293. if (orientation == 1)
  294. {
  295. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx());
  296. aBlock[aShape.GetBlockMarker(1)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx() + BLOCK_WIDTH);
  297. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx());
  298.  
  299. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety() - BLOCK_HEIGHT);
  300. aBlock[aShape.GetBlockMarker(1)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety());
  301. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety() + BLOCK_HEIGHT);
  302.  
  303. }
  304.  
  305. if (orientation == 2)
  306. {
  307. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx() - BLOCK_WIDTH);
  308. aBlock[aShape.GetBlockMarker(1)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx());
  309. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx() + BLOCK_WIDTH);
  310.  
  311. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety());
  312. aBlock[aShape.GetBlockMarker(1)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety()+ BLOCK_HEIGHT);
  313. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety());
  314. }
  315.  
  316. if (orientation == 3)
  317. {
  318. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx());
  319. aBlock[aShape.GetBlockMarker(1)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx());
  320. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx() - BLOCK_WIDTH);
  321.  
  322. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety() - BLOCK_HEIGHT);
  323. aBlock[aShape.GetBlockMarker(1)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety() + BLOCK_HEIGHT);
  324. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety());
  325. }
  326.  
  327. if (orientation == 4)
  328. {
  329. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx() + BLOCK_WIDTH);
  330. aBlock[aShape.GetBlockMarker(1)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx());
  331. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(2)].Getx() - BLOCK_WIDTH);
  332.  
  333. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety());
  334. aBlock[aShape.GetBlockMarker(1)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety() - BLOCK_HEIGHT);
  335. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(2)].Gety());
  336. }
  337. }
  338.  
  339. //SShape
  340. if (shape == 7)
  341. {
  342. if (orientation == 1)
  343. {
  344. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  345. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  346. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  347.  
  348. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
  349. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  350. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  351. }
  352.  
  353. if (orientation == 2)
  354. {
  355. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  356. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  357. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  358.  
  359. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  360. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  361. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  362. }
  363. if (orientation == 3)
  364. {
  365. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  366. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  367. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  368.  
  369. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() - BLOCK_HEIGHT);
  370. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  371. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  372. }
  373.  
  374. if (orientation == 4)
  375. {
  376. aBlock[aShape.GetBlockMarker(0)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() + BLOCK_WIDTH);
  377. aBlock[aShape.GetBlockMarker(2)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx() - BLOCK_WIDTH);
  378. aBlock[aShape.GetBlockMarker(3)].Setx(aBlock[aShape.GetBlockMarker(1)].Getx());
  379.  
  380. aBlock[aShape.GetBlockMarker(0)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety());
  381. aBlock[aShape.GetBlockMarker(2)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  382. aBlock[aShape.GetBlockMarker(3)].Sety(aBlock[aShape.GetBlockMarker(1)].Gety() + BLOCK_HEIGHT);
  383. }
  384.  
  385. }
  386. orientation++;
  387. if (orientation == 5)
  388. orientation = 1;
  389. FlipShape = false;
  390. }
  391.  
  392. int CollisionResult = -1;
  393. CollisionResult = aShape.CheckCollision(aBlock, maxsize, CurrentyPosition, CurrentxPosition);
  394. if (CollisionResult == 1)
  395. {
  396. counter = 0;
  397. while (counter < 4)
  398. {
  399. aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter]);
  400. aBlock[aShape.GetBlockMarker(counter)].Sety(CurrentyPosition[counter]);
  401. counter++;
  402. }
  403. }
  404.  
  405. if (CollisionResult == 2)
  406. {
  407. counter = 0;
  408. while (counter < 4)
  409. {
  410. aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter]);
  411. aBlock[aShape.GetBlockMarker(counter)].Sety(CurrentyPosition[counter]);
  412. counter++;
  413. }
  414. }
  415. }
  416.  
  417. bool Shape::move(Block* aBlock, Shape aShape, int maxsize)
  418. {
  419. int counter = 0;
  420. int CurrentxPosition[4] = {0};
  421. int CurrentyPosition[4] = {0};
  422. while (counter < 4)
  423. {
  424. CurrentxPosition[counter] = aBlock[aShape.GetBlockMarker(counter)].Getx();
  425. CurrentyPosition[counter] = aBlock[aShape.GetBlockMarker(counter)].Gety();
  426. counter++;
  427. }
  428.  
  429. counter = 0;
  430. while (RxVel == true)
  431. {
  432. while (counter < 4)
  433. {
  434. aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter] + BLOCK_WIDTH);
  435. counter++;
  436. }
  437. RxVel = false;
  438. }
  439.  
  440. counter = 0;
  441. while (LxVel == true)
  442. {
  443. while (counter < 4)
  444. {
  445. aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter] - BLOCK_WIDTH);
  446. counter++;
  447. }
  448. LxVel = false;
  449. }
  450.  
  451. counter = 0;
  452. while (yVel == true)
  453. {
  454. while (counter < 4)
  455. {
  456. aBlock[aShape.GetBlockMarker(counter)].Sety(CurrentyPosition[counter] + BLOCK_HEIGHT);
  457. counter++;
  458. }
  459. yVel = false;
  460. }
  461.  
  462.  
  463. //This section is to make it so if you're holding down a direction, it'll go fast in that direction.
  464. //I wasn't sure how to do this to be honest, and this is the first thing I came up with that worked.
  465. //I'm 100% sure I'm doing this in a silly way, but I'm not sure how it should be done.
  466. counter = 0;
  467. if (Fast == true)
  468. {
  469. if (LxVelFast == true)
  470. {
  471. while (counter < 4)
  472. {
  473. aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter] - BLOCK_WIDTH);
  474. counter++;
  475. }
  476. }
  477.  
  478. counter = 0;
  479. if (yVelFast == true)
  480. {
  481. while (counter < 4)
  482. {
  483. aBlock[aShape.GetBlockMarker(counter)].Sety(CurrentyPosition[counter] + BLOCK_HEIGHT);
  484. counter++;
  485. }
  486. }
  487.  
  488. counter = 0;
  489. if (RxVelFast == true)
  490. {
  491. while (counter < 4)
  492. {
  493. aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter] + BLOCK_WIDTH);
  494. counter++;
  495. }
  496. }
  497. }
  498.  
  499. int CollisionResult = -1;
  500. CollisionResult = aShape.CheckCollision(aBlock, maxsize, CurrentyPosition, CurrentxPosition);
  501. if (CollisionResult == 1)
  502. {
  503. counter = 0;
  504. while (counter < 4)
  505. {
  506. aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter]);
  507. aBlock[aShape.GetBlockMarker(counter)].Sety(CurrentyPosition[counter]);
  508. counter++;
  509. }
  510. return 0;
  511. }
  512. if (CollisionResult == 2)
  513. {
  514. counter = 0;
  515. while (counter < 4)
  516. {
  517. aBlock[aShape.GetBlockMarker(counter)].Setx(CurrentxPosition[counter]);
  518. aBlock[aShape.GetBlockMarker(counter)].Sety(CurrentyPosition[counter]);
  519. counter++;
  520. }
  521. return 1;
  522. }
  523. return 0;
  524. }
  525.  
  526. int Shape::CheckCollision(Block* aBlock, int maxsize, int* OriginalyPosition, int* OriginalxPosition)
  527. {
  528. int counter = 0;
  529. int NewxPosition[4] = {0};
  530. int NewyPosition[4] = {0};
  531. while (counter < 4)
  532. {
  533. NewxPosition[counter] = aBlock[GetBlockMarker(counter)].Getx();
  534. NewyPosition[counter] = aBlock[GetBlockMarker(counter)].Gety();
  535. counter++;
  536. }
  537. counter = 0;
  538. //Too far to right
  539. while (counter < 4)
  540. {
  541. if (NewxPosition[counter] + BLOCK_WIDTH > SCREEN_PLAYABLE_WIDTH)
  542. return 1;
  543. counter++;
  544. }
  545.  
  546. counter = 0;
  547. while (counter < 4)
  548. {
  549. if (NewxPosition[counter] < 0)
  550. return 1;
  551. counter++;
  552. }
  553.  
  554. counter = 0;
  555. //Too far down
  556. while (counter < 4)
  557. {
  558. if (NewyPosition[counter] + BLOCK_HEIGHT > SCREEN_HEIGHT)
  559. return 2;
  560. counter++;
  561. }
  562. counter = 0;
  563. int counter2 = 0;
  564. //Collision with another block
  565. while (counter < (maxsize - 1))
  566. {
  567. while (counter2 < 4){
  568. if (aBlock[counter].Getx() != -1 && counter != GetBlockMarker(0) && counter != GetBlockMarker(1) && counter != GetBlockMarker(2) && counter != GetBlockMarker(3))
  569. if (NewyPosition[counter2] == aBlock[counter].Gety())
  570. if (NewxPosition[counter2] == aBlock[counter].Getx())
  571. {
  572. counter = 0;
  573. counter2 = 0;
  574. while (counter < (maxsize - 1))
  575. {
  576. while (counter2 < 4)
  577. {
  578. if (aBlock[counter].Getx() != -1 && counter != GetBlockMarker(0) && counter != GetBlockMarker(1) && counter != GetBlockMarker(2) && counter != GetBlockMarker(3))
  579. if (OriginalyPosition[counter2] + BLOCK_HEIGHT == NewyPosition[counter2])
  580. if (OriginalyPosition[counter2] + BLOCK_HEIGHT == aBlock[counter].Gety())
  581. if (OriginalxPosition[counter2] == aBlock[counter].Getx())
  582. {
  583. return 2;
  584. }
  585. counter2++;
  586. }
  587. counter++;
  588. counter2 = 0;
  589. }
  590. return 1;
  591. }
  592. counter2++;
  593. }
  594. counter2 = 0;
  595. counter++;
  596. }
  597.  
  598. return 0;
  599. }
  600.  
  601. void Shape::SetFast(bool fastvalue)
  602. {
  603. Fast = fastvalue;
  604. if (fastvalue == 0)
  605. {
  606. LxVelFast = RxVelFast = yVelFast = 0;
  607. }
  608. }
  609.  
  610. bool Shape::GetIfKeyHeldDown()
  611. {
  612. if (LxVelFast == true || RxVelFast == true || yVelFast == true)
  613. return 1;
  614. return 0;
  615. }
  616.  
  617. void Shape::SetOrientation(int OrientationValue)
  618. {
  619. orientation = OrientationValue;
  620. }
  621.  
  622. void Shape::SetShape(int shapevalue, Block* aBlock, int maxsize)
  623. {
  624. shape = shapevalue;
  625. int counter = 0, index = 0, xvalue = 0, yvalue = 0, BlockMarkerIndex = 0,
  626.  
  627. SetOrientation(1);
  628.  
  629. //I shape
  630. if (shape == 1)
  631. {
  632. xvalue = 175;
  633. yvalue = 0;
  634. while (counter < 4)
  635. {
  636. if (index >= maxsize)
  637. index = 0;
  638. while (aBlock[index].Getx() != -1)
  639. {
  640. index++;
  641. if (index >= maxsize)
  642. index = 0;
  643. }
  644.  
  645. if (counter == 1)
  646. yvalue = BLOCK_HEIGHT;
  647. else if (counter !=1 && counter != 0)
  648. yvalue += BLOCK_HEIGHT;
  649.  
  650. aBlock[index].Setx(xvalue);
  651. aBlock[index].Sety(yvalue);
  652. aBlock[index].SetShowBlock(1);
  653. aBlock[index].SetShapeColor(1);
  654. BlockMarker[BlockMarkerIndex] = index;
  655.  
  656. BlockMarkerIndex++;
  657. index++;
  658. counter++;
  659. }
  660. }
  661.  
  662. //J Shape
  663. if (shape == 2)
  664. {
  665. xvalue = SCREEN_PLAYABLE_WIDTH / 2;
  666. yvalue = 0;
  667. while (counter < 4)
  668. {
  669. if (index >= maxsize)
  670. index = 0;
  671. while (aBlock[index].Getx() != -1)
  672. {
  673. index++;
  674. if (index >= maxsize)
  675. index = 0;
  676. }
  677.  
  678. if (counter == 1)
  679. yvalue = BLOCK_HEIGHT;
  680. else if (counter != 1 && counter != 0)
  681. yvalue += yvalue;
  682.  
  683. if (counter == 3)
  684. {
  685. xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - BLOCK_WIDTH;
  686. yvalue = BLOCK_HEIGHT * 2;
  687. }
  688. aBlock[index].Setx(xvalue);
  689. aBlock[index].Sety(yvalue);
  690. aBlock[index].SetShowBlock(1);
  691. aBlock[index].SetShapeColor(2);
  692. BlockMarker[BlockMarkerIndex] = index;
  693.  
  694. BlockMarkerIndex++;
  695. index++;
  696. counter++;
  697. }
  698. }
  699.  
  700. //L Shape
  701. if (shape == 3)
  702. {
  703. xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - BLOCK_WIDTH;
  704. yvalue = 0;
  705. while (counter < 4)
  706. {
  707. if (index >= maxsize)
  708. index = 0;
  709. while (aBlock[index].Getx() != -1)
  710. {
  711. index++;
  712. if (index >= maxsize)
  713. index = 0;
  714. }
  715.  
  716.  
  717. if (counter == 1 || counter == 2)
  718. {
  719. yvalue = 35;
  720. yvalue = yvalue * counter;
  721. }
  722.  
  723. if (counter == 3)
  724. {
  725. xvalue = (SCREEN_PLAYABLE_WIDTH / 2);
  726. yvalue = BLOCK_HEIGHT * 2;
  727. }
  728.  
  729. aBlock[index].Setx(xvalue);
  730. aBlock[index].Sety(yvalue);
  731. aBlock[index].SetShowBlock(1);
  732. aBlock[index].SetShapeColor(3);
  733. BlockMarker[BlockMarkerIndex] = index;
  734.  
  735. BlockMarkerIndex++;
  736. index++;
  737. counter++;
  738. }
  739. }
  740.  
  741. //O Shape
  742. if (shape == 4)
  743. {
  744. yvalue = 0;
  745. xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - BLOCK_WIDTH;
  746. while (counter < 4)
  747. {
  748. if (index >= maxsize)
  749. index = 0;
  750. while (aBlock[index].Getx() != -1)
  751. {
  752. index++;
  753. if (index >= maxsize)
  754. index = 0;
  755. }
  756.  
  757. if (counter == 1)
  758. xvalue = (SCREEN_PLAYABLE_WIDTH / 2);
  759.  
  760. if (counter == 2)
  761. {
  762. xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - BLOCK_WIDTH;
  763. yvalue = BLOCK_HEIGHT;
  764. }
  765.  
  766. if (counter == 3)
  767. xvalue = (SCREEN_PLAYABLE_WIDTH / 2);
  768.  
  769.  
  770. aBlock[index].Setx(xvalue);
  771. aBlock[index].Sety(yvalue);
  772. aBlock[index].SetShowBlock(1);
  773. aBlock[index].SetShapeColor(4);
  774. BlockMarker[BlockMarkerIndex] = index;
  775.  
  776. BlockMarkerIndex++;
  777. index++;
  778. counter++;
  779. }
  780. }
  781.  
  782. //Z Shape
  783. if (shape == 5)
  784. {
  785. yvalue = 0;
  786. xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - BLOCK_WIDTH;
  787. while (counter < 4)
  788. {
  789. if (index >= maxsize)
  790. index = 0;
  791. while (aBlock[index].Getx() != -1)
  792. {
  793. index++;
  794. if (index >= maxsize)
  795. index = 0;
  796. }
  797.  
  798. if (counter == 1)
  799. xvalue = (SCREEN_PLAYABLE_WIDTH / 2);
  800.  
  801. else if (counter == 2)
  802. yvalue = BLOCK_HEIGHT;
  803.  
  804. else if (counter == 3)
  805. xvalue = (SCREEN_PLAYABLE_WIDTH / 2) + BLOCK_WIDTH;
  806.  
  807. aBlock[index].Setx(xvalue);
  808. aBlock[index].Sety(yvalue);
  809. aBlock[index].SetShowBlock(1);
  810. aBlock[index].SetShapeColor(5);
  811. BlockMarker[BlockMarkerIndex] = index;
  812.  
  813. BlockMarkerIndex++;
  814. index++;
  815. counter++;
  816. }
  817.  
  818. }
  819.  
  820. //T Shape
  821. if (shape == 6)
  822. {
  823. yvalue = BLOCK_HEIGHT;
  824. xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - (BLOCK_WIDTH);
  825. while (counter < 4)
  826. {
  827. if (index >= maxsize)
  828. index = 0;
  829. while (aBlock[index].Getx() != -1)
  830. {
  831. index++;
  832. if (index >= maxsize)
  833. index = 0;
  834. }
  835.  
  836. if (counter == 1)
  837. {
  838. xvalue = (SCREEN_PLAYABLE_WIDTH / 2);
  839. yvalue = 0;
  840. }
  841.  
  842. if (counter == 2)
  843. yvalue = BLOCK_HEIGHT;
  844.  
  845. if (counter == 3)
  846. {
  847. xvalue += BLOCK_WIDTH;
  848. }
  849.  
  850. aBlock[index].Setx(xvalue);
  851. aBlock[index].Sety(yvalue);
  852. aBlock[index].SetShowBlock(1);
  853. aBlock[index].SetShapeColor(6);
  854. BlockMarker[BlockMarkerIndex] = index;
  855.  
  856. BlockMarkerIndex++;
  857. index++;
  858. counter++;
  859. }
  860. }
  861. //S Shape
  862. if (shape == 7)
  863. {
  864. yvalue = BLOCK_HEIGHT;
  865. xvalue = (SCREEN_PLAYABLE_WIDTH / 2) - BLOCK_WIDTH;
  866. while (counter < 4)
  867. {
  868. if (index >= maxsize)
  869. index = 0;
  870. while (aBlock[index].Getx() != -1)
  871. {
  872. index++;
  873. if (index >= maxsize)
  874. index = 0;
  875. }
  876.  
  877. if (counter == 1)
  878. xvalue += BLOCK_WIDTH;
  879.  
  880. if (counter == 2)
  881. yvalue = 0;
  882.  
  883. if (counter == 3)
  884. xvalue = (SCREEN_PLAYABLE_WIDTH / 2) + BLOCK_WIDTH;
  885.  
  886. aBlock[index].Setx(xvalue);
  887. aBlock[index].Sety(yvalue);
  888. aBlock[index].SetShowBlock(1);
  889. aBlock[index].SetShapeColor(7);
  890. BlockMarker[BlockMarkerIndex] = index;
  891.  
  892. BlockMarkerIndex++;
  893. index++;
  894. counter++;
  895. }
  896. }
  897. }
  898.  
  899. void Shape::SetBlockMarker(int value, int index)
  900. {
  901. BlockMarker[index] = value;
  902. }
  903.  
  904. int Shape::GetBlockMarker(int index)
  905. {
  906. return BlockMarker[index];
  907. }
  908.  
  909. bool Shape::GetRestart()
  910. {
  911. return restart;
  912. }
  913.  
  914. void Shape::handle_input()
  915. {
  916. if(event.type == SDL_KEYDOWN)
  917. {
  918. switch(event.key.keysym.sym)
  919. {
  920. case SDLK_UP: FlipShape = true; break;
  921. case SDLK_DOWN: yVel = true; yVelFast = true; break;
  922. case SDLK_LEFT: LxVel = true; LxVelFast = true; break;
  923. case SDLK_RIGHT: RxVel = true; RxVelFast = true; break;
  924. case SDLK_BACKSPACE:
  925. if (pause == true)
  926. pause = false;
  927. else
  928. pause = true;
  929. break;
  930. case SDLK_RETURN: restart = true; break;
  931. }
  932. }
  933.  
  934. //If a key was released
  935. else if(event.type == SDL_KEYUP)
  936. {
  937. //Adjust the velocity
  938. switch(event.key.keysym.sym)
  939. {
  940. case SDLK_UP: break;
  941. case SDLK_DOWN: yVelFast = false; break;
  942. case SDLK_LEFT: LxVelFast = false; break;
  943. case SDLK_RIGHT: RxVelFast = false; break;
  944. case SDLK_BACKSPACE: break;
  945. }
  946. }
  947.  
  948. }
  949.  
  950. bool Shape::MoveShapeDown(Block* aBlock, Shape aShape, int maxsize)
  951. {
  952. int counter = 0;
  953. int CurrentxPosition[4] = {0};
  954. int CurrentyPosition[4] = {0};
  955. while (counter < 4)
  956. {
  957. CurrentxPosition[counter] = aBlock[GetBlockMarker(counter)].Getx();
  958. CurrentyPosition[counter] = aBlock[GetBlockMarker(counter)].Gety();
  959. counter++;
  960. }
  961. counter = 0;
  962.  
  963. while (counter < 4)
  964. {
  965. aBlock[GetBlockMarker(counter)].Sety(CurrentyPosition[counter] + BLOCK_HEIGHT);
  966. counter++;
  967. }
  968.  
  969. //Check Collision
  970. int CollisionResult = -1;
  971. CollisionResult = CheckCollision(aBlock, maxsize, CurrentyPosition, CurrentxPosition);
  972. if (CollisionResult == 1)
  973. {
  974. counter = 0;
  975. while (counter < 4)
  976. {
  977. aBlock[GetBlockMarker(counter)].Setx(CurrentxPosition[counter]);
  978. aBlock[GetBlockMarker(counter)].Sety(CurrentyPosition[counter]);
  979. counter++;
  980. }
  981. return 0;
  982. }
  983. if (CollisionResult == 2)
  984. {
  985. counter = 0;
  986. while (counter < 4)
  987. {
  988. aBlock[GetBlockMarker(counter)].Setx(CurrentxPosition[counter]);
  989. aBlock[GetBlockMarker(counter)].Sety(CurrentyPosition[counter]);
  990. counter++;
  991. }
  992. return 1;
  993. }
  994. return 0;
  995. }
  996.  
  997. void Shape::SpawnNewShapeIfNeeded(bool &SpawnShapeAnswer, Block* aBlock, int maxsize, int &nextblockshape, int &linesclearedint, int &scorevalue)
  998. {
  999. if (SpawnShapeAnswer == true)
  1000. {
  1001. SetShape(nextblockshape, aBlock, maxsize);
  1002. nextblockshape = 1 + (rand() % 6);
  1003. CheckForLine(aBlock, maxsize, linesclearedint, scorevalue);
  1004. SetFast(0);
  1005. }
  1006. SpawnShapeAnswer = 0;
  1007. }
  1008.  
  1009. void Shape::SpawnNextShapeInSidebar(int shapevalue, Block* aBlock)
  1010. {
  1011. shape = shapevalue;
  1012. int counter = 0, index = 0, xvalue = 0, yvalue = 0, BlockMarkerIndex = 0;
  1013.  
  1014. //I shape
  1015. if (shape == 1)
  1016. {
  1017. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2);
  1018. yvalue = 0;
  1019. while (counter < 4)
  1020. {
  1021. if (counter == 1)
  1022. yvalue = BLOCK_HEIGHT;
  1023. else if (counter !=1 && counter != 0)
  1024. yvalue += BLOCK_HEIGHT;
  1025.  
  1026. aBlock[index].Setx(xvalue);
  1027. aBlock[index].Sety(yvalue);
  1028. aBlock[index].SetShowBlock(1);
  1029. aBlock[index].SetShapeColor(1);
  1030. BlockMarker[BlockMarkerIndex] = index;
  1031.  
  1032. BlockMarkerIndex++;
  1033. index++;
  1034. counter++;
  1035. }
  1036. }
  1037.  
  1038. //J Shape
  1039. if (shape == 2)
  1040. {
  1041. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2);
  1042. yvalue = 0;
  1043. while (counter < 4)
  1044. {
  1045. if (counter == 1)
  1046. yvalue = BLOCK_HEIGHT;
  1047. else if (counter != 1 && counter != 0)
  1048. yvalue += yvalue;
  1049.  
  1050. if (counter == 3)
  1051. {
  1052. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) - BLOCK_WIDTH;
  1053. yvalue = BLOCK_HEIGHT * 2;
  1054. }
  1055. aBlock[index].Setx(xvalue);
  1056. aBlock[index].Sety(yvalue);
  1057. aBlock[index].SetShowBlock(1);
  1058. aBlock[index].SetShapeColor(2);
  1059. BlockMarker[BlockMarkerIndex] = index;
  1060.  
  1061. BlockMarkerIndex++;
  1062. index++;
  1063. counter++;
  1064. }
  1065. }
  1066.  
  1067. //L Shape
  1068. if (shape == 3)
  1069. {
  1070. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2);
  1071. yvalue = 0;
  1072. while (counter < 4)
  1073. {
  1074. if (counter == 1 || counter == 2)
  1075. {
  1076. yvalue = 35;
  1077. yvalue = yvalue * counter;
  1078. }
  1079.  
  1080. if (counter == 3)
  1081. {
  1082. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) + BLOCK_WIDTH;
  1083. yvalue = BLOCK_HEIGHT * 2;
  1084. }
  1085.  
  1086. aBlock[index].Setx(xvalue);
  1087. aBlock[index].Sety(yvalue);
  1088. aBlock[index].SetShowBlock(1);
  1089. aBlock[index].SetShapeColor(3);
  1090. BlockMarker[BlockMarkerIndex] = index;
  1091.  
  1092. BlockMarkerIndex++;
  1093. index++;
  1094. counter++;
  1095. }
  1096. }
  1097.  
  1098. //O Shape
  1099. if (shape == 4)
  1100. {
  1101. yvalue = 0;
  1102. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - BLOCK_WIDTH;
  1103. while (counter < 4)
  1104. {
  1105. if (counter == 1)
  1106. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH;
  1107.  
  1108. if (counter == 2)
  1109. {
  1110. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - BLOCK_WIDTH;
  1111. yvalue = BLOCK_HEIGHT;
  1112. }
  1113.  
  1114. if (counter == 3)
  1115. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH;
  1116.  
  1117.  
  1118. aBlock[index].Setx(xvalue);
  1119. aBlock[index].Sety(yvalue);
  1120. aBlock[index].SetShowBlock(1);
  1121. aBlock[index].SetShapeColor(4);
  1122. BlockMarker[BlockMarkerIndex] = index;
  1123.  
  1124. BlockMarkerIndex++;
  1125. index++;
  1126. counter++;
  1127. }
  1128. }
  1129.  
  1130. //Z Shape
  1131. if (shape == 5)
  1132. {
  1133. yvalue = 0;
  1134. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) - BLOCK_WIDTH;
  1135. while (counter < 4)
  1136. {
  1137. if (counter == 1)
  1138. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2);
  1139.  
  1140. else if (counter == 2)
  1141. yvalue = BLOCK_HEIGHT;
  1142.  
  1143. else if (counter == 3)
  1144. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) + BLOCK_WIDTH;
  1145.  
  1146. aBlock[index].Setx(xvalue);
  1147. aBlock[index].Sety(yvalue);
  1148. aBlock[index].SetShowBlock(1);
  1149. aBlock[index].SetShapeColor(5);
  1150. BlockMarker[BlockMarkerIndex] = index;
  1151.  
  1152. BlockMarkerIndex++;
  1153. index++;
  1154. counter++;
  1155. }
  1156.  
  1157. }
  1158.  
  1159. //T Shape
  1160. if (shape == 6)
  1161. {
  1162. yvalue = BLOCK_HEIGHT;
  1163. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) - (BLOCK_WIDTH);
  1164. while (counter < 4)
  1165. {
  1166. if (counter == 1)
  1167. {
  1168. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2);
  1169. yvalue = 0;
  1170. }
  1171.  
  1172. if (counter == 2)
  1173. yvalue = BLOCK_HEIGHT;
  1174.  
  1175. if (counter == 3)
  1176. {
  1177. xvalue += BLOCK_WIDTH;
  1178. }
  1179.  
  1180. aBlock[index].Setx(xvalue);
  1181. aBlock[index].Sety(yvalue);
  1182. aBlock[index].SetShowBlock(1);
  1183. aBlock[index].SetShapeColor(6);
  1184. BlockMarker[BlockMarkerIndex] = index;
  1185.  
  1186. BlockMarkerIndex++;
  1187. index++;
  1188. counter++;
  1189. }
  1190. }
  1191.  
  1192. //S Shape
  1193. if (shape == 7)
  1194. {
  1195. yvalue = BLOCK_HEIGHT;
  1196. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) - BLOCK_WIDTH;
  1197. while (counter < 4)
  1198. {
  1199. if (counter == 1)
  1200. xvalue += BLOCK_WIDTH;
  1201.  
  1202. if (counter == 2)
  1203. yvalue = 0;
  1204.  
  1205. if (counter == 3)
  1206. xvalue = ((SCREEN_WIDTH - SCREEN_PLAYABLE_WIDTH) / 2) + SCREEN_PLAYABLE_WIDTH - (BLOCK_WIDTH / 2) + BLOCK_WIDTH;
  1207.  
  1208. aBlock[index].Setx(xvalue);
  1209. aBlock[index].Sety(yvalue);
  1210. aBlock[index].SetShowBlock(1);
  1211. aBlock[index].SetShapeColor(7);
  1212. BlockMarker[BlockMarkerIndex] = index;
  1213.  
  1214. BlockMarkerIndex++;
  1215. index++;
  1216. counter++;
  1217. }
  1218. }
  1219. }
  1220.  
  1221. bool Shape::GetPause()
  1222. {
  1223. return pause;
  1224. }
  1225.  
  1226. void Shape::SetPause(bool pausevalue)
  1227. {
  1228. pause = pausevalue;
  1229. }
  1230.  
  1231. bool Shape::CheckGameOver(Block* aBlock, int maxsize)
  1232. {
  1233. int counter = 0;
  1234. int counter2 = 0;
  1235. int CurrentxPosition[4] = {0};
  1236. int CurrentyPosition[4] = {0};
  1237. while (counter < 4)
  1238. {
  1239. CurrentxPosition[counter] = aBlock[GetBlockMarker(counter)].Getx();
  1240. CurrentyPosition[counter] = aBlock[GetBlockMarker(counter)].Gety();
  1241. counter++;
  1242. }
  1243. counter = 0;
  1244.  
  1245. while (counter < (maxsize - 1))
  1246. {
  1247. while (counter2 < 4){
  1248. if (aBlock[counter].Getx() != -1 && counter != GetBlockMarker(0) && counter != GetBlockMarker(1) && counter != GetBlockMarker(2) && counter != GetBlockMarker(3))
  1249. if (aBlock[counter].Gety() == 0)
  1250. return 1;
  1251. counter2++;
  1252. }
  1253. counter2 = 0;
  1254. counter++;
  1255. }
  1256. return 0;
  1257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement