def update(self, player, dt, platforms, camera=None): global walk_time, slide_time # Игрок не может прыгать с большой скоростью if not player.wall_jump_done: walk_time = get_length(walk_sound) slide_time = get_length(sliding_sound) if player.sounds: # Воспроизводим звук play_sound(jump_sound) self.velocity_x = self.velocity_x if player.last_dir == "left" else -self.velocity_x player.vel.x = self.velocity_x player.rect.x += self.velocity_x player.collide(player.vel.x, 0, platforms) player.vel.y = self.velocity_y player.gravitation() player.collide(0, player.vel.y, platforms) player.sliding_timer = .7 player.timer_cd = .1 player.wall_jump_done = True player.double_jump = True player.dash_done = False player.falling = True player.touched_wall = False player.onWall = False player.wall_first_touch = True player.state = self.next_state else: player.state = self.next_state
def update(self, player, dt, platforms, camera=None): global walk_time, slide_time # Воспроизводим звуки ходьбы if player.onGround and player.sounds: if walk_time >= get_length(walk_sound): play_sound(walk_sound) walk_time = 0 else: walk_time += dt # Воспроизводим анимацию движения if self.anim_count >= fps: self.anim_count = 0 if player.last_dir == 'right': player.image = go_right[self.anim_count // 10] if player.last_dir == 'left': player.image = go_left[self.anim_count // 10] self.anim_count += 1 # Если персонаж находится на стене и двигается в ее сторону, он начинает скользить if player.onWall and not player.onGround: if player.wall_pos == player.last_dir: player.isSliding = True if player.sounds: if slide_time >= get_length(sliding_sound): play_sound(sliding_sound) slide_time = 0 else: slide_time += dt else: stop_sound() player.isSliding = True if not player.falling: player.timer(dt) player.sliding_timer = .7 # Обновляем координаты персонажа и проверям на столкновения player.vel.x = self.velocity_x player.rect.x += player.vel.x player.collide(player.vel.x, 0, platforms) player.gravitation() player.collide(0, player.vel.y, platforms)
def update(self, player, dt, platforms, camera=None): global walk_time, slide_time walk_time = get_length(walk_sound) slide_time = get_length(sliding_sound) if player.sounds: # Воспроизводим звук play_sound(jump_sound) player.vel.y = -self.velocity_y player.gravitation() player.collide(0, player.vel.y, platforms) player.double_jump = False player.state = self.next_state
def handle_event(self, player, event): global walk_time if event.type == pygame.KEYDOWN: if event.key == pygame.K_LSHIFT and player.last_dir: return DashState(dash_speed, player.state, player) if event.key == pygame.K_LEFT: walk_time = get_length(walk_sound) player.go_left = True player.last_dir = "left" self.velocity_x = -hero_speed if event.key == pygame.K_RIGHT: walk_time = get_length(walk_sound) player.go_right = True player.last_dir = "right" self.velocity_x = hero_speed elif event.key == pygame.K_SPACE: if player.double_jump and not player.onWall: return DoubleJumpState(jump_force, player.state) elif player.isSliding and not player.wall_jump_done: return WallJumpState(wall_jump[0], wall_jump[1], player.state) return JumpState(jump_force, player.state) if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: player.go_left = False if event.key == pygame.K_RIGHT: player.go_right = False if event.key == pygame.K_LEFT and self.velocity_x < 0: player.left = False return IdleState() elif event.key == pygame.K_RIGHT and self.velocity_x > 0: player.right = False return IdleState() if event.key == pygame.K_a and self.velocity_x < 0: return IdleState() elif event.key == pygame.K_d and self.velocity_x > 0: return IdleState()
def update(self, player, dt, platforms, camera=None): global walk_time, slide_time if not player.dash_done: # В воздухе может быть выполнен только один рывок walk_time = get_length(walk_sound) slide_time = get_length(sliding_sound) self.dash_timer -= dt # Таймер self.velocity_x = dash_speed # В зависимости от последнего направления персонажа вектор скорости рывка меняется if player.last_dir == "left": self.velocity_x = -self.velocity_x player.rect.x += self.velocity_x player.collide(self.velocity_x, 0, platforms) # Если таймер истек if self.dash_timer <= 0: player.vel.y = 0 player.dash_done = True player.state = self.next_state else: player.state = self.next_state
def set_similarity_score(self): """Calculates the similarity score of the match. It is a weighted sum of scaled attributes, which are difference in length, difference in distance (hausdorff distance) and difference in area.""" length_diff = length_difference(self.strokes_ref, self.strokes_target) hausdorff = session.query( func.st_hausdorffdistance(self.geom_ref, self.geom_target))[0][0] area_diff = self.set_area_difference() area_diff_normalized = area_diff / get_length(self.strokes_ref) weights = [0.5, 0.35, 0.15] # sum equal to 1 metrics = [ length_diff / tolerance_length, hausdorff / tolerance_hausdorff, area_diff_normalized / tolerance_area_normalized ] score = 0 for index, metric in enumerate(metrics): score += weights[index] * (1 - metric) return score
def __init__(self, velocity_x): global walk_time self.velocity_x = velocity_x self.anim_count = 0 walk_time = get_length(walk_sound)
config.read("settings.ini") hero_speed = config.getfloat('PLAYER', 'hero_speed') jump_force = config.getfloat('PLAYER', 'jump_force') dash_speed = config.getint('PLAYER', 'dash_speed') wall_jump = json.loads(config.get("PLAYER", "wall_jump")) down_timer = config.getfloat("CAMERA", "down_timer") width, height = json.loads(config.get("MAIN", "res")) h_width, h_height = json.loads(config.get("PLAYER", "size")) fps = config.getint("MAIN", "fps") # Загрузка звуков walk_sound = load_sound("data/sounds/walk.wav") walk_sound.set_volume(0.5) walk_time = get_length(walk_sound) jump_sound = load_sound("data/sounds/jump.wav") jump_sound.set_volume(0.4) dash_sound = load_sound("data/sounds/dash.wav") dash_sound.set_volume(0.4) sliding_sound = load_sound("data/sounds/wall_slide.wav") sliding_sound.set_volume(0.4) slide_time = get_length(sliding_sound) idle_right = [ load_image('data/PassiveReaper_Right/PassiveIdleReaper-Sheet.png', h_width, h_height), load_image('data/PassiveReaper_Right/PassiveIdleReaper-Sheet2.png', h_width, h_height), load_image('data/PassiveReaper_Right/PassiveIdleReaper-Sheet3.png', h_width, h_height),
def extend_matching_pair(stroke_ref, stroke_target, junction_ref, junction_target, tolerance_distance): """Extends the input delimited strokes with strokes that have good continuity at input junction, until a good match is found or if no match is possible. Stroke_ref and stroke_target are both lists of delimited strokes.""" # create local variables of which stroke to extend and which to compare to when a new stroke is added if get_length(stroke_ref) < get_length(stroke_target): stroke_to_extend = stroke_ref stroke_to_compare = stroke_target junction_to_extend = junction_ref junction_to_compare = junction_target else: stroke_to_extend = stroke_target stroke_to_compare = stroke_ref junction_to_extend = junction_target junction_to_compare = junction_ref new_stroke = None # if the junction where the next stroke is added is a W-junction (type 1), select the stroke of the outer road # sections to be added if junction_to_extend.type_k3 == 1: if angle_at_junction( stroke_to_extend[-1], junction_to_extend) != junction_to_extend.angle_k3: for road_section in junction_to_extend.road_sections: if road_section.delimited_stroke != stroke_to_extend[-1] and junction_to_extend.angle_k3 != \ angle_at_junction(road_section, junction_to_extend): new_stroke = road_section.delimited_stroke # for other junctions, select the stroke that has good continuity if junction_to_extend.degree > 1: for road_section in junction_to_extend.road_sections: if road_section.delimited_stroke != stroke_to_extend[ -1] and has_good_continuity(road_section, stroke_to_extend[-1], junction_to_extend): new_stroke = road_section.delimited_stroke if new_stroke and (new_stroke.begin_junction == junction_to_extend or new_stroke.end_junction == junction_to_extend): stroke_to_extend.append(new_stroke) junction_to_extend = other_junction(stroke_to_extend[-1], junction_to_extend) point_distance = session.query( func.st_distance(junction_to_extend.geom, junction_to_compare.geom))[0][0] if point_distance < tolerance_distance: return Match(stroke_ref, stroke_target) elif session.query(func.st_distance(junction_to_extend.geom, stroke_to_compare[-1].geom))[0][0] < tolerance_distance or \ session.query(func.st_distance(junction_to_compare.geom, stroke_to_extend[-1].geom))[0][0] < tolerance_distance: if stroke_to_extend == stroke_ref: return extend_matching_pair(stroke_ref, stroke_target, junction_to_extend, junction_target, tolerance_distance) elif stroke_to_extend == stroke_target: return extend_matching_pair(stroke_ref, stroke_target, junction_ref, junction_to_extend, tolerance_distance) else: print('Error: wrong stroke') return None