lego11

PROTECTOR

Jul 16th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 27.12 KB | None | 0 0
  1. function initVariables()
  2.     w,h =term.getSize()  -- 51,  19
  3.     shipYPos = 10
  4.     shipXPos = 24
  5.     shipFacingRight=true
  6.     pressedKey=0
  7.     killedState = false
  8.     lives=3
  9.     score =0
  10.     aliens=10
  11.     killedDelay=0
  12.     running=true
  13.     moveLeft=false
  14.     moveRight=true
  15.     moveUp=false
  16.     moveDown=false
  17.     human1x = 3
  18.     human1y = 18
  19.     human2x = 15
  20.     human2y = 18
  21.     human3x = 40
  22.     human3y = 18
  23.     human4x = 60
  24.     human4y = 18
  25.     human5x = 70
  26.     human5y = 18
  27.     human6x = 85
  28.     human6y = 18
  29.     human1 = true
  30.     human2 = true
  31.     human3 = true
  32.     human4 = true
  33.     human5 = true
  34.     human6 = true
  35.     human1Abducted=false
  36.     human2Abducted=false
  37.     human3Abducted=false
  38.     human4Abducted=false
  39.     human5Abducted=false
  40.     human6Abducted=false
  41.     humansLeft=6
  42.     bulletXPos=0
  43.     bulletYPos=0
  44.     bulletState=false
  45.     bulletGoingRight=true
  46.     alien1 = false
  47.     alien1y = 2
  48.     alien1x =84
  49.     alien1Abduct=false
  50.     alien1Carry=false
  51.     alien1Step=2
  52.     stepValue=0.1 --0.1
  53. end
  54.  
  55. function monSign()
  56.     monitor=peripheral.wrap("top")
  57.     monitor.setTextScale(0.5)
  58.     monW,monH=monitor.getSize()  --w 15  h 10
  59.     monitor.clear()
  60.     monitor.setCursorPos(4,5)
  61.     monitor.write("PROTECTOR")
  62. end
  63.  
  64. function clear()
  65.     term.clear()
  66.     term.setCursorPos(1,1)
  67.     term.setBackgroundColour(colours.black)
  68.     term.setTextColour(colours.white)
  69. end
  70.  
  71. function drawGrass()
  72.     term.setCursorPos(1,h)
  73.     term.setBackgroundColour(colours.green)
  74.     write(string.rep(" ",w))
  75.     term.setCursorPos(1,1)
  76.     term.setBackgroundColour(colours.black)
  77. end
  78.  
  79. function drawShip(yPos)
  80.     if shipFacingRight==true then
  81.         term.setCursorPos(24,yPos)
  82.         term.setBackgroundColour(colours.orange)
  83.         print(" ")
  84.         term.setCursorPos(25,yPos)
  85.         term.setBackgroundColour(colours.white)
  86.         print("  ")
  87.     else
  88.         term.setCursorPos(26,yPos)
  89.         term.setBackgroundColour(colours.orange)
  90.         print(" ")
  91.         term.setCursorPos(24,yPos)
  92.         term.setBackgroundColour(colours.white)
  93.         print("  ")
  94.     end
  95.     term.setBackgroundColour(colours.black)
  96. end
  97.  
  98. function delShip(yPos)
  99.     term.setCursorPos(24,yPos)
  100.     term.setBackgroundColour(colours.black)
  101.     print("   ")
  102. end
  103.  
  104. function drawAliens()
  105.     term.setBackgroundColour(colours.cyan)
  106.     if alien1==true then
  107.         term.setCursorPos(alien1x,alien1y)
  108.         write("   ")
  109.     end
  110.     term.setBackgroundColour(colours.black)
  111. end
  112.  
  113. function delAliens()
  114.     term.setBackgroundColour(colours.black)
  115.     if alien1==true then
  116.         term.setCursorPos(alien1x,alien1y)
  117.         write("   ")
  118.     end
  119. end
  120.  
  121. function drawHumans()
  122.     term.setBackgroundColour(colours.pink)
  123.     if human1==true then
  124.         term.setCursorPos(human1x,human1y)
  125.         write(" ")
  126.     end
  127.     if human2==true then
  128.         term.setCursorPos(human2x,human2y)
  129.         write(" ")
  130.     end
  131.     if human3==true then
  132.         term.setCursorPos(human3x,human3y)
  133.         write(" ")
  134.     end
  135.     if human4==true then
  136.         term.setCursorPos(human4x,human4y)
  137.         write(" ")
  138.     end
  139.     if human5==true then
  140.         term.setCursorPos(human5x,human5y)
  141.         write(" ")
  142.     end
  143.     if human6==true then
  144.         term.setCursorPos(human6x,human6y)
  145.         write(" ")
  146.     end
  147.     term.setBackgroundColour(colours.green)
  148.     term.setCursorPos(1,19)
  149.     write("   ")
  150.     term.setBackgroundColour(colours.black)
  151. end
  152.  
  153. function delHumans()
  154.     term.setBackgroundColour(colours.black)
  155.     if human1==true then
  156.         term.setCursorPos(human1x,human1y)
  157.         write(" ")
  158.     end
  159.     if human2==true then
  160.         term.setCursorPos(human2x,human2y)
  161.         write(" ")
  162.     end
  163.     if human3==true then
  164.         term.setCursorPos(human3x,human3y)
  165.         write(" ")
  166.     end
  167.     if human4==true then
  168.         term.setCursorPos(human4x,human4y)
  169.         write(" ")
  170.     end
  171.     if human5==true then
  172.         term.setCursorPos(human5x,human5y)
  173.         write(" ")
  174.     end
  175.     if human6==true then
  176.         term.setCursorPos(human6x,human6y)
  177.         write(" ")
  178.     end
  179. end
  180.  
  181. function drawBullet()
  182.     term.setBackgroundColour(colours.yellow)
  183.     term.setCursorPos(bulletXPos,bulletYPos)
  184.     write(" ")
  185.     term.setBackgroundColour(colours.black)
  186. end
  187.  
  188. function delBullet()
  189.     term.setBackgroundColour(colours.black)
  190.     term.setCursorPos(bulletXPos,bulletYPos)
  191.     write(" ")
  192. end
  193.  
  194. function gameOver(gameOverMsg)
  195.     clear()
  196.     delShip(shipYPos)
  197.     term.setCursorPos(40,1)
  198.     write("Lives: "..lives.."  ")
  199.     term.setCursorPos(5,1)
  200.     if score<0 then score=0 end
  201.     write("Score: "..score.."  ")
  202.     term.setTextColour(colours.red)
  203.     term.setCursorPos( (w/2)-5 , h/2 -1)
  204.     print("GAME OVER")
  205.     term.setCursorPos( (w/2)-(string.len(gameOverMsg)/2) , (h/2)+1)
  206.     print(gameOverMsg)
  207.     term.setTextColour(colours.white)
  208.     running=false
  209.     playAgain()
  210. end
  211.  
  212. function playAgain()
  213.     sleep(1)
  214.     term.setCursorPos((w/2)-9, (h/2)+3)
  215.     print("Play again (Y or N)")
  216.    
  217.     while true do
  218.         local event,p1,p2,p3 = os.pullEvent()
  219.         if event=="char" then
  220.             if string.lower(p1)=="y" then
  221.                 runGame()
  222.             elseif string.lower(p1)=="n" then
  223.                 os.shutdown()
  224.             end
  225.         end
  226.     end
  227.    
  228. end
  229.  
  230. function killPlayer()
  231.     moveLeft=false
  232.     moveRight=false
  233.     moveUp=false
  234.     moveDown=false
  235.     delShip(shipYPos)
  236.     lives=lives-1
  237.     if lives==0 then
  238.         gameOver("OUT OF LIVES")
  239.     end
  240.     killedState=true
  241.     --killedStr="true"
  242. end
  243.  
  244. function left()
  245.     delHumans()
  246.     delAliens()
  247.     human1x=human1x+1
  248.     human2x=human2x+1
  249.     human3x=human3x+1
  250.     human4x=human4x+1
  251.     human5x=human5x+1
  252.     human6x=human6x+1
  253.     alien1x=alien1x+1
  254.     if human1x>100 then human1x=0 end
  255.     if human2x>100 then human2x=0 end
  256.     if human3x>100 then human3x=0 end
  257.     if human4x>100 then human4x=0 end
  258.     if human5x>100 then human5x=0 end
  259.     if human6x>100 then human6x=0 end
  260.     if alien1x>100 then alien1x=0 end
  261.     shipFacingRight=false
  262.     checkShipCollision()
  263.     drawShip(shipYPos)
  264.     drawHumans()
  265.     drawAliens()
  266.     drawBorder()
  267.     moveRight=false
  268. end
  269.  
  270. function right()
  271.     delHumans()
  272.     delAliens()
  273.     human1x=human1x-1
  274.     human2x=human2x-1
  275.     human3x=human3x-1
  276.     human4x=human4x-1
  277.     human5x=human5x-1
  278.     human6x=human6x-1
  279.     alien1x=alien1x-1
  280.     if human1x<1 then human1x=100 end
  281.     if human2x<1 then human2x=100 end
  282.     if human3x<1 then human3x=100 end
  283.     if human4x<1 then human4x=100 end
  284.     if human5x<1 then human5x=100 end
  285.     if human6x<1 then human6x=100 end
  286.     if alien1x<1 then alien1x=100 end
  287.     shipFacingRight=true
  288.     checkShipCollision()
  289.     drawShip(shipYPos)
  290.     drawHumans()
  291.     drawAliens()
  292.     drawBorder()
  293.     moveLeft=false
  294. end
  295.  
  296. function up()
  297.     if shipYPos > 2 then
  298.         delShip(shipYPos)
  299.         shipYPos=shipYPos-1
  300.         checkShipCollision()
  301.         drawShip(shipYPos)
  302.     end
  303.     moveUp=false
  304.     moveDown=false
  305. end
  306.  
  307. function down()
  308.     if shipYPos<17 then
  309.         delShip(shipYPos)
  310.         shipYPos=shipYPos+1
  311.         checkShipCollision()
  312.         drawShip(shipYPos)
  313.     end
  314.     moveDown=false
  315.     moveUp=false
  316. end
  317.  
  318. function checkShipCollision()
  319.     if killedState==false then
  320.         if shipYPos == alien1y and alien1== true then
  321.             if alien1x >= 22 and alien1x <= 26 then
  322.                 alien1Hit()
  323.                 killPlayer()
  324.             end
  325.         elseif human1==true and human1y==shipYPos then
  326.             if human1x >=24 and human1x <= 26 then
  327.                 human1=false
  328.                 humanHitRoutine()
  329.             end
  330.         elseif human2==true and human2y==shipYPos then
  331.             if human2x >=24 and human2x <= 26 then
  332.                 human2=false
  333.                 humanHitRoutine()
  334.             end
  335.         elseif human3==true and human3y==shipYPos then
  336.             if human3x >=24 and human3x <= 26 then
  337.                 human3=false
  338.                 humanHitRoutine()
  339.             end
  340.         elseif human4==true and human4y==shipYPos then
  341.             if human4x >=24 and human4x <= 26 then
  342.                 human4=false
  343.                 humanHitRoutine()
  344.             end
  345.         elseif human5==true and human5y==shipYPos then
  346.             if human5x >=24 and human5x <= 26 then
  347.                 human5=false
  348.                 humanHitRoutine()
  349.             end
  350.         elseif human6==true and human6y==shipYPos then
  351.             if human6x >=24 and human6x <= 26 then
  352.                 human6=false
  353.                 humanHitRoutine()
  354.             end
  355.         end
  356.     end
  357. end
  358.  
  359. function alienGen()
  360.     if alien1==false then
  361.         local alienChance= math.random(1,10)
  362.         if alienChance==1 then
  363.             if human1==true then
  364.                 alien1 = true
  365.                 alien1y = 2
  366.                 alien1x = human1x - 1
  367.             end
  368.         elseif alienChance == 2 then
  369.             if human2==true then
  370.                 alien1 = true
  371.                 alien1y=2
  372.                 alien1x = human2x-1
  373.             end
  374.         elseif alienChance == 3 then
  375.             if human3==true then
  376.                 alien1 = true
  377.                 alien1y=2
  378.                 alien1x = human3x-1
  379.             end
  380.         elseif alienChance == 4 then
  381.             if human4==true then
  382.                 alien1 = true
  383.                 alien1y=2
  384.                 alien1x = human4x-1
  385.             end
  386.         elseif alienChance == 5 then
  387.             if human5==true then
  388.                 alien1 = true
  389.                 alien1y=2
  390.                 alien1x = human5x-1
  391.             end
  392.         elseif alienChance == 6 then
  393.             if human6==true then
  394.                 alien1 = true
  395.                 alien1y=2
  396.                 alien1x = human6x-1
  397.             end
  398.         end
  399.     end
  400. end
  401.  
  402. function alienDown()
  403.     if alien1==true and alien1Abduct==false and alien1y<19 then
  404.         alien1Step=alien1Step+stepValue
  405.         alien1y=math.floor(alien1Step)
  406.         if alien1==true and alien1Abduct==false and alien1y==17 then
  407.             alien1Abduct=true
  408.             alien1Carry=true
  409.             alien1Step=17
  410.         end
  411.     end
  412. end
  413.  
  414. function alienRoutine()
  415.     alien1=false
  416.     alien1Step=2
  417.     if alien1Carry==true then
  418.         score= score -50
  419.         humansLeft=humansLeft-1
  420.     end
  421.     alien1Abduct=false
  422.     alien1Carry=false
  423.     if humansLeft==0 then
  424.         gameOver("NO HUMANS LEFT")
  425.     end
  426.    
  427. end
  428.  
  429. function alienUp()
  430.     if alien1==true and alien1Abduct==true then
  431.         if alien1x+1 == human1x then
  432.             human1Abducted=true
  433.             alien1Step=alien1Step-stepValue
  434.             alien1y=math.floor(alien1Step)
  435.             human1y=math.floor(alien1Step)+1
  436.             human1x=alien1x+1
  437.             if human1y<=2 then
  438.                 alienRoutine()
  439.                 human1=false
  440.             end
  441.         elseif alien1x+1 == human2x then
  442.             human2Abducted=true
  443.             alien1Step=alien1Step-stepValue
  444.             alien1y=math.floor(alien1Step)
  445.             human2y=math.floor(alien1Step)+1
  446.             human2x=alien1x+1
  447.             if human2y<=2 then
  448.                 alienRoutine()
  449.                 human2=false
  450.             end
  451.         elseif alien1x+1 == human3x then
  452.             human3Abducted=true
  453.             alien1Step=alien1Step-stepValue
  454.             alien1y=math.floor(alien1Step)
  455.             human3y=math.floor(alien1Step)+1
  456.             human3x=alien1x+1
  457.             if human3y<=2 then
  458.                 alienRoutine()
  459.                 human3=false
  460.             end
  461.         elseif alien1x+1 == human4x then
  462.             human4Abducted=true
  463.             alien1Step=alien1Step-stepValue
  464.             alien1y=math.floor(alien1Step)
  465.             human4y=math.floor(alien1Step)+1
  466.             human4x=alien1x+1
  467.             if human4y<=2 then
  468.                 alienRoutine()
  469.                 human4=false
  470.             end
  471.         elseif alien1x+1 == human5x then
  472.             human5Abducted=true
  473.             alien1Step=alien1Step-stepValue
  474.             alien1y=math.floor(alien1Step)
  475.             human5y=math.floor(alien1Step)+1
  476.             human5x=alien1x+1
  477.             if human5y<=2 then
  478.                 alienRoutine()
  479.                 human5=false
  480.             end
  481.         elseif alien1x+1 == human6x then
  482.             human6Abducted=true
  483.             alien1Step=alien1Step-stepValue
  484.             alien1y=math.floor(alien1Step)
  485.             human6y=math.floor(alien1Step)+1
  486.             human6x=alien1x+1
  487.             if human6y<=2 then
  488.                 alienRoutine()
  489.                 human6=false
  490.             end
  491.         end
  492.     end
  493.     if alien1==false then alienGen() end
  494. end
  495.  
  496. function keyPress()  -- 200 UP, 208 DOWN, 203 LEFT,  205 RIGHT,  57 SPACE, 16 Q
  497.         if pressedKey==200 or pressedKey == 17 then -- up
  498.             moveUp=true
  499.             moveDown=false
  500.         elseif pressedKey==208 or pressedKey == 31 then -- DOWN
  501.             moveDown=true
  502.             moveUp=false
  503.         elseif pressedKey==203 or pressedKey == 30 then -- left
  504.             moveLeft=true  
  505.             moveRight=false
  506.         elseif pressedKey==205 or pressedKey == 32 then -- right
  507.             moveRight=true
  508.             moveLeft=false
  509.         elseif pressedKey==57 then -- space
  510.                 if bulletState==false then
  511.                     bulletYPos=shipYPos
  512.                     bulletState=true
  513.                     if shipFacingRight==true then
  514.                         bulletXPos=shipXPos+3
  515.                         bulletGoingRight=true
  516.                     else
  517.                         bulletXPos=shipXPos-1
  518.                         bulletGoingRight=false
  519.                     end
  520.                 end
  521.         elseif pressedKey==16 or pressedKey==25 then -- q  (use 25 if p for quit)
  522.                 gameOver("YOU QUIT")
  523.         end
  524.        
  525.         --term.setCursorPos(30,1)
  526.         --write(pressedKey.."  ")
  527. end
  528.  
  529. function removeBullet()
  530.     if bulletGoingRight==true then
  531.         bulletXPos = 60
  532.     else
  533.         bulletXPos = -10
  534.     end
  535. end
  536.  
  537. function alien1Hit()
  538.     delAliens()
  539.     alien1=false
  540.     score=score+20
  541.     alien1Step=2
  542.     alien1Abduct=false
  543.     removeBullet()
  544.     drawAliens()
  545. end
  546.  
  547. function humanHitRoutine()
  548.     score=score-50
  549.     humansLeft=humansLeft-1
  550.     if humansLeft==0 then
  551.         gameOver("NO HUMANS LEFT")
  552.     end
  553.     if alien1Carry==true then alien1Carry=false end
  554. end
  555.  
  556.  
  557. function checkBulletCollision()
  558.     if alien1 == true and bulletYPos == alien1y then
  559.         if bulletXPos >= alien1x  and bulletXPos <= alien1x + 3 then
  560.             alien1Hit()
  561.         end
  562.     end
  563.     if human1 == true and bulletYPos == human1y and bulletXPos == human1x then human1=false humanHitRoutine()  end
  564.     if human2 == true and bulletYPos == human2y and bulletXPos == human2x then human2=false humanHitRoutine()  end
  565.     if human3 == true and bulletYPos == human3y and bulletXPos == human3x then human3=false humanHitRoutine()  end
  566.     if human4 == true and bulletYPos == human4y and bulletXPos == human4x then human4=false humanHitRoutine()  end
  567.     if human5 == true and bulletYPos == human5y and bulletXPos == human5x then human5=false humanHitRoutine()  end
  568.     if human6 == true and bulletYPos == human6y and bulletXPos == human6x then human6=false humanHitRoutine()  end
  569. end
  570.  
  571. function drawBorder()
  572.     term.setBackgroundColour(colours.black)
  573.     for i=1,h-2 do
  574.         term.setCursorPos(1,i+1)
  575.         write(" ")
  576.         term.setCursorPos(w,i+1)
  577.         write(" ")
  578.     end
  579. end
  580.  
  581. function dropHumans()
  582.     if alien1Abduct==false then
  583.         if human1y<18 then human1y = human1y+1 end
  584.         if human2y<18 then human2y = human2y+1 end
  585.         if human3y<18 then human3y = human3y+1 end
  586.         if human4y<18 then human4y = human4y+1 end
  587.         if human5y<18 then human5y = human5y+1 end
  588.         if human6y<18 then human6y = human6y+1 end
  589.     end
  590. end
  591.  
  592.  
  593. function gameControl()
  594.  
  595.     gameTimer=os.startTimer(0.1)
  596.        
  597.     while running do
  598.         local event,p1,p2,p3 = os.pullEvent()
  599.         if score<0 then score=0 end
  600.         term.setCursorPos(1,1)
  601.         term.setBackgroundColour(colours.yellow)
  602.         write(string.rep(" ",w))
  603.    
  604.    
  605.         term.setTextColour(colours.red)
  606.         term.setCursorPos(5,1)
  607.         write("Score: "..score.."  ")
  608.         term.setCursorPos(20,1)
  609.         write("Humans Left: "..humansLeft.."  ")
  610.         term.setCursorPos(40,1)
  611.         write("Lives: "..lives.."  ")
  612.    
  613.         term.setBackgroundColour(colours.black)
  614.         term.setTextColour(colours.white)
  615.        
  616.         local newStepValue = (score+0.1)/1000
  617.         if newStepValue > stepValue then stepValue= newStepValue end
  618.         if stepValue>0.4 then stepValue=0.4 end
  619.        
  620.        
  621.         --[[DEBUG
  622.         term.setCursorPos(2,2)
  623.         write("human1x "..human1x.."  ")
  624.         term.setCursorPos(2,3)
  625.         write("human2x "..human2x.."  ")
  626.         term.setCursorPos(2,4)
  627.         write("human3x "..human3x.."  ")
  628.         term.setCursorPos(2,5)
  629.         write("human4x "..human4x.."  ")
  630.         term.setCursorPos(2,6)
  631.         write("human5x "..human5x.."  ")
  632.         term.setCursorPos(2,7)
  633.         write("human6x "..human6x.."  ")
  634.         ]]--
  635.        
  636.                
  637.         if event=="timer" and gameTimer == p1 then
  638.             if killedState==true then
  639.                 delShip(shipYPos)
  640.                 delHumans()
  641.                 dropHumans()
  642.                 drawHumans()
  643.                 killedDelay = killedDelay + 1
  644.                 if killedDelay>20 then
  645.                     shipYPos = 10
  646.                     killedState = false
  647.                     term.setBackgroundColour(colours.black)
  648.                     for i = 2, h-2 do
  649.                         term.setCursorPos(1,i)
  650.                         write(string.rep(" ",w))
  651.                     end
  652.                     drawGrass()
  653.                     if shipFacingRight==true then
  654.                         moveRight=true
  655.                         moveLeft=false
  656.                     else
  657.                         moveLeft=true
  658.                         moveRight=false
  659.                     end
  660.                     killedDelay=0
  661.                 end
  662.             else
  663.                
  664.                 --alienGen()
  665.                 drawShip(shipYPos)
  666.                 delAliens()
  667.                
  668.                 delHumans()
  669.                 dropHumans()
  670.                 alienDown()
  671.                 alienUp()
  672.                 drawAliens()
  673.                 drawHumans()
  674.                 drawBorder()
  675.             end
  676.            
  677.             if bulletState==true then
  678.                 if bulletGoingRight==true then
  679.                     delBullet()
  680.                     bulletXPos=bulletXPos+1
  681.                     checkBulletCollision()
  682.                     if bulletXPos>45 then
  683.                         bulletState=false
  684.                     else
  685.                         if killedState==false then drawBullet() end
  686.                     end
  687.                 else
  688.                     delBullet()
  689.                     bulletXPos=bulletXPos-1
  690.                     checkBulletCollision()
  691.                     if bulletXPos<6 then
  692.                         bulletState=false
  693.                     else
  694.                         if killedState==false then drawBullet() end
  695.                     end
  696.                 end
  697.             end
  698.            
  699.             if moveLeft==true then
  700.                 left()
  701.             end
  702.             if moveRight==true then
  703.                 right()
  704.             end
  705.             if moveUp==true then
  706.                 up()
  707.             end
  708.             if moveDown==true then
  709.                 down()
  710.             end
  711.            
  712.             gameTimer=os.startTimer(0.1)
  713.        
  714.         elseif event=="key" and killedState==false then
  715.             pressedKey=p1
  716.             keyPress()
  717.         end
  718.        
  719.     end
  720.    
  721. end
  722.  
  723. function runGame()
  724.     initVariables()
  725.     clear()
  726.     drawGrass()
  727.     drawHumans()
  728.     alienGen()
  729.     gameControl()
  730. end
  731.  
  732.  
  733. function pix(xCo,yCo,text,col)
  734.     if col== nil then term.setBackgroundColour(colours.black)
  735.     elseif col =="white" then term.setBackgroundColour(colours.white)
  736.     elseif col =="green" then term.setBackgroundColour(colours.green)
  737.     elseif col =="pink" then term.setBackgroundColour(colours.pink)
  738.     elseif col =="orange" then term.setBackgroundColour(colours.orange)
  739.     elseif col =="cyan" then term.setBackgroundColour(colours.cyan)
  740.     elseif col =="yellow" then term.setBackgroundColour(colours.yellow)
  741.     end
  742.     term.setCursorPos(xCo,yCo)
  743.     write(text)
  744. end
  745.  
  746. function drawHumanPix()
  747.     pix(23,humanPixY," ","pink")
  748.     pix(27,humanPixY," ","pink")
  749.     pix(24,humanPixY-1," ","pink")
  750.     pix(26,humanPixY-1," ","pink")
  751.     pix(25,humanPixY-2," ","pink")
  752.     pix(23,humanPixY-3,"     ","pink")
  753.     pix(25,humanPixY-4," ","pink")
  754.     pix(24,humanPixY-5,"   ","pink")
  755.     pix(24,humanPixY-6,"   ","pink")
  756. end
  757.  
  758. function delHumanPix()
  759.     pix(23,humanPixY," ")
  760.     pix(27,humanPixY," ")
  761.     pix(24,humanPixY-1," ")
  762.     pix(26,humanPixY-1," ")
  763.     pix(25,humanPixY-2," ")
  764.     pix(23,humanPixY-3,"     ")
  765.     pix(25,humanPixY-4," ")
  766.     pix(24,humanPixY-5,"   ")
  767.     pix(24,humanPixY-6,"   ")
  768. end
  769.  
  770. function drawAlienPix()
  771.     pix(19,alienPixY,"             ","cyan")
  772.     pix(17,alienPixY+1,"                 ","cyan")
  773.     pix(19,alienPixY+2,"             ","cyan")
  774. end
  775.  
  776. function delAlienPix()
  777.     pix(19,alienPixY,"             ")
  778.     pix(17,alienPixY+1,"                 ")
  779.     pix(19,alienPixY+2,"             ")
  780. end
  781.  
  782. function drawShipPix()
  783.     pix(shipPixX+3,3,"  ","white")
  784.     pix(shipPixX+3,4,"   ","white")
  785.     pix(shipPixX+3,5,"           ","white")
  786.     pix(shipPixX+3,6,"               ","white")
  787.     pix(shipPixX+3,7,"                 ","white")
  788.     pix(shipPixX+2,5," ","orange")
  789.     pix(shipPixX+2,6," ","yellow")
  790.     pix(shipPixX+2,7," ","orange")
  791.     pix(shipPixX,6,"  ","orange")
  792.     pix(shipPixX+14,5,"  ","cyan")
  793. end
  794.  
  795. function delShipPix()
  796.     pix(shipPixX+3,3,"  ")
  797.     pix(shipPixX+3,4,"   ")
  798.     pix(shipPixX+3,5,"           ")
  799.     pix(shipPixX+3,6,"               ")
  800.     pix(shipPixX+3,7,"                 ")
  801.     pix(shipPixX+2,5," ")
  802.     pix(shipPixX+2,6," ")
  803.     pix(shipPixX+2,7," ")
  804.     pix(shipPixX,6,"  ")
  805.     pix(shipPixX+14,5,"  ")
  806. end
  807.  
  808. function line1()
  809.     pix(8,4,"   ","white")
  810.     pix(12,4,"  ","white")
  811.     pix(16,4,"   ","white")
  812.     pix(20,4,"   ","white")
  813.     pix(24,4,"   ","white")
  814.     pix(28,4,"   ","white")
  815.     pix(32,4,"   ","white")
  816.     pix(36,4,"   ","white")
  817.     pix(40,4,"  ","white")
  818. end
  819.  
  820. function line2()
  821.     pix(8,5," ","white")
  822.     pix(10,5," ","white")
  823.     pix(12,5," ","white")
  824.     pix(14,5," ","white")
  825.     pix(16,5," ","white")
  826.     pix(18,5," ","white")
  827.     pix(21,5," ","white")
  828.     pix(24,5," ","white")
  829.     pix(28,5," ","white")
  830.     pix(33,5," ","white")
  831.     pix(36,5," ","white")
  832.     pix(38,5," ","white")
  833.     pix(40,5," ","white")
  834.     pix(42,5," ","white")
  835.    
  836. end
  837.  
  838. function line3()
  839.     pix(8,6,"   ","white")
  840.     pix(12,6,"   ","white")
  841.     pix(16,6," ","white")
  842.     pix(18,6," ","white")
  843.     pix(21,6," ","white")
  844.     pix(24,6,"   ","white")
  845.     pix(28,6," ","white")
  846.     pix(33,6," ","white")
  847.     pix(36,6," ","white")
  848.     pix(38,6," ","white")
  849.     pix(40,6,"   ","white")
  850. end
  851.  
  852. function line4()
  853.     pix(8,7," ","white")
  854.     pix(12,7,"  ","white")
  855.     pix(16,7," ","white")
  856.     pix(18,7," ","white")
  857.     pix(21,7," ","white")
  858.     pix(24,7," ","white")
  859.     pix(28,7," ","white")
  860.     pix(33,7," ","white")
  861.     pix(36,7," ","white")
  862.     pix(38,7," ","white")
  863.     pix(40,7,"  ","white")
  864. end
  865.  
  866. function line5()
  867.     pix(8,8," ","white")
  868.     pix(12,8," ","white")
  869.     pix(14,8," ","white")
  870.     pix(16,8,"   ","white")
  871.     pix(21,8," ","white")
  872.     pix(24,8,"   ","white")
  873.     pix(28,8,"   ","white")
  874.     pix(33,8," ","white")
  875.     pix(36,8,"   ","white")
  876.     pix(40,8," ","white")
  877.     pix(42,8," ","white")
  878. end
  879.  
  880.  
  881. function startScreen()
  882.  
  883.     clear()
  884.     term.setBackgroundColour(colours.green)
  885.     term.setCursorPos(1,h)
  886.     write(string.rep(" ",w))
  887.     local screenStage=0
  888.    
  889.     screenTimer=os.startTimer(0.1)
  890.     while true do
  891.         local event,p1,p2,p3=os.pullEvent()
  892.         if event=="key"and p1==57 then
  893.             term.setBackgroundColour(colours.black)
  894.             clear()
  895.             runGame()
  896.         elseif event=="timer" and screenTimer == p1 then
  897.        
  898.             --term.setCursorPos(1,1) write("screenStage: "..screenStage.."  ")
  899.            
  900.             term.setBackgroundColour(colours.black)
  901.             term.setCursorPos(35,1) write("SPACE WHEN READY")
  902.            
  903.             if screenStage>0 and screenStage<0.5 then
  904.                 humanPixY = 18
  905.                 drawHumanPix()
  906.             elseif screenStage>2 and screenStage<2.9 then
  907.                 alienPixY = -2
  908.                 drawAlienPix()
  909.             elseif screenStage>3 and screenStage<3.9 then
  910.                 alienPixY = -2
  911.                 delAlienPix()
  912.                 alienPixY = -1
  913.                 drawAlienPix()
  914.             elseif screenStage>4 and screenStage<4.9 then
  915.                 alienPixY = -1
  916.                 delAlienPix()
  917.                 alienPixY = 0
  918.                 drawAlienPix()  
  919.             elseif screenStage>5 and screenStage<5.9 then
  920.                 alienPixY = 0
  921.                 delAlienPix()
  922.                 alienPixY = 1
  923.                 drawAlienPix()
  924.             elseif screenStage>6 and screenStage<6.9 then
  925.                 alienPixY = 1
  926.                 delAlienPix()
  927.                 alienPixY = 2
  928.                 drawAlienPix()
  929.             elseif screenStage>7 and screenStage<7.9 then
  930.                 alienPixY = 2
  931.                 delAlienPix()
  932.                 alienPixY = 3
  933.                 drawAlienPix()
  934.             elseif screenStage>8 and screenStage<8.9 then
  935.                 alienPixY = 3
  936.                 delAlienPix()
  937.                 alienPixY = 4
  938.                 drawAlienPix() 
  939.             elseif screenStage>8 and screenStage<9.9 then
  940.                 alienPixY = 4
  941.                 delAlienPix()
  942.                 alienPixY = 5
  943.                 drawAlienPix()
  944.             elseif screenStage>10 and screenStage<10.4 then
  945.                 pix(25,8," ","yellow")
  946.                 pix(25,9," ","yellow")
  947.                 pix(25,10," ","yellow")
  948.                 pix(25,11," ","yellow")
  949.                 pix(25,17," ","yellow")
  950.                 pix(25,18," ","yellow")
  951.             elseif screenStage>10.4 and screenStage<10.6 then
  952.                 pix(25,8," ","yellow")
  953.                 pix(25,9," ","yellow")
  954.                 pix(25,10," ","yellow")
  955.                 pix(24,11,"   ","yellow")
  956.                 pix(24,12,"   ","yellow")
  957.                 pix(24,13,"   ","yellow")
  958.                 pix(24,14,"   ","yellow")
  959.                 pix(23,15,"     ","yellow")
  960.                 pix(23,16,"     ","yellow")
  961.                 pix(23,17,"     ","yellow")
  962.                 pix(23,18,"     ","yellow")
  963.                 humanPixY = 18
  964.                 drawHumanPix()
  965.             elseif screenStage>10.6 and screenStage<10.8 then
  966.                 pix(25,8," ","yellow")
  967.                 pix(25,9," ","yellow")
  968.                 pix(24,10,"   ","yellow")
  969.                 pix(24,11,"   ","yellow")
  970.                 pix(24,12,"   ","yellow")
  971.                 pix(23,13,"     ","yellow")
  972.                 pix(23,14,"     ","yellow")
  973.                 pix(23,15,"     ","yellow")
  974.                 pix(22,16,"       ","yellow")
  975.                 pix(22,17,"       ","yellow")
  976.                 pix(22,18,"       ","yellow")
  977.                 humanPixY = 18
  978.                 drawHumanPix() 
  979.             elseif screenStage>10.8 and screenStage<11 then
  980.                 pix(25,8," ","yellow")
  981.                 pix(24,9,"   ","yellow")
  982.                 pix(24,10,"   ","yellow")
  983.                 pix(23,11,"     ","yellow")
  984.                 pix(23,12,"     ","yellow")
  985.                 pix(22,13,"       ","yellow")
  986.                 pix(22,14,"       ","yellow")
  987.                 pix(21,15,"         ","yellow")
  988.                 pix(21,16,"         ","yellow")
  989.                 pix(20,17,"           ","yellow")
  990.                 pix(20,18,"           ","yellow")
  991.                 humanPixY = 18
  992.                 drawHumanPix()     
  993.             elseif screenStage>11.9 and screenStage<12 then
  994.                 pix(1,6,"  ","yellow")
  995.             elseif screenStage>12 and screenStage<12.1 then
  996.                 pix(1,6,"  ")
  997.                 pix(3,6,"  ","yellow")
  998.             elseif screenStage>12.1 and screenStage<12.2 then
  999.                 pix(3,6,"  ")
  1000.                 pix(5,6,"  ","yellow") 
  1001.             elseif screenStage>12.2 and screenStage<12.3 then
  1002.                 pix(5,6,"  ")
  1003.                 pix(7,6,"  ","yellow")
  1004.             elseif screenStage>12.3 and screenStage<12.4 then
  1005.                 pix(7,6,"  ")
  1006.                 pix(9,6,"  ","yellow")
  1007.             elseif screenStage>12.4 and screenStage<12.5 then
  1008.                 pix(9,6,"  ")
  1009.                 pix(11,6,"  ","yellow")
  1010.             elseif screenStage>12.5 and screenStage<12.6 then
  1011.                 pix(11,6,"  ")
  1012.                 pix(13,6,"  ","yellow")
  1013.             elseif screenStage>12.6 and screenStage<12.7 then
  1014.                 pix(13,6,"  ")
  1015.                 pix(15,6,"  ","yellow")
  1016.             elseif screenStage>12.7 and screenStage<12.8 then
  1017.                 term.setBackgroundColour(colours.black)
  1018.                 for i= 5, h-1 do
  1019.                     term.setCursorPos(15,i)
  1020.                     write("                    ")
  1021.                 end
  1022.                 humanPixY=18
  1023.                 drawHumanPix()
  1024.             elseif screenStage>13 and screenStage<13.1 then
  1025.                 shipPixX= -16
  1026.                 drawShipPix()
  1027.             elseif screenStage>13 and screenStage<13.1 then
  1028.                 delShipPix()
  1029.                 shipPixX= -15
  1030.                 drawShipPix()  
  1031.             elseif screenStage>13.1 and screenStage<13.2 then  
  1032.                 delShipPix()
  1033.                 shipPixX= -12
  1034.                 drawShipPix()  
  1035.             elseif screenStage>13.2 and screenStage<13.3 then  
  1036.                 delShipPix()
  1037.                 shipPixX= -9
  1038.                 drawShipPix()
  1039.             elseif screenStage>13.2 and screenStage<13.3 then  
  1040.                 delShipPix()
  1041.                 shipPixX= -6
  1042.                 drawShipPix()
  1043.             elseif screenStage>13.3 and screenStage<13.4 then  
  1044.                 delShipPix()
  1045.                 shipPixX= -3
  1046.                 drawShipPix()
  1047.             elseif screenStage>13.4 and screenStage<13.5 then  
  1048.                 delShipPix()
  1049.                 shipPixX= 0
  1050.                 drawShipPix()
  1051.             elseif screenStage>13.6 and screenStage<13.7 then  
  1052.                 delShipPix()
  1053.                 shipPixX= 3
  1054.                 drawShipPix()
  1055.             elseif screenStage>13.8 and screenStage<13.9 then  
  1056.                 delShipPix()
  1057.                 shipPixX= 6
  1058.                 drawShipPix()
  1059.             elseif screenStage>13.9 and screenStage<14 then
  1060.                 delShipPix()
  1061.                 shipPixX= 9
  1062.                 drawShipPix()
  1063.             elseif screenStage>14.1 and screenStage<14.2 then  
  1064.                 delShipPix()
  1065.                 shipPixX= 12
  1066.                 drawShipPix()
  1067.             elseif screenStage>14.2 and screenStage<14.3 then  
  1068.                 delShipPix()
  1069.                 shipPixX= 15
  1070.                 drawShipPix()
  1071.             elseif screenStage>14.3 and screenStage<14.4 then  
  1072.                 delShipPix()
  1073.                 shipPixX= 18
  1074.                 drawShipPix()
  1075.             elseif screenStage>14.4 and screenStage<14.5 then  
  1076.                 delShipPix()
  1077.                 shipPixX= 21
  1078.                 drawShipPix()
  1079.             elseif screenStage>14.5 and screenStage<14.6 then  
  1080.                 delShipPix()
  1081.                 shipPixX= 24
  1082.                 drawShipPix()
  1083.             elseif screenStage>14.6 and screenStage<14.7 then  
  1084.                 delShipPix()
  1085.                 shipPixX= 27
  1086.                 drawShipPix()
  1087.             elseif screenStage>14.7 and screenStage<14.8 then  
  1088.                 delShipPix()
  1089.                 shipPixX= 30
  1090.                 drawShipPix()
  1091.             elseif screenStage>14.8 and screenStage<14.9 then  
  1092.                 delShipPix()
  1093.                 shipPixX= 33
  1094.                 drawShipPix()
  1095.             elseif screenStage>14.9 and screenStage<15 then
  1096.                 delShipPix()
  1097.                 shipPixX= 36
  1098.                 drawShipPix()
  1099.             elseif screenStage>15 and screenStage<15.1 then
  1100.                 delShipPix()
  1101.                 shipPixX= 39
  1102.                 drawShipPix()
  1103.             elseif screenStage>15.1 and screenStage<15.2 then  
  1104.                 delShipPix()
  1105.                 shipPixX= 41
  1106.                 drawShipPix()
  1107.             elseif screenStage>15.2 and screenStage<15.3 then  
  1108.                 delShipPix()
  1109.                 shipPixX= 44
  1110.                 drawShipPix()
  1111.             elseif screenStage>15.3 and screenStage<15.4 then  
  1112.                 delShipPix()
  1113.                 shipPixX= 47
  1114.                 drawShipPix()
  1115.             elseif screenStage>15.4 and screenStage<15.5 then  
  1116.                 delShipPix()
  1117.                 shipPixX= 50
  1118.                 drawShipPix()
  1119.             elseif screenStage>15.5 and screenStage<15.6 then  
  1120.                 delShipPix()
  1121.             elseif screenStage>16 and screenStage<16.9 then
  1122.                 humanPixY=18
  1123.                 delHumanPix()
  1124.                 line1()
  1125.                 line2()
  1126.                 line3()
  1127.                 line4()
  1128.                 line5()
  1129.             elseif screenStage>17 and screenStage<20 then
  1130.                 term.setCursorPos((w/2)-6,10)
  1131.                 write("by FredTHead")
  1132.                 term.setCursorPos((w/2)-13,12)
  1133.                 write("WSAD or arrow keys to move")
  1134.                 term.setCursorPos((w/2)-6,13)
  1135.                 write("SPACE to fire")
  1136.                 term.setCursorPos((w/2)-4,14)
  1137.                 write("P to quit")
  1138.                 term.setCursorPos((w/2)-8,16)
  1139.                 write("Fire when ready")
  1140.             elseif screenStage>25 then 
  1141.                 term.setBackgroundColour(colours.black)
  1142.                 for i = 2,h-1 do
  1143.                     term.setCursorPos(1,i)
  1144.                     write(string.rep(" ",w-1))
  1145.                 end
  1146.                 screenStage=0
  1147.             end
  1148.            
  1149.             screenStage=screenStage+0.1
  1150.             screenTimer=os.startTimer(0.025)
  1151.         end
  1152.     end
  1153. end
  1154.  
  1155. initVariables()
  1156. monSign()
  1157. startScreen()
Add Comment
Please, Sign In to add comment