Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. Tab 0:
  2. --unknown ocean
  3. --markus
  4.  
  5. --init
  6. tile=0
  7. found=0
  8. fb=0
  9. v=0
  10. pos=0
  11. mode=0
  12. state=0
  13. r=0
  14. blueprint=0
  15. p = {
  16. x=16,
  17. y=16,
  18. celx=16/8,
  19. cely=16/8
  20. }
  21.  
  22. slct={
  23. n=0,
  24. x=8
  25. }
  26.  
  27. mouse={
  28. x=0,
  29. y=0,
  30. b=0
  31. }
  32. pattern = {}
  33.  
  34. Tab 1:
  35. --update
  36. music(0)
  37. function _update()
  38. p.celx = p.x/8
  39. p.cely = p.y/8
  40. if r==0 then
  41. if state==0 then
  42. update_menu()
  43. elseif state==1 then
  44. update_blueprnt()
  45. elseif state==2 then
  46. update_game()
  47. end
  48. end
  49. if state==3 then
  50. update_win()
  51. end
  52. mouse_coord()
  53. if r==1 then end_update() end
  54. end
  55.  
  56. function update_menu()
  57. if btnp(1) or mouse.b==1then
  58. random()
  59. state=1
  60. music(1)
  61. end
  62. end
  63.  
  64. function update_game()
  65. end_check()
  66. if btnp(4) then
  67. if mode!= 2 then
  68. mode+=1
  69. else mode=0 end
  70. end
  71. if mode==0 then update_move()
  72. elseif mode==1 then update_build()
  73. else update_place() end
  74. --move hotbar
  75. slct.x = slct.n*8
  76. end
  77.  
  78. function update_build()
  79. if btnp(1) then
  80. if slct.n!=4 then
  81. slct.n+=1
  82. else slct.n=0 end
  83. elseif btnp(0) then
  84. if slct.n!=0 then
  85. slct.n-=1
  86. else slct.n=4 end
  87. end
  88. end
  89.  
  90. function update_move()
  91. if btnp(5) then
  92. r=1
  93. find_pattern()
  94. if found==1 then
  95. found=0
  96. state = 3
  97. end
  98. end
  99. if btnp(0) and fget(mget(p.celx-1,p.cely),0)==false then
  100. p.x-=8
  101. sfx(4)
  102. elseif btnp(1) and fget(mget(p.celx+1,p.cely),0)==false then
  103. p.x+=8
  104. sfx(4)
  105. elseif btnp(2) and fget(mget(p.celx,p.cely-1),0)==false then
  106. p.y-=8
  107. sfx(4)
  108. elseif btnp(3) and fget(mget(p.celx,p.cely+1),0)==false then
  109. p.y+=8
  110. sfx(4)
  111. end
  112. end
  113.  
  114. function update_place()
  115. if btnp(0) then pos=0
  116. elseif btnp(1) then pos=1
  117. elseif btnp(2) then pos=2
  118. elseif btnp(3) then pos=3 end
  119.  
  120. if btnp(5) or mouse.b==1 then
  121. fb=3
  122. if pos==0 then
  123. mset(p.celx-1,p.cely,slct.n+3)
  124. sfx(3)
  125. elseif pos==1 then
  126. mset(p.celx+1,p.cely,slct.n+3)
  127. sfx(3)
  128. elseif pos==2 then
  129. mset(p.celx,p.cely-1,slct.n+3)
  130. sfx(3)
  131. elseif pos==3 then
  132. mset(p.celx,p.cely+1,slct.n+3)
  133. sfx(3)
  134. end
  135. end
  136. end
  137.  
  138. function mouse_coord()
  139. poke(0x5f2d, 1)
  140. mouse.x = stat(32)
  141. mouse.y = stat(33)
  142. mouse.b = stat(34)
  143. end
  144.  
  145. function end_check()
  146. if fget(mget(p.celx-1,p.cely),0)and
  147. fget(mget(p.celx+1,p.cely),0)and
  148. fget(mget(p.celx,p.cely-1),0)and
  149. fget(mget(p.celx,p.cely+1),0)then
  150. r=1
  151. end
  152. end
  153.  
  154. function end_update()
  155. if btnp(1) then
  156. for i=0,4 do
  157. for j=0,5 do
  158. mset(i,j,2)
  159. end
  160. end
  161. for i=0,16 do
  162. mset(i,15,18)
  163. end
  164. p.x=16
  165. p.y=16
  166. mode=0
  167. pos=0
  168. r=0
  169. slct.n=0
  170. slct.x=8
  171. mset(0,0,21)
  172. mset(1,0,22)
  173. mset(2,0,19)
  174. mset(3,0,20)
  175. mset(4,0,35)
  176. end
  177. end
  178.  
  179. function random()
  180. pattern={}
  181. for j=17,19 do
  182. for i=17,19 do
  183. tile=(flr(rnd(6))+3)
  184. if tile == 8 then
  185. tile=2
  186. end
  187. mset(i,j,tile)
  188. add(pattern,mget(i,j))
  189. end
  190. end
  191. end
  192.  
  193. function update_blueprnt()
  194. if btnp(1) then state=2 end
  195. end
  196.  
  197. function update_win()
  198. if v==1 then
  199. if btnp(1) then
  200. state = 0
  201. v=0
  202. end
  203. end
  204. end
  205.  
  206. function find_pattern()
  207. for y=1,4 do
  208. for x=0,3 do
  209. if mget(x,y)==pattern[1] then
  210. if mget(x+1,y)==pattern[2] then
  211. if mget(x+2,y)==pattern[3] then
  212. if mget(x,y+1)==pattern[4] then
  213. if mget(x+1,y+1)==pattern[5] then
  214. if mget(x+2,y+1)==pattern[6] then
  215. if mget(x,y+2)==pattern[7] then
  216. if mget(x+1,y+2)==pattern[8] then
  217. if mget(x+2,y+2)==pattern[9] then
  218. found=1
  219. end
  220. end
  221. end
  222. end
  223. end
  224. end
  225. end
  226. end
  227. end
  228. end
  229. end
  230. end
  231.  
  232. Tab 2:
  233. --draw
  234. function _draw()
  235. if state==0 then
  236. draw_menu()
  237. elseif state==1 then
  238. draw_blueprnt()
  239. elseif state==2 then
  240. draw_game()
  241. elseif state==3 then
  242. draw_game()
  243. end
  244. spr(9,mouse.x,mouse.y)
  245. end
  246.  
  247. function draw_menu()
  248. cls()
  249. rectfill(0,0,128,128,1)
  250. print("unknown ocean",40,20,0)
  251. print("press ➡️ or left click to start",3,70)
  252. end
  253.  
  254. function draw_game()
  255. cls()
  256. if fb==1 then
  257. feedback()
  258. end
  259. if fb !=0 then
  260. fb-=1
  261. end
  262. map(0,0,0,0,5,6)
  263. spr(17,slct.x,0)
  264. spr(1,p.x,p.y)
  265. if r==0 then
  266. draw_dark()
  267. if mode==0 then
  268. print("move",105,4,7)
  269. elseif mode==1 then
  270. print("select",105,4,7)
  271. else print("build",105,4,7) end
  272. end
  273. --place block
  274. if mode==2 then
  275. if r==0 then
  276. if pos==0 then
  277. spr(17,p.x-8,p.y)
  278. elseif pos==1 then
  279. spr(17,p.x+8,p.y)
  280. elseif pos==2 then
  281. spr(17,p.x,p.y-8)
  282. elseif pos==3 then
  283. spr(17,p.x,p.y+8)
  284. end
  285. end
  286. end
  287.  
  288. if state==3 and btnp(1)then
  289. v=1
  290. end
  291. if v==1 then draw_win() end
  292. end
  293.  
  294. function draw_dark()
  295. rectfill(0,8,39,47,5)
  296. end
  297.  
  298. function draw_blueprnt()
  299. cls()
  300. rectfill(0,0,128,128,1)
  301. rectfill(46,46,77,77,2)
  302. map(17,17,50,50,3,3)
  303. end
  304.  
  305. function draw_win()
  306. rectfill(0,0,128,128,1)
  307. print("you win!",50,40,0)
  308. end
  309.  
  310. function feedback()
  311. rectfill(0,0,42,50,7)
  312. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement