Advertisement
paramus

Space shooter

Feb 21st, 2025 (edited)
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | Gaming | 0 0
  1. local w,a,s,d,space = false,false,false,false,false
  2. local x,y = 26,17
  3. local cooldown = 10
  4.  
  5. function Paint()
  6.     term.setBackgroundColor(colors.black)
  7.     term.clear()
  8.    
  9.     -- Player
  10.     paintutils.drawPixel(x,y,colors.green)
  11.     paintutils.drawLine(x-1,y+1,x+1,y+1,colors.green)
  12.    
  13.     -- Enemies
  14. end
  15.  
  16. function Movement()
  17.     if (w==true) then y=y-1 end
  18.     if (a==true) then x=x-1 end
  19.     if (s==true) then y=y+1 end
  20.     if (d==true) then x=x+1 end
  21.    
  22.     --Shooting ¿How tho...?
  23.     cooldown=cooldown-1
  24.     if (space==true and cooldown<=0) then
  25.         print("Pew Pew Im a bullet >:)")
  26.         cooldown=10
  27.     end
  28.    
  29.     --Correction
  30.     if (x>=50) then x=49 end
  31.     if (x<=2) then x=3 end
  32.     if (y>=18) then y=17 end
  33.     if (y<=1) then y=2 end
  34. end
  35.  
  36. -- Main --
  37. while(true) do
  38.     parallel.waitForAny(function()
  39.             Movement()
  40.             Paint()
  41.             sleep(0.2)
  42.         end,
  43.         function()
  44.             local e,k = os.pullEvent("key")
  45.             if (k == keys.space) then space=true
  46.             elseif (k == keys.w) then w=true
  47.             elseif (k == keys.a) then a=true
  48.             elseif (k == keys.s) then s=true
  49.             elseif (k == keys.d) then d=true
  50.             end
  51.         end,
  52.         function()
  53.             local e,k = os.pullEvent("key_up")
  54.             if (k == keys.space) then space=false
  55.             elseif (k == keys.w) then w=false
  56.             elseif (k == keys.a) then a=false
  57.             elseif (k == keys.s) then s=false
  58.             elseif (k == keys.d) then d=false
  59.             end
  60.         end
  61.     )
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement