[Medium] Implement phases

This commit is contained in:
Alan Alexander Cerna 2021-11-11 20:34:53 +02:00
parent a3b67d7203
commit 589392a1b8
3 changed files with 39 additions and 9 deletions

View File

@ -146,15 +146,15 @@ func process_rotation():
func _process(delta: float) -> void: func _process(delta: float) -> void:
user_input = UIN_preset_pre_processor_instance.update()
enter_phase_limits()
if get_tree().is_network_server(): if get_tree().is_network_server():
Global.phase_update_global() Global.phase_update_global()
clientPhase = Global.get_current_phase() clientPhase = Global.get_current_phase()
print("MASTER:",clientPhase)
else: else:
if puppet_phase != null: if puppet_phase != null:
clientPhase = puppet_phase clientPhase = puppet_phase
Global.set_current_phase(clientPhase) Global.set_current_phase(clientPhase)
print("SLAVE:",clientPhase)
$"weaponHolder/Player-character-theme-gun".play(theme) $"weaponHolder/Player-character-theme-gun".play(theme)
particleImage.load("res://source/assets/sprites/character/player/theme/" + theme + "/na/Player-character-theme-particle-"+theme+".png") particleImage.load("res://source/assets/sprites/character/player/theme/" + theme + "/na/Player-character-theme-particle-"+theme+".png")
particleTexture.create_from_image(particleImage) particleTexture.create_from_image(particleImage)
@ -167,7 +167,6 @@ func _process(delta: float) -> void:
elif $Particles2D.position.x < 0 and direction != "right": elif $Particles2D.position.x < 0 and direction != "right":
$Particles2D.position = Vector2(-$Particles2D.position.x,$Particles2D.position.y) $Particles2D.position = Vector2(-$Particles2D.position.x,$Particles2D.position.y)
$Particles2D.scale = -$Particles2D.scale $Particles2D.scale = -$Particles2D.scale
user_input = UIN_preset_pre_processor_instance.update()
user_state = get_user_state() user_state = get_user_state()
dimensions = get_dimensions() dimensions = get_dimensions()
VDIR = VDIR_preset_pre_processor_instance.update(user_state, dimensions) VDIR = VDIR_preset_pre_processor_instance.update(user_state, dimensions)
@ -261,7 +260,7 @@ func _physics_process(delta) -> void:
rotate_weapon() rotate_weapon()
choose_trajectory() choose_trajectory()
enable_trajectory_line(trajectory_line) enable_trajectory_line(trajectory_line)
if Input.is_action_just_released("input_shoot") and can_shoot and not is_reloading: if user_input["shoot"] and can_shoot and not is_reloading:
rpc("shoot", trajectory, get_tree().get_network_unique_id()) rpc("shoot", trajectory, get_tree().get_network_unique_id())
is_reloading = true is_reloading = true
reload_timer.start() reload_timer.start()
@ -480,5 +479,30 @@ func rotate_weapon():
$"weaponHolder/Player-character-theme-gun".rotation_degrees = weaponAngle $"weaponHolder/Player-character-theme-gun".rotation_degrees = weaponAngle
pass pass
func enter_phase_limits():
if clientPhase != null and clientPhase["active"] != null:
if clientPhase["active"]["phase_id"] == 0:
user_input["r_inc"] = false
user_input["r_dec"] = false
user_input["shoot"] = false
elif clientPhase["active"]["phase_id"] == 1:
user_input["left"] = false
user_input["right"] = false
user_input["up"] = false
user_input["down"] = false
user_input["shoot"] = false
elif clientPhase["active"]["phase_id"] == 2:
user_input["left"] = false
user_input["right"] = false
user_input["up"] = false
user_input["down"] = false
user_input["r_inc"] = false
user_input["r_dec"] = false
else:
user_input["left"] = false
user_input["right"] = false
user_input["up"] = false
user_input["down"] = false
user_input["r_inc"] = false
user_input["r_dec"] = false
user_input["shoot"] = false

View File

@ -11,7 +11,8 @@ func _init() -> void:
"debug": false, "debug": false,
"enter": false, "enter": false,
"r_inc": false, "r_inc": false,
"r_dec": false "r_dec": false,
"shoot": false
} }
pass pass
@ -25,6 +26,7 @@ func update():
"boost": Input.is_action_pressed("input_shift"), "boost": Input.is_action_pressed("input_shift"),
"enter": Input.is_action_pressed("input_enter"), "enter": Input.is_action_pressed("input_enter"),
"r_inc": Input.is_action_pressed("rotation_increase"), "r_inc": Input.is_action_pressed("rotation_increase"),
"r_dec": Input.is_action_pressed("rotation_decrease") "r_dec": Input.is_action_pressed("rotation_decrease"),
"shoot": Input.is_action_pressed("input_shoot")
} }
return inputState return inputState

View File

@ -6,21 +6,25 @@ var alive_players = []
var clientPhase = { var clientPhase = {
"0": { "0": {
"phase_id": 0,
"phase_name": "Movement phase", "phase_name": "Movement phase",
"length": 2, "length": 2,
"start_time": null "start_time": null
}, },
"1": { "1": {
"phase_id": 1,
"phase_name": "Weapon adjustment phase", "phase_name": "Weapon adjustment phase",
"length": 2, "length": 2,
"start_time": null "start_time": null
}, },
"2": { "2": {
"phase_id": 2,
"phase_name": "Bullet simulation phase", "phase_name": "Bullet simulation phase",
"length": 2, "length": 2,
"start_time": null "start_time": null
}, },
"3": { "3": {
"phase_id": 3,
"phase_name": "Idle phase", "phase_name": "Idle phase",
"length": 2, "length": 2,
"start_time": null "start_time": null
@ -37,7 +41,7 @@ func phase_update_global():
if activePhaseTracker != null: if activePhaseTracker != null:
if clientPhase[str(activePhaseTracker)]["start_time"] != null: if clientPhase[str(activePhaseTracker)]["start_time"] != null:
if currentTime["second"] + currentTime["minute"] * 60 - clientPhase[str(activePhaseTracker)]["start_time"]["second"] - clientPhase[str(activePhaseTracker)]["start_time"]["minute"] * 60 > clientPhase[str(activePhaseTracker)]["length"]: if currentTime["second"] + currentTime["minute"] * 60 - clientPhase[str(activePhaseTracker)]["start_time"]["second"] - clientPhase[str(activePhaseTracker)]["start_time"]["minute"] * 60 > clientPhase[str(activePhaseTracker)]["length"]:
if activePhaseTracker == clientPhase.size - 1: if activePhaseTracker == clientPhase.size() - 2:
clientPhase[str(activePhaseTracker)]["start_time"] = null clientPhase[str(activePhaseTracker)]["start_time"] = null
activePhaseTracker = 0 activePhaseTracker = 0
else: else: