Guest User

Untitled

a guest
Jul 16th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. pygame.init()
  2.  
  3. isRunning = True
  4.  
  5. windowWidth = 1280
  6. windowHeight = 720
  7.  
  8. playerHeight = 64
  9. playerWidth = 64
  10. playerX = (windowWidth / 2) - (playerWidth / 2) + 100
  11. playerY = (windowHeight / 2) - (playerHeight / 2)
  12. playerXLate = playerX
  13. playerYLate = playerY
  14. playerSpeed = 4
  15.  
  16. blockHeight = 64
  17. blockWidth = 64
  18. blockX = 0
  19. blockY = 0
  20.  
  21. number = 3
  22.  
  23. playerMovingForewards = False
  24. playerMovingLeft = False
  25. playerMovingBackwards = False
  26. playerMovingRight = False
  27.  
  28. playerColor = (0, 255, 0)
  29. blockColor = (255, 255, 0)
  30. backgroundColor = (0, 0, 255)
  31.  
  32. window = pygame.display.set_mode((windowWidth, windowHeight))
  33.  
  34. while isRunning == True:
  35.  
  36. Map = open('Map', 'r')
  37. mapY = Map.readlines()
  38. mapX = mapY[0].split()
  39.  
  40. for y in range(len(mapY)):
  41. mapX = mapY[y]
  42. for x in range(len(mapX)):
  43. if mapX[x] == "1":
  44. if playerX + playerWidth >= (x * 64) and playerX <= (x * 64) + blockWidth and playerY + playerHeight >= (y * 64) and playerY <= (y * 64) + blockHeight:
  45. playerX = playerXLate
  46. playerY = playerYLate
  47. pygame.draw.rect (window, (blockColor), ((x / 2) * 64, y * 64, blockWidth, blockHeight))
  48.  
  49. Map.close()
  50.  
  51. playerXLate = playerX
  52. playerYLate = playerY
  53.  
  54. for event in pygame.event.get():
  55.  
  56. if (event.type == pygame.QUIT):
  57. isRunning = False
  58. pygame.quit()
  59. sys.exit()
  60.  
  61. if(event.type == pygame.KEYDOWN):
  62. if (event.key == pygame.K_w):
  63. playerMovingForewards = True
  64. if (event.key == pygame.K_a):
  65. playerMovingLeft = True
  66. if (event.key == pygame.K_s):
  67. playerMovingBackwards = True
  68. if (event.key == pygame.K_d):
  69. playerMovingRight = True
  70.  
  71. if(event.type == pygame.KEYUP):
  72. if (event.key == pygame.K_w):
  73. playerMovingForewards = False
  74. if (event.key == pygame.K_a):
  75. playerMovingLeft = False
  76. if (event.key == pygame.K_s):
  77. playerMovingBackwards = False
  78. if (event.key == pygame.K_d):
  79. playerMovingRight = False
  80.  
  81. if playerMovingForewards == True:
  82. playerY = playerY + -playerSpeed
  83. if playerMovingLeft == True:
  84. playerX = playerX + -playerSpeed
  85. if playerMovingBackwards == True:
  86. playerY = playerY + playerSpeed
  87. if playerMovingRight == True:
  88. playerX = playerX + playerSpeed
  89.  
  90. #Graphics (Start)
  91.  
  92. pygame.draw.rect (window, (playerColor), (playerX, playerY, playerWidth, playerHeight))
  93.  
  94. pygame.display.update()
  95.  
  96. pygame.draw.rect (window, (0, 0, 0), (0, 0, windowWidth, windowHeight))
  97.  
  98. pygame.draw.rect (window, (backgroundColor), (windowWidth - windowWidth, windowHeight - windowHeight, windowWidth, windowHeight))
  99.  
  100. #Graphics (End)
  101.  
  102. time.sleep(0.01)
  103.  
  104. pygame.quit()
  105. sys.exit()
  106.  
  107. 1 1 1 1 0 0 1 1 1 1
  108. 1 0 0 0 0 0 0 0 0 1
  109. 1 0 0 0 0 0 0 0 0 1
  110. 1 0 0 0 0 0 2 0 0 1
  111. 0 0 0 0 0 0 0 0 0 0
  112. 0 0 0 0 0 0 0 0 0 0
  113. 1 0 0 0 0 0 0 0 0 1
  114. 1 0 0 0 0 0 0 0 0 1
  115. 1 0 0 0 0 0 0 0 0 1
  116. 1 1 1 1 0 0 1 1 1 1
Add Comment
Please, Sign In to add comment