Advertisement
Guest User

Tetris computer craft

a guest
Mar 17th, 2013
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. term.clear()
  2. sleep(0.1)
  3. wt = 0
  4. width, height = term.getSize()
  5. width = width/2
  6. height = height/2
  7. os.pullEvent = os.pullEventRaw
  8. function blockstart()
  9. -- Telling it to draw the shape
  10. term.setCursorPos(spw1, sph1)
  11. write("#")
  12. term.setCursorPos(spw2, sph2)
  13. write("#")
  14. term.setCursorPos(spw3, sph3)
  15. write("#")
  16. term.setCursorPos(spw4, sph4)
  17. write("#")
  18. end
  19. function newblock()
  20. --Setting Rotation to 1
  21. rot = 1
  22. -- Shape
  23. local bshape = math.ceil(math.random(0,3))
  24. if bshape == 0 then
  25. shape = "square"
  26. end
  27. if bshape == 1 then
  28. shape = "line"
  29. end
  30. if bshape == 2 then
  31. shape = "l"
  32. end
  33. if bshape == 3 then
  34. shape="hill"
  35. end
  36. startposw = width/2
  37. startposh = 1
  38. -- setting what shapes look like
  39. if shape == "hill" then
  40. spw1 = startposw
  41. spw2 = spw1 -1
  42. spw3 = spw1 +1
  43. spw4 = spw1
  44. sph1 = startposh
  45. sph2 = sph1 -1
  46. sph3 = sph1 -1
  47. sph4 = sph1 -1
  48. blockstart()
  49. end
  50. if shape == "l" then
  51. spw1 = startposw
  52. spw2 = spw1
  53. spw3 = spw1
  54. spw4 = spw3 +1
  55. sph1 = startposh
  56. sph2 = sph1 -1
  57. sph3 = sph2 -1
  58. sph4 = sph3
  59. blockstart()
  60. end
  61. if shape == "line" then
  62. spw1 = startposw
  63. spw2 = spw1
  64. spw3 = spw1
  65. spw4 = spw1
  66. sph1 = startposh
  67. sph2 = sph1 -1
  68. sph3 = sph2 -1
  69. sph4 = sph3 -1
  70. blockstart()
  71. end
  72. if shape == "square" then
  73. spw1 = startposw
  74. spw2 = spw1 +1
  75. spw3 = spw1
  76. spw4 = spw2
  77. sph1 = startposh
  78. sph2 = sph1
  79. sph3 = sph1 -1
  80. sph4 = sph1 -1
  81. blockstart()
  82. end
  83. end
  84. function updateblock()
  85. if wt ~= 4 then
  86. wt = wt +1
  87. end
  88. if wt == 4 then
  89. sph1 = sph1 -1
  90. sph2 = sph2 -1
  91. sph3 = sph3 -1
  92. sph4 = sph4 -1
  93. blockstart()
  94. end
  95. end
  96. function rotl()
  97. if rot == 1 then
  98. rot = 4
  99. if shape == "hill" then
  100. spw3 = spw1
  101. spw1 = spw2
  102. spw4 = spw4
  103. spw2 = spw4
  104. sph3 = sph1
  105. sph1 = sph2
  106. sph4 = sph4
  107. sph2 = sph4 -1
  108. end
  109. if shape == "square" then
  110. end
  111. if shape == "line" then
  112. spw3 = spw4 -1
  113. spw2 = spw3 -1
  114. spw1 = spw2 -1
  115. spw4 = spw4
  116. sph1 = sph4
  117. sph2 = sph4
  118. sph3 = sph4
  119. sph4 = sph4
  120. end
  121. if shape == "l" then
  122. sph4 = sph2
  123. sph2 = sph3
  124. sph1 = sph3
  125. sph3 = sph3
  126. spw2 = spw3 -1
  127. spw1 = spw2 -1
  128. spw4 = spw3
  129. spw3 = spw3
  130. end
  131. end
  132. if rot == 4 then
  133. rot = 3
  134. if shape == "hill" then
  135. spw3 = spw1
  136. spw1 = spw2
  137. spw4 = spw4
  138. spw2 = spw4 +1
  139. sph3 = sph1
  140. sph1 = sph2
  141. sph2 = sph4
  142. sph4 = sph4
  143. end
  144. if shape == "square" then
  145. end
  146. if shape == "line" then
  147. spw1 = spw4
  148. spw2 = spw4
  149. spw3 = spw4
  150. spw4 = spw4
  151. sph3 = sph4 -1
  152. sph2 = sph3 -1
  153. sph1 = sph2 -1
  154. sph4 = sph4
  155. end
  156. if shape == "l" then
  157. spw4 = spw4
  158. spw3 = spw4 +1
  159. spw2 = spw3
  160. spw1 = spw3
  161. sph4 = sph4
  162. sph3 = sph4
  163. sph2 = sph4 -1
  164. sph1 = sph2 -1
  165. end
  166. end
  167. if rot == 3 then
  168. rot = 2
  169. if shape == "l" then
  170. sph4 = sph2
  171. sph2 = sph3
  172. sph1 = sph3
  173. sph3 = sph3
  174. spw2 = spw3 +1
  175. spw1 = spw2 +1
  176. spw4 = spw4
  177. spw3 = spw3
  178. end
  179. if shape == "square" then
  180. end
  181. if shape == "line" then
  182. spw3 = spw4 +1
  183. spw2 = spw3 +1
  184. spw1 = spw2 +1
  185. spw4 = spw4
  186. sph3 = sph4
  187. sph2 = sph4
  188. sph1 = sph4
  189. sph4 = sph4
  190. end
  191. if shape == "hill" then
  192. spw3 = spw1
  193. spw1 = spw2
  194. spw2 = spw4
  195. spw4 = spw4
  196. sph3 = sph1
  197. sph1 = sph4
  198. sph2 = sph4 +1
  199. sph4 = sph4
  200. end
  201. end
  202. if rot == 2 then
  203. rot = 1
  204. if shape == "square" then
  205. end
  206. if shape == "line" then
  207. spw1 = spw4
  208. spw2 = spw4
  209. spw3 = spw4
  210. spw4 = spw4
  211. spw3 = spw4 +1
  212. spw2 = spw3 +1
  213. spw1 = spw2 +1
  214. end
  215. if shape == "hill" then
  216. spw3 = spw1
  217. spw1 = spw2
  218. spw2 = spw4 -1
  219. spw4 = spw4
  220. sph3 = sph4
  221. sph2 = sph4
  222. sph1 = sph4 +1
  223. end
  224. if shape == "l" then
  225. end
  226. end
  227. end
  228. function update()
  229. updateblock()
  230. os.startTimer(.1)
  231. end
  232. newblock()
  233. timer1 = os.startTimer(.1)
  234. while true do
  235. event , varx = os.pullEvent()
  236. if event == "timer" then
  237. if varx == "timer1" then
  238. update()
  239. end
  240. end
  241. if event == "char" then
  242. if varx == "a" then
  243. rotl()
  244. end
  245. if varx == "e" then
  246. break
  247. end
  248. end
  249. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement