Chaos_Cash

minigames backup 07.01.24

Jan 7th, 2024
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.84 KB | None | 0 0
  1. --Use w/s to control player one and arrow up/down
  2. --for Player two
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11. if not fs.exists("settings") then
  12. game_settings=fs.open("settings","w")
  13. game_settings.writeLine("key")
  14. game_settings.writeLine("17")
  15. game_settings.writeLine("key")
  16. game_settings.writeLine("31")
  17. game_settings.writeLine("key")
  18. game_settings.writeLine("200")
  19. game_settings.writeLine("key")
  20. game_settings.writeLine("208")
  21. game_settings.writeLine("key")
  22. game_settings.writeLine("17")
  23. game_settings.writeLine("key")
  24. game_settings.writeLine("31")
  25. game_settings.writeLine("key")
  26. game_settings.writeLine("30")
  27. game_settings.writeLine("key")
  28. game_settings.writeLine("32")
  29. game_settings.flush()
  30. game_settings.close()
  31. end
  32.  
  33. if not fs.exists("highscore") then
  34. highscore=fs.open("highscore","w")
  35. for i=1,30 do
  36. highscore.writeLine("0")
  37. end
  38. highscore.flush()
  39. highscore.close()
  40. end
  41.  
  42.  
  43. --
  44.  
  45.  
  46. function assign_highscore()
  47. highscore=fs.open("highscore","r")
  48. pong_easy_highscore=tonumber(highscore.readLine())
  49. pong_normal_highscore=tonumber(highscore.readLine())
  50. pong_hard_highscore=tonumber(highscore.readLine())
  51. pong_extreme_highscore=tonumber(highscore.readLine())
  52. pong_insane_highscore=tonumber(highscore.readLine())
  53. click_me_easy_highscore=tonumber(highscore.readLine())
  54. click_me_normal_highscore=tonumber(highscore.readLine())
  55. click_me_hard_highscore=tonumber(highscore.readLine())
  56. click_me_extreme_highscore=tonumber(highscore.readLine())
  57. click_me_insane_highscore=tonumber(highscore.readLine())
  58. snake_easy_highscore=tonumber(highscore.readLine())
  59. snake_normal_highscore=tonumber(highscore.readLine())
  60. snake_hard_highscore=tonumber(highscore.readLine())
  61. snake_extreme_highscore=tonumber(highscore.readLine())
  62. snake_insane_highscore=tonumber(highscore.readLine())
  63. highscore.close()
  64. end
  65.  
  66.  
  67.  
  68. function assign_settings()
  69. game_settings=fs.open("settings","r")
  70. pong_p1_up_kind=game_settings.readLine()
  71. pong_p1_up_num=tonumber(game_settings.readLine())
  72. pong_p1_down_kind=game_settings.readLine()
  73. pong_p1_down_num=tonumber(game_settings.readLine())
  74. pong_p2_up_kind=game_settings.readLine()
  75. pong_p2_up_num=tonumber(game_settings.readLine())
  76. pong_p2_down_kind=game_settings.readLine()
  77. pong_p2_down_num=tonumber(game_settings.readLine())
  78. snake_up_kind=game_settings.readLine()
  79. snake_up_num=tonumber(game_settings.readLine())
  80. snake_down_kind=game_settings.readLine()
  81. snake_down_num=tonumber(game_settings.readLine())
  82. snake_left_kind=game_settings.readLine()
  83. snake_left_num=tonumber(game_settings.readLine())
  84. snake_right_kind=game_settings.readLine()
  85. snake_right_num=tonumber(game_settings.readLine())
  86. end
  87.  
  88.  
  89.  
  90. function startup_menu()
  91. term.setBackgroundColor(colors.black)
  92. term.clear()
  93. headline("Start menu")
  94. button(" Pong",16,6,25,8)
  95. button(" Exit",44,16,51,18)
  96. button(" Update",15,10,26,13)
  97. button("Click me",27,6,37,8)
  98. button("Sounds:",28,10,37,13)
  99. button("Snake",28,14,37,16)
  100. button(" Settings",15,14,26,16)
  101. term.setCursorPos(17,12)
  102. term.write("History")
  103. term.setCursorPos(31,12)
  104. term.write(sound_status.." ")
  105. b_check=false
  106. while true do
  107. pull()
  108.  
  109. if button_check(28,10,37,13) then
  110. if sound_status=="on" then
  111. sound_status="off"
  112. volume=0
  113. else
  114. sound_status="on"
  115. volume=1
  116. end
  117. term.setCursorPos(31,12)
  118. term.write(sound_status.." ")
  119. end
  120.  
  121. if button_check(15,14,26,16) then
  122. settings_pong()
  123. end
  124.  
  125. if button_check(28,14,37,16) then
  126. difficulty_menu("Snake")
  127. end
  128.  
  129. if button_check(16,6,25,8) then
  130. info_1=0
  131. player_menu()
  132. end
  133.  
  134. if button_check(44,16,51,18) then
  135. term.clear()
  136. term.setCursorPos(-1,1)
  137. error()
  138. end
  139.  
  140. if button_check(15,10,26,13) then
  141. update_history()
  142. end
  143.  
  144. if button_check(27,6,37,8) then
  145. difficulty_menu("Click me")
  146. end
  147. end
  148. end
  149.  
  150.  
  151.  
  152. function update_history()
  153. term.clear()
  154. headline("Update History")
  155. term.setCursorPos(1,4)
  156. print("1.0: Completed basic game")
  157. print("1.1: Difficulties, Better Interface, start menu")
  158. print("1.2: Singleplayer mode, Better Interface, bug fixes")
  159. print("1.3: Pong Vs bot mode, Update History, added Score")
  160. print("1.4: Added Click me, some sounds, major bug fixes")
  161. button("Home",38,16,50,18)
  162. while 1==1 do
  163. pull()
  164. if button_check(38,16,50,18) then
  165. info_1=0
  166. startup_menu()
  167. end
  168. end
  169. end
  170.  
  171.  
  172.  
  173. function settings_pong()
  174. term.clear()
  175. headline("Settings")
  176. button(" Home",44,16,51,18)
  177. term.setCursorPos(1,3)
  178. term.setTextColor(colors.red)
  179. term.write("-Pong:")
  180. button(" Up P1",2,5,12,7)
  181. button(" Down P1",14,5,26,7)
  182. button(" Up P2",2,9,12,11)
  183. button(" Down P2",14,9,26,11)
  184. button(" Next",14,17,26,19)
  185. while true do
  186. pull()
  187.  
  188. if button_check(44,16,51,18) then
  189. startup_menu()
  190. end
  191.  
  192. if button_check(2,5,12,7) then
  193. change_settings(1)
  194. end
  195.  
  196. if button_check(14,5,26,7) then
  197. change_settings(3)
  198. end
  199.  
  200. if button_check(2,9,12,11) then
  201. change_settings(5)
  202. end
  203.  
  204. if button_check(14,9,26,11) then
  205. change_settings(7)
  206. end
  207.  
  208. if button_check(14,17,26,19) then
  209. settings_snake()
  210. end
  211. end
  212. end
  213.  
  214.  
  215.  
  216.  
  217. function settings_snake()
  218. term.clear()
  219. headline("Settings")
  220. button(" Home",44,16,51,18)
  221. term.setCursorPos(1,3)
  222. term.setTextColor(colors.red)
  223. term.write("-Snake:")
  224. button(" Up",2,5,12,7)
  225. button(" Down",14,5,26,7)
  226. button(" Left",2,9,12,11)
  227. button(" Right ",14,9,26,11)
  228. button(" Last",1,17,13,19)
  229. while true do
  230. pull()
  231.  
  232. if button_check(44,16,51,18) then
  233. startup_menu()
  234. end
  235.  
  236. if button_check(2,5,12,7) then
  237. change_settings(9)
  238. end
  239.  
  240. if button_check(14,5,26,7) then
  241. change_settings(11)
  242. end
  243.  
  244. if button_check(2,9,12,11) then
  245. change_settings(13)
  246. end
  247.  
  248. if button_check(14,9,26,11) then
  249. change_settings(15)
  250. end
  251.  
  252. if button_check(1,17,13,19) then
  253. settings_pong()
  254. end
  255. end
  256. end
  257.  
  258.  
  259.  
  260. function change_settings(change_line)
  261. os.sleep(0.5)
  262. term.setTextColor(colors.red)
  263. term.setCursorPos(10,2)
  264. term.write("Please press a key ")
  265. pull()
  266. old_settings={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
  267. settings_len=(fs.attributes("settings")["size"]-6)/2
  268. cur_line=1
  269. game_settings=fs.open("settings","r")
  270. for i=1,settings_len do
  271. old_settings[cur_line]=game_settings.readLine()
  272. cur_line=cur_line+1
  273. end
  274. game_settings=fs.open("settings","w")
  275. cur_line=1
  276. for i=1,settings_len do
  277. if cur_line~=change_line then
  278. game_settings.writeLine(old_settings[cur_line])
  279. cur_line=cur_line+1
  280. else
  281. game_settings.writeLine(info_1)
  282. game_settings.writeLine(info_2)
  283. cur_line=cur_line+2
  284. end
  285. end
  286. game_settings.flush()
  287. term.setCursorPos(10,2)
  288. term.write("The new Keybind is: ")
  289. term.setTextColor(colors.green)
  290. term.write(info_1.." "..info_2)
  291. assign_settings()
  292. end
  293.  
  294.  
  295. function player_menu()
  296. is_bot=false
  297. term.clear()
  298. headline("Pong")
  299. button(" 1 Player",5,6,17,10)
  300. button(" 2 Players",19,6,31,10)
  301. button("Vs Bot",33,6,45,10)
  302. b_check=false
  303. while true do
  304. pull()
  305. if button_check(5,6,17,10) then
  306. is_bot=false
  307. info_1=0
  308. player_count=1
  309. difficulty_menu("Pong")
  310. end
  311.  
  312. if button_check(19,6,31,10) then
  313. is_bot=false
  314. info_1=0
  315. player_count=2
  316. difficulty_menu("Pong")
  317. end
  318.  
  319. if button_check(33,6,45,10) then
  320. info_1=0
  321. player_count=2
  322. is_bot=true
  323. difficulty_menu("Pong")
  324. end
  325. end
  326. end
  327.  
  328.  
  329.  
  330. function minecraft_or_craftos_pc()
  331. term.clear()
  332. term.setCursorPos(7,3)
  333. term.setTextColor(colors.white)
  334. term.write("Are you using this program in ")
  335. term.setTextColor(colors.red)
  336. term.write("minecraft")
  337. term.setTextColor(colors.white)
  338. term.setCursorPos(18,4)
  339. term.write("or ")
  340. term.setTextColor(colors.red)
  341. term.write("CraftOS-PC?")
  342.  
  343. button(" Minecraft",8,8,22,10)
  344. button(" CraftOS-PC",30,8,44,10)
  345.  
  346. while minecraft_or_pc==nil do
  347. pull()
  348.  
  349. if button_check(8,8,22,10) then
  350. minecraft_or_pc="minecraft"
  351. end
  352.  
  353. if button_check(30,8,44,10) then
  354. minecraft_or_pc="pc"
  355. end
  356. end
  357.  
  358. if minecraft_or_pc=="pc" then
  359. periphemu.create("top","speaker",1)
  360. end
  361. speaker = peripheral.wrap("top")
  362. sound_status="off"
  363. volume=0
  364. end
  365.  
  366.  
  367.  
  368. function difficulty_menu(what_game)
  369. term.clear()
  370. headline(what_game)
  371. button("Easy",8,7,18,11)
  372. button("Normal",22,7,32,11)
  373. button("Hard",36,7,46,11)
  374. button(" Extreme",22,13,32,17)
  375. button("Insane",36,13,46,17)
  376. b_check=false
  377. while true do
  378. pull()
  379.  
  380. if button_check(8,7,18,11) then
  381. game_dif="easy"
  382. if what_game=="Pong" then
  383. info_1=0
  384. bot_dif=6
  385. pong(0.13)
  386. end
  387. if what_game=="Click me" then
  388. click_me(1)
  389. end
  390. if what_game=="Snake" then
  391. snake(0.15)
  392. end
  393. end
  394.  
  395. if button_check(22,7,32,11) then
  396. game_dif="normal"
  397. if what_game=="Pong" then
  398. info_1=0
  399. bot_dif=7
  400. pong(0.1)
  401. end
  402. if what_game=="Click me" then
  403. click_me(0.8)
  404. end
  405. if what_game=="Snake" then
  406. snake(0.125)
  407. end
  408. end
  409.  
  410. if button_check(36,7,46,11) then
  411. game_dif="hard"
  412. if what_game=="Pong" then
  413. info_1=0
  414. bot_dif=8
  415. pong(0.07)
  416. end
  417. if what_game=="Click me" then
  418. click_me(0.6)
  419. end
  420. if what_game=="Snake" then
  421. snake(0.1)
  422. end
  423. end
  424.  
  425. if button_check(22,13,32,17) then
  426. game_dif="extreme"
  427. if what_game=="Pong" then
  428. info_1=0
  429. bot_dif=9
  430. pong(0.05)
  431. end
  432. if what_game=="Click me" then
  433. click_me(0.5)
  434. end
  435. if what_game=="Snake" then
  436. snake(0.075)
  437. end
  438. end
  439.  
  440. if button_check(36,13,46,17) then
  441. game_dif="insane"
  442. if what_game=="Pong" then
  443. info_1=0
  444. bot_dif=9
  445. pong(0.04)
  446. end
  447. if what_game=="Click me" then
  448. click_me(0.45)
  449. end
  450. if what_game=="Snake" then
  451. snake(0.05)
  452. end
  453. end
  454. end
  455. end
  456.  
  457.  
  458. function snake(game_speed)
  459. score=0
  460. level=1
  461. do_set_level_2=true
  462. game_running=true
  463. check_change_snake_color=0
  464. snake_len=2
  465. new_dir="up"
  466. snake_head_x=18
  467. snake_head_y=9
  468. snake_field_x1=1
  469. snake_field_y1=1
  470. snake_field_x2=36
  471. snake_field_y2=18
  472. snake_x={0,0,0,0}
  473. snake_y={0,0,0,0}
  474. do_gen_point=true
  475. term.clear()
  476. square(snake_field_x1,snake_field_y1,snake_field_x2,snake_field_y2,colors.cyan," "," ")
  477. button(" Home",44,16,51,18)
  478. print_snake()
  479. write_score()
  480. os.sleep(1)
  481. while game_running do
  482. if do_gen_point then
  483. gen_point()
  484. end
  485. print_snake()
  486. info_1=0
  487. check_snake()
  488. if do_set_level_2 and score==200 then
  489. level=2
  490. reset_snake()
  491. do_set_level_2=false
  492. line_y(12,5,14,colors.gray)
  493. line_y(24,5,14,colors.gray)
  494. new_dir="up"
  495. os.sleep(1)
  496. end
  497.  
  498. i=snake_len+1
  499. while i>0 do
  500. snake_x[i] = snake_x[i-1]
  501. snake_y[i] = snake_y[i-1]
  502. i=i-1
  503. end
  504. snake_x[1] = snake_head_x
  505. snake_y[1] = snake_head_y
  506. write_score()
  507. clear_snake()
  508. os.startTimer(game_speed)
  509. while info_1~="timer" do
  510. pull()
  511.  
  512. if button_check(44,16,51,18) then
  513. startup_menu()
  514. end
  515.  
  516. if info_1==snake_up_kind and info_2==snake_up_num and snake_dir~="down" then
  517. new_dir="up"
  518. end
  519.  
  520. if info_1==snake_down_kind and info_2==snake_down_num and snake_dir~="up" then
  521. new_dir="down"
  522. end
  523.  
  524. if info_1==snake_left_kind and info_2==snake_left_num and snake_dir~="right" then
  525. new_dir="left"
  526. end
  527.  
  528. if info_1==snake_right_kind and info_2==snake_right_num and snake_dir~="left" then
  529. new_dir="right"
  530. end
  531. end
  532. snake_dir=new_dir
  533. if snake_dir=="up" then
  534. snake_head_y=snake_head_y-1
  535. end
  536.  
  537. if snake_dir=="down" then
  538. snake_head_y=snake_head_y+1
  539. end
  540.  
  541. if snake_dir=="left" then
  542. snake_head_x=snake_head_x-1
  543. end
  544.  
  545. if snake_dir=="right" then
  546. snake_head_x=snake_head_x+1
  547. end
  548.  
  549. if snake_head_x==snake_field_x1 then
  550. snake_head_x=snake_field_x2-1
  551. end
  552.  
  553.  
  554. if snake_head_x==snake_field_x2 then
  555. snake_head_x=snake_field_x1+1
  556. end
  557.  
  558.  
  559. if snake_head_y==snake_field_y1 then
  560. snake_head_y=snake_field_y2-1
  561. end
  562.  
  563.  
  564. if snake_head_y==snake_field_y2 then
  565. snake_head_y=snake_field_y1+1
  566. end
  567. end
  568. end_snake()
  569. while true do
  570. pull()
  571. if button_check(44,16,51,18) then
  572. startup_menu()
  573. end
  574. end
  575. end
  576.  
  577.  
  578.  
  579. function end_snake()
  580.  
  581. square(snake_field_x1,snake_field_y1,snake_field_x2,snake_field_y2,colors.lightGray," "," ")
  582. if level==2 then
  583. line_y(12,5,14,colors.lightGray)
  584. line_y(24,5,14,colors.lightGray)
  585. end
  586.  
  587. i=snake_len
  588. term.setBackgroundColor(colors.lightGray)
  589. term.setCursorPos(point_pos_x,point_pos_y)
  590. term.write(" ")
  591. term.setBackgroundColor(colors.gray)
  592. while i>0 do
  593. term.setCursorPos(snake_x[i],snake_y[i])
  594. term.write(" ")
  595. i=i-1
  596. end
  597. term.setCursorPos(snake_x[1],snake_y[1])
  598. term.setBackgroundColor(colors.red)
  599. term.write(" ")
  600.  
  601. if game_dif=="easy" and score>snake_easy_highscore then
  602. broke_highscore(snake_easy_highscore,11)
  603. end
  604. if game_dif=="normal" and score>snake_normal_highscore then
  605. broke_highscore(snake_normal_highscore,12)
  606. end
  607. if game_dif=="hard" and score>snake_hard_highscore then
  608. broke_highscore(snake_hard_highscore,13)
  609. end
  610. if game_dif=="extreme" and score>snake_extreme_highscore then
  611. broke_highscore(snake_extreme_highscore,14)
  612. end
  613. if game_dif=="insane" and score>snake_insane_highscore then
  614. broke_highscore(snake_insane_highscore,15)
  615. end
  616. end
  617.  
  618.  
  619. function reset_snake()
  620. term.setBackgroundColor(colors.black)
  621. term.clear()
  622. square(snake_field_x1,snake_field_y1,snake_field_x2,snake_field_y2,colors.cyan," "," ")
  623. button(" Home",44,16,51,18)
  624. write_score()
  625. for i=1,40 do
  626. snake_x[i]=0
  627. snake_y[i]=0
  628. end
  629. snake_head_x=17
  630. snake_head_y=8
  631. snake_len=2
  632. print_snake()
  633. end
  634.  
  635.  
  636.  
  637.  
  638. function gen_point()
  639. do_for=1
  640. while do_for>0 do
  641. point_pos_x=math.random(snake_field_x1+1,snake_field_x2-1)
  642. point_pos_y=math.random(snake_field_y1+1,snake_field_y2-1)
  643. i=snake_len
  644. while i>0 do
  645. if point_pos_x==snake_x[i] and point_pos_y==snake_y[i] then
  646. do_for=do_for+2
  647. end
  648. i=i-1
  649. end
  650.  
  651. if do_for<3 and (point_pos_x==12 or point_pos_x==24) and point_pos_y<15 and point_pos_y>4 then
  652. do_for=do_for+2
  653. end
  654. do_for=do_for-1
  655. end
  656. term.setBackgroundColor(colors.yellow)
  657. term.setCursorPos(point_pos_x,point_pos_y)
  658. term.write(" ")
  659. do_gen_point=false
  660. end
  661.  
  662.  
  663.  
  664.  
  665. function check_snake()
  666. i=2
  667. while i<snake_len+1 do
  668. if snake_head_x==snake_x[i] and snake_head_y==snake_y[i] then
  669. game_running=false
  670. end
  671. i=i+1
  672. end
  673.  
  674. if level==2 then
  675. if (snake_head_x==12 or snake_head_x==24) and snake_head_y>4 and snake_head_y<15 then
  676. game_running=false
  677. end
  678. end
  679.  
  680. if snake_head_x==point_pos_x and snake_head_y==point_pos_y then
  681. snake_len=snake_len+1
  682. do_gen_point=true
  683. score=score+5
  684. end
  685. end
  686.  
  687.  
  688. function clear_snake()
  689. term.setBackgroundColor(colors.black)
  690. term.setCursorPos(snake_x[snake_len+1],snake_y[snake_len+1])
  691. term.write(" ")
  692. end
  693.  
  694.  
  695. function print_snake()
  696. term.setCursorPos(snake_head_x,snake_head_y)
  697. term.setBackgroundColor(colors.lime)
  698. term.write(" ")
  699. if check_change_snake_color>1 then
  700. term.setCursorPos(snake_x[1],snake_y[1])
  701. term.setBackgroundColor(colors.green)
  702. term.write(" ")
  703. end
  704. check_change_snake_color=check_change_snake_color+1
  705. end
  706.  
  707.  
  708.  
  709. function line_x(start_x,start_y,end_x,color)
  710. term.setBackgroundColor(color)
  711. cur_x=start_x
  712. for i=1,end_x-start_x+1 do
  713. term.setCursorPos(cur_x,start_y)
  714. term.write(" ")
  715. cur_x=cur_x+1
  716. end
  717. end
  718.  
  719.  
  720.  
  721. function line_y(start_x,start_y,end_y,color)
  722. term.setBackgroundColor(color)
  723. cur_y=start_y
  724. for i=1,end_y-start_y+1 do
  725. term.setCursorPos(start_x,cur_y)
  726. term.write(" ")
  727. cur_y=cur_y+1
  728. end
  729. end
  730.  
  731.  
  732.  
  733.  
  734.  
  735. function click_me(game_speed)
  736. term.clear()
  737. click_speed=game_speed
  738. game_time=10
  739. score=0
  740.  
  741.  
  742. while game_time~=0 do
  743. filled_square(3,3,9,6,colors.lightGray)
  744. filled_square(11,3,17,6,colors.lightGray)
  745. filled_square(19,3,25,6,colors.lightGray)
  746. filled_square(3,8,9,11,colors.lightGray)
  747. filled_square(11,8,17,11,colors.lightGray)
  748. filled_square(19,8,25,11,colors.lightGray)
  749. filled_square(3,13,9,16,colors.lightGray)
  750. filled_square(11,13,17,16,colors.lightGray)
  751. filled_square(19,13,25,16,colors.lightGray)
  752.  
  753. old_cw=cw
  754. while old_cw==cw do
  755. cw=math.random(1,9)
  756. end
  757. ct=0
  758.  
  759. if cw==1 then
  760. filled_square(3,3,9,6,colors.green)
  761. end
  762.  
  763. if cw==2 then
  764. filled_square(11,3,17,6,colors.green)
  765. end
  766.  
  767. if cw==3 then
  768. filled_square(19,3,25,6,colors.green)
  769. end
  770.  
  771. if cw==4 then
  772. filled_square(3,8,9,11,colors.green)
  773. end
  774.  
  775. if cw==5 then
  776. filled_square(11,8,17,11,colors.green)
  777. end
  778.  
  779. if cw==6 then
  780. filled_square(19,8,25,11,colors.green)
  781. end
  782.  
  783. if cw==7 then
  784. filled_square(3,13,9,16,colors.green)
  785. end
  786.  
  787. if cw==8 then
  788. filled_square(11,13,17,16,colors.green)
  789. end
  790.  
  791. if cw==9 then
  792. filled_square(19,13,25,16,colors.green)
  793. end
  794. write_score()
  795. write_lives_c()
  796. timer_number=os.startTimer(game_speed)
  797.  
  798. while info_1~="timer" and ct==0 do
  799. pull()
  800.  
  801. if button_check(3,3,9,6) then
  802. ct=1
  803. end
  804.  
  805. if button_check(11,3,17,6) then
  806. ct=2
  807. end
  808.  
  809. if button_check(19,3,25,6) then
  810. ct=3
  811. end
  812.  
  813. if button_check(3,8,9,11) then
  814. ct=4
  815. end
  816.  
  817. if button_check(11,8,17,11) then
  818. ct=5
  819. end
  820.  
  821. if button_check(19,8,25,11) then
  822. ct=6
  823. end
  824.  
  825. if button_check(3,13,9,16) then
  826. ct=7
  827. end
  828.  
  829. if button_check(11,13,17,16) then
  830. ct=8
  831. end
  832.  
  833. if button_check(19,13,25,16) then
  834. ct=9
  835. end
  836. end
  837.  
  838. if ct==cw then
  839. score=score+10
  840. speaker.playNote("bit",volume/2.5,20)
  841. else
  842. game_time=game_time-1
  843. write_lives_c()
  844. if cw==1 then
  845. filled_square(3,3,9,6,colors.red)
  846. end
  847.  
  848. if cw==2 then
  849. filled_square(11,3,17,6,colors.red)
  850. end
  851.  
  852. if cw==3 then
  853. filled_square(19,3,25,6,colors.red)
  854. end
  855.  
  856. if cw==4 then
  857. filled_square(3,8,9,11,colors.red)
  858. end
  859.  
  860. if cw==5 then
  861. filled_square(11,8,17,11,colors.red)
  862. end
  863.  
  864. if cw==6 then
  865. filled_square(19,8,25,11,colors.red)
  866. end
  867.  
  868. if cw==7 then
  869. filled_square(3,13,9,16,colors.red)
  870. end
  871.  
  872. if cw==8 then
  873. filled_square(11,13,17,16,colors.red)
  874. end
  875.  
  876. if cw==9 then
  877. filled_square(19,13,25,16,colors.red)
  878. end
  879. speaker.playNote("bit",volume,0)
  880. sleep(0.3)
  881. end
  882. os.cancelTimer(timer_number)
  883. info_1=0
  884. end
  885. sleep(0.8)
  886. term.clear()
  887. term.setCursorPos(13,9)
  888. term.write(" Your Score is: "..score)
  889. term.setTextColor(colors.white)
  890. square(11,7,34,11,colors.black,"-","|")
  891. button(" Home",44,16,51,18)
  892. button(" Play again",1,16,14,18)
  893.  
  894. if game_dif=="easy" and score>click_me_easy_highscore then
  895. broke_highscore(click_me_easy_highscore,6)
  896. end
  897. if game_dif=="normal" and score>click_me_normal_highscore then
  898. broke_highscore(click_me_normal_highscore,7)
  899. end
  900. if game_dif=="hard" and score>click_me_hard_highscore then
  901. broke_highscore(click_me_hard_highscore,8)
  902. end
  903. if game_dif=="extreme" and score>click_me_extreme_highscore then
  904. broke_highscore(click_me_extreme_highscore,9)
  905. end
  906. if game_dif=="insane" and score>click_me_insane_highscore then
  907. broke_highscore(click_me_insane_highscore,10)
  908. end
  909.  
  910. while 1==1 do
  911. pull()
  912.  
  913. if button_check(45,16,51,18) then
  914. startup_menu()
  915. end
  916.  
  917. if button_check(1,16,13,18) then
  918. click_me(click_speed)
  919. end
  920. end
  921. end
  922.  
  923.  
  924.  
  925. function write_lives_c()
  926. term.setBackgroundColor(colors.black)
  927. term.setTextColor(colors.red)
  928. term.setCursorPos(10,1)
  929. if game_time>1 then
  930. term.write(game_time.." ".."Lives left ")
  931. else
  932. term.write(game_time.." ".."Live left ")
  933. end
  934. end
  935.  
  936.  
  937.  
  938. function filled_square(fill_x1,fill_y1,fill_x2,fill_y2,fill_color)
  939. term.setBackgroundColor(fill_color)
  940. curr_fill_pos_x=fill_x1
  941. curr_fill_pos_y=fill_y1
  942. while curr_fill_pos_y~=fill_y2+1 do
  943. while curr_fill_pos_x~=fill_x2+1 do
  944. term.setCursorPos(curr_fill_pos_x,curr_fill_pos_y)
  945. term.write(" ")
  946. curr_fill_pos_x=curr_fill_pos_x+1
  947. end
  948. curr_fill_pos_x=fill_x1
  949. curr_fill_pos_y=curr_fill_pos_y+1
  950. end
  951. term.setBackgroundColor(colors.black)
  952. end
  953.  
  954.  
  955.  
  956.  
  957.  
  958. function button_check(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
  959. if info_1=="mouse_click" and info_3 > b_check_x1-1 and info_3 < b_check_x2+1 and info_4 > b_check_y1-1 and info_4 < b_check_y2+1 then
  960. return true
  961. else
  962. return false
  963. end
  964. end
  965.  
  966.  
  967.  
  968. function button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2)
  969. term.setTextColor(colors.green)
  970. square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
  971. term.setCursorPos(button_pos_x1-string.len(button_text)/2+(button_pos_x2-button_pos_x1)/2,button_pos_y1+(button_pos_y2-button_pos_y1)/2)
  972. term.write(button_text)
  973. end
  974.  
  975.  
  976.  
  977.  
  978.  
  979.  
  980. function headline(headline)
  981. headline_lenght=string.len(" "..headline.." ")
  982. headline_pos=27-headline_lenght/2
  983. term.setCursorPos(headline_pos,1)
  984. term.setBackgroundColor(colors.yellow)
  985. term.setTextColor(colors.blue)
  986. term.write(" "..headline.." ")
  987. term.setBackgroundColor(colors.black)
  988. term.setTextColor(colors.white)
  989. end
  990.  
  991.  
  992.  
  993. function reset_players()
  994. player_clear=2
  995. for i=1,12 do
  996. term.setCursorPos(2,player_clear)
  997. term.write(" ")
  998. term.setCursorPos(39,player_clear)
  999. term.write(" ")
  1000. player_clear=player_clear+1
  1001. end
  1002. pla1_a=6
  1003. pla1_b=9
  1004. pla2_a=6
  1005. pla2_b=9
  1006. player_1_pos(0)
  1007. if player_count>1 then
  1008. bot_reset=true
  1009. player_2_pos(0)
  1010. end
  1011. end
  1012.  
  1013.  
  1014.  
  1015. function reset_player_data()
  1016. player_1_lives=3
  1017. player_2_lives=3
  1018.  
  1019. player_1_pos_a=6
  1020. player_1_pos_b=8
  1021. pla1_a=player_1_pos_a
  1022. pla1_b=player_1_pos_b
  1023.  
  1024. player_2_pos_a=6
  1025. player_2_pos_b=8
  1026. pla2_a=player_2_pos_a
  1027. pla2_b=player_2_pos_b
  1028. end
  1029.  
  1030.  
  1031.  
  1032. function write_lives_p()
  1033. term.setCursorPos(1,16)
  1034. term.setTextColor(colors.red)
  1035. if player_1_lives > 1 then
  1036. term.write("Player 1: "..player_1_lives.." lives")
  1037. else
  1038. term.write("Player 1: "..player_1_lives.." live")
  1039. end
  1040. if player_count>1 then
  1041. term.setCursorPos(1,17)
  1042. if player_2_lives > 1 then
  1043. term.write("Player 2: "..player_2_lives.." lives")
  1044. else
  1045. term.write("Player 2: "..player_2_lives.." live")
  1046. end
  1047. end
  1048. term.setTextColor(colors.white)
  1049. end
  1050.  
  1051.  
  1052.  
  1053. function check_ball_pos()
  1054. if pos_x==pong_field_x1+2 then
  1055. if pos_y==pla1_a or pos_y==pla1_a+1 or pos_y==pla1_a+2 then
  1056. return true
  1057. end
  1058. end
  1059.  
  1060. if player_count>1 then
  1061. if pos_x==pong_field_x2-2 then
  1062. if pos_y==pla2_a or pos_y==pla2_a+1 or pos_y==pla2_a+2 then
  1063. return true
  1064. end
  1065. end
  1066. end
  1067. end
  1068.  
  1069.  
  1070.  
  1071. function player_bot_pos(plus_min2)
  1072. if math.random(0,10) < bot_dif+1 or bot_reset then
  1073. if plus_min2==1 then
  1074. if pla2_a~=11 then
  1075. term.setCursorPos(39,pla2_a)
  1076. print(" ")
  1077. end
  1078. else
  1079. if pla2_a~=2 then
  1080. term.setCursorPos(39,pla2_b-1)
  1081. print(" ")
  1082. end
  1083. end
  1084. term.setTextColor(colors.green)
  1085. if pla2_a~=2 or plus_min2~=-1 then
  1086. if pla2_a~=11 or plus_min2~=1 then
  1087. pla2_a=pla2_a+plus_min2
  1088. pla2_b=pla2_b+plus_min2
  1089. pos2_a=pla2_a
  1090. for i=1,3 do
  1091. term.setCursorPos(39,pos2_a)
  1092. term.write("|")
  1093. pos2_a=pos2_a+1
  1094. end
  1095. end
  1096. end
  1097. term.setTextColor(colors.white)
  1098. end
  1099. bot_reset=false
  1100. end
  1101.  
  1102.  
  1103.  
  1104. function player_2_pos(plus_min2)
  1105. if is_bot then
  1106. if do_bot_move then
  1107. do_bot_move=false
  1108. player_bot_pos(plus_min2)
  1109. end
  1110. else
  1111.  
  1112. if plus_min2==1 then
  1113. if pla2_a~=11 then
  1114. term.setCursorPos(39,pla2_a)
  1115. print(" ")
  1116. end
  1117. else
  1118. if pla2_a~=2 then
  1119. term.setCursorPos(39,pla2_b-1)
  1120. print(" ")
  1121. end
  1122. end
  1123. term.setTextColor(colors.green)
  1124. if pla2_a~=2 or plus_min2~=-1 then
  1125. if pla2_a~=11 or plus_min2~=1 then
  1126. pla2_a=pla2_a+plus_min2
  1127. pla2_b=pla2_b+plus_min2
  1128. pos2_a=pla2_a
  1129. for i=1,3 do
  1130. term.setCursorPos(39,pos2_a)
  1131. term.write("|")
  1132. pos2_a=pos2_a+1
  1133. end
  1134. end
  1135. end
  1136. term.setTextColor(colors.white)
  1137. end
  1138. end
  1139.  
  1140.  
  1141.  
  1142. function player_1_pos(plus_min)
  1143. if plus_min==1 then
  1144. if pla1_a~=11 then
  1145. term.setCursorPos(2,pla1_a)
  1146. print(" ")
  1147. end
  1148. else
  1149. if pla1_a~=2 then
  1150. term.setCursorPos(2,pla1_b-1)
  1151. print(" ")
  1152. end
  1153. end
  1154. term.setTextColor(colors.green)
  1155. if pla1_a~=2 or plus_min~=-1 then
  1156. if pla1_a~=11 or plus_min~=1 then
  1157. pla1_a=pla1_a+plus_min
  1158. pla1_b=pla1_b+plus_min
  1159. pos1_a=pla1_a
  1160. for i=1,3 do
  1161. term.setCursorPos(2,pos1_a)
  1162. term.write("|")
  1163. pos1_a=pos1_a+1
  1164. end
  1165. end
  1166. end
  1167. term.setTextColor(colors.white)
  1168. end
  1169.  
  1170.  
  1171.  
  1172. function square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
  1173. x_1=x1
  1174. y_1=y1
  1175. x_2=x2
  1176. y_2=y2
  1177. while x_1~=x2+1 do
  1178. term.setBackgroundColor(back_color_square)
  1179. term.setCursorPos(x_1,y_1)
  1180. if text_color~=nil then
  1181. term.setTextColor(text_color)
  1182. end
  1183. term.write(symbol_square_x)
  1184. x_1=x_1+1
  1185. end
  1186.  
  1187. while y_1~=y2-1 do
  1188. term.setCursorPos(x_1-1,y_1+1)
  1189. term.write(symbol_square_y)
  1190. y_1=y_1+1
  1191. end
  1192. x2=x2-1
  1193. while x_2~=x1-1 do
  1194. term.setCursorPos(x_2,y_2)
  1195. term.write(symbol_square_x)
  1196. x_2=x_2-1
  1197. end
  1198.  
  1199. while y_2~=y1+1 do
  1200. term.setCursorPos(x_2+1,y_2-1)
  1201. term.write(symbol_square_y)
  1202. y_2=y_2-1
  1203. end
  1204. term.setBackgroundColor(colors.black)
  1205. end
  1206.  
  1207.  
  1208.  
  1209. function ball()
  1210. if ball_test~=1 then
  1211. pos_x=20
  1212. pos_y=7
  1213. term.setCursorPos(pos_x,pos_y)
  1214. term.write("o")
  1215. reset_players()
  1216. sleep(1)
  1217. speaker.playNote("bit",volume*2,22)
  1218. dir_x=math.random(0,1)
  1219. dir_y=math.random(0,1)
  1220. ball_test=1
  1221. end
  1222. old_dir_x=dir_x
  1223. old_x=pos_x
  1224. old_y=pos_y
  1225.  
  1226. if dir_x==0 then
  1227. pos_x=pos_x+1
  1228. else
  1229. pos_x=pos_x-1
  1230. end
  1231.  
  1232. if dir_y==0 then
  1233. pos_y=pos_y+1
  1234. else
  1235. pos_y=pos_y-1
  1236. end
  1237.  
  1238. if pos_x==pong_field_x2-2 and player_count>1 or pos_x==pong_field_x1+2 then
  1239.  
  1240. if check_ball_pos() then
  1241. if dir_x==0 then
  1242. dir_x=1
  1243. else
  1244. dir_x=0
  1245. end
  1246. end
  1247. end
  1248.  
  1249. if pos_y==13 or pos_y==2 then
  1250. if dir_y==0 then
  1251. dir_y=1
  1252. else
  1253. dir_y=0
  1254. end
  1255. end
  1256. term.setCursorPos(pos_x,pos_y)
  1257. term.write("o")
  1258.  
  1259. if pos_x==pong_field_x2-1 then
  1260. if player_count>1 then
  1261. clear_ball()
  1262. player_2_lives=player_2_lives-1
  1263. speaker.playNote("bit",volume,3)
  1264. sleep(0.1)
  1265. speaker.playNote("bit",volume,2)
  1266. sleep(0.1)
  1267. speaker.playNote("bit",volume,0)
  1268. ball_test=0
  1269. else
  1270. if dir_x==0 then
  1271. dir_x=1
  1272. else
  1273. dir_x=0
  1274. end
  1275. end
  1276. end
  1277.  
  1278. if pos_x==pong_field_x1+1 then
  1279. clear_ball()
  1280. player_1_lives=player_1_lives-1
  1281. ball_test=0
  1282. speaker.playNote("bit",volume,3)
  1283. sleep(0.1)
  1284. speaker.playNote("bit",volume,2)
  1285. sleep(0.1)
  1286. speaker.playNote("bit",volume,0)
  1287. end
  1288.  
  1289. if old_dir_x~=dir_x and (player_count==2 or pos_x==pong_field_x1+2) then
  1290. speaker.playNote("bit",volume,18)
  1291. end
  1292. end
  1293.  
  1294.  
  1295.  
  1296. function pull()
  1297. info_1,info_2,info_3,info_4=os.pullEvent()
  1298. end
  1299.  
  1300.  
  1301.  
  1302. function clear_ball()
  1303. term.setCursorPos(old_x,old_y)
  1304. term.write(" ")
  1305. end
  1306.  
  1307.  
  1308.  
  1309. function write_score()
  1310. term.setBackgroundColor(colors.black)
  1311. term.setTextColor(colors.green)
  1312. term.setCursorPos(42,2)
  1313. term.write("Score:")
  1314. term.setTextColor(colors.red)
  1315. term.setCursorPos(44,4)
  1316. term.write(score)
  1317. term.setTextColor(colors.white)
  1318. end
  1319.  
  1320. function dofile(file)
  1321. local f = assert(loadfile(file))
  1322. return f()
  1323. end
  1324.  
  1325.  
  1326. function s_key()
  1327. if info_1=="key" and (info_2==83 or info_2==31) then
  1328. return true
  1329. end
  1330. end
  1331.  
  1332.  
  1333.  
  1334. function w_key()
  1335. if info_1=="key" and (info_2==87 or info_2==17) then
  1336. return true
  1337. end
  1338. end
  1339.  
  1340.  
  1341.  
  1342. function arrow_down_key()
  1343. if info_1=="key" and (info_2==265 or info_2==200) then
  1344. return true
  1345. end
  1346. end
  1347.  
  1348.  
  1349.  
  1350. function arrow_up_key()
  1351. if info_1=="key" and (info_2==264 or info_2==208) then
  1352. return true
  1353. end
  1354. end
  1355.  
  1356.  
  1357.  
  1358. function a_key()
  1359. if info_1=="key" and info_2==30 then
  1360. return true
  1361. end
  1362. end
  1363.  
  1364.  
  1365.  
  1366. function d_key()
  1367. if info_1=="key" and info_2==32 then
  1368. return true
  1369. end
  1370. end
  1371.  
  1372.  
  1373.  
  1374.  
  1375. function pong(ball_speed)
  1376. term.clear()
  1377.  
  1378. score=0
  1379. pong_field_x1=1
  1380. pong_field_y1=1
  1381. do_bot_move=true
  1382.  
  1383. if player_count==2 then
  1384. pong_field_x2=40
  1385. pong_field_y2=14
  1386. end
  1387.  
  1388. if player_count==1 then
  1389. pong_field_x2=30
  1390. pong_field_y2=14
  1391. end
  1392.  
  1393.  
  1394. current_ball_speed=ball_speed
  1395. reset_player_data()
  1396. square(pong_field_x1,pong_field_y1,pong_field_x2,pong_field_y2,colors.white," "," ")
  1397. player_1_pos(0)
  1398. write_score()
  1399. if player_count>1 then
  1400. player_2_pos(0)
  1401. end
  1402.  
  1403. while player_1_lives>0 and player_2_lives>0 do
  1404. do_bot_move=true
  1405. write_lives_p()
  1406. ball()
  1407. clear_ball()
  1408. info_1=0
  1409. write_score()
  1410. os.startTimer(ball_speed)
  1411. while info_1~="timer" do
  1412. info_1=0
  1413. pull()
  1414.  
  1415. if info_1==pong_p1_up_kind and info_2==tonumber(pong_p1_up_num) then
  1416. player_1_pos(-1)
  1417. player_1_pos(-1)
  1418. end
  1419.  
  1420. if info_1==pong_p1_down_kind and info_2==pong_p1_down_num then
  1421. player_1_pos(1)
  1422. player_1_pos(1)
  1423. end
  1424.  
  1425. if player_count>1 and not is_bot then
  1426. if info_1==pong_p2_up_kind and info_2==pong_p2_up_num then
  1427. player_2_pos(-1)
  1428. player_2_pos(-1)
  1429. end
  1430.  
  1431. if info_1==pong_p2_down_kind and info_2==pong_p2_down_num then
  1432. player_2_pos(1)
  1433. player_2_pos(1)
  1434. end
  1435. end
  1436.  
  1437. if is_bot then
  1438. if pla2_a+1 > pos_y then
  1439. player_2_pos(-1)
  1440. do_check=true
  1441. check_ball_for_bot=pos_y
  1442. end
  1443.  
  1444. if pla2_a+1 < pos_y then
  1445. player_2_pos(1)
  1446. check_ball_for_bot=pos_y
  1447. end
  1448. end
  1449. end
  1450. score=score+1
  1451. write_score()
  1452. end
  1453. write_lives_p()
  1454. sleep(1)
  1455. term.clear()
  1456. square(13,8,35,12,colors.black,"-","|")
  1457. term.setTextColor(colors.red)
  1458. term.setCursorPos(16,10)
  1459. if player_1_lives~=0 then
  1460. term.write("Player 1 wins")
  1461. else
  1462. term.write("Player 2 wins")
  1463. end
  1464.  
  1465. if game_dif=="easy" and score>pong_easy_highscore then
  1466. broke_highscore(pong_easy_highscore,1)
  1467. end
  1468. if game_dif=="normal" and score>pong_normal_highscore then
  1469. broke_highscore(pong_normal_highscore,2)
  1470. end
  1471. if game_dif=="hard" and score>pong_hard_highscore then
  1472. broke_highscore(pong_hard_highscore,3)
  1473. end
  1474. if game_dif=="extreme" and score>pong_extreme_highscore then
  1475. broke_highscore(pong_extreme_highscore,4)
  1476. end
  1477. if game_dif=="insane" and score>pong_insane_highscore then
  1478. broke_highscore(pong_insane_highscore,5)
  1479. end
  1480.  
  1481. button("Home",1,16,16,18)
  1482. button(" Play again",38,16,51,18)
  1483. b_check=false
  1484. while not b_check do
  1485. pull()
  1486. b_check=button_check(1,16,16,18)
  1487. if b_check then
  1488. startup_menu()
  1489. end
  1490. b_check=button_check(38,16,51,18)
  1491. if b_check then
  1492. pong(current_ball_speed)
  1493. end
  1494. end
  1495. end
  1496.  
  1497.  
  1498.  
  1499. function broke_highscore(highscore,change_highscore)
  1500. square(10,2,38,6,colors.black,"-","|",colors.yellow)
  1501. term.setCursorPos(12,3)
  1502. term.write("You broke your highscore")
  1503. term.setCursorPos(12,4)
  1504. term.setTextColor(colors.red)
  1505. term.write("Old score:")
  1506. term.setCursorPos(12,5)
  1507. term.setTextColor(colors.green)
  1508. term.write(highscore)
  1509. term.setTextColor(colors.red)
  1510. term.setCursorPos(28,4)
  1511. term.write("New score:")
  1512. term.setCursorPos(28,5)
  1513. term.setTextColor(colors.green)
  1514. term.write(score)
  1515.  
  1516. highscore_len=fs.attributes("highscore")["size"]/2
  1517. highscore=fs.open("highscore","r")
  1518. old_highscore={0}
  1519.  
  1520. for i=1,highscore_len do
  1521. old_highscore[i]=highscore.readLine()
  1522. end
  1523.  
  1524. highscore.close()
  1525. highscore=fs.open("highscore","w")
  1526.  
  1527. for i=1,highscore_len do
  1528. if i~=change_highscore then
  1529. highscore.writeLine(old_highscore[i])
  1530. else
  1531. highscore.writeLine(score)
  1532. end
  1533. end
  1534.  
  1535. highscore.flush()
  1536. highscore.close()
  1537. assign_highscore()
  1538. end
  1539.  
  1540.  
  1541.  
  1542.  
  1543. minecraft_or_craftos_pc()
  1544. assign_highscore()
  1545. assign_settings()
  1546. startup_menu()
Advertisement
Add Comment
Please, Sign In to add comment