Guest User

game 1

a guest
Mar 18th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. --SECTION 1, VARIABLES
  2. local posX, posY = 5, 5
  3. local w,h = term.getSize()
  4. weapon = "bow"
  5. local char = {
  6. " ",
  7. "@",
  8. " ",
  9. }
  10. local arrow = {
  11. "-"
  12. }
  13.  
  14. --ART FUNCTIONS
  15.  
  16. function printCenter(str, nolp)
  17. term.setCursorPos(w/2 - #str/2, nolp)
  18. term.write(str)
  19. end
  20.  
  21. function printRight(str, nolpW)
  22. term.setCursorPos(w - #str, nolpW)
  23. term.write(str)
  24. end
  25.  
  26. function drawHeader()
  27. printCenter("Game!", 1)
  28. printCenter(string.rep("#", w), 2)
  29. end
  30.  
  31. local function picture(image,positionX,positionY)
  32. for y = 1,#image do
  33. term.setCursorPos(positionX,positionY + y - 1)
  34. term.write(image[y])
  35. end
  36. end
  37.  
  38.  
  39. --weapon functions
  40.  
  41. function weapon()
  42. if weapon == "bow" then
  43. print("_")
  44. end
  45. end
  46.  
  47.  
  48. --MOVMENT
  49.  
  50.  
  51. while true do
  52.  
  53. term.clear()
  54. drawHeader()
  55. picture(char,posX,posY)
  56.  
  57. local event = {os.pullEvent()}
  58.  
  59. --Movement
  60.  
  61. if event[1] == "key" then
  62. if event[2] == 200 then --up
  63. posY = posY - 1
  64. elseif event[2] == 208 then --down
  65. posY = posY + 1
  66. elseif event[2] == 205 then --left
  67. posX = posX + 1
  68. elseif event[2] == 203 then --right
  69. posX = posX - 1
  70. elseif event[2] == 57 then
  71. weapon()
  72. end
  73. end
  74.  
  75. end
  76.  
  77. --Weapons
  78. weapon = "bow"
  79. arrow = {
  80. "-"
  81. }
  82. --bow
  83.  
  84. while true do
  85. if weapon == "bow" then
  86.  
  87. local event = {os.pullEvent()}
  88.  
  89. if event[1] == "key" then
  90. if event[2] == 57 then
  91. Xpos = Xpos - 1
  92. end
  93. end
  94. end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment