From 16afe2b983a99ffe3fff4f8c2e16a2ab827bf502 Mon Sep 17 00:00:00 2001 From: Waldemar Tomme Date: Sat, 27 Jan 2024 13:08:34 +0100 Subject: [PATCH] Transmit jokes to the audience --- godot/scenes/Tim.gd | 8 +++++++- godot/scenes/crowd/person.gd | 4 ++++ godot/scenes/crowd/person.tscn | 9 ++++++++- godot/scenes/stage.tscn | 15 +++++++++++++-- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/godot/scenes/Tim.gd b/godot/scenes/Tim.gd index 968cdf5..37151d2 100644 --- a/godot/scenes/Tim.gd +++ b/godot/scenes/Tim.gd @@ -3,6 +3,7 @@ extends Node2D @export var move_speed = 100 @export var boundary: Boundary @export var tim_sprite : Sprite2D +@export var transmitter_area: Area2D # Called when the node enters the scene tree for the first time. func _ready(): @@ -24,4 +25,9 @@ func _process(delta): func _on_joke_button_button_pressed(joke): - pass # Replace with function body. + for body in transmitter_area.get_overlapping_bodies(): + var person = body.find_parent("Person") + if not (person is Person): + continue + + person.on_joke(joke) diff --git a/godot/scenes/crowd/person.gd b/godot/scenes/crowd/person.gd index f11181b..792b84a 100644 --- a/godot/scenes/crowd/person.gd +++ b/godot/scenes/crowd/person.gd @@ -1,3 +1,4 @@ +class_name Person extends Sprite2D @export var head : Node2D @@ -24,3 +25,6 @@ func set_random_face(): var face_res = load(known_faces[randi() % known_faces.size()]) face = face_res.instantiate() head.add_child(face) + +func on_joke(joke: Joke): + pass diff --git a/godot/scenes/crowd/person.tscn b/godot/scenes/crowd/person.tscn index d45e71c..380218c 100644 --- a/godot/scenes/crowd/person.tscn +++ b/godot/scenes/crowd/person.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=3 format=3 uid="uid://cl4fax7fbh2g7"] +[gd_scene load_steps=4 format=3 uid="uid://cl4fax7fbh2g7"] [ext_resource type="Script" path="res://scenes/crowd/person.gd" id="1_mx0i8"] [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_kbo53"] size = Vector2(20, 30) +[sub_resource type="RectangleShape2D" id="RectangleShape2D_5rd5b"] + [node name="Person" type="Sprite2D" node_paths=PackedStringArray("head")] texture = SubResource("PlaceholderTexture2D_kbo53") script = ExtResource("1_mx0i8") @@ -13,3 +15,8 @@ head = NodePath("Head") [node name="Head" type="Node2D" parent="."] position = Vector2(0, -16) scale = Vector2(0.3, 0.3) + +[node name="StaticBody2D" type="StaticBody2D" parent="."] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] +shape = SubResource("RectangleShape2D_5rd5b") diff --git a/godot/scenes/stage.tscn b/godot/scenes/stage.tscn index 70fd8b6..58c1216 100644 --- a/godot/scenes/stage.tscn +++ b/godot/scenes/stage.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=7 format=3 uid="uid://cicyfp5xjvvu4"] +[gd_scene load_steps=8 format=3 uid="uid://cicyfp5xjvvu4"] [ext_resource type="Script" path="res://scenes/Tim.gd" id="1_g3k2b"] [ext_resource type="Texture2D" uid="uid://kq63ictuirhc" path="res://sprites/tim_side.png" id="1_saxit"] @@ -11,6 +11,9 @@ size = Vector2(600, 200) [sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_k2q2d"] size = Vector2(150, 50) +[sub_resource type="RectangleShape2D" id="RectangleShape2D_wmfel"] +size = Vector2(100, 10000) + [node name="Stage" type="Node2D"] [node name="Sprite2D" type="Sprite2D" parent="."] @@ -18,10 +21,11 @@ scale = Vector2(1, 0.3) texture = SubResource("PlaceholderTexture2D_3hx6l") offset = Vector2(0, -100) -[node name="Tim" type="Node2D" parent="." node_paths=PackedStringArray("boundary", "tim_sprite")] +[node name="Tim" type="Node2D" parent="." node_paths=PackedStringArray("boundary", "tim_sprite", "transmitter_area")] script = ExtResource("1_g3k2b") boundary = NodePath("../Boundary") tim_sprite = NodePath("Sprite2D") +transmitter_area = NodePath("Joke Transmitter/Area2D") [node name="Sprite2D" type="Sprite2D" parent="Tim"] position = Vector2(-12, -142) @@ -55,6 +59,13 @@ action = "joke_button_3" position = Vector2(150, -50) texture = SubResource("PlaceholderTexture2D_k2q2d") +[node name="Joke Transmitter" type="Node2D" parent="Tim"] + +[node name="Area2D" type="Area2D" parent="Tim/Joke Transmitter"] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Tim/Joke Transmitter/Area2D"] +shape = SubResource("RectangleShape2D_wmfel") + [node name="Boundary" type="Node2D" parent="."] script = ExtResource("2_8p6ir")