fixed camera controls

This commit is contained in:
Luca 2024-11-17 13:06:55 +01:00
parent cd62e12389
commit d6a0911801
78 changed files with 4044 additions and 81 deletions

View file

@ -13,6 +13,8 @@ var enemy: Monster = null
const SPEED: float = 5.0
const JUMP_VELOCITY: float = 4.5
const ROTATION_SPEED: float = 12.0
const CAMERA_ROTATION_SPEED: float = 1.3
const MANUAL_CAMERA_ROTATION_SPEED: float = 5.0
func _ready() -> void:
# Set the global reference to the player
@ -43,9 +45,9 @@ func _physics_process(delta: float) -> void:
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Camera rotation
# Manual camera rotation
var camera_input_dir : Vector2 = Input.get_vector("joystick_right_left", "joystick_right_right", "joystick_right_left", "joystick_right_right")
$CameraRoot.rotation.y += camera_input_dir.x
$CameraRoot.rotation.y += camera_input_dir.x * MANUAL_CAMERA_ROTATION_SPEED * delta
# Get the input direction and handle the movement / deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
@ -60,16 +62,19 @@ func _physics_process(delta: float) -> void:
# Rotate the direction with the camera, so that the cameras forward direction
# is the joysticks and the players forward direction
direction = direction.rotated(Vector3.UP, $CameraRoot.rotation.y)
var camera_direction: Vector3 = direction.rotated(Vector3.UP, $CameraRoot.rotation.y)
# Move character to the direction
if direction.length() != 0:
var target_angle: float = Vector3.BACK.signed_angle_to(direction, Vector3.UP)
if camera_direction.length() != 0:
var target_angle: float = Vector3.BACK.signed_angle_to(camera_direction, Vector3.UP)
$GobotSkin.rotation.y = lerp_angle(%GobotSkin.rotation.y, target_angle, ROTATION_SPEED * delta)
var camera_rotation_angle: float = Vector3.FORWARD.signed_angle_to(camera_direction, Vector3.UP)
$CameraRoot.rotation.y = lerp_angle(%CameraRoot.rotation.y, camera_rotation_angle, CAMERA_ROTATION_SPEED * delta)
if direction:
velocity.x = direction.x * SPEED
velocity.z = direction.z * SPEED
if camera_direction:
velocity.x = camera_direction.x * SPEED
velocity.z = camera_direction.z * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
velocity.z = move_toward(velocity.z, 0, SPEED)
@ -143,8 +148,14 @@ func handle_battle() -> void:
handle_battle()
Enums.BattleState.CATCH:
print("TODO: Catch")
await get_tree().create_timer(3.0).timeout
SoundManager.play_background_music("Unexplored Fields")
UI.battle_ui.disable()
player_monster.queue_free()
enemy.queue_free()
UI.ingame_menu.update()
UI.show_battle_ui(false)
UI.show_ingame_controls(true)
battle_state = Enums.BattleState.NOT_IN_BATTLE
Enums.BattleState.WIN:
SoundManager.play_sound_effect("Battle Win")
@ -239,3 +250,29 @@ func attack_enemy() -> void:
await get_tree().create_timer(1.0).timeout
battle_state = Enums.BattleState.ENEMY_TURN
handle_battle()
func catch_enemy() -> void:
UI.battle_ui.set_message("You tried to catch the enemy!")
await get_tree().create_timer(1.0).timeout
var p: float = enemy.data.calculate_catch_probability()
var random: float = randi_range(0, 255)
# Determine if the monster is catched or not
if p > random:
UI.battle_ui.set_message("You catched the enemy!")
handle_catch()
else:
UI.battle_ui.set_message("The monster resisted the catch!")
await get_tree().create_timer(1.0).timeout
battle_state = Enums.BattleState.ENEMY_TURN
handle_battle()
func handle_catch() -> void:
UI.battle_ui.set_message("Congratulations on catching %s!" % enemy.data.name)
# TODO: If more than 6 monsters in team, add to box, else add to next slot in team
if SaveManager.current_save.party.size() > 6:
print("Send to box")
await get_tree().create_timer(2.0).timeout