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 class_name SceneConfig extends Resource
@export var scene_name: String = "" @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_scale: Vector2 = Vector2(1.2, 1.2)
@export var foreground_position: Vector2 = Vector2(0, 0) @export var foreground_position: Vector2 = Vector2(0, 0)
@export var background_scale: Vector2 = Vector2(1.0, 1.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_position: Vector2 = Vector2(300, 186)
@export var player_initial_direction: Vector2 = Vector2(1, -1) @export var player_initial_direction: Vector2 = Vector2(1, -1)
@export var player_movement_rect: Rect2 = Rect2(0, 0, 0, 0) @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, CLIMBING,
} }
@export var player_movement_rect := Rect2(50, -500, 1400, 1000)
@export var action_locked := false: @export var action_locked := false:
set(val): set(val):
action_locked = val action_locked = val
_process_action_lock() _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 facing_direction := Vector2(1.0, -1.0)
@export var is_laying := false: @export var is_laying := false:
set(val): set(val):
@ -42,12 +43,15 @@ enum MOVEMENT_STATUS {
@onready var camera = %MainCamera as Camera2D @onready var camera = %MainCamera as Camera2D
@onready var sprite = %AnimatedSprite2D as AnimatedSprite2D @onready var sprite = %AnimatedSprite2D as AnimatedSprite2D
func _ready() -> void: func _ready() -> void:
_reset_face_direction() _reset_face_direction()
func _reset_face_direction() -> void: func _reset_face_direction() -> void:
facing_direction = Vector2(1, -1) facing_direction = Vector2(1, -1)
func _process_action_lock() -> void: func _process_action_lock() -> void:
# reset status to idle or stay # reset status to idle or stay
if action_locked: if action_locked:
@ -59,6 +63,7 @@ func _process_action_lock() -> void:
current_status = MOVEMENT_STATUS.CLIMBING_STAY current_status = MOVEMENT_STATUS.CLIMBING_STAY
_play_animation() _play_animation()
# return whether the player status or facing direction has changed. # return whether the player status or facing direction has changed.
func _check_status(direction) -> bool: func _check_status(direction) -> bool:
var tmp_status = current_status var tmp_status = current_status
@ -89,6 +94,7 @@ func _check_status(direction) -> bool:
return true return true
return false return false
func _play_animation() -> void: func _play_animation() -> void:
match current_status: match current_status:
MOVEMENT_STATUS.IDLE: MOVEMENT_STATUS.IDLE:
@ -124,6 +130,7 @@ func _play_animation() -> void:
else: else:
sprite.play(&"climbing_up") sprite.play(&"climbing_up")
func _get_speed(direction: Vector2) -> Vector2: func _get_speed(direction: Vector2) -> Vector2:
match current_status: match current_status:
MOVEMENT_STATUS.WALKING: MOVEMENT_STATUS.WALKING:
@ -136,6 +143,7 @@ func _get_speed(direction: Vector2) -> Vector2:
return Vector2(0, speed_climbing * direction.y) return Vector2(0, speed_climbing * direction.y)
return Vector2(0, 0) return Vector2(0, 0)
func _physics_process(_delta: float) -> void: func _physics_process(_delta: float) -> void:
if action_locked: if action_locked:
velocity = Vector2.ZERO velocity = Vector2.ZERO
@ -143,9 +151,9 @@ func _physics_process(_delta: float) -> void:
# Add the gravity. # Add the gravity.
#if not is_on_floor(): #if not is_on_floor():
#velocity += get_gravity() * delta #velocity += get_gravity() * delta
#if Input.is_action_just_pressed("jump") and is_on_floor(): #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 x_direction := Input.get_axis("left", "right")
var y_direction := Input.get_axis("up", "down") var y_direction := Input.get_axis("up", "down")
var direction := Vector2(x_direction, y_direction) 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.x = move_toward(velocity.x, speed.x, 300.0)
velocity.y = move_toward(velocity.y, speed.y, 300.0) velocity.y = move_toward(velocity.y, speed.y, 300.0)
move_and_slide() move_and_slide()
position = position.clamp(player_movement_rect.position, player_movement_rect.end)
_tweak_camera_marker() _tweak_camera_marker()
# drag the camera marker against the player movement # drag the camera marker against the player movement
# so there will be a better vision in front of the player. # so there will be a better vision in front of the player.
func _tweak_camera_marker(): func _tweak_camera_marker():