Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --If control is not not working rebind your settings
- --For new Ideas Please leave a comment on Pastebin
- if not fs.exists("settings") then
- game_settings=fs.open("settings","w")
- game_settings.writeLine("key")
- game_settings.writeLine("17")
- game_settings.writeLine("key")
- game_settings.writeLine("31")
- game_settings.writeLine("key")
- game_settings.writeLine("200")
- game_settings.writeLine("key")
- game_settings.writeLine("208")
- game_settings.writeLine("key")
- game_settings.writeLine("17")
- game_settings.writeLine("key")
- game_settings.writeLine("31")
- game_settings.writeLine("key")
- game_settings.writeLine("30")
- game_settings.writeLine("key")
- game_settings.writeLine("32")
- game_settings.flush()
- game_settings.close()
- end
- if not fs.exists("highscore") then
- highscore=fs.open("highscore","w")
- for i=1,30 do
- highscore.writeLine("0")
- end
- highscore.flush()
- highscore.close()
- end
- --
- function swipeCheck()
- if info_1 == "mouse_click" then
- lastClickPos = info_3
- lastClickPosY = info_4
- end
- if info_1 == "mouse_drag" and lastClickPos then
- if lastClickPos - info_3 > 1 then
- lastClickPos = nil
- lastClickPosY = nil
- return "left"
- elseif lastClickPos - info_3 < -1 then
- lastClickPos = nil
- lastClickPosY = nil
- return "right"
- elseif lastClickPosY - info_4 > 1 then
- lastClickPos = nil
- lastClickPosY = nil
- return "up"
- elseif lastClickPosY - info_4 < -1 then
- lastClickPos = nil
- lastClickPosY = nil
- return "down"
- end
- end
- end
- function assign_highscore()
- highscore=fs.open("highscore","r")
- pong_easy_highscore=tonumber(highscore.readLine())
- pong_normal_highscore=tonumber(highscore.readLine())
- pong_hard_highscore=tonumber(highscore.readLine())
- pong_extreme_highscore=tonumber(highscore.readLine())
- pong_insane_highscore=tonumber(highscore.readLine())
- click_me_easy_highscore=tonumber(highscore.readLine())
- click_me_normal_highscore=tonumber(highscore.readLine())
- click_me_hard_highscore=tonumber(highscore.readLine())
- click_me_extreme_highscore=tonumber(highscore.readLine())
- click_me_insane_highscore=tonumber(highscore.readLine())
- snake_easy_highscore=tonumber(highscore.readLine())
- snake_normal_highscore=tonumber(highscore.readLine())
- snake_hard_highscore=tonumber(highscore.readLine())
- snake_extreme_highscore=tonumber(highscore.readLine())
- snake_insane_highscore=tonumber(highscore.readLine())
- highscore.close()
- end
- function assign_settings()
- game_settings=fs.open("settings","r")
- pong_p1_up_kind=game_settings.readLine()
- pong_p1_up_num=tonumber(game_settings.readLine())
- pong_p1_down_kind=game_settings.readLine()
- pong_p1_down_num=tonumber(game_settings.readLine())
- pong_p2_up_kind=game_settings.readLine()
- pong_p2_up_num=tonumber(game_settings.readLine())
- pong_p2_down_kind=game_settings.readLine()
- pong_p2_down_num=tonumber(game_settings.readLine())
- snake_up_kind=game_settings.readLine()
- snake_up_num=tonumber(game_settings.readLine())
- snake_down_kind=game_settings.readLine()
- snake_down_num=tonumber(game_settings.readLine())
- snake_left_kind=game_settings.readLine()
- snake_left_num=tonumber(game_settings.readLine())
- snake_right_kind=game_settings.readLine()
- snake_right_num=tonumber(game_settings.readLine())
- end
- function startup_menu()
- term.setBackgroundColor(colors.black)
- term.clear()
- headline("Start menu")
- button(" Pong",16,6,25,8)
- button(" Exit",44,16,51,18)
- button(" Update",15,10,26,13)
- button("Click me",27,6,37,8)
- button("Sounds:",28,10,37,13)
- button("Snake",28,14,37,16)
- button(" Settings",15,14,26,16)
- term.setCursorPos(17,12)
- term.write("History")
- term.setCursorPos(31,12)
- term.write(sound_status.." ")
- b_check=false
- while true do
- pull()
- if button_check(28,10,37,13) then
- if sound_status=="on" then
- sound_status="off"
- volume=0
- else
- sound_status="on"
- volume=1
- end
- term.setCursorPos(31,12)
- term.write(sound_status.." ")
- end
- if button_check(15,14,26,16) then
- settings_pong()
- end
- if button_check(28,14,37,16) then
- difficulty_menu("Snake")
- end
- if button_check(16,6,25,8) then
- info_1=0
- player_menu()
- end
- if button_check(44,16,51,18) then
- term.clear()
- term.setCursorPos(-1,1)
- error()
- end
- if button_check(15,10,26,13) then
- update_history()
- end
- if button_check(27,6,37,8) then
- difficulty_menu("Click me")
- end
- end
- end
- function update_history()
- term.clear()
- headline("Update History")
- term.setCursorPos(1,4)
- print("1.0: Completed basic game")
- print("1.1: Difficulties, Better Interface, start menu")
- print("1.2: Singleplayer mode, Better Interface, bug fixes")
- print("1.3: Pong Vs bot mode, Update History, added Score")
- print("1.4: Added Click me, some sounds, major bug fixes")
- button("Home",38,16,50,18)
- while 1==1 do
- pull()
- if button_check(38,16,50,18) then
- info_1=0
- startup_menu()
- end
- end
- end
- function settings_pong()
- term.clear()
- headline("Settings")
- button(" Home",44,16,51,18)
- term.setCursorPos(1,3)
- term.setTextColor(colors.red)
- term.write("-Pong:")
- button(" Up P1",2,5,12,7)
- button(" Down P1",14,5,26,7)
- button(" Up P2",2,9,12,11)
- button(" Down P2",14,9,26,11)
- button(" Next",14,17,26,19)
- while true do
- pull()
- if button_check(44,16,51,18) then
- startup_menu()
- end
- if button_check(2,5,12,7) then
- change_settings(1)
- end
- if button_check(14,5,26,7) then
- change_settings(3)
- end
- if button_check(2,9,12,11) then
- change_settings(5)
- end
- if button_check(14,9,26,11) then
- change_settings(7)
- end
- if button_check(14,17,26,19) then
- settings_snake()
- end
- end
- end
- function settings_snake()
- term.clear()
- headline("Settings")
- button(" Home",44,16,51,18)
- term.setCursorPos(1,3)
- term.setTextColor(colors.red)
- term.write("-Snake:")
- button(" Up",2,5,12,7)
- button(" Down",14,5,26,7)
- button(" Left",2,9,12,11)
- button(" Right ",14,9,26,11)
- button(" Last",1,17,13,19)
- while true do
- pull()
- if button_check(44,16,51,18) then
- startup_menu()
- end
- if button_check(2,5,12,7) then
- change_settings(9)
- end
- if button_check(14,5,26,7) then
- change_settings(11)
- end
- if button_check(2,9,12,11) then
- change_settings(13)
- end
- if button_check(14,9,26,11) then
- change_settings(15)
- end
- if button_check(1,17,13,19) then
- settings_pong()
- end
- end
- end
- function change_settings(change_line)
- os.sleep(0.5)
- term.setTextColor(colors.red)
- term.setCursorPos(10,2)
- term.write("Please press a key ")
- pull()
- old_settings={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
- settings_len=(fs.attributes("settings")["size"]-6)/2
- cur_line=1
- game_settings=fs.open("settings","r")
- for i=1,settings_len do
- old_settings[cur_line]=game_settings.readLine()
- cur_line=cur_line+1
- end
- game_settings=fs.open("settings","w")
- cur_line=1
- for i=1,settings_len do
- if cur_line~=change_line then
- game_settings.writeLine(old_settings[cur_line])
- cur_line=cur_line+1
- else
- game_settings.writeLine(info_1)
- game_settings.writeLine(info_2)
- cur_line=cur_line+2
- end
- end
- game_settings.flush()
- term.setCursorPos(10,2)
- term.write("The new Keybind is: ")
- term.setTextColor(colors.green)
- term.write(info_1.." "..info_2)
- assign_settings()
- end
- function player_menu()
- is_bot=false
- term.clear()
- headline("Pong")
- button(" 1 Player",5,6,17,10)
- button(" 2 Players",19,6,31,10)
- button("Vs Bot",33,6,45,10)
- b_check=false
- while true do
- pull()
- if button_check(5,6,17,10) then
- is_bot=false
- info_1=0
- player_count=1
- difficulty_menu("Pong")
- end
- if button_check(19,6,31,10) then
- is_bot=false
- info_1=0
- player_count=2
- difficulty_menu("Pong")
- end
- if button_check(33,6,45,10) then
- info_1=0
- player_count=2
- is_bot=true
- difficulty_menu("Pong")
- end
- end
- end
- function minecraft_or_craftos_pc()
- term.clear()
- term.setCursorPos(7,3)
- term.setTextColor(colors.white)
- term.write("Are you using this program in ")
- term.setTextColor(colors.red)
- term.write("minecraft")
- term.setTextColor(colors.white)
- term.setCursorPos(18,4)
- term.write("or ")
- term.setTextColor(colors.red)
- term.write("CraftOS-PC?")
- button(" Minecraft",8,8,22,10)
- button(" CraftOS-PC",30,8,44,10)
- while minecraft_or_pc==nil do
- pull()
- if button_check(8,8,22,10) then
- minecraft_or_pc="minecraft"
- term.clear()
- term.setCursorPos(3,3)
- term.write("Please place a Speaker on top of the Computer")
- sleep(3)
- end
- if button_check(30,8,44,10) then
- minecraft_or_pc="pc"
- end
- end
- if minecraft_or_pc=="pc" then
- periphemu.create("top","speaker",1)
- end
- speaker = peripheral.wrap("top")
- sound_status="off"
- volume=0
- end
- function difficulty_menu(what_game)
- term.clear()
- headline(what_game)
- button("Easy",8,7,18,11)
- button("Normal",22,7,32,11)
- button("Hard",36,7,46,11)
- button(" Extreme",22,13,32,17)
- button("Insane",36,13,46,17)
- b_check=false
- while true do
- pull()
- if button_check(8,7,18,11) then
- game_dif="easy"
- if what_game=="Pong" then
- info_1=0
- bot_dif=6
- pong(0.13)
- end
- if what_game=="Click me" then
- click_me(1)
- end
- if what_game=="Snake" then
- snake(0.15)
- end
- end
- if button_check(22,7,32,11) then
- game_dif="normal"
- if what_game=="Pong" then
- info_1=0
- bot_dif=7
- pong(0.1)
- end
- if what_game=="Click me" then
- click_me(0.8)
- end
- if what_game=="Snake" then
- snake(0.125)
- end
- end
- if button_check(36,7,46,11) then
- game_dif="hard"
- if what_game=="Pong" then
- info_1=0
- bot_dif=8
- pong(0.07)
- end
- if what_game=="Click me" then
- click_me(0.6)
- end
- if what_game=="Snake" then
- snake(0.1)
- end
- end
- if button_check(22,13,32,17) then
- game_dif="extreme"
- if what_game=="Pong" then
- info_1=0
- bot_dif=9
- pong(0.05)
- end
- if what_game=="Click me" then
- click_me(0.5)
- end
- if what_game=="Snake" then
- snake(0.075)
- end
- end
- if button_check(36,13,46,17) then
- game_dif="insane"
- if what_game=="Pong" then
- info_1=0
- bot_dif=9
- pong(0.04)
- end
- if what_game=="Click me" then
- click_me(0.45)
- end
- if what_game=="Snake" then
- snake(0.05)
- end
- end
- end
- end
- function snake(game_speed)
- score=0
- level=1
- do_set_level_2=true
- game_running=true
- check_change_snake_color=0
- snake_len=2
- new_dir="up"
- snake_head_x=18
- snake_head_y=9
- snake_field_x1=1
- snake_field_y1=1
- snake_field_x2=36
- snake_field_y2=18
- snake_x={0,0,0,0}
- snake_y={0,0,0,0}
- do_gen_point=true
- term.clear()
- square(snake_field_x1,snake_field_y1,snake_field_x2,snake_field_y2,colors.cyan," "," ")
- button(" Home",44,16,51,18)
- print_snake()
- write_score()
- os.sleep(1)
- while game_running do
- if do_gen_point then
- gen_point()
- end
- print_snake()
- info_1=0
- check_snake()
- if do_set_level_2 and score==150 then
- level=2
- reset_snake()
- do_set_level_2=false
- line_y(12,5,14,colors.gray)
- line_y(24,5,14,colors.gray)
- new_dir="up"
- speaker.playNote("bit",volume,20)
- os.sleep(0.20)
- speaker.playNote("bit",volume,22)
- os.sleep(0.20)
- speaker.playNote("bit",volume,24)
- os.sleep(0.20)
- end
- i=snake_len+1
- while i>0 do
- snake_x[i] = snake_x[i-1]
- snake_y[i] = snake_y[i-1]
- i=i-1
- end
- snake_x[1] = snake_head_x
- snake_y[1] = snake_head_y
- write_score()
- clear_snake()
- os.startTimer(game_speed)
- while info_1~="timer" do
- pull()
- if button_check(44,16,51,18) then
- startup_menu()
- end
- output = swipeCheck()
- if (output == "up" and snake_dir ~= "down") or (output == "down" and snake_dir ~= "up") or (output == "left" and snake_dir ~= "right") or (output == "right" and snake_dir ~= "left") then
- new_dir = output
- end
- end
- snake_dir=new_dir
- if snake_dir=="up" then
- snake_head_y=snake_head_y-1
- end
- if snake_dir=="down" then
- snake_head_y=snake_head_y+1
- end
- if snake_dir=="left" then
- snake_head_x=snake_head_x-1
- end
- if snake_dir=="right" then
- snake_head_x=snake_head_x+1
- end
- if snake_head_x==snake_field_x1 then
- snake_head_x=snake_field_x2-1
- end
- if snake_head_x==snake_field_x2 then
- snake_head_x=snake_field_x1+1
- end
- if snake_head_y==snake_field_y1 then
- snake_head_y=snake_field_y2-1
- end
- if snake_head_y==snake_field_y2 then
- snake_head_y=snake_field_y1+1
- end
- end
- end_snake()
- while true do
- pull()
- if button_check(44,16,51,18) then
- startup_menu()
- end
- end
- end
- function end_snake()
- square(snake_field_x1,snake_field_y1,snake_field_x2,snake_field_y2,colors.lightGray," "," ")
- if level==2 then
- line_y(12,5,14,colors.lightGray)
- line_y(24,5,14,colors.lightGray)
- end
- i=snake_len
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(point_pos_x,point_pos_y)
- term.write(" ")
- term.setBackgroundColor(colors.gray)
- while i>0 do
- term.setCursorPos(snake_x[i],snake_y[i])
- term.write(" ")
- i=i-1
- end
- term.setCursorPos(snake_x[1],snake_y[1])
- term.setBackgroundColor(colors.red)
- term.write(" ")
- if game_dif=="easy" and score>snake_easy_highscore then
- broke_highscore(snake_easy_highscore,11)
- end
- if game_dif=="normal" and score>snake_normal_highscore then
- broke_highscore(snake_normal_highscore,12)
- end
- if game_dif=="hard" and score>snake_hard_highscore then
- broke_highscore(snake_hard_highscore,13)
- end
- if game_dif=="extreme" and score>snake_extreme_highscore then
- broke_highscore(snake_extreme_highscore,14)
- end
- if game_dif=="insane" and score>snake_insane_highscore then
- broke_highscore(snake_insane_highscore,15)
- end
- end
- function reset_snake()
- term.setBackgroundColor(colors.black)
- term.clear()
- square(snake_field_x1,snake_field_y1,snake_field_x2,snake_field_y2,colors.cyan," "," ")
- button(" Home",44,16,51,18)
- write_score()
- for i=1,40 do
- snake_x[i]=0
- snake_y[i]=0
- end
- snake_head_x=17
- snake_head_y=8
- snake_len=2
- print_snake()
- end
- function gen_point()
- do_for=1
- while do_for>0 do
- point_pos_x=math.random(snake_field_x1+1,snake_field_x2-1)
- point_pos_y=math.random(snake_field_y1+1,snake_field_y2-1)
- i=snake_len
- while i>0 do
- if point_pos_x==snake_x[i] and point_pos_y==snake_y[i] then
- do_for=do_for+2
- end
- i=i-1
- end
- 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
- do_for=do_for+2
- end
- do_for=do_for-1
- end
- term.setBackgroundColor(colors.yellow)
- term.setCursorPos(point_pos_x,point_pos_y)
- term.write(" ")
- do_gen_point=false
- end
- function check_snake()
- i=2
- while i<snake_len do
- if snake_head_x==snake_x[i] and snake_head_y==snake_y[i] then
- game_running=false
- end
- i=i+1
- end
- if level==2 then
- if (snake_head_x==12 or snake_head_x==24) and snake_head_y>4 and snake_head_y<15 then
- game_running=false
- end
- end
- if snake_head_x==point_pos_x and snake_head_y==point_pos_y then
- snake_len=snake_len+1
- do_gen_point=true
- score=score+5
- if score~=150 then
- speaker.playNote("bit",volume,18)
- end
- end
- end
- function clear_snake()
- term.setBackgroundColor(colors.black)
- term.setCursorPos(snake_x[snake_len+1],snake_y[snake_len+1])
- term.write(" ")
- end
- function print_snake()
- term.setCursorPos(snake_head_x,snake_head_y)
- term.setBackgroundColor(colors.lime)
- term.write(" ")
- if check_change_snake_color>1 then
- term.setCursorPos(snake_x[1],snake_y[1])
- term.setBackgroundColor(colors.green)
- term.write(" ")
- end
- check_change_snake_color=check_change_snake_color+1
- end
- function line_x(start_x,start_y,end_x,color)
- term.setBackgroundColor(color)
- cur_x=start_x
- for i=1,end_x-start_x+1 do
- term.setCursorPos(cur_x,start_y)
- term.write(" ")
- cur_x=cur_x+1
- end
- end
- function line_y(start_x,start_y,end_y,color)
- term.setBackgroundColor(color)
- cur_y=start_y
- for i=1,end_y-start_y+1 do
- term.setCursorPos(start_x,cur_y)
- term.write(" ")
- cur_y=cur_y+1
- end
- end
- function click_me(game_speed)
- term.clear()
- click_speed=game_speed
- game_time=10
- score=0
- while game_time~=0 do
- filled_square(3,3,9,6,colors.lightGray)
- filled_square(11,3,17,6,colors.lightGray)
- filled_square(19,3,25,6,colors.lightGray)
- filled_square(3,8,9,11,colors.lightGray)
- filled_square(11,8,17,11,colors.lightGray)
- filled_square(19,8,25,11,colors.lightGray)
- filled_square(3,13,9,16,colors.lightGray)
- filled_square(11,13,17,16,colors.lightGray)
- filled_square(19,13,25,16,colors.lightGray)
- old_cw=cw
- while old_cw==cw do
- cw=math.random(1,9)
- end
- ct=0
- if cw==1 then
- filled_square(3,3,9,6,colors.green)
- end
- if cw==2 then
- filled_square(11,3,17,6,colors.green)
- end
- if cw==3 then
- filled_square(19,3,25,6,colors.green)
- end
- if cw==4 then
- filled_square(3,8,9,11,colors.green)
- end
- if cw==5 then
- filled_square(11,8,17,11,colors.green)
- end
- if cw==6 then
- filled_square(19,8,25,11,colors.green)
- end
- if cw==7 then
- filled_square(3,13,9,16,colors.green)
- end
- if cw==8 then
- filled_square(11,13,17,16,colors.green)
- end
- if cw==9 then
- filled_square(19,13,25,16,colors.green)
- end
- write_score()
- write_lives_c()
- timer_number=os.startTimer(game_speed)
- while info_1~="timer" and ct==0 do
- pull()
- if button_check(3,3,9,6) then
- ct=1
- end
- if button_check(11,3,17,6) then
- ct=2
- end
- if button_check(19,3,25,6) then
- ct=3
- end
- if button_check(3,8,9,11) then
- ct=4
- end
- if button_check(11,8,17,11) then
- ct=5
- end
- if button_check(19,8,25,11) then
- ct=6
- end
- if button_check(3,13,9,16) then
- ct=7
- end
- if button_check(11,13,17,16) then
- ct=8
- end
- if button_check(19,13,25,16) then
- ct=9
- end
- end
- if ct==cw then
- score=score+10
- speaker.playNote("bit",volume/2.5,20)
- else
- game_time=game_time-1
- write_lives_c()
- if cw==1 then
- filled_square(3,3,9,6,colors.red)
- end
- if cw==2 then
- filled_square(11,3,17,6,colors.red)
- end
- if cw==3 then
- filled_square(19,3,25,6,colors.red)
- end
- if cw==4 then
- filled_square(3,8,9,11,colors.red)
- end
- if cw==5 then
- filled_square(11,8,17,11,colors.red)
- end
- if cw==6 then
- filled_square(19,8,25,11,colors.red)
- end
- if cw==7 then
- filled_square(3,13,9,16,colors.red)
- end
- if cw==8 then
- filled_square(11,13,17,16,colors.red)
- end
- if cw==9 then
- filled_square(19,13,25,16,colors.red)
- end
- speaker.playNote("bit",volume,0)
- sleep(0.3)
- end
- os.cancelTimer(timer_number)
- info_1=0
- end
- sleep(0.8)
- term.clear()
- term.setCursorPos(13,9)
- term.write(" Your Score is: "..score)
- term.setTextColor(colors.white)
- square(11,7,34,11,colors.black,"-","|")
- button(" Home",44,16,51,18)
- button(" Play again",1,16,14,18)
- if game_dif=="easy" and score>click_me_easy_highscore then
- broke_highscore(click_me_easy_highscore,6)
- end
- if game_dif=="normal" and score>click_me_normal_highscore then
- broke_highscore(click_me_normal_highscore,7)
- end
- if game_dif=="hard" and score>click_me_hard_highscore then
- broke_highscore(click_me_hard_highscore,8)
- end
- if game_dif=="extreme" and score>click_me_extreme_highscore then
- broke_highscore(click_me_extreme_highscore,9)
- end
- if game_dif=="insane" and score>click_me_insane_highscore then
- broke_highscore(click_me_insane_highscore,10)
- end
- while 1==1 do
- pull()
- if button_check(45,16,51,18) then
- startup_menu()
- end
- if button_check(1,16,13,18) then
- click_me(click_speed)
- end
- end
- end
- function write_lives_c()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- term.setCursorPos(10,1)
- if game_time>1 then
- term.write(game_time.." ".."Lives left ")
- else
- term.write(game_time.." ".."Live left ")
- end
- end
- function filled_square(fill_x1,fill_y1,fill_x2,fill_y2,fill_color)
- term.setBackgroundColor(fill_color)
- curr_fill_pos_x=fill_x1
- curr_fill_pos_y=fill_y1
- while curr_fill_pos_y~=fill_y2+1 do
- while curr_fill_pos_x~=fill_x2+1 do
- term.setCursorPos(curr_fill_pos_x,curr_fill_pos_y)
- term.write(" ")
- curr_fill_pos_x=curr_fill_pos_x+1
- end
- curr_fill_pos_x=fill_x1
- curr_fill_pos_y=curr_fill_pos_y+1
- end
- term.setBackgroundColor(colors.black)
- end
- function button_check(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
- 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
- return true
- else
- return false
- end
- end
- function button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2)
- term.setTextColor(colors.green)
- square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
- 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)
- term.write(button_text)
- end
- function headline(headline)
- headline_lenght=string.len(" "..headline.." ")
- headline_pos=27-headline_lenght/2
- term.setCursorPos(headline_pos,1)
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.blue)
- term.write(" "..headline.." ")
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function reset_players()
- player_clear=2
- for i=1,12 do
- term.setCursorPos(2,player_clear)
- term.write(" ")
- term.setCursorPos(39,player_clear)
- term.write(" ")
- player_clear=player_clear+1
- end
- pla1_a=6
- pla1_b=9
- pla2_a=6
- pla2_b=9
- player_1_pos(0)
- if player_count>1 then
- bot_reset=true
- player_2_pos(0)
- end
- end
- function reset_player_data()
- player_1_lives=3
- player_2_lives=3
- player_1_pos_a=6
- player_1_pos_b=8
- pla1_a=player_1_pos_a
- pla1_b=player_1_pos_b
- player_2_pos_a=6
- player_2_pos_b=8
- pla2_a=player_2_pos_a
- pla2_b=player_2_pos_b
- end
- function write_lives_p()
- term.setCursorPos(1,16)
- term.setTextColor(colors.red)
- if player_1_lives > 1 then
- term.write("Player 1: "..player_1_lives.." lives")
- else
- term.write("Player 1: "..player_1_lives.." live")
- end
- if player_count>1 then
- term.setCursorPos(1,17)
- if player_2_lives > 1 then
- term.write("Player 2: "..player_2_lives.." lives")
- else
- term.write("Player 2: "..player_2_lives.." live")
- end
- end
- term.setTextColor(colors.white)
- end
- function check_ball_pos()
- if pos_x==pong_field_x1+2 then
- if pos_y==pla1_a or pos_y==pla1_a+1 or pos_y==pla1_a+2 then
- return true
- end
- end
- if player_count>1 then
- if pos_x==pong_field_x2-2 then
- if pos_y==pla2_a or pos_y==pla2_a+1 or pos_y==pla2_a+2 then
- return true
- end
- end
- end
- end
- function player_bot_pos(plus_min2)
- if math.random(0,10) < bot_dif+1 or bot_reset then
- if plus_min2==1 then
- if pla2_a~=11 then
- term.setCursorPos(39,pla2_a)
- print(" ")
- end
- else
- if pla2_a~=2 then
- term.setCursorPos(39,pla2_b-1)
- print(" ")
- end
- end
- term.setTextColor(colors.green)
- if pla2_a~=2 or plus_min2~=-1 then
- if pla2_a~=11 or plus_min2~=1 then
- pla2_a=pla2_a+plus_min2
- pla2_b=pla2_b+plus_min2
- pos2_a=pla2_a
- for i=1,3 do
- term.setCursorPos(39,pos2_a)
- term.write("|")
- pos2_a=pos2_a+1
- end
- end
- end
- term.setTextColor(colors.white)
- end
- bot_reset=false
- end
- function player_2_pos(plus_min2)
- if is_bot then
- if do_bot_move then
- do_bot_move=false
- player_bot_pos(plus_min2)
- end
- else
- if plus_min2==1 then
- if pla2_a~=11 then
- term.setCursorPos(39,pla2_a)
- print(" ")
- end
- else
- if pla2_a~=2 then
- term.setCursorPos(39,pla2_b-1)
- print(" ")
- end
- end
- term.setTextColor(colors.green)
- if pla2_a~=2 or plus_min2~=-1 then
- if pla2_a~=11 or plus_min2~=1 then
- pla2_a=pla2_a+plus_min2
- pla2_b=pla2_b+plus_min2
- pos2_a=pla2_a
- for i=1,3 do
- term.setCursorPos(39,pos2_a)
- term.write("|")
- pos2_a=pos2_a+1
- end
- end
- end
- term.setTextColor(colors.white)
- end
- end
- function player_1_pos(plus_min)
- if plus_min==1 then
- if pla1_a~=11 then
- term.setCursorPos(2,pla1_a)
- print(" ")
- end
- else
- if pla1_a~=2 then
- term.setCursorPos(2,pla1_b-1)
- print(" ")
- end
- end
- term.setTextColor(colors.green)
- if pla1_a~=2 or plus_min~=-1 then
- if pla1_a~=11 or plus_min~=1 then
- pla1_a=pla1_a+plus_min
- pla1_b=pla1_b+plus_min
- pos1_a=pla1_a
- for i=1,3 do
- term.setCursorPos(2,pos1_a)
- term.write("|")
- pos1_a=pos1_a+1
- end
- end
- end
- term.setTextColor(colors.white)
- end
- function square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
- x_1=x1
- y_1=y1
- x_2=x2
- y_2=y2
- while x_1~=x2+1 do
- term.setBackgroundColor(back_color_square)
- term.setCursorPos(x_1,y_1)
- if text_color~=nil then
- term.setTextColor(text_color)
- end
- term.write(symbol_square_x)
- x_1=x_1+1
- end
- while y_1~=y2-1 do
- term.setCursorPos(x_1-1,y_1+1)
- term.write(symbol_square_y)
- y_1=y_1+1
- end
- x2=x2-1
- while x_2~=x1-1 do
- term.setCursorPos(x_2,y_2)
- term.write(symbol_square_x)
- x_2=x_2-1
- end
- while y_2~=y1+1 do
- term.setCursorPos(x_2+1,y_2-1)
- term.write(symbol_square_y)
- y_2=y_2-1
- end
- term.setBackgroundColor(colors.black)
- end
- function ball()
- if ball_test~=1 then
- pos_x=20
- pos_y=7
- term.setCursorPos(pos_x,pos_y)
- term.write("o")
- reset_players()
- sleep(1)
- speaker.playNote("bit",volume*2,22)
- dir_x=math.random(0,1)
- dir_y=math.random(0,1)
- ball_test=1
- end
- old_dir_x=dir_x
- old_x=pos_x
- old_y=pos_y
- if dir_x==0 then
- pos_x=pos_x+1
- else
- pos_x=pos_x-1
- end
- if dir_y==0 then
- pos_y=pos_y+1
- else
- pos_y=pos_y-1
- end
- if pos_x==pong_field_x2-2 and player_count>1 or pos_x==pong_field_x1+2 then
- if check_ball_pos() then
- if dir_x==0 then
- dir_x=1
- else
- dir_x=0
- end
- end
- end
- if pos_y==13 or pos_y==2 then
- if dir_y==0 then
- dir_y=1
- else
- dir_y=0
- end
- end
- term.setCursorPos(pos_x,pos_y)
- term.write("o")
- if pos_x==pong_field_x2-1 then
- if player_count>1 then
- clear_ball()
- player_2_lives=player_2_lives-1
- speaker.playNote("bit",volume,3)
- sleep(0.1)
- speaker.playNote("bit",volume,2)
- sleep(0.1)
- speaker.playNote("bit",volume,0)
- ball_test=0
- else
- if dir_x==0 then
- dir_x=1
- else
- dir_x=0
- end
- end
- end
- if pos_x==pong_field_x1+1 then
- clear_ball()
- player_1_lives=player_1_lives-1
- ball_test=0
- speaker.playNote("bit",volume,3)
- sleep(0.1)
- speaker.playNote("bit",volume,2)
- sleep(0.1)
- speaker.playNote("bit",volume,0)
- end
- if old_dir_x~=dir_x and (player_count==2 or pos_x==pong_field_x1+2) then
- speaker.playNote("bit",volume,18)
- end
- end
- function pull()
- info_1,info_2,info_3,info_4=os.pullEvent()
- end
- function clear_ball()
- term.setCursorPos(old_x,old_y)
- term.write(" ")
- end
- function write_score()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.green)
- term.setCursorPos(42,2)
- term.write("Score:")
- term.setTextColor(colors.red)
- term.setCursorPos(44,4)
- term.write(score)
- term.setTextColor(colors.white)
- end
- function dofile(file)
- local f = assert(loadfile(file))
- return f()
- end
- function s_key()
- if info_1=="key" and (info_2==83 or info_2==31) then
- return true
- end
- end
- function w_key()
- if info_1=="key" and (info_2==87 or info_2==17) then
- return true
- end
- end
- function arrow_down_key()
- if info_1=="key" and (info_2==265 or info_2==200) then
- return true
- end
- end
- function arrow_up_key()
- if info_1=="key" and (info_2==264 or info_2==208) then
- return true
- end
- end
- function a_key()
- if info_1=="key" and info_2==30 then
- return true
- end
- end
- function d_key()
- if info_1=="key" and info_2==32 then
- return true
- end
- end
- function pong(ball_speed)
- term.clear()
- score=0
- pong_field_x1=1
- pong_field_y1=1
- do_bot_move=true
- if player_count==2 then
- pong_field_x2=40
- pong_field_y2=14
- end
- if player_count==1 then
- pong_field_x2=30
- pong_field_y2=14
- end
- current_ball_speed=ball_speed
- reset_player_data()
- square(pong_field_x1,pong_field_y1,pong_field_x2,pong_field_y2,colors.white," "," ")
- player_1_pos(0)
- write_score()
- if player_count>1 then
- player_2_pos(0)
- end
- while player_1_lives>0 and player_2_lives>0 do
- do_bot_move=true
- write_lives_p()
- ball()
- clear_ball()
- info_1=0
- write_score()
- os.startTimer(ball_speed)
- while info_1~="timer" do
- info_1=0
- pull()
- if info_1==pong_p1_up_kind and info_2==tonumber(pong_p1_up_num) then
- player_1_pos(-1)
- player_1_pos(-1)
- end
- if info_1==pong_p1_down_kind and info_2==pong_p1_down_num then
- player_1_pos(1)
- player_1_pos(1)
- end
- if player_count>1 and not is_bot then
- if info_1==pong_p2_up_kind and info_2==pong_p2_up_num then
- player_2_pos(-1)
- player_2_pos(-1)
- end
- if info_1==pong_p2_down_kind and info_2==pong_p2_down_num then
- player_2_pos(1)
- player_2_pos(1)
- end
- end
- if is_bot then
- if pla2_a+1 > pos_y then
- player_2_pos(-1)
- do_check=true
- check_ball_for_bot=pos_y
- end
- if pla2_a+1 < pos_y then
- player_2_pos(1)
- check_ball_for_bot=pos_y
- end
- end
- end
- score=score+1
- write_score()
- end
- write_lives_p()
- sleep(1)
- term.clear()
- square(13,8,35,12,colors.black,"-","|")
- term.setTextColor(colors.red)
- term.setCursorPos(16,10)
- if player_1_lives~=0 then
- term.write("Player 1 wins")
- else
- term.write("Player 2 wins")
- end
- if game_dif=="easy" and score>pong_easy_highscore then
- broke_highscore(pong_easy_highscore,1)
- end
- if game_dif=="normal" and score>pong_normal_highscore then
- broke_highscore(pong_normal_highscore,2)
- end
- if game_dif=="hard" and score>pong_hard_highscore then
- broke_highscore(pong_hard_highscore,3)
- end
- if game_dif=="extreme" and score>pong_extreme_highscore then
- broke_highscore(pong_extreme_highscore,4)
- end
- if game_dif=="insane" and score>pong_insane_highscore then
- broke_highscore(pong_insane_highscore,5)
- end
- button("Home",1,16,16,18)
- button(" Play again",38,16,51,18)
- b_check=false
- while not b_check do
- pull()
- b_check=button_check(1,16,16,18)
- if b_check then
- startup_menu()
- end
- b_check=button_check(38,16,51,18)
- if b_check then
- pong(current_ball_speed)
- end
- end
- end
- function broke_highscore(highscore,change_highscore)
- square(10,2,38,6,colors.black,"-","|",colors.yellow)
- term.setCursorPos(12,3)
- term.write("You broke your highscore")
- term.setCursorPos(12,4)
- term.setTextColor(colors.red)
- term.write("Old score:")
- term.setCursorPos(12,5)
- term.setTextColor(colors.green)
- term.write(highscore)
- term.setTextColor(colors.red)
- term.setCursorPos(28,4)
- term.write("New score:")
- term.setCursorPos(28,5)
- term.setTextColor(colors.green)
- term.write(score)
- highscore_len=fs.attributes("highscore")["size"]/2
- highscore=fs.open("highscore","r")
- old_highscore={0}
- for i=1,highscore_len do
- old_highscore[i]=highscore.readLine()
- end
- highscore.close()
- highscore=fs.open("highscore","w")
- for i=1,highscore_len do
- if i~=change_highscore then
- highscore.writeLine(old_highscore[i])
- else
- highscore.writeLine(score)
- end
- end
- highscore.flush()
- highscore.close()
- assign_highscore()
- end
- minecraft_or_craftos_pc()
- assign_highscore()
- assign_settings()
- startup_menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement