map.tiles.append({'src': 'rect', 'pos_x': 50, 'pos_y': 82, 'width': 32, 'height': 32, 'walkable': False}) map.tiles.append({'src': 'rect', 'pos_x': 18, 'pos_y': 82, 'width': 32, 'height': 32, 'walkable': False}) map.tiles.append({'src': 'rect', 'pos_x': -14, 'pos_y': 114, 'width': 32, 'height': 32, 'walkable': False}) map.tiles.append({'src': 'rect', 'pos_x': -46, 'pos_y': 82, 'width': 32, 'height': 32, 'walkable': False}) up = False down = False left = False right = False gameW = 640 gameH = 480 while True: screen.fill((0, 0, 0)) map.draw_map(screen, 0, 0) if hero.moving: dx = 0 dy = 0 if hero.dir == 'n': dy = -4 if hero.dir == 's': dy = 4 if hero.dir == 'e': dx = 4 if hero.dir == 'w': dx = -4 hero.hittest(dx=dx, dy=dy, map=map)
font = pygame.font.Font(None, 20) while True: if no_key_yet: font = pygame.font.Font(None, 20) screen.blit(font.render('Press any key to continue', True, (255, 255, 255)), (50, 50)) screen.blit(font.render('Controls:', True, (255, 255, 255)), (50, 80)) screen.blit(font.render('- Arrow keys to move', True, (255, 255, 255)), (50, 110)) screen.blit(font.render('- Plus and minus to increase move speed', True, (255, 255, 255)), (50, 130)) screen.blit(font.render('- Page up and down to jump North and South', True, (255, 255, 255)), (50, 150)) screen.blit(font.render('- F5 to reload the map from map file', True, (255, 255, 255)), (50, 170)) else: screen.fill((0, 0, 0)) map.draw_map(screen, x, y) screen.blit(font.render('x: ' + str(x) + ', y: ' + str(y), True, (255, 255, 255)), (15, 15)) pygame.draw.line(screen, (255, 255, 255), (320, 0), (320, 480)) pygame.draw.line(screen, (255, 255, 255), (0, 240), (640, 240)) pygame.display.flip() for event in pygame.event.get(): #print(event) if event.type == pygame.QUIT: sys.exit(0) elif event.type == pygame.KEYDOWN: no_key_yet = False if event.key == 273: # up up = True if event.key == 274: # down down = True