Bläddra i källkod

Catch balls and emit signal

DricomDragon 3 år sedan
förälder
incheckning
353aa6378b
5 ändrade filer med 76 tillägg och 23 borttagningar
  1. 13 2
      godot/project.godot
  2. 27 0
      godot/scenes/Ball.tscn
  3. 24 21
      godot/scenes/main.tscn
  4. 3 0
      godot/scripts/Ball.gd
  5. 9 0
      godot/scripts/Catcher.gd

+ 13 - 2
godot/project.godot

@@ -8,9 +8,20 @@
 
 config_version=4
 
-_global_script_classes=[  ]
+_global_script_classes=[ {
+"base": "RigidBody2D",
+"class": "Ball",
+"language": "GDScript",
+"path": "res://scripts/Ball.gd"
+}, {
+"base": "Area2D",
+"class": "Catcher",
+"language": "GDScript",
+"path": "res://scripts/Catcher.gd"
+} ]
 _global_script_class_icons={
-
+"Ball": "",
+"Catcher": ""
 }
 
 [application]

+ 27 - 0
godot/scenes/Ball.tscn

@@ -0,0 +1,27 @@
+[gd_scene load_steps=5 format=2]
+
+[ext_resource path="res://image/ball.png" type="Texture" id=1]
+[ext_resource path="res://scripts/Ball.gd" type="Script" id=2]
+
+[sub_resource type="PhysicsMaterial" id=1]
+friction = 0.0
+bounce = 1.0
+
+[sub_resource type="CircleShape2D" id=2]
+radius = 5.0
+
+[node name="Ball" type="RigidBody2D" groups=[
+"ball",
+]]
+mode = 2
+physics_material_override = SubResource( 1 )
+gravity_scale = 0.0
+linear_velocity = Vector2( 100, 100 )
+linear_damp = 0.0
+script = ExtResource( 2 )
+
+[node name="Circle" type="CollisionShape2D" parent="."]
+shape = SubResource( 2 )
+
+[node name="Sprite" type="Sprite" parent="."]
+texture = ExtResource( 1 )

+ 24 - 21
godot/scenes/main.tscn

@@ -1,7 +1,8 @@
 [gd_scene load_steps=10 format=2]
 
-[ext_resource path="res://image/ball.png" type="Texture" id=1]
+[ext_resource path="res://scenes/Ball.tscn" type="PackedScene" id=1]
 [ext_resource path="res://image/brik.png" type="Texture" id=2]
+[ext_resource path="res://scripts/Catcher.gd" type="Script" id=3]
 
 [sub_resource type="PhysicsMaterial" id=5]
 friction = 0.0
@@ -34,11 +35,8 @@ points = PoolVector2Array( 0, 0, 40, 0, 40, 20, 0, 20 )
 } ]
 0/z_index = 0
 
-[sub_resource type="PhysicsMaterial" id=4]
-friction = 0.0
-bounce = 1.0
-
-[sub_resource type="CircleShape2D" id=3]
+[sub_resource type="RectangleShape2D" id=8]
+extents = Vector2( 200, 50 )
 
 [node name="Node2D" type="Node2D"]
 
@@ -63,19 +61,24 @@ tile_set = SubResource( 2 )
 cell_size = Vector2( 40, 20 )
 cell_custom_transform = Transform2D( 40, 0, 0, 20, 0, 0 )
 format = 1
-tile_data = PoolIntArray( 65540, 0, 0, 65541, 0, 0, 393217, 0, 0, 393218, 0, 0, 393223, 0, 0, 393224, 0, 0, 458753, 0, 0, 458754, 0, 0, 458759, 0, 0, 458760, 0, 0, 524289, 0, 0, 524290, 0, 0, 524295, 0, 0, 524296, 0, 0, 1245184, 0, 0, 1245185, 0, 0, 1245186, 0, 0, 1245187, 0, 0, 1245188, 0, 0, 1245189, 0, 0, 1245190, 0, 0, 1245191, 0, 0, 1245192, 0, 0, 1245193, 0, 0 )
+tile_data = PoolIntArray( 65540, 0, 0, 65541, 0, 0, 393217, 0, 0, 393218, 0, 0, 393223, 0, 0, 393224, 0, 0, 458753, 0, 0, 458754, 0, 0, 458759, 0, 0, 458760, 0, 0, 524289, 0, 0, 524290, 0, 0, 524295, 0, 0, 524296, 0, 0, 720899, 0, 0, 720900, 0, 0, 720901, 0, 0, 720902, 0, 0 )
 
-[node name="Ball" type="RigidBody2D" parent="."]
-mode = 2
-physics_material_override = SubResource( 4 )
-gravity_scale = 0.0
-linear_velocity = Vector2( 100, 100 )
-linear_damp = 0.0
-
-[node name="Circle" type="CollisionShape2D" parent="Ball"]
-position = Vector2( 180.82, 302.182 )
-shape = SubResource( 3 )
-
-[node name="Sprite" type="Sprite" parent="Ball"]
-position = Vector2( 180.82, 302.182 )
-texture = ExtResource( 1 )
+[node name="Ball" parent="." instance=ExtResource( 1 )]
+position = Vector2( 306.503, 282.76 )
+linear_velocity = Vector2( 100, -100 )
+
+[node name="Ball2" parent="." instance=ExtResource( 1 )]
+position = Vector2( 280.601, 315.137 )
+linear_velocity = Vector2( 100, -100 )
+
+[node name="Ball3" parent="." instance=ExtResource( 1 )]
+position = Vector2( 254.699, 347.514 )
+linear_velocity = Vector2( 100, -100 )
+
+[node name="Catcher" type="Area2D" parent="."]
+position = Vector2( 200, 470 )
+script = ExtResource( 3 )
+
+[node name="Area" type="CollisionShape2D" parent="Catcher"]
+shape = SubResource( 8 )
+[connection signal="body_entered" from="Catcher" to="Catcher" method="_on_Catcher_body_entered"]

+ 3 - 0
godot/scripts/Ball.gd

@@ -0,0 +1,3 @@
+class_name Ball
+extends RigidBody2D
+

+ 9 - 0
godot/scripts/Catcher.gd

@@ -0,0 +1,9 @@
+class_name Catcher
+extends Area2D
+
+signal kace_catch
+
+func _on_Catcher_body_entered(body):
+	if (body.is_in_group("ball")):
+		body.queue_free()
+	emit_signal("kace_catch")