Skip to content

Commit

Permalink
Merge pull request #37 from ligen131/add-card-color
Browse files Browse the repository at this point in the history
添加改变 Card 和 Card Base 卡背颜色功能
  • Loading branch information
cutekibry authored Feb 10, 2024
2 parents 52ed33e + f049ab1 commit 772943c
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 91 deletions.
23 changes: 17 additions & 6 deletions objects/card/card.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var is_shaking := false
func _ready():
origin_global_position = global_position
last_global_position = global_position
$HighlightSprite.visible = false

func _on_mouse_release():
#prints(entered_area.name, is_card_entered, entered_area.occupied)
Expand Down Expand Up @@ -97,6 +98,7 @@ func _process(_delta: float) -> void:
var progress = $ShakeTimer.time_left / $ShakeTimer.wait_time * 2 * PI
offset = int(sin(progress) * shake_amount)
$CardBackSprite.position.x = offset
$HighlightSprite.position.x = offset
$Word.position.x = offset

func on_card_entered(area: Block) -> void:
Expand All @@ -116,8 +118,17 @@ func on_card_base_exited() -> void:
is_card_base_entered -= 1
#print(is_card_entered)

func set_word(e: String) -> void:
$Word.set_word(e)
func set_word(value: String) -> void:
$Word.set_word(value)
var card_type := "card-%s" % ExprValidator.get_char_type_as_str(get_word()).to_lower()
if ImageLib.PALETTE.has(card_type):
ImageLib.update_animation(
$CardBackSprite, 1, 3, 1, "res://objects/card/card%d.png",
ImageLib.PALETTE["lightblue"], ImageLib.PALETTE[card_type]
)
print($CardBackSprite.animation)
print($CardBackSprite.sprite_frames.animations)


func get_word() -> String:
return $Word.get_word()
Expand All @@ -135,22 +146,22 @@ func shake(is_letter_red: bool, amount: float, duration: float) -> void:
if is_letter_red:
$Word.set_color(ImageLib.PALETTE["red"])
else:
$CardBackSprite.animation = "default"
$HighlightSprite.visible = false




func _on_mouse_entered():
$CardBackSprite.animation = "highlighted"
$HighlightSprite.visible = true
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)

func _on_mouse_exited():
$CardBackSprite.animation = "default"
$HighlightSprite.visible = false
Input.set_default_cursor_shape(Input.CURSOR_ARROW)

func set_color(value: Color) -> void:
$Word.set_color(value)


