Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. --[[
  2. --------------------------------------------------------------
  3. funtion to show the menu on the screen for the user to see
  4. ----------------------------------------------------
  5. ]]
  6. function display_menu()
  7. -- Display a menu on the console
  8. print("+----------------------------------")
  9. print("| Welcome, brave soul, today is "..os.date())
  10. print("+----------------------------------")
  11. print("| 1.Generate random enemy position")
  12. print("| 2.Distance from enemy to player")
  13. print("| 3.Get angle from enemy to player")
  14. print("| 4.Exit")
  15. print("+----------------------------------")
  16. end
  17.  
  18. --[[
  19. My InSaNe code
  20. jk... its really not that P but idk
  21. just a starter
  22. ]]
  23.  
  24. math.random(os.time())
  25.  
  26. --delcaring player pos in the middle of the screen
  27. local player_x, player_y = 400,300
  28.  
  29. local enemy_x, enemy_y = 0,0
  30.  
  31.  
  32. local user_option = 0
  33.  
  34. --loop while user option is different
  35. while user_option ~= 4 do
  36. display_menu()
  37.  
  38. --read the user option from the keyboard
  39. print("Please, select your option:")
  40. user_option = io.read("*n")
  41.  
  42. if user_option == 1 then
  43. enemy_x = math.random(0, 800)
  44. enemy_y = math.random(0, 600)
  45. print("New enemy pos ("..enemy_x..","..enemy_y..")")
  46. end
  47.  
  48. if user_option == 2 then
  49. local d = math.sqrt((enemy_x-player_x)^2 + (enemy_y-player_y)^2)
  50. print("Distance from enemy to player: "..d)
  51. end
  52.  
  53. if user_option == 3 then
  54. local a = math.atan2((enemy_y-player_y) (enemy_x-player_x))
  55. local a_deg = math.deg(a)
  56. print("Angle between enemy and player is: ".. a_deg.." degrees")
  57. end
  58. end
  59. -- quick little user survey
  60. print("+----------------------------------")
  61. print("Please take a quick minute to fill out this short survey")
  62. print("+----------------------------------")
  63. print("1.The program was good")
  64. print("2.The program was bad")
  65. print("3.Take me out of this trash program once and for all")
  66. survey_answer = io.read("*n")
  67. if survey_answer == 1 then
  68. print("+----------------------------------")
  69. print("GLAD TO HEAR THAT, goodbye")
  70. print("+----------------------------------")
  71. end
  72. if survey_answer == 2 then
  73. print("+----------------------------------")
  74. print("AWW sorry to hear that")
  75. print("+----------------------------------")
  76. end
  77. if survey_answer == 3 then
  78. print("+----------------------------------")
  79. print("GOODBYE!!")
  80. print("+----------------------------------")
  81. os.exit()
  82. end
  83.  
  84. print("Thank you for your time, goodbye!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement