Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pygame.init()
- isRunning = True
- windowWidth = 1280
- windowHeight = 720
- playerHeight = 64
- playerWidth = 64
- playerX = (windowWidth / 2) - (playerWidth / 2) + 100
- playerY = (windowHeight / 2) - (playerHeight / 2)
- playerXLate = playerX
- playerYLate = playerY
- playerSpeed = 4
- blockHeight = 64
- blockWidth = 64
- blockX = 0
- blockY = 0
- number = 3
- playerMovingForewards = False
- playerMovingLeft = False
- playerMovingBackwards = False
- playerMovingRight = False
- playerColor = (0, 255, 0)
- blockColor = (255, 255, 0)
- backgroundColor = (0, 0, 255)
- window = pygame.display.set_mode((windowWidth, windowHeight))
- while isRunning == True:
- Map = open('Map', 'r')
- mapY = Map.readlines()
- mapX = mapY[0].split()
- for y in range(len(mapY)):
- mapX = mapY[y]
- for x in range(len(mapX)):
- if mapX[x] == "1":
- if playerX + playerWidth >= (x * 64) and playerX <= (x * 64) + blockWidth and playerY + playerHeight >= (y * 64) and playerY <= (y * 64) + blockHeight:
- playerX = playerXLate
- playerY = playerYLate
- pygame.draw.rect (window, (blockColor), ((x / 2) * 64, y * 64, blockWidth, blockHeight))
- Map.close()
- playerXLate = playerX
- playerYLate = playerY
- for event in pygame.event.get():
- if (event.type == pygame.QUIT):
- isRunning = False
- pygame.quit()
- sys.exit()
- if(event.type == pygame.KEYDOWN):
- if (event.key == pygame.K_w):
- playerMovingForewards = True
- if (event.key == pygame.K_a):
- playerMovingLeft = True
- if (event.key == pygame.K_s):
- playerMovingBackwards = True
- if (event.key == pygame.K_d):
- playerMovingRight = True
- if(event.type == pygame.KEYUP):
- if (event.key == pygame.K_w):
- playerMovingForewards = False
- if (event.key == pygame.K_a):
- playerMovingLeft = False
- if (event.key == pygame.K_s):
- playerMovingBackwards = False
- if (event.key == pygame.K_d):
- playerMovingRight = False
- if playerMovingForewards == True:
- playerY = playerY + -playerSpeed
- if playerMovingLeft == True:
- playerX = playerX + -playerSpeed
- if playerMovingBackwards == True:
- playerY = playerY + playerSpeed
- if playerMovingRight == True:
- playerX = playerX + playerSpeed
- #Graphics (Start)
- pygame.draw.rect (window, (playerColor), (playerX, playerY, playerWidth, playerHeight))
- pygame.display.update()
- pygame.draw.rect (window, (0, 0, 0), (0, 0, windowWidth, windowHeight))
- pygame.draw.rect (window, (backgroundColor), (windowWidth - windowWidth, windowHeight - windowHeight, windowWidth, windowHeight))
- #Graphics (End)
- time.sleep(0.01)
- pygame.quit()
- sys.exit()
- 1 1 1 1 0 0 1 1 1 1
- 1 0 0 0 0 0 0 0 0 1
- 1 0 0 0 0 0 0 0 0 1
- 1 0 0 0 0 0 2 0 0 1
- 0 0 0 0 0 0 0 0 0 0
- 0 0 0 0 0 0 0 0 0 0
- 1 0 0 0 0 0 0 0 0 1
- 1 0 0 0 0 0 0 0 0 1
- 1 0 0 0 0 0 0 0 0 1
- 1 1 1 1 0 0 1 1 1 1
Add Comment
Please, Sign In to add comment