Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import turtle
- #background and UI
- wn = turtle.Screen()
- wn.bgcolor('#ffd26c')
- wn.title('Desert Temple Maze')
- wn.setup(700, 700)
- #maze walLs
- class Pen(turtle.Turtle):
- def __init__(self):
- turtle.Turtle.__init__(self)
- self.shape('square')
- self.color('#ff7227')
- self.penup()
- self.speed(0)
- #player model
- class Player(turtle.Turtle):
- def __init__(self):
- turtle.Turtle.__init__(self)
- self.shape('circle')
- self.color('#fe5d5d')
- self.penup()
- self.speed(0)
- #definition of the key presses
- def go_up(self):
- move_to_x = player.xcor()
- move_to_y = player.xcor() + 24
- #checks to see if theres a wall
- if (move_to_x, move_to_y) not in walls:
- self.goto(move_to_x, move_to_y)
- def go_down(self):
- move_to_x = player.xcor()
- move_to_y = player.xcor() - 24
- #checks to see if theres a wall
- if (move_to_x, move_to_y) not in walls:
- self.goto(move_to_x, move_to_y)
- def go_left(self):
- move_to_x = player.xcor() - 24
- move_to_y = player.xcor()
- #checks to see if theres a wall
- if (move_to_x, move_to_y) not in walls:
- self.goto(move_to_x, move_to_y)
- def go_right(self):
- move_to_x = player.xcor() + 24
- move_to_y = player.xcor()
- #checks to see if theres a wall
- if (move_to_x, move_to_y) not in walls:
- self.goto(move_to_x, move_to_y)
- levels = [""]
- level_1 = [
- "XXXXXXXXXXXXXXXXXXXXXXXXX",
- "XPX X X",
- "X X XXXXX XXXXXX XXXXXX X",
- "X X X X X",
- "X XXXXXXX XXXXXXXXXXXXX X",
- "X X X X X",
- "XXXXXXXXXXX XXX X XXXXX X",
- "X X X X X X",
- "X X X XXXXX X XXXXXXXXX",
- "X X X XXX X",
- "X X XXXXXXXXX XXX X",
- "X XXXXXX XX X X X X",
- "X X X XXXXX X X X X",
- "XXXXXX XX X X X X X X",
- "X X X XX XXXX X X X",
- "X XXXXXXXXX X X X X",
- "X X X XXXXX X XXXXX",
- "X XXX X X X X X X X",
- "X X X X X XXX XXXXXXX",
- "XXXXX X X X X X X",
- "X X XXXXXXXXX X XXX X",
- "X X X X X XXXXX X",
- "X XXX XXXXX X X X X X",
- "X X X X X",
- "XXXXXXXXXXXXXXXXXXXXXXXXX"
- ]
- levels.append(level_1)
- #level setup
- def setup_maze(level):
- for y in range(len(level)):
- for x in range(len(level[y])):
- character = level[y][x]
- #cooridinates of screen setup
- screen_x = -288 + (x * 24)
- screen_y = 288 - (y * 24)
- #coordinates of wall
- if character == "X":
- pen.goto(screen_x, screen_y)
- pen.stamp()
- #adds coordinates to wall list
- walls.append((screen_x, screen_y))
- #coordinates of player
- if character == "P":
- player.goto(screen_x, screen_y)
- #variables
- pen = Pen()
- player = Player()
- #creates list for wall coordinates
- walls = []
- #sets up level
- setup_maze(levels[1])
- #so the code responds to key presses
- turtle.listen()
- turtle.onkey(player.go_left,"a")
- turtle.onkey(player.go_right,"d")
- turtle.onkey(player.go_up,"w")
- turtle.onkey(player.go_down,"s")
- #turn off screen updates
- wn.tracer(0)
- #game loop
- while True:
- wn.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement