浏览代码

:tada: Create physics demo

Problem in firefox scale.
DricomDragon 1 周之前
父节点
当前提交
d2554bb321

+ 32 - 2
godot/slides/204/PhysicsEngine.tscn

@@ -1,11 +1,14 @@
-[gd_scene load_steps=4 format=3 uid="uid://cfr23honh8ul7"]
+[gd_scene load_steps=6 format=3 uid="uid://cfr23honh8ul7"]
 
 [ext_resource type="Script" uid="uid://dujtdgtfgki4c" path="res://addons/slide_show/projector/slide/Slide.gd" id="1_ag2av"]
 [ext_resource type="PackedScene" uid="uid://bvrtmyq4g1qes" path="res://common/components/title/title.tscn" id="2_xa84e"]
 [ext_resource type="Texture2D" uid="uid://b48de8cccfnjn" path="res://slides/204/physics_engine_2d.png" id="3_olm1w"]
+[ext_resource type="PackedScene" uid="uid://dpbr2u8co4824" path="res://slides/204/physics_demo/Bar.tscn" id="4_l048w"]
+[ext_resource type="Script" uid="uid://cqv2vfpwp78h2" path="res://slides/204/physics_demo/Spawner.gd" id="5_g1qkm"]
 
 [node name="PhysicsEngine" type="Node2D"]
 script = ExtResource("1_ag2av")
+processing_keep_when_disabled = true
 
 [node name="Title" parent="." instance=ExtResource("2_xa84e")]
 offset_left = 41.0
@@ -15,5 +18,32 @@ offset_bottom = 196.0
 text = "Moteur physique"
 
 [node name="Sprite2D" type="Sprite2D" parent="."]
-position = Vector2(927, 605)
+position = Vector2(218, 131)
+scale = Vector2(0.39117, 0.39117)
 texture = ExtResource("3_olm1w")
+
+[node name="Demo" type="Node2D" parent="."]
+
+[node name="Bar1" parent="Demo" instance=ExtResource("4_l048w")]
+position = Vector2(948, 473)
+rotation = 0.785397
+
+[node name="Bar2" parent="Demo" instance=ExtResource("4_l048w")]
+position = Vector2(1128, 954)
+
+[node name="Bar3" parent="Demo" instance=ExtResource("4_l048w")]
+position = Vector2(421, 911)
+rotation = 0.261799
+
+[node name="Bar4" parent="Demo" instance=ExtResource("4_l048w")]
+position = Vector2(1258, 634)
+rotation = -0.785397
+
+[node name="Bar5" parent="Demo" instance=ExtResource("4_l048w")]
+position = Vector2(760, 728)
+
+[node name="Spawner" type="Marker2D" parent="Demo"]
+position = Vector2(906, 239)
+script = ExtResource("5_g1qkm")
+dispersion_scale = Vector2(80, 40)
+delay = 0.25

+ 10 - 0
godot/slides/204/physics_demo/Ball.gd

@@ -0,0 +1,10 @@
+class_name Ball
+extends RigidBody2D
+
+
+func die():
+	queue_free()
+
+
+func _on_VisibilityNotifier2D_screen_exited():
+	die()

+ 1 - 0
godot/slides/204/physics_demo/Ball.gd.uid

@@ -0,0 +1 @@
+uid://ccwphojv6ic0

+ 26 - 0
godot/slides/204/physics_demo/Ball.tscn

@@ -0,0 +1,26 @@
+[gd_scene load_steps=5 format=3 uid="uid://82mseyru28tc"]
+
+[ext_resource type="Texture2D" uid="uid://bfhetobgi7o6j" path="res://slides/204/physics_demo/firefox-logo.png" id="1"]
+[ext_resource type="Script" uid="uid://ccwphojv6ic0" path="res://slides/204/physics_demo/Ball.gd" id="2"]
+
+[sub_resource type="PhysicsMaterial" id="2"]
+friction = 0.61
+bounce = 0.26
+
+[sub_resource type="CircleShape2D" id="1"]
+radius = 32.0
+
+[node name="Ball" type="RigidBody2D"]
+physics_material_override = SubResource("2")
+script = ExtResource("2")
+
+[node name="FirefoxSprite" type="Sprite2D" parent="."]
+scale = Vector2(0.512, 0.512)
+texture = ExtResource("1")
+
+[node name="RoundFixture" type="CollisionShape2D" parent="."]
+shape = SubResource("1")
+
+[node name="VisibilityNotifier2D" type="VisibleOnScreenNotifier2D" parent="."]
+
+[connection signal="screen_exited" from="VisibilityNotifier2D" to="." method="_on_VisibilityNotifier2D_screen_exited"]

+ 15 - 0
godot/slides/204/physics_demo/Bar.tscn

@@ -0,0 +1,15 @@
+[gd_scene load_steps=3 format=3 uid="uid://dpbr2u8co4824"]
+
+[ext_resource type="Texture2D" uid="uid://co3mhslawua87" path="res://slides/204/physics_demo/clay.png" id="1"]
+
+[sub_resource type="RectangleShape2D" id="1"]
+size = Vector2(248, 120.412)
+
+[node name="Bar" type="StaticBody2D"]
+
+[node name="Sprite" type="Sprite2D" parent="."]
+scale = Vector2(8, 4)
+texture = ExtResource("1")
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
+shape = SubResource("1")

+ 24 - 0
godot/slides/204/physics_demo/Spawner.gd

@@ -0,0 +1,24 @@
+extends Node2D
+
+var BallScene: PackedScene = preload("res://slides/204/physics_demo/Ball.tscn")
+
+@export var dispersion_scale : Vector2 = Vector2.ONE
+@export var delay := 1.0
+
+
+func _ready():
+	spawn()
+
+
+func spawn():
+	var ball: PhysicsBody2D = BallScene.instantiate()
+	var dispersion = Vector2(randf_range(-1.0, 1.0) * dispersion_scale.x, randf_range(-1.0, 1.0) * dispersion_scale.y)
+	ball.position = dispersion
+
+	add_child(ball)
+
+	get_tree().create_timer(delay).connect("timeout", _on_delay_time_out)
+
+
+func _on_delay_time_out():
+	spawn()

+ 1 - 0
godot/slides/204/physics_demo/Spawner.gd.uid

@@ -0,0 +1 @@
+uid://cqv2vfpwp78h2

二进制
godot/slides/204/physics_demo/clay.png


+ 34 - 0
godot/slides/204/physics_demo/clay.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://co3mhslawua87"
+path="res://.godot/imported/clay.png-f4c5f5659cd7a699d9461d16160d96f3.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://slides/204/physics_demo/clay.png"
+dest_files=["res://.godot/imported/clay.png-f4c5f5659cd7a699d9461d16160d96f3.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

二进制
godot/slides/204/physics_demo/firefox-logo.png


+ 34 - 0
godot/slides/204/physics_demo/firefox-logo.png.import

@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://bfhetobgi7o6j"
+path="res://.godot/imported/firefox-logo.png-b4ca97f9fea21a07018f3baad248ba7c.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://slides/204/physics_demo/firefox-logo.png"
+dest_files=["res://.godot/imported/firefox-logo.png-b4ca97f9fea21a07018f3baad248ba7c.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