Added weapons systems

pull/1/head
DAMO238 2020-08-29 17:32:40 +01:00
parent 256be6d741
commit 8b05248180
5 changed files with 181 additions and 7 deletions

View File

@ -9,6 +9,7 @@ panorama = ExtResource( 1 )
background_mode = 2 background_mode = 2
background_sky = SubResource( 1 ) background_sky = SubResource( 1 )
ambient_light_color = Color( 0.117647, 0.117647, 0.117647, 1 ) ambient_light_color = Color( 0.117647, 0.117647, 0.117647, 1 )
ambient_light_energy = 10.16
fog_sun_amount = 0.1 fog_sun_amount = 0.1
ss_reflections_enabled = true ss_reflections_enabled = true
glow_enabled = true glow_enabled = true

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=14 format=2] [gd_scene load_steps=17 format=2]
[ext_resource path="res://Scripts/Player.gd" type="Script" id=1] [ext_resource path="res://Scripts/Player.gd" type="Script" id=1]
[ext_resource path="res://Models/Arrow.obj" type="ArrayMesh" id=2] [ext_resource path="res://Models/Arrow.obj" type="ArrayMesh" id=2]
@ -10,6 +10,9 @@
[ext_resource path="res://Images/TurnEndBanner.png" type="Texture" id=8] [ext_resource path="res://Images/TurnEndBanner.png" type="Texture" id=8]
[ext_resource path="res://Animations/TurnEndBanner.anim" type="Animation" id=9] [ext_resource path="res://Animations/TurnEndBanner.anim" type="Animation" id=9]
[ext_resource path="res://Models/spaceship-gun.tscn" type="PackedScene" id=10] [ext_resource path="res://Models/spaceship-gun.tscn" type="PackedScene" id=10]
[ext_resource path="res://Images/BatteryBolt.png" type="Texture" id=11]
[ext_resource path="res://Images/BatteryFilling.png" type="Texture" id=12]
[ext_resource path="res://Images/BatteryBackground.png" type="Texture" id=13]
[sub_resource type="CapsuleShape" id=1] [sub_resource type="CapsuleShape" id=1]
radius = 0.15 radius = 0.15
@ -438,6 +441,7 @@ anims/ShowEndTurnBanner = ExtResource( 9 )
[node name="GunContainer" type="Spatial" parent="."] [node name="GunContainer" type="Spatial" parent="."]
transform = Transform( -4.37114e-09, 4.37114e-09, 0.1, 0.1, -4.37114e-09, 4.37114e-09, 4.37114e-09, 0.1, -4.37114e-09, 0, -0.0222926, 0.382747 ) transform = Transform( -4.37114e-09, 4.37114e-09, 0.1, 0.1, -4.37114e-09, 4.37114e-09, 4.37114e-09, 0.1, -4.37114e-09, 0, -0.0222926, 0.382747 )
visible = false
[node name="spaceship-gun" parent="GunContainer" instance=ExtResource( 10 )] [node name="spaceship-gun" parent="GunContainer" instance=ExtResource( 10 )]
transform = Transform( 1, 0, 1.64203e-15, 0, 1, 0, 1.64203e-15, 0, 1, 4.47035e-08, 0.811224, -3.54597e-08 ) transform = Transform( 1, 0, 1.64203e-15, 0, 1, 0, 1.64203e-15, 0, 1, 4.47035e-08, 0.811224, -3.54597e-08 )
@ -445,14 +449,91 @@ transform = Transform( 1, 0, 1.64203e-15, 0, 1, 0, 1.64203e-15, 0, 1, 4.47035e-0
[node name="RayCast" type="RayCast" parent="GunContainer"] [node name="RayCast" type="RayCast" parent="GunContainer"]
transform = Transform( 1, 0, 1.64203e-15, 0, 1, 0, 1.64203e-15, 0, 1, 7.45058e-08, 1.76881, -7.73171e-08 ) transform = Transform( 1, 0, 1.64203e-15, 0, 1, 0, 1.64203e-15, 0, 1, 7.45058e-08, 1.76881, -7.73171e-08 )
enabled = true enabled = true
cast_to = Vector3( 0, 1, 0 ) cast_to = Vector3( 0, 500, 0 )
[node name="CSGCylinder" type="CSGCylinder" parent="GunContainer/RayCast"] [node name="CSGCylinder" type="CSGCylinder" parent="GunContainer/RayCast"]
transform = Transform( 1, 0, 1.64203e-15, 0, 1, 0, 1.64203e-15, 0, 1, 7.45058e-08, 1.445, -6.3163e-08 ) transform = Transform( 1, 0, 1.64203e-15, 0, 1, 0, 1.64203e-15, 0, 1, 0, 1, 0 )
visible = false
material_override = SubResource( 3 ) material_override = SubResource( 3 )
radius = 0.09 radius = 0.09
height = 2.0
sides = 32 sides = 32
[node name="WeaponsPanel" type="Panel" parent="."]
visible = false
anchor_top = 1.0
anchor_bottom = 1.0
margin_top = -300.0
margin_right = 300.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Background" type="TextureRect" parent="WeaponsPanel"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_top = -75.0
margin_right = 100.0
margin_bottom = 75.0
texture = ExtResource( 13 )
expand = true
[node name="Filling" type="TextureRect" parent="WeaponsPanel"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_top = -75.0
margin_right = 100.0
margin_bottom = 75.0
texture = ExtResource( 12 )
expand = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="FillingBlocker" type="ColorRect" parent="WeaponsPanel"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = 14.0
margin_top = -55.0
margin_right = 87.0
margin_bottom = -55.0
color = Color( 0, 0, 0, 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Bolt" type="TextureRect" parent="WeaponsPanel"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = 17.4106
margin_top = -59.1193
margin_right = 102.411
margin_bottom = 72.8807
texture = ExtResource( 11 )
expand = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="WeaponsSwitch" type="CheckButton" parent="WeaponsPanel"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -100.0
margin_top = -40.0
margin_right = -30.0
margin_bottom = 40.0
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="value_changed" from="MainPanel/TimeBar" to="." method="_on_TimeBar_value_changed"] [connection signal="value_changed" from="MainPanel/TimeBar" to="." method="_on_TimeBar_value_changed"]
[connection signal="pressed" from="MainPanel/AddButton" to="." method="_on_AddButton_pressed"] [connection signal="pressed" from="MainPanel/AddButton" to="." method="_on_AddButton_pressed"]
[connection signal="pressed" from="MainPanel/PlayButton" to="." method="_on_PlayButton_pressed"] [connection signal="pressed" from="MainPanel/PlayButton" to="." method="_on_PlayButton_pressed"]

View File

@ -1,6 +1,7 @@
extends RigidBody extends RigidBody
var thrust_plan : Plan = Plan.new() var thrust_plan : Plan = Plan.new()
var weapons_plan : Plan = Plan.new()
var is_local : bool = false var is_local : bool = false
var running_plan : bool = false var running_plan : bool = false
var plan_time : float = 0.0 var plan_time : float = 0.0
@ -16,6 +17,8 @@ var round_time : float = 0.0
var end_of_round_translation : Vector3 = get_translation() var end_of_round_translation : Vector3 = get_translation()
var end_of_round_rotation : Vector3 = get_rotation() var end_of_round_rotation : Vector3 = get_rotation()
var time_of_death : float = -1
onready var arrow_obj : Spatial = $ArrowContainer onready var arrow_obj : Spatial = $ArrowContainer
onready var arrow_scale_obj : Spatial = $ArrowContainer/ArrowScaleContainer onready var arrow_scale_obj : Spatial = $ArrowContainer/ArrowScaleContainer
onready var rotate_arrow_obj : Spatial = $RotateArrowContainer onready var rotate_arrow_obj : Spatial = $RotateArrowContainer
@ -37,12 +40,18 @@ func init() -> void:
if is_local: if is_local:
$MainPanel.visible = true $MainPanel.visible = true
$ThrustPanel.visible = true $ThrustPanel.visible = true
$WeaponsPanel.visible = true
func send_thrust_plan() -> void: func send_thrust_plan() -> void:
for element in thrust_plan.current_elements: for element in thrust_plan.current_elements:
get_parent().get_parent().console_print('Sending data = ' + String(element.time) + String(element.linear_thrust) + String(element.rotational_thrust)) get_parent().get_parent().console_print('Sending data = ' + String(element.time) + String(element.linear_thrust) + String(element.rotational_thrust))
rpc_id(1, "add_thrust_element", element.time, element.linear_thrust, element.rotational_thrust) rpc_id(1, "add_thrust_element", element.time, element.linear_thrust, element.rotational_thrust)
func send_weapons_plan() -> void:
for element in weapons_plan.current_elements:
get_parent().get_parent().console_print('Sending data = ' + String(element.time) + String(element.firing))
rpc_id(1, "add_weapons_element", element.time, element.firing)
remote func add_thrust_element(time: float, linear_thrust : Vector3, rotational_thrust : Vector3) -> void: remote func add_thrust_element(time: float, linear_thrust : Vector3, rotational_thrust : Vector3) -> void:
if is_local: if is_local:
return return
@ -53,8 +62,18 @@ remote func add_thrust_element(time: float, linear_thrust : Vector3, rotational_
get_parent().get_parent().console_print(String(is_local) + ": Adding thrust element with the following params: time = " + String(time) + ", lin = " + String(linear_thrust) + ", rot = " + String(rotational_thrust) + ".") get_parent().get_parent().console_print(String(is_local) + ": Adding thrust element with the following params: time = " + String(time) + ", lin = " + String(linear_thrust) + ", rot = " + String(rotational_thrust) + ".")
thrust_plan.add_element(element) thrust_plan.add_element(element)
remote func r_end_turn() -> void: remote func add_weapons_element(time : float, firing : bool) -> void:
if is_local:
return
var element : WeaponsElement = WeaponsElement.new()
element.time = time
element.firing = firing
get_parent().get_parent().console_print(String(is_local) + ": Adding weapons element with the following params: time = " + String(time) + ", firing = " + String(firing))
weapons_plan.add_element(element)
remote func r_end_turn(r_time_of_death : float) -> void:
self._on_PlayButton_pressed() self._on_PlayButton_pressed()
time_of_death = r_time_of_death
if is_local: if is_local:
$MainPanel/EndTurnButton.disabled = false $MainPanel/EndTurnButton.disabled = false
$MainPanel/TimeBar.value = 0 $MainPanel/TimeBar.value = 0
@ -62,10 +81,11 @@ remote func r_end_turn() -> void:
$TurnEndBanner/AnimationPlayer.play() $TurnEndBanner/AnimationPlayer.play()
return return
thrust_plan.new_turn() thrust_plan.new_turn()
weapons_plan.new_turn()
func _on_TimeBar_value_changed(value : float) -> void: func _on_TimeBar_value_changed(value : float) -> void:
var min_time : float = thrust_plan.current_time() var min_time : float = thrust_plan.current_time()
get_parent().get_parent().console_print(String(is_local) + ": Current plan time is " + String(min_time)) #get_parent().get_parent().console_print(String(is_local) + ": Current plan time is " + String(min_time))
if value <= min_time: if value <= min_time:
$MainPanel/TimeBar.value = min_time $MainPanel/TimeBar.value = min_time
@ -78,18 +98,29 @@ func _on_AddButton_pressed() -> void:
get_parent().get_parent().console_print(String(is_local) + ": Added thrust element with " + String(new_thrust_element.time) + String(new_thrust_element.rotational_thrust) + String(new_thrust_element.linear_thrust)) get_parent().get_parent().console_print(String(is_local) + ": Added thrust element with " + String(new_thrust_element.time) + String(new_thrust_element.rotational_thrust) + String(new_thrust_element.linear_thrust))
else: else:
get_parent().get_parent().console_print(String(is_local) + ": Failed to add thrust element") get_parent().get_parent().console_print(String(is_local) + ": Failed to add thrust element")
var new_weapons_element : WeaponsElement = WeaponsElement.new()
new_weapons_element.firing = $WeaponsPanel/WeaponsSwitch.pressed
new_weapons_element.time = $MainPanel/TimeBar.value - weapons_plan.current_time()
if (weapons_plan.add_element(new_weapons_element)):
get_parent().get_parent().console_print(String(is_local) + ": Added weapons element with " + String(new_weapons_element.firing))
else:
get_parent().get_parent().console_print(String(is_local) + ": Failed to add weapons element")
func _on_RemoveButton_pressed() -> void: func _on_RemoveButton_pressed() -> void:
thrust_plan.remove_last_element() thrust_plan.remove_last_element()
weapons_plan.remove_last_element()
func _on_ClearButton_pressed() -> void: func _on_ClearButton_pressed() -> void:
thrust_plan.remove_all_elements() thrust_plan.remove_all_elements()
weapons_plan.remove_all_elements()
func _on_EndTurnButton_pressed() -> void: func _on_EndTurnButton_pressed() -> void:
$MainPanel/EndTurnButton.disabled = true $MainPanel/EndTurnButton.disabled = true
send_thrust_plan() send_thrust_plan()
send_weapons_plan()
rpc_id(1, "end_turn") rpc_id(1, "end_turn")
thrust_plan.new_turn() thrust_plan.new_turn()
weapons_plan.new_turn()
round_time += 5 round_time += 5
# TODO: Add the rest functionality # TODO: Add the rest functionality
@ -193,16 +224,32 @@ func _get_all_thrust_elements():
all_elements.append(element) all_elements.append(element)
return all_elements return all_elements
func _get_all_weapons_elements():
var all_elements = []
for element in weapons_plan.elements:
all_elements.append(element)
for element in weapons_plan.current_elements:
all_elements.append(element)
return all_elements
func _physics_process(delta : float) -> void: func _physics_process(delta : float) -> void:
if !enable_physics: if !enable_physics:
return return
if !running_plan: if !running_plan:
$GunContainer.visible = false
arrow_obj.visible = true arrow_obj.visible = true
rotate_arrow_obj.visible = true rotate_arrow_obj.visible = true
disable_all_engine_particles() disable_all_engine_particles()
set_translation(last_translation) set_translation(last_translation)
set_rotation(last_rotation) set_rotation(last_rotation)
return return
if time_of_death > 0 and plan_time > time_of_death:
self.visible = false
$CollisionShape.disabled = true
else:
self.visible = true
$CollisionShape.disabled = false
var all_thrust_elements = _get_all_thrust_elements() var all_thrust_elements = _get_all_thrust_elements()
var current_thrust_element : ThrustElement = _get_current_plan_element(all_thrust_elements) var current_thrust_element : ThrustElement = _get_current_plan_element(all_thrust_elements)
if current_thrust_element == null: if current_thrust_element == null:
@ -215,6 +262,18 @@ func _physics_process(delta : float) -> void:
add_central_force(self.transform.basis.xform(current_thrust_element.linear_thrust)) add_central_force(self.transform.basis.xform(current_thrust_element.linear_thrust))
add_torque(self.transform.basis.xform(current_thrust_element.rotational_thrust)) add_torque(self.transform.basis.xform(current_thrust_element.rotational_thrust))
update_engine_particles(current_thrust_element.linear_thrust, current_thrust_element.rotational_thrust) update_engine_particles(current_thrust_element.linear_thrust, current_thrust_element.rotational_thrust)
var all_weapons_elements = _get_all_weapons_elements()
var current_weapons_element : WeaponsElement = _get_current_plan_element(all_weapons_elements)
if current_weapons_element == null:
$GunContainer.visible = false
running_plan = false
return
if current_weapons_element.firing:
_fire_gun()
else:
$GunContainer.visible = false
plan_time += delta plan_time += delta
func disable_all_engine_particles() -> void: func disable_all_engine_particles() -> void:
@ -352,3 +411,21 @@ func play_full_plan():
func _on_PlayButton_pressed(): func _on_PlayButton_pressed():
play_all_plans() play_all_plans()
func _update_battery_visuals(value : float):
# Assume value is between 0 and 100
$WeaponsPanel/FillingBlocker.margin_bottom = 65 - (value * 1.2)
func _update_laser(length : float):
$GunContainer/RayCast/CSGCylinder.height = length
$GunContainer/RayCast/CSGCylinder.translation = Vector3(0, length/2, 0)
func _fire_gun():
$GunContainer.visible = true
if $GunContainer/RayCast.is_colliding():
var raycast_pos : Vector3 = $GunContainer/RayCast.global_transform.origin
var target_pos : Vector3 = $GunContainer/RayCast.get_collision_point()
var diff : Vector3 = raycast_pos - target_pos
_update_laser(diff.length())
else:
_update_laser($GunContainer/RayCast.cast_to.y)

View File

@ -0,0 +1,9 @@
extends "res://Scripts/PlanElement.gd"
class_name WeaponsElement
var firing : bool = false
func sanity_check() -> bool:
return true

View File

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