Created Thrust Element and some Player GUI

pull/1/head
DAMO238 2020-04-02 19:24:42 +01:00
parent 052353b8ac
commit 8e4a264711
6 changed files with 269 additions and 2 deletions

View File

@ -12,3 +12,224 @@ script = ExtResource( 1 )
[node name="MeshInstance" type="MeshInstance" parent="."]
mesh = SubResource( 1 )
material/0 = null
[node name="MainPanel" type="Panel" parent="."]
anchor_left = 0.5
anchor_right = 0.5
margin_left = -390.0
margin_top = 15.0
margin_right = 390.0
margin_bottom = 50.0
grow_horizontal = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TimeBar" type="HSlider" parent="MainPanel"]
anchor_top = 0.5
anchor_right = 0.6
anchor_bottom = 0.5
margin_left = 10.0
grow_vertical = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="AddButton" type="Button" parent="MainPanel"]
anchor_left = 0.6
anchor_top = 0.5
anchor_right = 0.7
anchor_bottom = 0.5
margin_left = 6.0
margin_right = -1.0
grow_vertical = 2
text = "Add"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="RemoveButton" type="Button" parent="MainPanel"]
anchor_left = 0.7
anchor_top = 0.5
anchor_right = 0.8
anchor_bottom = 0.5
margin_left = 5.0
margin_right = -3.0
grow_vertical = 2
text = "Remove"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ClearButton" type="Button" parent="MainPanel"]
anchor_left = 0.8
anchor_top = 0.5
anchor_right = 0.9
anchor_bottom = 0.5
margin_left = 3.0
margin_right = -5.0
grow_vertical = 2
text = "Clear"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="EndTurnButton" type="Button" parent="MainPanel"]
anchor_left = 0.9
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
margin_left = 1.0
margin_right = -6.0
grow_vertical = 2
text = "End Turn"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ThrustPanel" type="Panel" parent="."]
anchor_left = 1.0
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = -300.0
margin_top = -175.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="XLin" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.4
anchor_top = 0.05
anchor_right = 0.4
anchor_bottom = 0.45
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
[node name="XRot" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.4
anchor_top = 0.55
anchor_right = 0.4
anchor_bottom = 0.95
margin_left = -8.0
margin_right = 8.0
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
[node name="YLin" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.6
anchor_top = 0.05
anchor_right = 0.6
anchor_bottom = 0.45
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
[node name="YRot" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.6
anchor_top = 0.55
anchor_right = 0.6
anchor_bottom = 0.95
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
[node name="ZLin" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.8
anchor_top = 0.05
anchor_right = 0.8
anchor_bottom = 0.45
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
[node name="ZRot" type="VSlider" parent="ThrustPanel"]
anchor_left = 0.8
anchor_top = 0.55
anchor_right = 0.8
anchor_bottom = 0.95
margin_top = -0.263489
margin_bottom = -0.263489
grow_horizontal = 2
min_value = -1.0
max_value = 1.0
step = 0.001
[node name="LabelHolder" type="Control" parent="ThrustPanel"]
anchor_right = 1.0
anchor_bottom = 1.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="ThrustPanel/LabelHolder"]
anchor_left = 0.2
anchor_top = 0.25
anchor_right = 0.2
anchor_bottom = 0.25
margin_left = -44.0
margin_top = -7.0
margin_right = 39.0
margin_bottom = 7.0
grow_horizontal = 2
grow_vertical = 2
text = "Linear Thrust"
[node name="Label3" type="Label" parent="ThrustPanel/LabelHolder"]
anchor_left = 0.4
anchor_top = 0.5
anchor_right = 0.4
anchor_bottom = 0.5
margin_left = -4.0
margin_top = -7.0
margin_right = 4.0
margin_bottom = 7.0
grow_horizontal = 2
grow_vertical = 2
text = "X"
[node name="Label4" type="Label" parent="ThrustPanel/LabelHolder"]
anchor_left = 0.8
anchor_top = 0.5
anchor_right = 0.8
anchor_bottom = 0.5
margin_left = -4.0
margin_top = -7.0
margin_right = 4.0
margin_bottom = 7.0
grow_horizontal = 2
grow_vertical = 2
text = "Z"
[node name="Label5" type="Label" parent="ThrustPanel/LabelHolder"]
anchor_left = 0.6
anchor_top = 0.5
anchor_right = 0.6
anchor_bottom = 0.5
margin_left = -3.5
margin_top = -7.0
margin_right = 3.5
margin_bottom = 7.0
grow_horizontal = 2
grow_vertical = 2
text = "Y"
[node name="Label2" type="Label" parent="ThrustPanel/LabelHolder"]
anchor_left = 0.2
anchor_top = 0.75
anchor_right = 0.2
anchor_bottom = 0.75
margin_left = -47.5
margin_top = -7.0
margin_right = 42.5
margin_bottom = 7.0
grow_horizontal = 2
grow_vertical = 2
text = "Vernier Thrust"

View File

@ -5,12 +5,32 @@ const TURN_TIME : float = 5.0
var elements = [] # All elements of the plan thus far
var current_elements = [] # All elements of the next 5 seconds
func add_element(element : PlanElement) -> bool:
var total_time : float = 0.0
for current_element in current_elements:
var _element : PlanElement = (current_element as PlanElement)
total_time += _element.time
if total_time + element.time > TURN_TIME:
return false
current_elements.append(element)
return true
func remove_last_element() -> void:
current_elements.pop_back()
func remove_all_elements() -> void:
current_elements.clear()
func new_turn() -> void:
for current_element in current_elements:
elements.push_back(current_elements.pop_back())
func sanity_check() -> bool:
# Returns true if sane and false if insane
var total_time : float = 0.0
for current_element in current_elements:
var element : PlanElement = (current_element as PlanElement)
total_time += elemet.time
total_time += element.time
if !element.sanity_check():
return false
if total_time > TURN_TIME:

View File

@ -1,3 +1,6 @@
class_name PlanElement
var time = 0.0
func sanity_check() -> bool:
return true # Needs to overridden in child classes

View File

@ -1,4 +1,5 @@
extends Spatial
var plan : Plan = Plan.new()

16
Scripts/ThrustElement.gd Normal file
View File

@ -0,0 +1,16 @@
extends "res://Scripts/PlanElement.gd"
class_name ThrustElement
const MAX_LINEAR_THRUST : int = 1
const MAX_ROTATIONAL_THRUST : int = 1
var linear_thrust : Vector3 = Vector3(0, 0, 0)
var rotational_thrust : Vector3 = Vector3(0, 0, 0)
func sanity_check() -> bool:
if linear_thrust.length() > MAX_LINEAR_THRUST:
return false
if rotational_thrust.length() > MAX_ROTATIONAL_THRUST:
return false
return true

View File

@ -18,10 +18,16 @@ _global_script_classes=[ {
"class": "PlanElement",
"language": "GDScript",
"path": "res://Scripts/PlanElement.gd"
}, {
"base": "Reference",
"class": "ThrustElement",
"language": "GDScript",
"path": "res://Scripts/ThrustElement.gd"
} ]
_global_script_class_icons={
"Plan": "",
"PlanElement": ""
"PlanElement": "",
"ThrustElement": ""
}
[application]