Skullblade

SkullPong

Jan 20th, 2013
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.11 KB | None | 0 0
  1. --Code By SkullBlade(Skullblade213)
  2. --You are allowed to modify and redistribute
  3. --You are not allowed to modify this header
  4. function Draw()
  5.     term.setBackgroundColor(counter)
  6.     term.clear()
  7.     term.setBackgroundColor(colors.white)
  8.     term.setCursorPos(Ball[1], Ball[2])
  9.     print(" ")
  10.     term.setBackgroundColor(colors.lime)
  11.     term.setCursorPos(You[1], You[2])
  12.     print(" ")
  13.     term.setCursorPos(You[1], You[3])
  14.     print(" ")
  15.     term.setCursorPos(You[1], You[4])
  16.     print(" ")
  17.     term.setBackgroundColor(colors.red)
  18.     term.setCursorPos(Op[1], Op[2])
  19.     print(" ")
  20.     term.setCursorPos(Op[1], Op[3])
  21.     print(" ")
  22.     term.setCursorPos(Op[1], Op[4])
  23.     print(" ")
  24. end
  25. function Update()
  26.     Ball={Ball[1]+Ball[3],Ball[2]+Ball[4],Ball[3],Ball[4]}
  27.     if Ball[1]==3 or Ball[1]==49 then
  28.         if Ball[1]==3 then
  29.             Check="L"
  30.         end
  31.         if Ball[1]==49 then
  32.             Check="R"
  33.         end
  34.         if (Ball[2]==You[2] and Check=="L") or (Ball[2]==Op[2] and Check=="R") then
  35.             Ball[3]=Ball[3]*-1
  36.             Ball[4]=-1
  37.             rans=math.random(1,5)
  38.         end
  39.         if (Ball[2]==You[3] and Check=="L") or (Ball[2]==Op[3] and Check=="R") then
  40.             Ball[3]=Ball[3]*-1
  41.             Ball[4]=Ball[4]*-1
  42.         end
  43.         if (Ball[2]==You[4] and Check=="L") or (Ball[2]==Op[4] and Check=="R") then
  44.             Ball[3]=Ball[3]*-1
  45.             Ball[4]=1
  46.         end
  47.     end
  48.     if Ball[2]==1 or Ball[2]==18 or Ball[2]==0 or Ball[2]==19 then
  49.         Ball[4]=Ball[4]*-1
  50.     end
  51.     if Ball[1]==1 then
  52.         score2=score2+1
  53.         Start()
  54.     end
  55.     if Ball[1]==51 then
  56.         score=score+1
  57.         Start()
  58.     end
  59. end
  60. function Move()
  61.     if key==200 then
  62.         You[2]=You[2]-1
  63.     end
  64.     if key==208 then
  65.         You[2]=You[2]+1
  66.     end
  67. end
  68. function AI()
  69.     if Ball[2]+Ball[4]>Op[2]+2 then
  70.         if Op[2]+3~=19 then
  71.             Op={Op[1],Op[2]+1,Op[2]+2,Op[2]+3}
  72.         end
  73.     end
  74.     if Ball[2]+Ball[4]<Op[2] then
  75.         if Op[2]-1~=0 then
  76.             Op={Op[1],Op[2]-1,Op[2],Op[2]+1}
  77.         end
  78.     end
  79. end
  80. function Start()
  81.     You={2,9,10,11}
  82.     Op={50,9,10,11}
  83.     ran=math.random(-1,1)
  84.     ran2=math.random(-1,1)
  85.     while ran==0 do
  86.         ran=math.random(-1,1)
  87.     end
  88.     while ran2==0 do
  89.         ran2=math.random(-1,1)
  90.     end
  91.     Ball={25,10,ran,ran2}
  92.     term.setCursorPos(20,10)
  93.     print(score.."   VS   "..score2)
  94.     if vars=="surv" and score2==1 then
  95.         ends="true"
  96.     end
  97.     sleep(1)
  98. end
  99. function Single(v)
  100.     vars=v
  101.     ends="false"
  102.     score=0
  103.     score2=0
  104.     if resume~="true" then
  105.         Start()
  106.     end
  107.     counter=1
  108.     breaks="false"
  109.     while true do
  110.         if vars=="surv" then
  111.             counter=counter*2
  112.             if counter==32 or counter==16384 then
  113.                 counter=counter*2
  114.             end
  115.             if counter==32768 then
  116.                 counter=2
  117.             end
  118.             term.setBackgroundColor(counter)
  119.         end
  120.         if vars~="surv" then
  121.             counter=32768
  122.         end
  123.         Draw()
  124.         os.startTimer(.1)
  125.         while true do
  126.             event, key = os.pullEvent()
  127.             if event=="key" then
  128.                 if vars~="Local" then
  129.                     Move()
  130.                 end
  131.                 if key==59 and (vars=="surv" or vars=="norm" or vars=="Local") then
  132.                     Menu("Paused","Resume","Info/Help","Quit")
  133.                     breaks="true"
  134.                     break
  135.                 end
  136.                 if vars=="Local" then
  137.                     if key==17 then
  138.                         You[2]=You[2]-1
  139.                     end
  140.                     if key==31 then
  141.                         You[2]=You[2]+1
  142.                     end
  143.                     if key==200 then
  144.                         Op[2]=Op[2]-1
  145.                     end
  146.                     if key==208 then
  147.                         Op[2]=Op[2]+1
  148.                     end
  149.                     if You[2]==0 then
  150.                         You[2]=1
  151.                     end
  152.                     if You[2]==17 then
  153.                         You[2]=16
  154.                     end
  155.                     if Op[2]==0 then
  156.                         Op[2]=1
  157.                     end
  158.                     if Op[2]==17 then
  159.                         Op[2]=16
  160.                     end
  161.                     You={You[1],You[2],You[2]+1,You[2]+2}
  162.                     Op={Op[1],Op[2],Op[2]+1,Op[2]+2}
  163.                 end
  164.                 if You[2]==0 then
  165.                     You[2]=1
  166.                 end
  167.                 if You[2]==17 then
  168.                     You[2]=16
  169.                 end
  170.                 You={You[1],You[2],You[2]+1,You[2]+2}
  171.             end
  172.             if event=="timer" then
  173.                 break
  174.             end
  175.         end
  176.         if breaks=="true" then
  177.             break
  178.         end
  179.         if vars~="Local" then
  180.             AI()
  181.         end
  182.         Update()
  183.         if ends=="true" then
  184.             ends="false"
  185.             Menu("SinglePlayer","Normal","Survival","Back")
  186.             break
  187.         end
  188.     end
  189. end
  190. function Set(x1,y1)
  191.     x=x1
  192.     y=y1
  193.     term.setCursorPos(x1,y1)
  194. end
  195. function PrintCenter(text)
  196.     textLen=string.len(text)
  197.     x = ((51-textLen)/2)
  198.     term.setCursorPos(x,y)
  199.     print(text)
  200.     y=y+1
  201. end
  202. function Menu(title,opt1,opt2,opt3)
  203.     resume="false"
  204.     term.setBackgroundColor(colors.black)
  205.     select=1
  206.     while true do
  207.     term.clear()
  208.     term.setCursorPos(1,1)
  209.     term.setTextColor(colors.lime)
  210.     print("SkullPong V1.10")
  211.     Set(1,6)
  212.     PrintCenter(title)
  213.     PrintCenter("------------")
  214.     term.setTextColor(colors.white)
  215.     PrintCenter(opt1)
  216.     PrintCenter(opt2)
  217.     PrintCenter(opt3)
  218.         if select==1 then
  219.             Set(1,8)
  220.             term.setTextColor(colors.blue)
  221.             PrintCenter(opt1)
  222.             term.setTextColor(colors.white)
  223.         end
  224.         if select==2 then
  225.             Set(1,9)
  226.             term.setTextColor(colors.blue)
  227.             PrintCenter(opt2)
  228.             term.setTextColor(colors.white)
  229.         end
  230.         if select==3 then
  231.             Set(1,10)
  232.             term.setTextColor(colors.blue)
  233.             PrintCenter(opt3)
  234.             term.setTextColor(colors.white)
  235.         end
  236.         event, param1, param2, param3 = os.pullEvent()
  237.         if event=="mouse_click" then
  238.             if param3==8 or param3==9 or param3==10 then
  239.                 sel=select
  240.                 if param3==8 then
  241.                     text=opt1
  242.                     select=1
  243.                 end
  244.                 if param3==9 then
  245.                     text=opt2
  246.                     select=2
  247.                 end
  248.                 if param3==10 then
  249.                     text=opt3
  250.                     select=3
  251.                 end
  252.                 strLen=string.len(text)
  253.                 start=(51-strLen)/2-1
  254.                 if param2>start and param2<start+strLen then
  255.                     if select==1 then
  256.                     if opt1=="SinglePlayer" then
  257.                         Menu("SinglePlayer","Normal","Survival","Back")
  258.                         break
  259.                     end
  260.                     if opt1=="Normal" then
  261.                         Single("norm")
  262.                         break
  263.                     end
  264.                     if opt1=="Resume" then
  265.                         resume="true"
  266.                         Single(vars)
  267.                         break
  268.                     end
  269.                     if opt1=="Local" then
  270.                         Single("Local")
  271.                         break
  272.                     end
  273.                 end
  274.                 if select==2 then
  275.                     if opt1=="SinglePlayer" then
  276.                         Menu("MultiPlayer","Local","Rednet","Back")
  277.                         break
  278.                     end
  279.                     if opt1=="Normal" then
  280.                         Single("surv")
  281.                         break
  282.                     end
  283.                     if opt1=="Resume" then
  284.                         if vars~="Local" then
  285.                             term.clear()
  286.                             term.setTextColor(colors.lime)
  287.                             term.setBackgroundColor(colors.black)
  288.                             term.setCursorPos(1,1)
  289.                            
  290.                             print("SkullPong V1.10")
  291.                             print("Help")
  292.                             print("---------------")
  293.                             term.setTextColor(colors.white)
  294.                             print("")
  295.                             print("Controls")
  296.                             print("UpArrow: Paddle Up")
  297.                             print("DownArrow: Paddle Down")
  298.                             print("Objective")
  299.                             print("Don't let the ball get pass the green paddle{You}")
  300.                             print("Get the ball pass the red paddle{AI}")
  301.                             print("")
  302.                             print("Press any key to continue")
  303.                             os.pullEvent("key")
  304.                         end
  305.                         if vars=="Local" then
  306.                             term.clear()
  307.                             term.setTextColor(colors.lime)
  308.                             term.setBackgroundColor(colors.black)
  309.                             term.setCursorPos(1,1)
  310.                             print("SkullPong V1.10")
  311.                             print("Help")
  312.                             print("---------------")
  313.                             term.setTextColor(colors.white)
  314.                             print("")
  315.                             print("Controls")
  316.                             print("UpArrow: Paddle Up-Red")
  317.                             print("DownArrow: Paddle Down-Red")
  318.                             print("W: Paddle Up-Green")
  319.                             print("A: Paddle Down-Green")
  320.                             print("Objective")
  321.                             print("Don't let the ball get pass the your paddle")
  322.                             print("Get the ball pass your opponent's paddle")
  323.                             print("")
  324.                             print("Press any key to continue")
  325.                             os.pullEvent("key")
  326.                         end
  327.                     end
  328.                     if opt1=="Local" then
  329.                         error("Not Implimented!")
  330.                     end
  331.                 end
  332.                 if select==3 then
  333.                     if opt1=="SinglePlayer" then
  334.                         term.clear()
  335.                         term.setCursorPos(1,1)
  336.                         break
  337.                     else
  338.                         Menu("Start","SinglePlayer","MultiPlayer","Quit")
  339.                         break
  340.                     end
  341.                 end
  342.                 else
  343.                     select=sel
  344.                 end
  345.             end
  346.         end
  347.         if event=="key" then
  348.             if param1==200 then
  349.                 select=select-1
  350.             end
  351.             if param1==208 then
  352.                 select=select+1
  353.             end
  354.             if param1==28 then
  355.                 if select==1 then
  356.                     if opt1=="SinglePlayer" then
  357.                         Menu("SinglePlayer","Normal","Survival","Back")
  358.                         break
  359.                     end
  360.                     if opt1=="Normal" then
  361.                         Single("norm")
  362.                         break
  363.                     end
  364.                     if opt1=="Resume" then
  365.                         resume="true"
  366.                         Single(vars)
  367.                         break
  368.                     end
  369.                     if opt1=="Local" then
  370.                         Single("Local")
  371.                         break
  372.                     end
  373.                 end
  374.                 if select==2 then
  375.                     if opt1=="SinglePlayer" then
  376.                         Menu("MultiPlayer","Local","Rednet","Back")
  377.                         break
  378.                     end
  379.                     if opt1=="Normal" then
  380.                         Single("surv")
  381.                         break
  382.                     end
  383.                     if opt1=="Resume" then
  384.                         if vars~="Local" then
  385.                             term.clear()
  386.                             term.setTextColor(colors.lime)
  387.                             term.setBackgroundColor(colors.black)
  388.                             term.setCursorPos(1,1)
  389.                            
  390.                             print("SkullPong V1.10")
  391.                             print("Help")
  392.                             print("---------------")
  393.                             term.setTextColor(colors.white)
  394.                             print("")
  395.                             print("Controls")
  396.                             print("UpArrow: Paddle Up")
  397.                             print("DownArrow: Paddle Down")
  398.                             print("Objective")
  399.                             print("Don't let the ball get pass the green paddle{You}")
  400.                             print("Get the ball pass the red paddle{AI}")
  401.                             print("")
  402.                             print("Press any key to continue")
  403.                             os.pullEvent("key")
  404.                         end
  405.                         if vars=="Local" then
  406.                             term.clear()
  407.                             term.setTextColor(colors.lime)
  408.                             term.setBackgroundColor(colors.black)
  409.                             term.setCursorPos(1,1)
  410.                             print("SkullPong V1.10")
  411.                             print("Help")
  412.                             print("---------------")
  413.                             term.setTextColor(colors.white)
  414.                             print("")
  415.                             print("Controls")
  416.                             print("UpArrow: Paddle Up-Red")
  417.                             print("DownArrow: Paddle Down-Red")
  418.                             print("W: Paddle Up-Green")
  419.                             print("A: Paddle Down-Green")
  420.                             print("Objective")
  421.                             print("Don't let the ball get pass the your paddle")
  422.                             print("Get the ball pass your opponent's paddle")
  423.                             print("")
  424.                             print("Press any key to continue")
  425.                             os.pullEvent("key")
  426.                         end
  427.                     end
  428.                     if opt1=="Local" then
  429.                         error("Not Implimented!")
  430.                     end
  431.                 end
  432.                 if select==3 then
  433.                     if opt1=="SinglePlayer" then
  434.                         term.clear()
  435.                         term.setCursorPos(1,1)
  436.                         break
  437.                     else
  438.                         Menu("Start","SinglePlayer","MultiPlayer","Quit")
  439.                         break
  440.                     end
  441.                 end
  442.             end
  443.             if select==0 then
  444.                 select=3
  445.             end
  446.             if select==4 then
  447.                 select=1
  448.             end
  449.         end
  450.     end
  451. end
  452. Menu("Start","SinglePlayer","MultiPlayer","Quit")
Advertisement
Add Comment
Please, Sign In to add comment