1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-11-24 00:24:19 +00:00

add randomizer and roller

This commit is contained in:
Matteo Balugani 2023-10-01 16:09:43 +02:00 committed by Stefano Pigozzi
parent aa2cf6612b
commit b40cc2d627
Signed by: steffo
GPG key ID: 2A24051445686895
9 changed files with 41 additions and 22 deletions

View file

@ -1,6 +1,8 @@
extends Node2D
func _on_roller_failure():
print("failure")
func _process(delta):
print($Evaluator.total_value)
func _on_roller_success():
print("success")

11
bottle/bottle.gd Normal file
View file

@ -0,0 +1,11 @@
extends TileMap
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass

View file

@ -31,11 +31,9 @@ func _on_body_entered(body: Node2D):
if body.collision_layer & collecting_collision_mask:
var collectible: Collectible = body.get_node("Collectible")
if collectible.type in collecting_types:
print("collezionato")
collected_count += 1
collectible.collect()
emit_signal("collected", body)
if collected_count >= collecting_amount:
print("goal")
emit_signal("goal")
collected_count = 0

View file

@ -1,11 +1,3 @@
extends Node2D
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
extends Node
class_name Randomizer
static var rng : RandomNumberGenerator = RandomNumberGenerator.new()

View file

@ -2,5 +2,5 @@
[ext_resource type="Script" path="res://random/randomizer.gd" id="1_nvy1v"]
[node name="Randomizer" type="Node2D"]
[node name="Randomizer" type="Node"]
script = ExtResource("1_nvy1v")

14
random/roller.gd Normal file
View file

@ -0,0 +1,14 @@
extends Node2D
@export_range(0,1) var slider : float = 0
signal success()
signal failure()
func roll():
if Randomizer.rng.randf() < slider:
success.emit()
else:
failure.emit()

6
random/roller.tscn Normal file
View file

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://dvgxb0ichkoe7"]
[ext_resource type="Script" path="res://random/roller.gd" id="1_vetpi"]
[node name="Roller" type="Node2D"]
script = ExtResource("1_vetpi")

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://cbccs6kwwf265"]
[gd_scene load_steps=12 format=3 uid="uid://cbccs6kwwf265"]
[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"]

View file

@ -25,19 +25,15 @@ 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()
score_changed.emit(total_value)
print("totale= "+str(total_value))
func _on_body_exited(body):
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()
score_changed.emit(total_value)
print("totale= "+str(total_value))