def test_no_movement_collision(): count = 0 collision = move(p, tile, tile_map) for key in collision: if collision[key]: count += 1 assert count == 0
def test_collision_left_top(): count = 0 p.move(0, 0, -5, True, False) tile[1].change_place(0, -9) collision = move(p, tile, tile_map) for key in collision: if collision[key] is True and (key == 'Top' or key == 'Left'): count += 1 assert count == 2
def test_collision_left_bottom(): count = 0 p.move(0, 0, -5, False, True) tile[1].change_place(0, 5) collision = move(p, tile, tile_map) for key in collision: if collision[key] is True and (key == 'Bottom' or key == 'Left'): count += 1 assert count == 2
def test_no_collision(): p.move(0, 0, 5, True, False) tile[0].change_place(50, 50) tile[1].change_place(60, 60) count = 0 collision = move(p, tile, tile_map) for key in collision: if collision[key]: count += 1 assert count == 0
def game(): try: player = end = 0 running = True change_map() global phase, death pygame.mixer.music.load('assets/sound/phase.mp3') pygame.mixer.music.play(-1) pygame.mixer.music.set_pos(10) # 10 all_sprites = pygame.sprite.Group() platforms = pygame.sprite.Group() for tile_object in tile_map.tmxdata.objects: if tile_object.name == 'player': player = Player(tile_object.x, tile_object.y) if tile_object.name == 'platform': Platforms(platforms, tile_object.x, tile_object.y, tile_object.width, tile_object.height) if tile_object.name == 'end': end = pygame.Rect(int(tile_object.x), int(tile_object.y), int(tile_object.width), int(tile_object.height)) else: end = pygame.Rect(3168, 867, 32, 32) all_sprites.add(player) camera = Camera(tile_map.width, tile_map.height) while running: if player.rect.colliderect(end): phase += 1 death += player.death running = False menu() for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() eventChange(event, player) if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: information() if event.key == pygame.K_RETURN: player.move_r = False player.move_l = False running = False death += player.death phase += 1 menu() all_sprites.update() player.movement = [0, 0] if player.move_r: player.movement[0] += 4 if player.move_l: player.movement[0] -= 4 player.movement[1] += player.momentum player.momentum += GRAV if player.momentum > 7: player.momentum = 7 collisions = move(player, platforms, tile_map) if collisions['Bottom']: player.jumping = False player.falling = False player.momentum = 0 player.jump_time = 0 else: player.jump_time += 1 if player.momentum > 1 and not player.jumping: player.falling = True camera.update(player) display.fill((85, 180, 255)) display.blit(map_img, camera.apply_rect(map_rect)) for sprite in all_sprites: display.blit(sprite.image, camera.apply(sprite)) screen.blit(pygame.transform.scale(display, SIZE), (0, 0)) show_text(SIZE[0] - 150, 10, "Deaths: " + str(death + player.death), WHITE, font_generics) pygame.display.update() clock.tick(FPS) except pygame.error as err: pygame_error(err) except FileNotFoundError as err: filenotfound_error(err)
def test_collision_bottom(): p.move(0, 0, 0, False, True) tile[0].change_place(0, 5) assert move(p, tile, tile_map)["Bottom"] is True
def test_collision_top(): p.move(0, 0, 0, True, False) tile[0].change_place(0, -9) assert move(p, tile, tile_map)["Top"] is True
def test_collision_left(): p.move(4, 0, -5, False, False) tile[0].change_place(0, 0) assert move(p, tile, tile_map)["Left"] is True
def test_collision_right(): p.move(0, 0, 5, False, False) tile[0].change_place(0, 0) assert move(p, tile, tile_map)["Right"] is True