Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. import turtle
  2. #background and UI
  3. wn = turtle.Screen()
  4. wn.bgcolor('#ffd26c')
  5. wn.title('Desert Temple Maze')
  6. wn.setup(700, 700)
  7.  
  8. #maze walLs
  9. class Pen(turtle.Turtle):
  10. def __init__(self):
  11. turtle.Turtle.__init__(self)
  12. self.shape('square')
  13. self.color('#ff7227')
  14. self.penup()
  15. self.speed(0)
  16. #player model
  17. class Player(turtle.Turtle):
  18. def __init__(self):
  19. turtle.Turtle.__init__(self)
  20. self.shape('circle')
  21. self.color('#fe5d5d')
  22. self.penup()
  23. self.speed(0)
  24.  
  25.  
  26. #definition of the key presses
  27. def go_up(self):
  28. move_to_x = player.xcor()
  29. move_to_y = player.xcor() + 24
  30.  
  31. #checks to see if theres a wall
  32. if (move_to_x, move_to_y) not in walls:
  33. self.goto(move_to_x, move_to_y)
  34.  
  35. def go_down(self):
  36. move_to_x = player.xcor()
  37. move_to_y = player.xcor() - 24
  38. #checks to see if theres a wall
  39.  
  40. if (move_to_x, move_to_y) not in walls:
  41. self.goto(move_to_x, move_to_y)
  42.  
  43. def go_left(self):
  44. move_to_x = player.xcor() - 24
  45. move_to_y = player.xcor()
  46. #checks to see if theres a wall
  47.  
  48. if (move_to_x, move_to_y) not in walls:
  49. self.goto(move_to_x, move_to_y)
  50.  
  51. def go_right(self):
  52. move_to_x = player.xcor() + 24
  53. move_to_y = player.xcor()
  54. #checks to see if theres a wall
  55.  
  56. if (move_to_x, move_to_y) not in walls:
  57. self.goto(move_to_x, move_to_y)
  58.  
  59.  
  60. levels = [""]
  61.  
  62. level_1 = [
  63. "XXXXXXXXXXXXXXXXXXXXXXXXX",
  64. "XPX X X",
  65. "X X XXXXX XXXXXX XXXXXX X",
  66. "X X X X X",
  67. "X XXXXXXX XXXXXXXXXXXXX X",
  68. "X X X X X",
  69. "XXXXXXXXXXX XXX X XXXXX X",
  70. "X X X X X X",
  71. "X X X XXXXX X XXXXXXXXX",
  72. "X X X XXX X",
  73. "X X XXXXXXXXX XXX X",
  74. "X XXXXXX XX X X X X",
  75. "X X X XXXXX X X X X",
  76. "XXXXXX XX X X X X X X",
  77. "X X X XX XXXX X X X",
  78. "X XXXXXXXXX X X X X",
  79. "X X X XXXXX X XXXXX",
  80. "X XXX X X X X X X X",
  81. "X X X X X XXX XXXXXXX",
  82. "XXXXX X X X X X X",
  83. "X X XXXXXXXXX X XXX X",
  84. "X X X X X XXXXX X",
  85. "X XXX XXXXX X X X X X",
  86. "X X X X X",
  87. "XXXXXXXXXXXXXXXXXXXXXXXXX"
  88. ]
  89.  
  90. levels.append(level_1)
  91.  
  92. #level setup
  93. def setup_maze(level):
  94. for y in range(len(level)):
  95. for x in range(len(level[y])):
  96. character = level[y][x]
  97. #cooridinates of screen setup
  98. screen_x = -288 + (x * 24)
  99. screen_y = 288 - (y * 24)
  100.  
  101. #coordinates of wall
  102. if character == "X":
  103. pen.goto(screen_x, screen_y)
  104. pen.stamp()
  105. #adds coordinates to wall list
  106. walls.append((screen_x, screen_y))
  107.  
  108. #coordinates of player
  109. if character == "P":
  110. player.goto(screen_x, screen_y)
  111. #variables
  112. pen = Pen()
  113. player = Player()
  114.  
  115. #creates list for wall coordinates
  116. walls = []
  117.  
  118. #sets up level
  119. setup_maze(levels[1])
  120.  
  121. #so the code responds to key presses
  122. turtle.listen()
  123. turtle.onkey(player.go_left,"a")
  124. turtle.onkey(player.go_right,"d")
  125. turtle.onkey(player.go_up,"w")
  126. turtle.onkey(player.go_down,"s")
  127.  
  128. #turn off screen updates
  129. wn.tracer(0)
  130.  
  131. #game loop
  132. while True:
  133. wn.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement