Skip to content

Commit 85a3a8f

Browse files
committed
add first class function snippets
1 parent b591521 commit 85a3a8f

4 files changed

+101
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
extends Node2D
2+
3+
4+
var disappear_function: Callable = fade_and_hide
5+
6+
7+
func _ready():
8+
# Wait for 0.5 seconds
9+
await get_tree().create_timer(0.5).timeout
10+
disappear_function.call()
11+
12+
13+
func scale_down_and_hide():
14+
var tween = create_tween()
15+
tween.tween_property(self, "scale", Vector2.ZERO, 1.0)
16+
await tween.finished
17+
hide()
18+
19+
20+
func fade_and_hide():
21+
var tween = create_tween()
22+
tween.tween_property(self, "modulate", Color.TRANSPARENT, 1.0)
23+
await tween.finished
24+
hide()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[gd_scene load_steps=8 format=3 uid="uid://bhcw3bsqrv71g"]
2+
3+
[ext_resource type="Shader" path="res://cutout_character/assets/moving_background.gdshader" id="1_n7j86"]
4+
[ext_resource type="Texture2D" uid="uid://b3x32i7av8vb2" path="res://2d_lighting_normal_map/assets/sun_pattern.png" id="2_t7fda"]
5+
[ext_resource type="Texture2D" uid="uid://4qq352a1j6m4" path="res://2d_lighting_normal_map/assets/dog_albedo.png" id="3_1lvlp"]
6+
[ext_resource type="Texture2D" uid="uid://djebcop0tgdes" path="res://2d_lighting_normal_map/assets/dog_normal.png" id="4_x0lag"]
7+
[ext_resource type="Script" path="res://additional/snippets/110-first-class-functions-assign.gd" id="5_ldbeg"]
8+
9+
[sub_resource type="CanvasTexture" id="CanvasTexture_jhywx"]
10+
diffuse_texture = ExtResource("3_1lvlp")
11+
normal_texture = ExtResource("4_x0lag")
12+
specular_shininess = 0.1
13+
texture_filter = 4
14+
15+
[sub_resource type="ShaderMaterial" id="ShaderMaterial_x1hlk"]
16+
shader = ExtResource("1_n7j86")
17+
shader_parameter/bg_color = Color(0.12549, 0.121569, 0.180392, 1)
18+
shader_parameter/pattern_color = Color(0.192157, 0.211765, 0.321569, 1)
19+
shader_parameter/scale = 4.0
20+
shader_parameter/ratio = 0.56
21+
shader_parameter/direction = Vector2(0.025, 0.025)
22+
shader_parameter/pattern_sampler = ExtResource("2_t7fda")
23+
24+
[node name="Node2D" type="Node2D"]
25+
26+
[node name="Dog" type="Sprite2D" parent="."]
27+
position = Vector2(940, 548)
28+
scale = Vector2(1.17366, 1.17366)
29+
texture = SubResource("CanvasTexture_jhywx")
30+
offset = Vector2(0, -28)
31+
script = ExtResource("5_ldbeg")
32+
33+
[node name="Background" type="CanvasLayer" parent="."]
34+
layer = -10
35+
36+
[node name="Background" type="ColorRect" parent="Background"]
37+
material = SubResource("ShaderMaterial_x1hlk")
38+
anchors_preset = 15
39+
anchor_right = 1.0
40+
anchor_bottom = 1.0
41+
grow_horizontal = 2
42+
grow_vertical = 2
43+
metadata/_edit_lock_ = true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
extends Node
2+
3+
4+
func _compare_property(a, b, property: String) -> bool:
5+
if property in a and property in b:
6+
return a[property] > b[property]
7+
else:
8+
return property in a
9+
10+
var items = [
11+
{"name": "Potion", "weight": 3},
12+
{"name": "Coin", "weight": 1},
13+
]
14+
15+
func sort_inventory():
16+
# Callable that sorts items using their weight property.
17+
var sort_by_weight := _compare_property.bind("weight")
18+
# We can pass the Callable to the the Array.sort_custom() function to use it for sorting.
19+
items.sort_custom(sort_by_weight)
20+
print(items)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
extends Area2D
2+
3+
4+
@onready var visibility_notifier: VisibleOnScreenNotifier2D = $VisibilityNotifier2D
5+
6+
7+
func _ready() -> void:
8+
visibility_notifier.screen_exited.connect(queue_free)
9+
10+
11+
func _physics_process(delta: float) -> void:
12+
var speed := 1200.0
13+
var direction := Vector2.ZERO
14+
position += speed * direction * delta

0 commit comments

Comments
 (0)