func set_victory(v: bool):
if v:
$CollisionShape2D.set_deferred("disabled", true)
Expand Down
27 changes: 9 additions & 18 deletions objects/card/card.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
[ext_resource type="Texture2D" uid="uid://cfbqh1k0etr6g" path="res://objects/card/card1.png" id="3_o4f0v"]
[ext_resource type="Texture2D" uid="uid://c8qjbksyn1bqt" path="res://objects/card/card2.png" id="4_c30j1"]
[ext_resource type="Texture2D" uid="uid://bevrfq1hhyqwe" path="res://objects/card/card3.png" id="5_w81n3"]
[ext_resource type="Texture2D" uid="uid://cmcc5xrpkrd0f" path="res://objects/card/card_highlighted.png" id="6_po2i6"]
[ext_resource type="Texture2D" uid="uid://pmapbo480in1" path="res://objects/card/card_highlight_border.png" id="7_kix4t"]
[ext_resource type="AudioStream" uid="uid://cj4v8ehypq3sk" path="res://objects/card/put_down.wav" id="7_u4ylf"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_gu6l6"]

[sub_resource type="SpriteFrames" id="SpriteFrames_fo0r0"]
animations = [{
"frames": [{
Expand All @@ -25,34 +23,27 @@ animations = [{
"loop": true,
"name": &"default",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("6_po2i6")
}],
"loop": true,
"name": &"highlighted",
"speed": 5.0
}]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_gu6l6"]

[node name="Card" type="Area2D"]
z_index = 50
script = ExtResource("1_0bviv")

[node name="Word" parent="." instance=ExtResource("1_ns36n")]
z_index = 1
frame_progress = 0.111549
text_id = 1
color = Color(0, 0, 0, 1)

[node name="CardBackSprite" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_fo0r0")

[node name="HighlightSprite" type="Sprite2D" parent="."]
texture = ExtResource("7_kix4t")

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
z_index = 15
shape = SubResource("RectangleShape2D_gu6l6")

[node name="CardBackSprite" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_fo0r0")
autoplay = "default"

[node name="SFXPutDown" type="AudioStreamPlayer" parent="."]
stream = ExtResource("7_u4ylf")
volume_db = 13.117
Expand Down
Binary file added objects/card/card_highlight_border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

importer="texture"
type="CompressedTexture2D"
uid="uid://cs7vfmsrhpomj"
path="res://.godot/imported/card_base_highlighted.png-50d4af98046c8a87d73d61ca6664f89e.ctex"
uid="uid://pmapbo480in1"
path="res://.godot/imported/card_highlight_border.png-c0b130850c2d1dcdc5af25ea7e1dafdc.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://objects/card_base/card_base_highlighted.png"
dest_files=["res://.godot/imported/card_base_highlighted.png-50d4af98046c8a87d73d61ca6664f89e.ctex"]
source_file="res://objects/card/card_highlight_border.png"
dest_files=["res://.godot/imported/card_highlight_border.png-c0b130850c2d1dcdc5af25ea7e1dafdc.ctex"]

[params]

Expand Down
Binary file removed objects/card/card_highlighted.png
Binary file not shown.
29 changes: 21 additions & 8 deletions objects/card_base/card_base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ signal card_put
var fade_flag := false
var mouse_on := false

enum { DEFAULT, HIGHLIGHT, DISABLED}
var available_stat := DEFAULT


var card_count = 0
var new_card_node: Card
Expand All @@ -25,11 +28,11 @@ func set_card_count(value):
card_count = value
if card_count > 0:
if mouse_on:
$AnimatedSprite2D.animation = "highlighted"
available_stat = HIGHLIGHT
else:
$AnimatedSprite2D.animation = "default"
available_stat = DEFAULT
else:
$AnimatedSprite2D.animation = "disabled"
available_stat = DISABLED
update_card_count_label()


Expand Down Expand Up @@ -74,6 +77,11 @@ func _input_event(_viewport: Object, event: InputEvent, _shape_idx: int) -> void
func set_word(e: String) -> void:
$Word.set_word(e)

var card_type := "card-%s" % ExprValidator.get_char_type_as_str(e).to_lower()
if ImageLib.PALETTE.has(card_type):
ImageLib.update_animation($CardBaseSprite, 1, 1, 1, "res://objects/card_base/card_base%d.png",
ImageLib.PALETTE["lightblue"], ImageLib.PALETTE[card_type])

func get_word() -> String:
return $Word.get_word()

Expand All @@ -98,18 +106,23 @@ func _process(_delta) -> void:
if fade_flag:
var offset = $FadeTimer.time_left / $FadeTimer.wait_time
offset = (1 - pow(offset, 1.5)) * FADE_MOVE_AMOUNT
$AnimatedSprite2D.position.y = offset
$CardBaseSprite.position.y = offset
$HighlightSprite.position.y = offset
$DisabledSprite.position.y = offset
$Word.position.y = offset

$HighlightSprite.visible = (available_stat == HIGHLIGHT)
$DisabledSprite.visible = (available_stat == DISABLED)


func _on_mouse_entered():
mouse_on = true
if $AnimatedSprite2D.animation == "default":
$AnimatedSprite2D.animation = "highlighted"
if available_stat == DEFAULT:
available_stat = HIGHLIGHT
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)

func _on_mouse_exited():
mouse_on = false
if $AnimatedSprite2D.animation == "highlighted":
$AnimatedSprite2D.animation = "default"
if available_stat == HIGHLIGHT:
available_stat = DEFAULT
Input.set_default_cursor_shape(Input.CURSOR_ARROW)
25 changes: 12 additions & 13 deletions objects/card_base/card_base.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[ext_resource type="FontFile" uid="uid://1000owdyvwfg" path="res://fonts/unifont-15.1.04.otf" id="3_0qykx"]
[ext_resource type="Texture2D" uid="uid://b5d2rfms7vyfi" path="res://objects/card_base/card_base1.png" id="3_h7i1h"]
[ext_resource type="Texture2D" uid="uid://bkjbrw1ppac5q" path="res://objects/card_base/card_base_disabled.png" id="4_0unxr"]
[ext_resource type="Texture2D" uid="uid://cs7vfmsrhpomj" path="res://objects/card_base/card_base_highlighted.png" id="5_tkdj2"]
[ext_resource type="Texture2D" uid="uid://bkuwo3g8pyuyi" path="res://objects/card_base/card_base_highlight_border.png" id="5_r41oe"]
[ext_resource type="AudioStream" uid="uid://0sefo32v1jne" path="res://objects/card_base/pick_up.wav" id="7_0c7kt"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_2cmwb"]
Expand All @@ -28,14 +28,6 @@ animations = [{
"loop": true,
"name": &"disabled",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("5_tkdj2")
}],
"loop": true,
"name": &"highlighted",
"speed": 5.0
}]

[node name="CardBase" type="Area2D"]
Expand All @@ -45,10 +37,20 @@ script = ExtResource("1_k5qn1")
shape = SubResource("RectangleShape2D_2cmwb")
debug_color = Color(0.65098, 0.431373, 0.756863, 0.419608)

[node name="CardBaseSprite" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_bhb3x")

[node name="Word" parent="." instance=ExtResource("2_jvsp3")]
z_index = 1
frame_progress = 0.953211

[node name="HighlightSprite" type="Sprite2D" parent="."]
visible = false
texture = ExtResource("5_r41oe")

[node name="DisabledSprite" type="Sprite2D" parent="."]
visible = false
texture = ExtResource("4_0unxr")

[node name="Label" type="Label" parent="."]
offset_left = -13.0
offset_top = 17.0
Expand All @@ -59,9 +61,6 @@ text = "0"
horizontal_alignment = 1
vertical_alignment = 1

[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_bhb3x")

[node name="Cards" type="Node" parent="."]

[node name="FadeTimer" type="Timer" parent="."]
Expand Down
Binary file added objects/card_base/card_base_highlight_border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions objects/card_base/card_base_highlight_border.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bkuwo3g8pyuyi"
path="res://.godot/imported/card_base_highlight_border.png-02641e6f6e23a694917134adadde948a.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://objects/card_base/card_base_highlight_border.png"
dest_files=["res://.godot/imported/card_base_highlight_border.png-02641e6f6e23a694917134adadde948a.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file removed objects/card_base/card_base_highlighted.png
Binary file not shown.
18 changes: 1 addition & 17 deletions objects/word/word.gd
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ func set_text_id(value: int) -> void:
update_animation()

func update_animation() -> void:
var animation_id = str(text_id) + color.to_html()
if not sprite_frames.has_animation(animation_id):
sprite_frames.add_animation(animation_id)
for i in range(3):
sprite_frames.add_frame(animation_id, load_image(i * STEP + text_id + 1, color))
animation = animation_id
ImageLib.update_animation(self, text_id + 1, 3, STEP, "res://objects/word/sprites/sprite%d.png", Color.BLACK, color)



Expand All @@ -53,11 +48,6 @@ func get_word() -> String:

func _ready():
update_animation()



func _process(_delta):
update_animation()

func set_color(value: Color) -> void:
color = value
Expand All @@ -72,9 +62,3 @@ func set_victory(v: bool) -> void:
set_color(ImageLib.PALETTE["golden"])
else:
set_color(ImageLib.PALETTE["default"])

func load_image(h: int, new_color: Color):
var image := load("res://objects/word/sprites/sprite" + str(h) + ".png")
if new_color != Color.BLACK:
return ImageLib.change_color(image, Color.BLACK, new_color)
return image
18 changes: 1 addition & 17 deletions objects/word/word.tscn
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
[gd_scene load_steps=6 format=3 uid="uid://cvx7wowcbfo0r"]
[gd_scene load_steps=4 format=3 uid="uid://cvx7wowcbfo0r"]

[ext_resource type="Texture2D" uid="uid://cyyu6tsje4x72" path="res://objects/word/sprites/sprite3.png" id="1_ariam"]
[ext_resource type="Script" path="res://objects/word/word.gd" id="1_lkxlh"]
[ext_resource type="Texture2D" uid="uid://bqtqgiv5etyny" path="res://objects/word/sprites/sprite28.png" id="2_l4ops"]
[ext_resource type="Texture2D" uid="uid://dua7hylyf4ws6" path="res://objects/word/sprites/sprite53.png" id="3_2kshj"]

[sub_resource type="SpriteFrames" id="SpriteFrames_3n85j"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("1_ariam")
}, {
"duration": 1.0,
"texture": ExtResource("2_l4ops")
}, {
"duration": 1.0,
"texture": ExtResource("3_2kshj")
}],
"loop": true,
"name": &"default",
"speed": 3.0
}, {
"frames": [],
"loop": true,
"name": &"new_animation",
"speed": 5.0
}]

[node name="Word" type="AnimatedSprite2D"]
sprite_frames = SubResource("SpriteFrames_3n85j")
autoplay = "default"
script = ExtResource("1_lkxlh")
text_id = null
color = null
Loading

0 comments on commit 772943c

Please sign in to comment.