1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-22 07:44:17 +00:00

valuable and evaluator works (enough)

This commit is contained in:
Matteo Balugani 2023-10-01 14:43:52 +02:00 committed by Stefano Pigozzi
parent abc6b06654
commit b84c1781c1
Signed by: steffo
GPG key ID: 2A24051445686895
6 changed files with 40 additions and 30 deletions

View file

@ -1,15 +1,8 @@
[gd_scene load_steps=3 format=3 uid="uid://c5w3b55aiui6c"] [gd_scene load_steps=2 format=3 uid="uid://c5w3b55aiui6c"]
[ext_resource type="Script" path="res://collector/collector.gd" id="1_1xtt5"] [ext_resource type="Script" path="res://collector/collector.gd" id="1_1xtt5"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_vcox2"]
size = Vector2(113, 65)
[node name="Collector" type="Area2D"] [node name="Collector" type="Area2D"]
script = ExtResource("1_1xtt5") script = ExtResource("1_1xtt5")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(87.5, 48.5)
shape = SubResource("RectangleShape2D_vcox2")
[connection signal="body_entered" from="." to="." method="_on_body_entered"] [connection signal="body_entered" from="." to="." method="_on_body_entered"]

View file

@ -1,9 +1,10 @@
[gd_scene load_steps=6 format=3 uid="uid://c3kitncwpi42j"] [gd_scene load_steps=7 format=3 uid="uid://c3kitncwpi42j"]
[ext_resource type="PhysicsMaterial" uid="uid://c6kn1an85lccr" path="res://entity/coin_physics_material.tres" id="1_8k46m"] [ext_resource type="PhysicsMaterial" uid="uid://c6kn1an85lccr" path="res://entity/coin_physics_material.tres" id="1_8k46m"]
[ext_resource type="Texture2D" uid="uid://dbdkb4vt7dh85" path="res://entity/coin_copper_4.png" id="1_wedw1"] [ext_resource type="Texture2D" uid="uid://dbdkb4vt7dh85" path="res://entity/coin_copper_4.png" id="1_wedw1"]
[ext_resource type="Texture2D" uid="uid://2vtvoj6ua3cb" path="res://entity/coin_copper_outline_2.png" id="2_2ifq3"] [ext_resource type="Texture2D" uid="uid://2vtvoj6ua3cb" path="res://entity/coin_copper_outline_2.png" id="2_2ifq3"]
[ext_resource type="PackedScene" uid="uid://bk1vvq5rug01m" path="res://collector/collectible.tscn" id="4_yefrx"] [ext_resource type="PackedScene" uid="uid://bk1vvq5rug01m" path="res://collector/collectible.tscn" id="4_yefrx"]
[ext_resource type="PackedScene" uid="uid://ujpra0s1kpqi" path="res://value/valuable.tscn" id="5_jdvvd"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_c6byl"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_c6byl"]
size = Vector2(16, 5) size = Vector2(16, 5)
@ -32,3 +33,6 @@ texture = ExtResource("2_2ifq3")
[node name="Collectible" parent="." instance=ExtResource("4_yefrx")] [node name="Collectible" parent="." instance=ExtResource("4_yefrx")]
type = &"Copper" type = &"Copper"
[node name="Valuable" parent="." instance=ExtResource("5_jdvvd")]
value = 1

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=6 format=3 uid="uid://cbccs6kwwf265"] [gd_scene load_steps=9 format=3 uid="uid://cbccs6kwwf265"]
[ext_resource type="Script" path="res://root.gd" id="1_8jrhk"] [ext_resource type="Script" path="res://root.gd" id="1_8jrhk"]
[ext_resource type="Theme" uid="uid://ba5utvfhnxa5i" path="res://interface/interface_theme.tres" id="1_h26ax"] [ext_resource type="Theme" uid="uid://ba5utvfhnxa5i" path="res://interface/interface_theme.tres" id="1_h26ax"]

View file

@ -9,22 +9,33 @@ var total_value: int = 0
## The types of [Collectible]s to value. ## The types of [Collectible]s to value.
## ##
## The strings will match only if exactly the same. ## The strings will match only if exactly the same.
@export var collecting_types: Array[StringName] #@export var collecting_types: Array[StringName]
## The collision mask to check colliding body against. ## The collision mask to check colliding body against.
@export_flags_2d_physics var collecting_collision_mask: int @export_flags_2d_physics var collecting_collision_mask: int
## The evaluator has added the value of an object to the total.
## The evaluator has added the value of an object.
signal added(what: PhysicsBody2D) signal added(what: PhysicsBody2D)
## The evaluator has removed the value of an object to the total.
## The evaluator has removed the value of an object.
signal removed(what: PhysicsBody2D) signal removed(what: PhysicsBody2D)
func _on_body_entered(body):
if body is PhysicsBody2D:
if body.collision_layer & collecting_collision_mask:
var evaluable: Valuable = body.get_node("Valuable")
print("sommato")
total_value += evaluable.value
evaluable.evaluate()
added.emit(body)
print("totale= "+str(total_value))
func _on_body_entered(body: Node2D): func _on_body_exited(body):
pass if body is PhysicsBody2D:
if body.collision_layer & collecting_collision_mask:
var evaluable: Valuable = body.get_node("Valuable")
print("sottratto")
total_value -= evaluable.value
evaluable.evaluate()
added.emit(body)
print("totale= "+str(total_value))

View file

@ -2,9 +2,8 @@
[ext_resource type="Script" path="res://value/evaluator.gd" id="1_sjx78"] [ext_resource type="Script" path="res://value/evaluator.gd" id="1_sjx78"]
[node name="Evaluator" type="Node2D"] [node name="Evaluator" type="Area2D"]
script = ExtResource("1_sjx78") script = ExtResource("1_sjx78")
[node name="Area2D" type="Area2D" parent="."] [connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_body_exited"]
[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]

View file

@ -3,8 +3,11 @@ class_name Valuable
@export var value: int @export var value: int
#signal object_value ## Emitted when this entity has been counted.
# signal evaluated
#
#func collect(): ## Mark this entity as evaluated.
# emit_signal("collected") ##
func evaluate():
emit_signal("evaluated")