ecco7777

CC dance game?

Apr 3rd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. m=peripheral.wrap("bottom")
  2. ship={"^","v","<",">"}
  3. xMax,yMax=m.getSize()
  4. x=xMax/2-0.5
  5. y=yMax/2-0.5
  6. score=0
  7. ex=math.random(1,xMax-2)
  8. ey=math.random(2,yMax-2)
  9. os.pullEvent=os.pullEventRaw
  10.  
  11. function printChar(x,y,char,ex,ey)
  12. m.clear()
  13. m.setCursorPos(1,1) m.write("score: "..tostring(score))
  14. m.setCursorPos(x,y)
  15. m.write(char)
  16. m.setCursorPos(ex,ey)
  17. m.write("o")
  18. end
  19.  
  20. while true do
  21. pos=0
  22. if redstone.testBundledInput("left",colors.blue)==true then pos=1 if y>2 then y=y-1 end end
  23. if redstone.testBundledInput("right",colors.orange)==true then pos=2 if y<yMax-1 then y=y+1 end end
  24. if redstone.testBundledInput("left",colors.red)==true then pos=3 if x>0 then x=x-1 end end
  25. if redstone.testBundledInput("right",colors.lime)==true then pos=4 if x<xMax-1 then x=x+1 end end
  26. if pos~=0 then
  27. printChar(x,y,ship[pos],ex,ey)
  28. end
  29. if x==ex and y==ey then
  30. score=score+1
  31. ex=math.random(1,xMax-2)
  32. ey=math.random(2,yMax-2)
  33. rs.setOutput("top",true)
  34. sleep(0.5)
  35. rs.setOutput("top",false)
  36. end
  37. sleep(0.5)
  38. end
Add Comment
Please, Sign In to add comment