Add costs to body building

This commit is contained in:
karl committed 2020-02-02 11:34:16 +01:00
1 parent 28f004b382
commit 493b171b0f
5 files changed
+52 -13

No files matched your search

+21 -4
View File
@@ -11,6 +11,7 @@ cameraPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport/Camera")
rayCastPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport/MouseLook")
viewPortPath = NodePath("GUI/HBoxC/ViewportContainer/Viewport")
playerNumPath = NodePath("PlayerCountLabel")
costProgressPath = NodePath("GUI/HBoxC/VBoxC/HBoxContainer/ProgressBar")
[node name="GUI" type="MarginContainer" parent="."]
anchor_right = 1.0
@@ -33,15 +34,31 @@ margin_bottom = 600.0
rect_min_size = Vector2( 300, 500 )
script = ExtResource( 3 )
[node name="Start" type="Button" parent="GUI/HBoxC/VBoxC"]
[node name="HBoxContainer" type="HBoxContainer" parent="GUI/HBoxC/VBoxC"]
margin_right = 300.0
margin_bottom = 20.0
margin_bottom = 14.0
[node name="Label" type="Label" parent="GUI/HBoxC/VBoxC/HBoxContainer"]
margin_right = 36.0
margin_bottom = 14.0
text = "Cost: "
[node name="ProgressBar" type="ProgressBar" parent="GUI/HBoxC/VBoxC/HBoxContainer"]
margin_left = 40.0
margin_right = 240.0
margin_bottom = 14.0
rect_min_size = Vector2( 200, 0 )
[node name="Start" type="Button" parent="GUI/HBoxC/VBoxC"]
margin_top = 18.0
margin_right = 300.0
margin_bottom = 38.0
text = "Start Game"
[node name="Delete" type="Button" parent="GUI/HBoxC/VBoxC"]
margin_top = 24.0
margin_top = 42.0
margin_right = 300.0
margin_bottom = 44.0
margin_bottom = 62.0
text = "Delete"
[node name="ViewportContainer" type="ViewportContainer" parent="GUI/HBoxC"]
+21 -6
View File
@@ -5,6 +5,7 @@ export(NodePath) var cameraPath
export(NodePath) var rayCastPath
export(NodePath) var viewPortPath
export(NodePath) var playerNumPath
export(NodePath) var costProgressPath
const ROT_MOD = 500
const ROT_DECLINE = 0.1
@@ -16,6 +17,7 @@ var _rayCast : RayCast
var _torso : RigidBody
var _viewport : Viewport
var _playerNum : Label
var _costProgress : ProgressBar
var _velx = 0
var _vely = 0
@@ -33,6 +35,7 @@ func _ready():
_rayCast = get_node(rayCastPath) as RayCast
_viewport = get_node(viewPortPath) as Viewport
_playerNum = get_node(playerNumPath) as Label
_costProgress = get_node(costProgressPath) as ProgressBar
# Keybinds of first player
_torso.get_node("DownFrontLeft").key = KEY_D
@@ -134,15 +137,26 @@ func body_part_chosen(params):
#no _attachment_point
if _attachment_point != null:
var limb = _attachment_point.get_node("Limb")
var new_part = BodyPartLoader.bodyparts[params].instance()
#adding only possible if no first child
#if limb.get_child(0) == null:
# limb.add_child(BodyPartLoader.bodyparts[params].instance())
# Check if we have enough cost points left
var current_cost = 0
#if spot already taken, DELETE
# If we already have something in that slot, we can place
# the new one if the total cost WITHOUT that existing part
# is low enough
if limb.get_child(0) != null:
delete_body_part()
limb.add_child(BodyPartLoader.bodyparts[params].instance())
current_cost += limb.get_child(0).cost
if _costProgress.value + new_part.cost - current_cost <= _costProgress.max_value:
#if spot already taken, DELETE
if limb.get_child(0) != null:
delete_body_part()
limb.add_child(new_part)
# Add the cost of that part
_costProgress.value += new_part.cost
func make_it_shine(highlight : bool):
@@ -154,6 +168,7 @@ func delete_body_part():
if _attachment_point != null:
var body_part = _attachment_point.get_node("Limb").get_child(0)
if body_part != null:
_costProgress.value -= body_part.cost
body_part.queue_free()