-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(utils.gd): 初始化 Utils.gd 可将一些常用的函数(如 max_by 等)写入 Utils,方便复用。 * feat(expr_validator): 添加笑脸列表函数及其余修改 - 添加 get_smile_inds() 函数,用于获取表达式中笑脸位置 - 将 check_valid() 改为 check_invalid(),并返回所有非法下标列表, 而不是仅返回部分 - 将 check() 改为 @deprecated * feat(shake_component): 添加 shake_component ShakeComponent 可对 ShakeComponent.attach_node: Node 的 position 应用抖动效果。 默认 attach_node = null,在 _ready 时设置 attach_node 为父节点。 ShakeComponent.shake(amount: float, duration: float) 可 令其抖动 duration 秒,幅度为 amount。 可通过 ShakeComponent.shake_type 设置抖动类型。 * docs(shake_componen.gd): 添加文档 * refactor: 将 card/block 的变色 / 震动逻辑重构 - 将震动逻辑独立到 ShakeComponent 中,交由其处理 - 当设置非法符号 / 金色符号时,可使用 set_is_invalid / set_is_golden 方法 * feat: 添加动态改变颜色的功能 现在当卡牌放置时,若卡牌非法,就会自动让卡牌变红,而不是等到全部放完 才变红。 * style: 小格式修正
- Loading branch information
Showing
10 changed files
with
251 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
## ShakeComponent 可对 ShakeComponent.attach_node: Node 的 position 应用抖动效果。 | ||
## 默认 attach_node = null,在 _ready 时设置 attach_node 为父节点。 | ||
## ShakeComponent.shake(amount: float, duration: float) 可令其抖动 duration 秒,幅度为 amount。 | ||
## 可通过 ShakeComponent.shake_type 设置抖动类型。 | ||
|
||
class_name ShakeComponent extends Node | ||
|
||
@export var shake_type := ShakeType.H_SIN | ||
@export var attached_node: Node = null | ||
|
||
var progress_ratio := 1.0 | ||
var shake_amount := 0.0 | ||
var duration := 0.001 | ||
|
||
enum ShakeType { | ||
H_SIN, ## 水平方向正弦抖动,[code]pos_delta = Vector2(sin(progress_ratio * 2.0 * PI) * shake_amount, 0)[/code]。 | ||
} | ||
|
||
## 返回抖动的位置偏移。 | ||
func get_position_delta(): | ||
match self.shake_type: | ||
ShakeType.H_SIN: | ||
return Vector2(sin(progress_ratio * 2.0 * PI) * shake_amount, 0) | ||
|
||
## 令其抖动 duration 秒,幅度为 amount。 | ||
func shake(amount: float, duration_time: float = 0.001) -> void: | ||
self.progress_ratio = 0.0 | ||
self.shake_amount = amount | ||
self.duration = duration_time | ||
|
||
func _ready(): | ||
if self.attached_node == null: | ||
self.attached_node = self.get_parent() | ||
|
||
func _process(delta: float): | ||
if self.progress_ratio < 1.0: | ||
self.progress_ratio = min(1.0, self.progress_ratio + delta / self.duration) | ||
self.attached_node.position = self.get_position_delta() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[gd_scene load_steps=2 format=3 uid="uid://oxlryy260uym"] | ||
|
||
[ext_resource type="Script" path="res://components/shake_component/shake_component.gd" id="1_3k4mj"] | ||
|
||
[node name="ShakeComponent" type="Node"] | ||
script = ExtResource("1_3k4mj") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.