From 11826ef9d5deea113508533b662961b654599d3e Mon Sep 17 00:00:00 2001 From: akshay Date: Sun, 14 Aug 2022 19:45:00 -0400 Subject: [PATCH] Updated power station to not use coin_machine and cleaned up some of my mess --- scenes/dev-akshay.tscn | 24 ++++++++++++++++-------- scenes/power_station.tscn | 13 ++++++------- scripts/crafting_machine.gd | 12 ++++++++---- scripts/power_station.gd | 12 +++++++----- 4 files changed, 37 insertions(+), 24 deletions(-) diff --git a/scenes/dev-akshay.tscn b/scenes/dev-akshay.tscn index 8535530..0ca6c87 100644 --- a/scenes/dev-akshay.tscn +++ b/scenes/dev-akshay.tscn @@ -1,32 +1,40 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=10 format=2] [ext_resource path="res://scenes/player.tscn" type="PackedScene" id=1] -[ext_resource path="res://scenes/moon.tscn" type="PackedScene" id=2] +[ext_resource path="res://assets/moonbase_whitebox/Moonbase_Whitebox.tscn" type="PackedScene" id=2] [ext_resource path="res://scenes/power_station.tscn" type="PackedScene" id=3] [ext_resource path="res://scenes/crafting_machine.tscn" type="PackedScene" id=4] [ext_resource path="res://scenes/item_holder.tscn" type="PackedScene" id=5] [ext_resource path="res://item_types/ore.tres" type="Resource" id=6] [ext_resource path="res://recipes/all_recipes.tres" type="Resource" id=7] [ext_resource path="res://item_types/raw_yam.tres" type="Resource" id=8] +[ext_resource path="res://scripts/main_camera.gd" type="Script" id=9] [node name="dev_akshay" type="Spatial"] -[node name="moon" parent="." instance=ExtResource( 2 )] +[node name="Moonbase_Whitebox" parent="." instance=ExtResource( 2 )] -[node name="power_station" parent="." instance=ExtResource( 3 )] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -10.645 ) -time_to_generate = 5.0 +[node name="main_camera" type="Camera" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 12.6083, 0 ) +current = true +script = ExtResource( 9 ) +target = NodePath("../Player") [node name="Player" parent="." instance=ExtResource( 1 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5.27448 ) + +[node name="power_station" parent="." instance=ExtResource( 3 )] +transform = Transform( 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 1, 0 ) +time_to_generate = 5.0 [node name="crafting_machine" parent="." instance=ExtResource( 4 )] transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.974658, 0.0662553, -4.70336 ) recipes = ExtResource( 7 ) [node name="item_holder" parent="." instance=ExtResource( 5 )] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.334, 0, 1 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.01389, 0, -8.61939 ) start_with_item = ExtResource( 6 ) [node name="item_holder2" parent="." instance=ExtResource( 5 )] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1.33, 0, 1 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -1.14543, 0, -8.61939 ) start_with_item = ExtResource( 8 ) diff --git a/scenes/power_station.tscn b/scenes/power_station.tscn index 588fa8a..3906023 100644 --- a/scenes/power_station.tscn +++ b/scenes/power_station.tscn @@ -1,20 +1,21 @@ [gd_scene load_steps=6 format=2] [ext_resource path="res://scripts/power_station.gd" type="Script" id=1] -[ext_resource path="res://scenes/coin_machine.tscn" type="PackedScene" id=2] [ext_resource path="res://assets/sound/forceField_004.ogg" type="AudioStream" id=3] [ext_resource path="res://assets/sound/error_008.ogg" type="AudioStream" id=4] +[sub_resource type="BoxShape" id=2] + [sub_resource type="CubeMesh" id=1] -[node name="power_station" type="Spatial"] +[node name="power_station" type="Area"] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 ) script = ExtResource( 1 ) time_to_generate = 1.0 -[node name="coin_machine" parent="." instance=ExtResource( 2 )] -transform = Transform( 1.4, 0, 0, 0, 1, 0, 0, 0, 1.4, 0, 0, 0 ) -coins_required = 0 +[node name="TriggerVolume" type="CollisionShape" parent="."] +transform = Transform( 1.2, 0, 0, 0, 1.2, 0, 0, 0, 1.2, 0, 0, 0 ) +shape = SubResource( 2 ) [node name="MeshInstance" type="MeshInstance" parent="."] mesh = SubResource( 1 ) @@ -30,5 +31,3 @@ stream = ExtResource( 3 ) [node name="error" type="AudioStreamPlayer" parent="sounds"] stream = ExtResource( 4 ) - -[connection signal="coin_requirement_met" from="coin_machine" to="." method="_on_coin_machine_coin_requirement_met"] diff --git a/scripts/crafting_machine.gd b/scripts/crafting_machine.gd index 7807723..239fcd7 100644 --- a/scripts/crafting_machine.gd +++ b/scripts/crafting_machine.gd @@ -5,6 +5,7 @@ export var recipes: Resource # Called when the node enters the scene tree for the first time. func _ready(): assert(recipes != null) + update_coin_machine_status() func get_craft_recipe_item(): var items_in_slots = [$slot_1.item_in_hold.item_type, $slot_2.item_in_hold.item_type] @@ -37,11 +38,14 @@ func should_enable_coin_machine(): return false return can_craft_recipe() +func update_coin_machine_status(): + $coin_machine.enabled = should_enable_coin_machine() + func _on_craft_item_holder_item_changed(item): - $coin_machine.enabled = should_enable_coin_machine() - + update_coin_machine_status() + func _on_slot_1_item_changed(item): - $coin_machine.enabled = should_enable_coin_machine() + update_coin_machine_status() func _on_slot_2_item_changed(item): - $coin_machine.enabled = should_enable_coin_machine() + update_coin_machine_status() diff --git a/scripts/power_station.gd b/scripts/power_station.gd index 13d1823..90ff450 100644 --- a/scripts/power_station.gd +++ b/scripts/power_station.gd @@ -30,11 +30,13 @@ func collect_charges_from_station(): self.current_holding = 0 return charges_to_return -func _on_coin_machine_coin_requirement_met(player): +func on_player_interact(player) -> bool: assert(player.has_method("modify_inventory")) var charges = collect_charges_from_station() - player.modify_inventory("coins", charges) - if charges > 0: - $sounds/charge_get.play() - else: + if charges <= 0: $sounds/error.play() + return false + + player.modify_inventory("coins", charges) + $sounds/charge_get.play() + return true