You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

272 lines
4.6 KiB

  1. /*
  2. * $Id: cacatris.h 1 2006-09-22 16:56:18Z jylam $
  3. *
  4. * This program is free software. It commes without any warranty, to
  5. * the extent permitted by applicable law. You can redistribute it
  6. * and/or modify it under the terms of the Do What The Fuck You Want
  7. * To Public License, Version 2, as published by Sam Hocevar. See
  8. * http://sam.zoy.org/wtfpl/COPYING for more details.
  9. */
  10. #ifndef __CACATRIS_H_
  11. #define __CACATRIS_H_
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <math.h>
  16. #ifndef M_PI
  17. # define M_PI 3.14159265358979323846
  18. #endif
  19. #include "cucul.h"
  20. #include "caca.h"
  21. #define INFO_WIDTH 20
  22. #define FIELD_WIDTH 10
  23. #define FIELD_HEIGHT 20
  24. #define FIELD_CANVAS_WIDTH 20
  25. #define FIELD_CANVAS_HEIGHT 20
  26. #define LEVEL_COUNT 11
  27. unsigned int points[LEVEL_COUNT*4] = {
  28. 40, 80, 120, 160, 200, 240, 280, 320, 360, 400, 440,
  29. 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100,
  30. 300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300,
  31. 1200, 2400, 3600, 4800, 6000, 7200, 8400, 9600, 10800, 12000, 13200
  32. };
  33. unsigned char playfield[FIELD_WIDTH*FIELD_HEIGHT];
  34. static cucul_canvas_t *field, *infos, *screen;
  35. unsigned int blocks_palette[] = {
  36. CUCUL_BLUE,
  37. CUCUL_GREEN,
  38. CUCUL_CYAN,
  39. CUCUL_RED,
  40. CUCUL_MAGENTA,
  41. CUCUL_BROWN,
  42. CUCUL_LIGHTGRAY
  43. };
  44. typedef struct piece_t_ {
  45. unsigned int w, h;
  46. unsigned int color;
  47. unsigned int data[4*4];
  48. } piece_t;
  49. void infos_populate(cucul_canvas_t *, unsigned int, unsigned char , unsigned char);
  50. void playfield_draw(cucul_canvas_t *);
  51. void put_piece(unsigned int, unsigned int, unsigned int, unsigned int);
  52. void remove_piece(unsigned int id, unsigned int x, unsigned int y, unsigned int rot);
  53. unsigned char movable(unsigned int id, int x, int y, unsigned int rot);
  54. unsigned char has_landed(unsigned int id, unsigned int x, unsigned int y, unsigned int rot);
  55. unsigned char maybe_remove_line(void);
  56. piece_t pieces[] = {
  57. /* I, rot 0*/
  58. {4,1,
  59. 1,
  60. {1,1,1,1,
  61. 0,0,0,0,
  62. 0,0,0,0,
  63. 0,0,0,0}},
  64. /* I, rot 1*/
  65. {1,4,
  66. 1,
  67. {1,0,0,0,
  68. 1,0,0,0,
  69. 1,0,0,0,
  70. 1,0,0,0}},
  71. /* I, rot 2*/
  72. {4,1,
  73. 1,
  74. {1,1,1,1,
  75. 0,0,0,0,
  76. 0,0,0,0,
  77. 0,0,0,0}},
  78. /* I, rot 3*/
  79. {1,4,
  80. 1,
  81. {1,0,0,0,
  82. 1,0,0,0,
  83. 1,0,0,0,
  84. 1,0,0,0}},
  85. /* J, rot 0*/
  86. {3,2,
  87. 2,
  88. {1,0,0,0,
  89. 1,1,1,0,
  90. 0,0,0,0,
  91. 0,0,0,0}},
  92. /* J, rot 1*/
  93. {2,3,
  94. 2,
  95. {1,1,0,0,
  96. 1,0,0,0,
  97. 1,0,0,0,
  98. 0,0,0,0}},
  99. /* J, rot 2*/
  100. {3,2,
  101. 2,
  102. {1,1,1,0,
  103. 0,0,1,0,
  104. 0,0,0,0,
  105. 0,0,0,0}},
  106. /* J, rot 3*/
  107. {2,3,
  108. 2,
  109. {0,1,0,0,
  110. 0,1,0,0,
  111. 1,1,0,0,
  112. 0,0,0,0}},
  113. /* L, rot 0*/
  114. {3,2,
  115. 3,
  116. {0,0,1,0,
  117. 1,1,1,0,
  118. 0,0,0,0,
  119. 0,0,0,0}},
  120. /* L, rot 1*/
  121. {2,3,
  122. 3,
  123. {1,0,0,0,
  124. 1,0,0,0,
  125. 1,1,0,0,
  126. 0,0,0,0}},
  127. /* L, rot 2*/
  128. {3,2,
  129. 3,
  130. {1,1,1,0,
  131. 1,0,0,0,
  132. 0,0,0,0,
  133. 0,0,0,0}},
  134. /* L, rot 3*/
  135. {2,3,
  136. 3,
  137. {1,1,0,0,
  138. 0,1,0,0,
  139. 0,1,0,0,
  140. 0,0,0,0}},
  141. /* O, rot 0*/
  142. {2,2,
  143. 4,
  144. {1,1,0,0,
  145. 1,1,0,0,
  146. 0,0,0,0,
  147. 0,0,0,0}},
  148. /* O, rot 1*/
  149. {2,2,
  150. 4,
  151. {1,1,0,0,
  152. 1,1,0,0,
  153. 0,0,0,0,
  154. 0,0,0,0}},
  155. /* O, rot 2*/
  156. {2,2,
  157. 4,
  158. {1,1,0,0,
  159. 1,1,0,0,
  160. 0,0,0,0,
  161. 0,0,0,0}},
  162. /* O, rot 3*/
  163. {2,2,
  164. 4,
  165. {1,1,0,0,
  166. 1,1,0,0,
  167. 0,0,0,0,
  168. 0,0,0,0}},
  169. /* S, rot 0*/
  170. {3,2,
  171. 5,
  172. {0,1,1,0,
  173. 1,1,0,0,
  174. 0,0,0,0,
  175. 0,0,0,0}},
  176. /* S, rot 1*/
  177. {2,3,
  178. 5,
  179. {1,0,0,0,
  180. 1,1,0,0,
  181. 0,1,0,0,
  182. 0,0,0,0}},
  183. /* S, rot 2*/
  184. {3,2,
  185. 5,
  186. {0,1,1,0,
  187. 1,1,0,0,
  188. 0,0,0,0,
  189. 0,0,0,0}},
  190. /* S, rot 3*/
  191. {2,3,
  192. 5,
  193. {1,0,0,0,
  194. 1,1,0,0,
  195. 0,1,0,0,
  196. 0,0,0,0}},
  197. /* T, rot 0*/
  198. {3,2,
  199. 6,
  200. {0,1,0,0,
  201. 1,1,1,0,
  202. 0,0,0,0,
  203. 0,0,0,0}},
  204. /* T, rot 1*/
  205. {2,3,
  206. 6,
  207. {1,0,0,0,
  208. 1,1,0,0,
  209. 1,0,0,0,
  210. 0,0,0,0}},
  211. /* T, rot 2*/
  212. {3,2,
  213. 6,
  214. {1,1,1,0,
  215. 0,1,0,0,
  216. 0,0,0,0,
  217. 0,0,0,0}},
  218. /* T, rot 3*/
  219. {2,3,
  220. 6,
  221. {0,1,0,0,
  222. 1,1,0,0,
  223. 0,1,0,0,
  224. 0,0,0,0}},
  225. /* Z, rot 0*/
  226. {3,2,
  227. 7,
  228. {1,1,0,0,
  229. 0,1,1,0,
  230. 0,0,0,0,
  231. 0,0,0,0}},
  232. /* Z, rot 1*/
  233. {2,3,
  234. 7,
  235. {0,1,0,0,
  236. 1,1,0,0,
  237. 1,0,0,0,
  238. 0,0,0,0}},
  239. /* Z, rot 2*/
  240. {3,2,
  241. 7,
  242. {1,1,0,0,
  243. 0,1,1,0,
  244. 0,0,0,0,
  245. 0,0,0,0}},
  246. /* Z, rot 3*/
  247. {2,3,
  248. 7,
  249. {0,1,0,0,
  250. 1,1,0,0,
  251. 1,0,0,0,
  252. 0,0,0,0}},
  253. };
  254. #endif /* __CACATRIS_H_ */