update config

This commit is contained in:
cakipaul 2024-12-23 21:12:13 +08:00
parent 6afa058aa8
commit d42e40a4a0
2 changed files with 14 additions and 4 deletions

View File

@ -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

View File

@ -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
@ -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():