blockbattle.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. -- title: blockbattle
  2. -- author: pixelbath
  3. -- desc: a falling blocks game totally not inspired by anything previous
  4. -- script: lua
  5. t=0
  6. local pieces = {
  7. {
  8. {
  9. {0, 0, 0, 0},
  10. {1, 1, 1, 1},
  11. {0, 0, 0, 0},
  12. {0, 0, 0, 0},
  13. },
  14. {
  15. {0, 1, 0, 0},
  16. {0, 1, 0, 0},
  17. {0, 1, 0, 0},
  18. {0, 1, 0, 0},
  19. },
  20. },
  21. {
  22. {
  23. {0, 0, 0, 0},
  24. {0, 4, 4, 0},
  25. {0, 4, 4, 0},
  26. {0, 0, 0, 0},
  27. },
  28. },
  29. {
  30. {
  31. {0, 0, 0, 0},
  32. {2, 2, 2, 0},
  33. {0, 0, 2, 0},
  34. {0, 0, 0, 0},
  35. },
  36. {
  37. {0, 2, 0, 0},
  38. {0, 2, 0, 0},
  39. {2, 2, 0, 0},
  40. {0, 0, 0, 0},
  41. },
  42. {
  43. {2, 0, 0, 0},
  44. {2, 2, 2, 0},
  45. {0, 0, 0, 0},
  46. {0, 0, 0, 0},
  47. },
  48. {
  49. {0, 2, 2, 0},
  50. {0, 2, 0, 0},
  51. {0, 2, 0, 0},
  52. {0, 0, 0, 0},
  53. },
  54. },
  55. {
  56. {
  57. {0, 0, 0, 0},
  58. {3, 3, 3, 0},
  59. {3, 0, 0, 0},
  60. {0, 0, 0, 0},
  61. },
  62. {
  63. {0, 3, 0, 0},
  64. {0, 3, 0, 0},
  65. {0, 3, 3, 0},
  66. {0, 0, 0, 0},
  67. },
  68. {
  69. {0, 0, 3, 0},
  70. {3, 3, 3, 0},
  71. {0, 0, 0, 0},
  72. {0, 0, 0, 0},
  73. },
  74. {
  75. {3, 3, 0, 0},
  76. {0, 3, 0, 0},
  77. {0, 3, 0, 0},
  78. {0, 0, 0, 0},
  79. },
  80. },
  81. {
  82. {
  83. {0, 0, 0, 0},
  84. {5, 5, 5, 0},
  85. {0, 5, 0, 0},
  86. {0, 0, 0, 0},
  87. },
  88. {
  89. {0, 5, 0, 0},
  90. {0, 5, 5, 0},
  91. {0, 5, 0, 0},
  92. {0, 0, 0, 0},
  93. },
  94. {
  95. {0, 5, 0, 0},
  96. {5, 5, 5, 0},
  97. {0, 0, 0, 0},
  98. {0, 0, 0, 0},
  99. },
  100. {
  101. {0, 5, 0, 0},
  102. {5, 5, 0, 0},
  103. {0, 5, 0, 0},
  104. {0, 0, 0, 0},
  105. },
  106. },
  107. {
  108. {
  109. {0, 0, 0, 0},
  110. {0, 6, 6, 0},
  111. {6, 6, 0, 0},
  112. {0, 0, 0, 0},
  113. },
  114. {
  115. {6, 0, 0, 0},
  116. {6, 6, 0, 0},
  117. {0, 6, 0, 0},
  118. {0, 0, 0, 0},
  119. },
  120. },
  121. {
  122. {
  123. {0, 0, 0, 0},
  124. {7, 7, 0, 0},
  125. {0, 7, 7, 0},
  126. {0, 0, 0, 0},
  127. },
  128. {
  129. {0, 7, 0, 0},
  130. {7, 7, 0, 0},
  131. {7, 0, 0, 0},
  132. {0, 0, 0, 0},
  133. },
  134. },
  135. }
  136. local board = {}
  137. local pieceType = 1
  138. local pieceRotation = 1
  139. local piece_x = 3
  140. local piece_y = 0
  141. function init_board()
  142. for y = 1, 20 do
  143. board[y] = {}
  144. for x = 1, 10 do
  145. board[y][x] = 0
  146. end
  147. end
  148. end
  149. function draw_piece()
  150. for y = 1, 4 do
  151. for x = 1, 4 do
  152. local block = pieces[pieceType][pieceRotation][y][x]
  153. if block ~= 0 then
  154. local blockSize = 8
  155. local blockDrawSize = blockSize - 1
  156. rect(
  157. (x - 1) * blockSize,
  158. (y - 1) * blockSize,
  159. blockDrawSize,
  160. blockDrawSize,
  161. 4
  162. )
  163. end
  164. end
  165. end
  166. end
  167. function handle_input()
  168. if btnp(4) then
  169. pieceRotation = pieceRotation + 1
  170. if pieceRotation > #pieces[pieceType] then
  171. pieceRotation = 1
  172. end
  173. end
  174. if btnp(5) then
  175. pieceRotation = pieceRotation - 1
  176. if pieceRotation < 1 then
  177. pieceRotation = #pieces[pieceType]
  178. end
  179. end
  180. end
  181. function TIC()
  182. handle_input()
  183. cls(0)
  184. draw_piece()
  185. end
  186. -- <PALETTE>
  187. -- 000:140c1c44243430346d4e4a4e854c30346524d04648757161597dced27d2c8595a16daa2cd2aa996dc2cadad45edeeed6
  188. -- </PALETTE>