From d42e40a4a0775c6a6a71f14f7779d25fe0c2e771 Mon Sep 17 00:00:00 2001 From: cakipaul Date: Mon, 23 Dec 2024 21:12:13 +0800 Subject: [PATCH] update config --- config/deploy/scene_config.gd | 2 +- scene/player/main_player.gd | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/config/deploy/scene_config.gd b/config/deploy/scene_config.gd index 6023f964..7fc7c7f6 100644 --- a/config/deploy/scene_config.gd +++ b/config/deploy/scene_config.gd @@ -1,7 +1,6 @@ class_name SceneConfig extends Resource @export var scene_name: String = "" -@export var camera_range: Rect2 = Rect2(0, -1000, 664, 1317) # 564*317, 16:9 @export var foreground_scale: Vector2 = Vector2(1.2, 1.2) @export var foreground_position: Vector2 = Vector2(0, 0) @export var background_scale: Vector2 = Vector2(1.0, 1.0) @@ -9,3 +8,4 @@ class_name SceneConfig extends Resource @export var player_initial_position: Vector2 = Vector2(300, 186) @export var player_initial_direction: Vector2 = Vector2(1, -1) @export var player_movement_rect: Rect2 = Rect2(0, 0, 0, 0) +@export var camera_rect: Rect2 = Rect2(0, -1000, 664, 2317) # 564*317, 16:9 diff --git a/scene/player/main_player.gd b/scene/player/main_player.gd index c62e46ea..9a004ebc 100644 --- a/scene/player/main_player.gd +++ b/scene/player/main_player.gd @@ -12,11 +12,12 @@ enum MOVEMENT_STATUS { CLIMBING, } +@export var player_movement_rect := Rect2(50, -500, 1400, 1000) @export var action_locked := false: set(val): action_locked = val _process_action_lock() -@export var current_status : MOVEMENT_STATUS +@export var current_status: MOVEMENT_STATUS @export var facing_direction := Vector2(1.0, -1.0) @export var is_laying := false: set(val): @@ -42,12 +43,15 @@ enum MOVEMENT_STATUS { @onready var camera = %MainCamera as Camera2D @onready var sprite = %AnimatedSprite2D as AnimatedSprite2D + func _ready() -> void: _reset_face_direction() + func _reset_face_direction() -> void: facing_direction = Vector2(1, -1) + func _process_action_lock() -> void: # reset status to idle or stay if action_locked: @@ -59,6 +63,7 @@ func _process_action_lock() -> void: current_status = MOVEMENT_STATUS.CLIMBING_STAY _play_animation() + # return whether the player status or facing direction has changed. func _check_status(direction) -> bool: var tmp_status = current_status @@ -89,6 +94,7 @@ func _check_status(direction) -> bool: return true return false + func _play_animation() -> void: match current_status: MOVEMENT_STATUS.IDLE: @@ -124,6 +130,7 @@ func _play_animation() -> void: else: sprite.play(&"climbing_up") + func _get_speed(direction: Vector2) -> Vector2: match current_status: MOVEMENT_STATUS.WALKING: @@ -136,6 +143,7 @@ func _get_speed(direction: Vector2) -> Vector2: return Vector2(0, speed_climbing * direction.y) return Vector2(0, 0) + func _physics_process(_delta: float) -> void: if action_locked: velocity = Vector2.ZERO @@ -143,9 +151,9 @@ func _physics_process(_delta: float) -> void: # Add the gravity. #if not is_on_floor(): - #velocity += get_gravity() * delta + #velocity += get_gravity() * delta #if Input.is_action_just_pressed("jump") and is_on_floor(): - #velocity.y = JUMP_VELOCITY + #velocity.y = JUMP_VELOCITY var x_direction := Input.get_axis("left", "right") var y_direction := Input.get_axis("up", "down") var direction := Vector2(x_direction, y_direction) @@ -155,8 +163,10 @@ func _physics_process(_delta: float) -> void: velocity.x = move_toward(velocity.x, speed.x, 300.0) velocity.y = move_toward(velocity.y, speed.y, 300.0) move_and_slide() + position = position.clamp(player_movement_rect.position, player_movement_rect.end) _tweak_camera_marker() + # drag the camera marker against the player movement # so there will be a better vision in front of the player. func _tweak_camera_marker():