def _process_inputs(self) -> InputBuffer: input_buffer = InputBuffer() if Input.is_action_just_pressed(action_name="left"): input_buffer.add_input(input=InputBuffer.Value.LEFT) self.add_to_position(Vector2.LEFT()) elif Input.is_action_just_pressed(action_name="right"): input_buffer.add_input(input=InputBuffer.Value.RIGHT) self.add_to_position(Vector2.RIGHT()) if Input.is_action_just_pressed(action_name="up"): input_buffer.add_input(input=InputBuffer.Value.UP) self.add_to_position(Vector2.UP()) elif Input.is_action_just_pressed(action_name="down"): input_buffer.add_input(input=InputBuffer.Value.DOWN) self.add_to_position(Vector2.DOWN()) return input_buffer
def _process_inputs(self) -> None: if Input.is_action_just_pressed(action_name="quit"): # Go back to main menu if (self.game_properties.player_opponent_mode == PropertyValue.PLAYER_OPPONENT_MODE_HOST_PLAYER_VS_PLAYER): Server.stop() elif (self.game_properties.player_opponent_mode == PropertyValue.PLAYER_OPPONENT_MODE_CLIENT_PLAYER_VS_PLAYER): Client.disconnect() SceneTree.change_scene( scene_path= "assets/game_projects/fighter/scenes/title_screen.json") # Engine.exit() if Input.is_action_just_pressed(action_name="zoom_in"): camera_zoom = Camera.get_zoom() camera_zoom -= Vector2(-0.1, -0.1) Camera.set_zoom(zoom=camera_zoom) if Input.is_action_just_pressed(action_name="zoom_out"): camera_zoom = Camera.get_zoom() camera_zoom -= Vector2(0.1, 0.1) Camera.set_zoom(zoom=camera_zoom) if Input.is_action_pressed(action_name="camera_left"): camera_position = Camera.get_viewport_position() camera_position += Vector2.LEFT() Camera.set_viewport_position(position=camera_position) elif Input.is_action_pressed(action_name="camera_right"): camera_position = Camera.get_viewport_position() camera_position += Vector2.RIGHT() Camera.set_viewport_position(position=camera_position) if Input.is_action_pressed(action_name="camera_up"): camera_position = Camera.get_viewport_position() camera_position += Vector2.UP() Camera.set_viewport_position(position=camera_position) elif Input.is_action_pressed(action_name="camera_down"): camera_position = Camera.get_viewport_position() camera_position += Vector2.DOWN() Camera.set_viewport_position(position=camera_position) if Input.is_action_pressed(action_name="camera_shake"): x_intensity_max = 5.0 y_intensity_max = 5.0 Camera.set_offset( Vector2( random.uniform(-x_intensity_max, x_intensity_max), random.uniform(-y_intensity_max, y_intensity_max), )) else: Camera.set_offset(offset=Vector2(0, 0)) for input_buffer in self.input_buffers: input_buffer.poll_client_inputs(frame=self.frame_counter)
def camera_controls(self) -> None: if Input.is_action_pressed("zoom_out"): self.zoom += Vector2(0.1, 0.1) self.zoom = max(Vector2(0.1, 0.1), self.zoom) Camera.set_zoom(zoom=self.zoom) elif Input.is_action_pressed("zoom_in"): self.zoom += Vector2(-0.1, -0.1) self.zoom = min(Vector2(10, 10), self.zoom) Camera.set_zoom(zoom=self.zoom) if Input.is_action_pressed(action_name="camera_up"): self.viewport.y -= 1 Camera.set_viewport_position(position=self.viewport) elif Input.is_action_pressed(action_name="camera_down"): self.viewport.y += 1 Camera.set_viewport_position(position=self.viewport) if Input.is_action_pressed(action_name="camera_left"): self.viewport.x -= 1 Camera.set_viewport_position(position=self.viewport) elif Input.is_action_pressed(action_name="camera_right"): self.viewport.x += 1 Camera.set_viewport_position(position=self.viewport)
def _simulate_player_state(self, frame: int, player_state_data: PlayerStateData) -> None: if player_state_data.player_input_buffer.is_empty(): player_state_data.player_node.play(animation_name="idle") else: for input in player_state_data.player_input_buffer.get_frame_inputs( frame=frame): if not self.attack_manager.node_has_attack( node=player_state_data.player_node): if input == InputBuffer.Value.LEFT.value: player_state_data.player_node.add_to_position( Vector2.LEFT()) player_state_data.player_node.play( animation_name="walk") # player_one_state_data.player_node.flip_h = True elif input == InputBuffer.Value.RIGHT.value: player_state_data.player_node.add_to_position( Vector2.RIGHT()) player_state_data.player_node.play( animation_name="walk") # player_one_state_data.player_node.flip_h = False elif input == InputBuffer.Value.WEAK_PUNCH.value: # TODO: Implement weak punch weak_punch_attack = Attack.new() # weak_punch_attack.collider_rect = Rect2(x=64, y=0, w=64, h=64) weak_punch_attack.collider_rect = Rect2(x=100, y=32, w=64, h=64) weak_punch_attack.color = Color(1.0, 0.0, 0.0, 0.75) player_state_data.player_node.add_child( child_node=weak_punch_attack) weak_punch_attack.frame_life_time = 100 self.attack_manager.add_attack( node=player_state_data.player_node, attack=weak_punch_attack)
def __init__(self): self.player = 1 self.position = Vector2(0.0, 0.0) self.inputs = ["l", "wp"] self.animation = AnimationState() self.state = "idle"
def __init__(self, player: int, health=10, position=Vector2(0, 0)): self.player = player self.health = health self.position = position self.frames_invincible_after_damage = 0
def movement_controls(self) -> None: if Input.is_action_pressed(action_name="left"): self.add_to_position(value=Vector2(-1, 0)) elif Input.is_action_pressed(action_name="right"): self.add_to_position(value=Vector2(1, 0))
def _start(self) -> None: self.viewport = Vector2(1, 1) self.zoom = Vector2(1, 1)