Advertisement
asweigart

mydance2

Dec 7th, 2016
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. --[[ A Better Dance program by Al Sweigart
  2. Make the turtle dance better! ]]
  3.  
  4. local isUp = false
  5. local isBack = false
  6. local danceMove
  7. print('Hold Ctrl-T to stop dancing.')
  8. while true do
  9. danceMove = math.random(1, 5)
  10.  
  11. if danceMove == 1 then
  12. -- turn left
  13. print('Turn to the left!')
  14. turtle.turnLeft()
  15.  
  16. elseif danceMove == 2 then
  17. -- turn right
  18. print('Turn to the right!')
  19. turtle.turnRight()
  20.  
  21. elseif danceMove == 3 then
  22. -- forward/back moves
  23. if isBack then
  24. print('Move forward!')
  25. turtle.forward()
  26. isBack = false
  27. else
  28. print('Move back!')
  29. turtle.back()
  30. isBack = true
  31. end
  32.  
  33. elseif danceMove == 4 then
  34. -- up/down moves
  35. if isUp then
  36. print('Get up!')
  37. turtle.down()
  38. isUp = false
  39. else
  40. print('Get down!')
  41. turtle.up()
  42. isUp = true
  43. end
  44.  
  45. else
  46. -- spin around
  47. print('Spin!')
  48. for i = 1, 4 do
  49. turtle.turnLeft()
  50. end
  51. end
  52. end
  53. print('Done.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement