1
Fork 0
mirror of https://github.com/Steffo99/swear-jar.git synced 2024-10-16 06:17:27 +00:00

Score and tweaks

This commit is contained in:
Steffo 2023-10-02 01:36:23 +02:00
parent 83962f7edb
commit d1bc2ca8a2
Signed by: steffo
GPG key ID: 2A24051445686895
11 changed files with 81 additions and 56 deletions

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="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="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_t8enr"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_c6byl"]
size = Vector2(14, 3)
@ -32,3 +33,6 @@ texture = ExtResource("2_2ifq3")
[node name="Collectible" parent="." instance=ExtResource("4_yefrx")]
type = &"Copper"
[node name="Valuable" parent="." instance=ExtResource("5_t8enr")]
value = 1

View file

@ -7,3 +7,9 @@ class_name Game
func trigger_spawn():
button_spawner.spawn()
signal score_changed(total: int)
func _on_score_changed(total: int):
score_changed.emit(total)

View file

@ -1,14 +1,18 @@
[gd_scene load_steps=7 format=3 uid="uid://c3rxmcwa5nqng"]
[gd_scene load_steps=9 format=3 uid="uid://c3rxmcwa5nqng"]
[ext_resource type="Script" path="res://game/game.gd" id="1_i3ly0"]
[ext_resource type="PackedScene" uid="uid://bllsprv8orpn4" path="res://bottle/bottle.tscn" id="1_y7o2l"]
[ext_resource type="PackedScene" uid="uid://d05b8jy3xmpcb" path="res://bottle/gravity_from_gyro.tscn" id="2_h2pfr"]
[ext_resource type="PackedScene" uid="uid://c67lfbk4gf1ga" path="res://spawner/spawner.tscn" id="3_qwsty"]
[ext_resource type="PackedScene" uid="uid://c3kitncwpi42j" path="res://entity/coin_copper.tscn" id="4_e5nwi"]
[ext_resource type="PackedScene" uid="uid://beg758fa6o0cs" path="res://value/evaluator.tscn" id="6_my6nv"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_4uksi"]
size = Vector2(80, 80)
[sub_resource type="RectangleShape2D" id="RectangleShape2D_rh35r"]
size = Vector2(240, 384)
[node name="Game" type="Node2D"]
texture_filter = 1
script = ExtResource("1_i3ly0")
@ -44,4 +48,12 @@ shape = SubResource("RectangleShape2D_4uksi")
[node name="GravityFromGyro" parent="." instance=ExtResource("2_h2pfr")]
[node name="Evaluator" parent="." instance=ExtResource("6_my6nv")]
position = Vector2(128, 256)
[node name="BottleShape" type="CollisionShape2D" parent="Evaluator"]
position = Vector2(8, 16)
shape = SubResource("RectangleShape2D_rh35r")
[connection signal="timeout" from="TimeSpawner/Timer" to="TimeSpawner" method="spawn"]
[connection signal="changed" from="Evaluator" to="." method="_on_score_changed"]

View file

@ -1,6 +1,8 @@
extends Control
class_name GameUI
@export var score_button: ScoreButton
## Emitted when the Score button is pressed.
signal score_button_pressed
@ -19,3 +21,6 @@ func _on_spawn_button_pressed():
func _on_shop_button_pressed():
shop_button_pressed.emit()
func _on_game_score_changed(total: int):
score_button.set_score(total)

View file

@ -1,9 +1,10 @@
[gd_scene load_steps=3 format=3 uid="uid://bo5unrhqpoyim"]
[gd_scene load_steps=4 format=3 uid="uid://bo5unrhqpoyim"]
[ext_resource type="Theme" uid="uid://ba5utvfhnxa5i" path="res://interface/interface_theme.tres" id="1_ppf8y"]
[ext_resource type="Script" path="res://interface/game_ui.gd" id="2_33nqa"]
[ext_resource type="PackedScene" uid="uid://bey5lilvteg32" path="res://interface/score_button.tscn" id="3_vobar"]
[node name="GameUI" type="Control"]
[node name="GameUI" type="Control" node_paths=PackedStringArray("score_button")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
@ -12,18 +13,15 @@ grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_ppf8y")
script = ExtResource("2_33nqa")
score_button = NodePath("ScoreButton")
[node name="ScoreButton" type="Button" parent="."]
custom_minimum_size = Vector2(72, 0)
layout_mode = 1
offset_right = 72.0
offset_bottom = 54.0
size_flags_horizontal = 0
text = "$0"
alignment = 0
[node name="ScoreButton" parent="." instance=ExtResource("3_vobar")]
custom_minimum_size = Vector2(88, 0)
layout_mode = 0
text = "$0.00"
[node name="SpawnButton" type="Button" parent="."]
custom_minimum_size = Vector2(72, 0)
custom_minimum_size = Vector2(88, 0)
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
@ -36,7 +34,7 @@ size_flags_horizontal = 4
text = "Drop"
[node name="ShopButton" type="Button" parent="."]
custom_minimum_size = Vector2(72, 0)
custom_minimum_size = Vector2(88, 0)
layout_mode = 1
anchors_preset = 1
anchor_left = 1.0
@ -48,6 +46,5 @@ size_flags_horizontal = 8
text = "Shop"
alignment = 2
[connection signal="pressed" from="ScoreButton" to="." method="_on_score_button_pressed"]
[connection signal="pressed" from="SpawnButton" to="." method="_on_spawn_button_pressed"]
[connection signal="pressed" from="ShopButton" to="." method="_on_shop_button_pressed"]

View file

@ -0,0 +1,6 @@
extends Button
class_name ScoreButton
func set_score(total: int):
text = "$%0.2f" % (float(total) / 100)

View file

@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://bey5lilvteg32"]
[ext_resource type="Script" path="res://interface/score_button.gd" id="1_ol56t"]
[node name="ScoreButton" type="Button"]
custom_minimum_size = Vector2(72, 0)
offset_right = 72.0
offset_bottom = 54.0
size_flags_horizontal = 0
text = "$0"
alignment = 0
script = ExtResource("1_ol56t")

View file

@ -22,7 +22,7 @@ grow_vertical = 2
size_flags_vertical = 8
theme = ExtResource("1_je7w1")
[node name="CenterContainer" type="CenterContainer" parent="UI"]
[node name="GameWorld" type="CenterContainer" parent="UI"]
custom_minimum_size = Vector2(270, 480)
layout_mode = 1
anchors_preset = 15
@ -31,18 +31,18 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="SubViewportContainer" type="SubViewportContainer" parent="UI/CenterContainer"]
[node name="GameViewport" type="SubViewportContainer" parent="UI/GameWorld"]
layout_mode = 2
[node name="SubViewport" type="SubViewport" parent="UI/CenterContainer/SubViewportContainer"]
[node name="Viewport" type="SubViewport" parent="UI/GameWorld/GameViewport"]
disable_3d = true
handle_input_locally = false
size = Vector2i(270, 480)
render_target_update_mode = 4
[node name="Game" parent="UI/CenterContainer/SubViewportContainer/SubViewport" instance=ExtResource("2_32lou")]
[node name="Game" parent="UI/GameWorld/GameViewport/Viewport" instance=ExtResource("2_32lou")]
[node name="Camera2D" type="Camera2D" parent="UI/CenterContainer/SubViewportContainer/SubViewport"]
[node name="Camera" type="Camera2D" parent="UI/GameWorld/GameViewport/Viewport"]
anchor_mode = 0
[node name="GameUI" parent="UI" instance=ExtResource("4_siim3")]
@ -53,9 +53,10 @@ process_mode = 3
visible = false
layout_mode = 1
[connection signal="score_changed" from="UI/GameWorld/GameViewport/Viewport/Game" to="UI/GameUI" method="_on_game_score_changed"]
[connection signal="score_button_pressed" from="UI/GameUI" to="." method="_on_game_ui_score_button_pressed"]
[connection signal="shop_button_pressed" from="UI/GameUI" to="." method="_on_game_ui_shop_button_pressed"]
[connection signal="spawn_button_pressed" from="UI/GameUI" to="UI/CenterContainer/SubViewportContainer/SubViewport/Game" method="trigger_spawn"]
[connection signal="spawn_button_pressed" from="UI/GameUI" to="UI/GameWorld/GameViewport/Viewport/Game" method="trigger_spawn"]
[connection signal="back_button_pressed" from="UI/ShopUI" to="." method="_on_shop_ui_back_button_pressed"]
[connection signal="delete_button_pressed" from="UI/ShopUI" to="." method="_on_shop_ui_delete_button_pressed"]
[connection signal="purchase_begin" from="UI/ShopUI" to="." method="_on_shop_ui_purchase_begin"]

View file

@ -4,36 +4,27 @@ class_name Evaluator
## The current amount of value evaluated.
var total_value: int = 0
## The types of [Collectible]s to value.
##
## The strings will match only if exactly the same.
#@export var collecting_types: Array[StringName]
## The collision mask to check colliding body against.
@export_flags_2d_physics var collecting_collision_mask: int
var total: int = 0
## The evaluator has added the value of an object to the total.
signal added(what: PhysicsBody2D, total_value: int)
signal added(what: Valuable, total: int)
## The evaluator has removed the value of an object to the total.
signal removed(what: PhysicsBody2D)
signal removed(what: Valuable, total: int)
signal score_changed(total_value: int)
## The total value of the evaluated items has changed.
signal changed(total: int)
func _on_body_entered(body):
if body is PhysicsBody2D:
if body.collision_layer & collecting_collision_mask:
var evaluable: Valuable = body.get_node("Valuable")
total_value += evaluable.value
evaluable.evaluate()
score_changed.emit(total_value)
func _on_body_entered(body: PhysicsBody2D):
var valuable: Valuable = body.get_node("Valuable")
total += valuable.value
added.emit(valuable, total)
changed.emit(total)
func _on_body_exited(body):
if body is PhysicsBody2D:
if body.collision_layer & collecting_collision_mask:
var evaluable: Valuable = body.get_node("Valuable")
total_value -= evaluable.value
evaluable.evaluate()
score_changed.emit(total_value)
func _on_body_exited(body: PhysicsBody2D):
var valuable: Valuable = body.get_node("Valuable")
total -= valuable.value
removed.emit(valuable, total)
changed.emit(total)

View file

@ -2,12 +2,3 @@ extends Node
class_name Valuable
@export var value: int
## Emitted when this entity has been counted.
signal evaluated
## Mark this entity as evaluated.
##
func evaluate():
emit_signal("evaluated")