矿车的触发器
This commit is contained in:
parent
731f265a68
commit
dd4baf6bc6
|
|
@ -2,8 +2,8 @@ extends Node2D
|
|||
|
||||
func _ready() -> void:
|
||||
#$L1_S1.switch_act_by_id(1)
|
||||
#$L1_S2.switch_act_by_id(1)
|
||||
$L1_S3.switch_act_by_id(1)
|
||||
$L1_S2.switch_act_by_id(1)
|
||||
#$L1_S3.switch_act_by_id(1)
|
||||
#$L1_S4.switch_act_by_id(1)
|
||||
#$L1_S5.switch_act_by_id(1)
|
||||
get_tree().call_group(&"PLAYER_RESPAWN",&"respawn_avatar")
|
||||
|
|
|
|||
|
|
@ -128,6 +128,13 @@ func _player_direction_changed(value: Direction):
|
|||
direction = value
|
||||
player_direction_changed.emit(direction)
|
||||
|
||||
func is_in_ground_state() -> bool:
|
||||
return %Grounded.is_active()
|
||||
|
||||
func is_in_climb_state() -> bool:
|
||||
return %Climb.is_active()
|
||||
|
||||
#region 特效广播
|
||||
##播放落地尘土特效
|
||||
func on_land_dust() -> void:
|
||||
v_land_dust.emit({"world_pos": foot_pos_marker.global_position})
|
||||
|
|
@ -140,7 +147,30 @@ func on_run_dust() -> void:
|
|||
func on_jump() -> void:
|
||||
v_jump_dust.emit({"world_pos": foot_pos_marker.global_position})
|
||||
s_jump_sound.emit()
|
||||
#endregion
|
||||
|
||||
|
||||
##工具函数
|
||||
##获取当前state下的目标state
|
||||
func _get_target_state_in_state(state : LimboState,target: LimboState) -> LimboState:
|
||||
if state == target:
|
||||
return target
|
||||
|
||||
var active_substate : LimboState = null
|
||||
|
||||
# 如果这个状态有 get_active_state() 方法,就调用
|
||||
if state.has_method("get_active_state"):
|
||||
active_substate = state.get_active_state()
|
||||
|
||||
if active_substate == target:
|
||||
return target
|
||||
|
||||
# 如果没有子状态,返回自己
|
||||
if active_substate == null:
|
||||
return null
|
||||
|
||||
# 如果有子状态,继续递归
|
||||
return _get_target_state_in_state(active_substate,target)
|
||||
|
||||
static func get_direction_vector(dir: Direction) -> Vector2:
|
||||
return Vector2(1,0) if dir == Direction.RIGHT else Vector2(-1,0)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ func _update(delta: float) -> void:
|
|||
## 更新並獲取到delta ditance
|
||||
var delta_distance = _update_accelerated_distance() as float
|
||||
|
||||
print(delta_distance)
|
||||
#print(delta_distance)
|
||||
|
||||
## 如果移動了一定的距離,則播放dust特效
|
||||
_run_dust_counter -= delta_distance
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ extends Node2D
|
|||
|
||||
@export var path2d: Path2D
|
||||
@export var plateform: Node2D
|
||||
@export var player_trigger: PlayerTriggerVolumn
|
||||
|
||||
@export var move_speed: float = 200.0 # 最大前进速度
|
||||
@export var returning_speed: float = 60.0 # 加速度
|
||||
|
|
@ -28,7 +29,7 @@ func _ready() -> void:
|
|||
_path_follow.visible = false
|
||||
path2d.add_child(_path_follow)
|
||||
|
||||
change_state(State.READY)
|
||||
change_state(State.IDLE)
|
||||
|
||||
func change_state(state:State) -> void:
|
||||
if _current_state == state:
|
||||
|
|
@ -50,13 +51,25 @@ func change_state(state:State) -> void:
|
|||
pass
|
||||
|
||||
|
||||
## 当平台被触发时,切换状态
|
||||
func _on_trigger() -> void:
|
||||
change_state(State.READY)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
match _current_state:
|
||||
State.IDLE:
|
||||
_process_idle(delta)
|
||||
State.MOVING:
|
||||
_process_moving(delta)
|
||||
State.RETURNING:
|
||||
_process_returning(delta)
|
||||
|
||||
func _process_idle(delta:float) -> void:
|
||||
if player_trigger and player_trigger._cached_player != null:
|
||||
var p:= player_trigger._cached_player as Player
|
||||
if p.is_in_ground_state() or p.is_in_climb_state():
|
||||
_on_trigger()
|
||||
|
||||
func _process_moving(delta) -> void:
|
||||
|
||||
_current_speed = min(_current_speed + acceleration * delta, move_speed)
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue