Add costs to body building

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

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"]

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 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:
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(BodyPartLoader.bodyparts[params].instance())
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()

View File

@ -9,6 +9,8 @@ onready var physics_shape = get_node("PartCollider")
var setup_done = false
export(float) var cost
# Called when the node enters the scene tree for the first time.
func _ready() -> void:

View File

@ -13,13 +13,14 @@ radius = 0.125064
[node name="HumanArm" instance=ExtResource( 1 )]
transform = Transform( -4.37114e-08, 1, 4.37114e-08, 0, -4.37114e-08, 1, 1, 4.37114e-08, 1.91069e-15, 0, 0, 0 )
script = ExtResource( 2 )
cost = 10.0
[node name="PartCollider" parent="." index="0"]
transform = Transform( 0.796097, 0, -0.605169, 0, 1, -3.55271e-15, 0.605169, 8.35188e-23, 0.796097, -0.894889, 1.42109e-14, -2.6182 )
shape = SubResource( 1 )
[node name="TouchArea" parent="." index="1"]
transform = Transform( -0.114995, 2.15415, 2.55188, -3.31495, -0.382831, 0.173782, 0.404395, -2.52562, 2.15021, -0.0333271, -0.131349, -3.878 )
transform = Transform( -0.118289, 2.18551, 2.52493, -3.31556, -0.378316, 0.172131, 0.398447, -2.49922, 2.18193, -0.0255739, -0.127111, -3.79535 )
[node name="CollisionShape" type="CollisionShape" parent="TouchArea" index="0"]
shape = SubResource( 2 )
@ -27,8 +28,11 @@ shape = SubResource( 2 )
[node name="Mesh" parent="." index="2" instance=ExtResource( 4 )]
transform = Transform( 2, 0, 0, 0, 2, 0, 0, 0, 2, -0.357728, -8.51476, 0 )
[node name="Skeleton" parent="Mesh/Armature" index="0"]
bones/7/bound_children = [ NodePath("BoneAttachment") ]
[node name="BoneAttachment" type="BoneAttachment" parent="Mesh/Armature/Skeleton" index="1"]
transform = Transform( 0.0638506, -0.727912, -0.682691, -0.242273, 0.652315, -0.718184, 0.968104, 0.211254, -0.134703, 0.0541456, 1.16231, 0.134369 )
transform = Transform( 0.0646207, -0.736312, -0.673549, -0.240426, 0.64359, -0.726627, 0.968514, 0.208894, -0.135439, 0.054756, 1.13784, 0.129916 )
bone_name = "bone_6"
[node name="RemoteTransform" type="RemoteTransform" parent="Mesh/Armature/Skeleton/BoneAttachment" index="0"]

View File

@ -17,13 +17,14 @@ albedo_texture = ExtResource( 4 )
[node name="HumanLeg" instance=ExtResource( 1 )]
transform = Transform( 1, 8.74228e-08, -3.82137e-15, 0, -4.37114e-08, -1, -8.74228e-08, 1, -4.37114e-08, 0, 0, 0 )
script = ExtResource( 2 )
cost = 20.0
[node name="PartCollider" parent="." index="0"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -3.37252, -0.326758 )
shape = SubResource( 1 )
[node name="TouchArea" parent="." index="1"]
transform = Transform( 3.95755, 9.02389e-13, -4.54747e-13, -1.36424e-12, -0.554944, -3.91846, 1.57933e-13, 3.91846, -0.554943, -1.33582e-12, -5.30189, -1.33664 )
transform = Transform( 3.95756, 9.05942e-13, -4.54747e-13, -1.33582e-12, -0.554944, -3.91846, 1.57933e-13, 3.91846, -0.554943, -1.3074e-12, -5.3019, -1.33665 )
[node name="CollisionShape" type="CollisionShape" parent="TouchArea" index="0"]
shape = SubResource( 2 )