Allow for taking damage from overcharging and running away
parent
40b23a78a0
commit
3bd16f4460
|
@ -3,17 +3,18 @@
|
|||
[ext_resource path="res://Scripts/Player.gd" type="Script" id=1]
|
||||
|
||||
[sub_resource type="CapsuleShape" id=1]
|
||||
radius = 0.1
|
||||
height = 0.5
|
||||
radius = 0.15
|
||||
height = 0.6
|
||||
|
||||
[node name="Player" type="RigidBody"]
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="CollisionShape" type="CollisionShape" parent="."]
|
||||
transform = Transform( 1, 0, 0, 0, 0.519, 0, 0, 0, 1, 0, 0, -0.034 )
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="GunContainer" type="Spatial" parent="."]
|
||||
transform = Transform( 2.65431e-15, 1.62921e-08, 0.1, 0.1, -1.62921e-08, 0, 1.62921e-08, 0.1, -1.62921e-08, 0, -0.22, 0.383 )
|
||||
transform = Transform( 2.65431e-15, 1.62921e-08, 0.1, 0.1, -1.62921e-08, 0, 1.62921e-08, 0.1, -1.62921e-08, 0, -0.022, 0.383 )
|
||||
|
||||
[node name="RayCast" type="RayCast" parent="GunContainer"]
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.769, 0 )
|
||||
|
|
|
@ -14,6 +14,8 @@ func init() -> void:
|
|||
add_child(players[player_id])
|
||||
players[player_id].set_translation(generate_translation())
|
||||
players[player_id].set_rotation(generate_rotation())
|
||||
players[player_id].set_linear_velocity(Vector3.ZERO)
|
||||
players[player_id].set_angular_velocity(Vector3.ZERO)
|
||||
get_parent().console_print('Player Coords: ' + String(players[player_id].get_translation()) + String(players[player_id].get_rotation()) )
|
||||
rpc('place_player', player_id, players[player_id].get_translation(), players[player_id].get_rotation())
|
||||
players[player_id].init()
|
||||
|
@ -21,12 +23,13 @@ func init() -> void:
|
|||
func _process(delta : float) -> void:
|
||||
var all_ready = true
|
||||
for player in players.values():
|
||||
if !player.is_ready and player.is_alive:
|
||||
if !player.is_ready and !player.has_died:
|
||||
all_ready = false
|
||||
if all_ready:
|
||||
for player in players.values():
|
||||
player.is_ready = false
|
||||
player.calculate_plans()
|
||||
if player.is_alive:
|
||||
player.is_ready = false
|
||||
player.calculate_plans()
|
||||
|
||||
func generate_translation() -> Vector3:
|
||||
#return Vector3(rand_range(-10,10),rand_range(-10,10),rand_range(-10,10))
|
||||
|
|
|
@ -2,6 +2,10 @@ extends RigidBody
|
|||
|
||||
const TIME_STEP : float = 0.01
|
||||
const BASE_DPS : float = 300.0
|
||||
const BASE_ENERGY_USAGE : float = 75.0
|
||||
const BASE_ENERGY_REGEN : float = 150.0
|
||||
const BASE_OVERCHARGE_DAMAGE : float = 5.0
|
||||
const OOB_DAMAGE : float = 100.0
|
||||
|
||||
var thrust_plan : Plan = Plan.new()
|
||||
var weapons_plan : Plan = Plan.new()
|
||||
|
@ -13,6 +17,9 @@ var plan_time : float = 0.0
|
|||
var health : float = 100.0
|
||||
var is_alive : bool = true
|
||||
var time_of_death : float = -1
|
||||
var has_died : bool = false
|
||||
|
||||
var turn_number : int = 0
|
||||
|
||||
var initial_translation : Vector3 = get_translation()
|
||||
var initial_rotation : Vector3 = get_rotation()
|
||||
|
@ -23,6 +30,13 @@ var last_rotation : Vector3 = get_rotation()
|
|||
var enable_physics : bool = false
|
||||
var waiting_for_completion : bool = false
|
||||
|
||||
var end_translation : Vector3 = Vector3.ZERO
|
||||
var end_rotation : Vector3 = Vector3.ZERO
|
||||
var end_linear_velocity : Vector3 = Vector3.ZERO
|
||||
var end_rotational_velocity : Vector3 = Vector3.ZERO
|
||||
|
||||
var energy : float = 100.0
|
||||
|
||||
func init():
|
||||
last_rotation = get_rotation()
|
||||
last_translation = get_translation()
|
||||
|
@ -53,7 +67,13 @@ func send_all_plans() -> void:
|
|||
for element in weapons_plan.current_elements:
|
||||
rpc("add_weapons_element", element.time, element.firing)
|
||||
get_parent().get_parent().console_print("Time of death is " + String(time_of_death) + " with health " + String(health) + ".")
|
||||
rpc("r_end_turn", time_of_death)
|
||||
end_translation = self.translation
|
||||
end_rotation = self.rotation
|
||||
end_linear_velocity = self.linear_velocity
|
||||
end_rotational_velocity = self.angular_velocity
|
||||
get_parent().get_parent().console_print("Starting parameters are: linear velocity = " + String(end_linear_velocity) + ", rotational_velocity = " + String(end_rotational_velocity) + ", position = " + String(end_translation) + ", rotation = " + String(end_rotation))
|
||||
rpc("r_end_turn", time_of_death, end_translation, end_rotation, end_linear_velocity, end_rotational_velocity)
|
||||
turn_number += 1
|
||||
thrust_plan.new_turn()
|
||||
weapons_plan.new_turn()
|
||||
|
||||
|
@ -111,21 +131,26 @@ func _physics_process(delta : float) -> void:
|
|||
return
|
||||
if current_weapons_element.firing and is_alive:
|
||||
fire(delta, plan_time)
|
||||
elif energy < 100:
|
||||
energy += BASE_ENERGY_REGEN * delta
|
||||
|
||||
calculate_other_damage(delta, plan_time)
|
||||
|
||||
plan_time += delta
|
||||
|
||||
func fire(delta : float, time : float) -> void:
|
||||
energy -= delta * BASE_ENERGY_USAGE
|
||||
if $GunContainer/RayCast.is_colliding():
|
||||
var target : RigidBody = $GunContainer/RayCast.get_collider()
|
||||
target.take_damage(BASE_DPS * delta, time)
|
||||
|
||||
func take_damage(damage : float, time : float) -> void:
|
||||
get_parent().get_parent().console_print("tmp")
|
||||
health -= damage
|
||||
if health < 0:
|
||||
if health < 0 and is_alive:
|
||||
self.die(time)
|
||||
|
||||
func die(time : float) -> void:
|
||||
has_died = true
|
||||
is_alive = false
|
||||
$CollisionShape.disabled = true
|
||||
time_of_death = time
|
||||
|
@ -143,6 +168,26 @@ func play_full_plan():
|
|||
is_alive = true
|
||||
$CollisionShape.disabled = false
|
||||
|
||||
func play_last_plan():
|
||||
set_linear_velocity(end_linear_velocity)
|
||||
set_angular_velocity(end_rotational_velocity)
|
||||
set_translation(end_translation)
|
||||
set_rotation(end_rotation)
|
||||
running_plan = true
|
||||
plan_time = 5 * turn_number
|
||||
if !has_died:
|
||||
is_alive = true
|
||||
$CollisionShape.disabled = false
|
||||
|
||||
func calculate_plans():
|
||||
play_full_plan()
|
||||
if turn_number == 0:
|
||||
play_full_plan()
|
||||
else:
|
||||
play_last_plan()
|
||||
waiting_for_completion = true
|
||||
|
||||
func calculate_other_damage(delta : float, time : float):
|
||||
if (translation.length_squared() > 100):
|
||||
take_damage(OOB_DAMAGE * delta, time)
|
||||
if energy < 0:
|
||||
take_damage(-energy * BASE_OVERCHARGE_DAMAGE * delta, time)
|
||||
|
|
|
@ -10,6 +10,8 @@ var peer : NetworkedMultiplayerENet = null
|
|||
var ids = []
|
||||
var console_output : TextEdit = null
|
||||
var ready_ids = []
|
||||
var name_dict = {}
|
||||
var color_dict = {}
|
||||
|
||||
func _ready() -> void:
|
||||
peer = NetworkedMultiplayerENet.new()
|
||||
|
@ -53,6 +55,20 @@ func start_game() -> void:
|
|||
add_child(arena)
|
||||
arena.init()
|
||||
console_print('Starting Game...')
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
send_name_dict()
|
||||
send_color_dict()
|
||||
|
||||
func send_name_dict() -> void:
|
||||
for element in name_dict.keys():
|
||||
rpc("add_name_to_dict", element, name_dict[element])
|
||||
|
||||
remote func set_display_name(id : int, display_name : String) -> void:
|
||||
name_dict[id] = display_name
|
||||
|
||||
func send_color_dict() -> void:
|
||||
for element in color_dict.keys():
|
||||
rpc("add_color_to_dict", element, color_dict[element])
|
||||
|
||||
remote func set_player_color(id : int, color : Color) -> void:
|
||||
console_print("Setting color of " + String(id) + " to " + String(color))
|
||||
color_dict[id] = color
|
||||
|
|
|
@ -42,6 +42,10 @@ config/name="Server"
|
|||
run/main_scene="res://Scenes/RootNode.tscn"
|
||||
config/icon="res://icon.png"
|
||||
|
||||
[physics]
|
||||
|
||||
3d/default_gravity=0.0
|
||||
|
||||
[rendering]
|
||||
|
||||
environment/default_environment="res://default_env.tres"
|
||||
|
|
Loading…
Reference in New Issue