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:
parent
aa2cf6612b
commit
b40cc2d627
9 changed files with 41 additions and 22 deletions
6
Game.gd
6
Game.gd
|
@ -1,6 +1,8 @@
|
||||||
extends Node2D
|
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
11
bottle/bottle.gd
Normal 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
|
|
@ -31,11 +31,9 @@ func _on_body_entered(body: Node2D):
|
||||||
if body.collision_layer & collecting_collision_mask:
|
if body.collision_layer & collecting_collision_mask:
|
||||||
var collectible: Collectible = body.get_node("Collectible")
|
var collectible: Collectible = body.get_node("Collectible")
|
||||||
if collectible.type in collecting_types:
|
if collectible.type in collecting_types:
|
||||||
print("collezionato")
|
|
||||||
collected_count += 1
|
collected_count += 1
|
||||||
collectible.collect()
|
collectible.collect()
|
||||||
emit_signal("collected", body)
|
emit_signal("collected", body)
|
||||||
if collected_count >= collecting_amount:
|
if collected_count >= collecting_amount:
|
||||||
print("goal")
|
|
||||||
emit_signal("goal")
|
emit_signal("goal")
|
||||||
collected_count = 0
|
collected_count = 0
|
||||||
|
|
|
@ -1,11 +1,3 @@
|
||||||
extends Node2D
|
extends Node
|
||||||
|
class_name Randomizer
|
||||||
|
static var rng : RandomNumberGenerator = RandomNumberGenerator.new()
|
||||||
# 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
|
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://random/randomizer.gd" id="1_nvy1v"]
|
[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")
|
script = ExtResource("1_nvy1v")
|
||||||
|
|
14
random/roller.gd
Normal file
14
random/roller.gd
Normal 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
6
random/roller.tscn
Normal 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")
|
|
@ -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="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"]
|
||||||
|
|
|
@ -25,19 +25,15 @@ func _on_body_entered(body):
|
||||||
if body is PhysicsBody2D:
|
if body is PhysicsBody2D:
|
||||||
if body.collision_layer & collecting_collision_mask:
|
if body.collision_layer & collecting_collision_mask:
|
||||||
var evaluable: Valuable = body.get_node("Valuable")
|
var evaluable: Valuable = body.get_node("Valuable")
|
||||||
print("sommato")
|
|
||||||
total_value += evaluable.value
|
total_value += evaluable.value
|
||||||
evaluable.evaluate()
|
evaluable.evaluate()
|
||||||
score_changed.emit(total_value)
|
score_changed.emit(total_value)
|
||||||
print("totale= "+str(total_value))
|
|
||||||
|
|
||||||
func _on_body_exited(body):
|
func _on_body_exited(body):
|
||||||
if body is PhysicsBody2D:
|
if body is PhysicsBody2D:
|
||||||
if body.collision_layer & collecting_collision_mask:
|
if body.collision_layer & collecting_collision_mask:
|
||||||
var evaluable: Valuable = body.get_node("Valuable")
|
var evaluable: Valuable = body.get_node("Valuable")
|
||||||
print("sottratto")
|
|
||||||
total_value -= evaluable.value
|
total_value -= evaluable.value
|
||||||
evaluable.evaluate()
|
evaluable.evaluate()
|
||||||
score_changed.emit(total_value)
|
score_changed.emit(total_value)
|
||||||
print("totale= "+str(total_value))
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue