From f9172b20cc1f253720c6b06b88e95d0a6675fa3b Mon Sep 17 00:00:00 2001 From: Frederic Aust <frederic.aust@hs-bochum.de> Date: Wed, 3 Feb 2021 10:57:40 +0100 Subject: [PATCH] TrainingsMode Grundlage Mensch vs Agent GameSettings: * Neuer Parameter fuer den Trainingsmodus hinzu gefuegt MainMenu: * Buttons fuer den Trainingsmodus mit Leben gefuellt Main: * Bei aktivierten Trainingsmodus wird nur auf die Stepeingabe von einem Agenten gewartet, je nachdem an welcher Position der Trainer sitzt * Mensch vs Agent ist nun moeglich aber die Aufzeichnung des menschlichen Spielers fehlt noch --- Battle Pong/GameSettings.gd | 1 + Battle Pong/Main.gd | 15 ++++++++++++++- Battle Pong/Main.tscn | 4 ++++ Battle Pong/MainMenu.gd | 21 ++++++++++++++------- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/Battle Pong/GameSettings.gd b/Battle Pong/GameSettings.gd index d147583..68109b6 100644 --- a/Battle Pong/GameSettings.gd +++ b/Battle Pong/GameSettings.gd @@ -2,6 +2,7 @@ extends Node export var rendering_enabled = false export var learn_with_images = true +export var trainings_mode_enabled = false var game_playtime_per_step diff --git a/Battle Pong/Main.gd b/Battle Pong/Main.gd index e633194..293e743 100644 --- a/Battle Pong/Main.gd +++ b/Battle Pong/Main.gd @@ -254,12 +254,20 @@ func _on_data(id): return_value = get_return_value_as_utf8_JSON() _server.get_peer(id).put_packet(return_value) pass - if(next_step_player_one and next_step_player_two): + if($"/root/GameSettings".trainings_mode_enabled): + if(($"/root/GameSettings".trainer_position == "Left" and next_step_player_two) or ($"/root/GameSettings".trainer_position == "Right" and next_step_player_one)): + unpause() + $PlayerOne.run(game_playtime_per_step) + $PlayerTwo.run(game_playtime_per_step) + ball.run(game_playtime_per_step) + timeout() + elif(next_step_player_one and next_step_player_two): unpause() $PlayerOne.run(game_playtime_per_step) $PlayerTwo.run(game_playtime_per_step) ball.run(game_playtime_per_step) timeout() + func get_observarion(): return {"PlayerOne":{"X":$PlayerOne.position.x,"Y":$PlayerOne.position.y}, "PlayerTwo":{"X":$PlayerTwo.position.x,"Y":$PlayerTwo.position.y}, "ball":ball.get_observation()} @@ -334,3 +342,8 @@ func unpause(): $PlayerOne.set_pause(false) $PlayerTwo.set_pause(false) + +# Wenn Trainerfunktion aktiv ist wird für einen menschlichen Spieler der Playtimer gestartet und die Eingabe +func _on_Playtimer_timeout(): + + pass # Replace with function body. diff --git a/Battle Pong/Main.tscn b/Battle Pong/Main.tscn index 804fb3c..9231412 100644 --- a/Battle Pong/Main.tscn +++ b/Battle Pong/Main.tscn @@ -79,5 +79,9 @@ __meta__ = { [node name="WallBottom" parent="." instance=ExtResource( 3 )] position = Vector2( 0, 600 ) + +[node name="Playtimer" type="Timer" parent="."] +one_shot = true [connection signal="hit" from="PlayerTwo" to="." method="_on_PlayerTwo_hit"] [connection signal="hit" from="PlayerOne" to="." method="_on_PlayerOne_hit"] +[connection signal="timeout" from="Playtimer" to="." method="_on_Playtimer_timeout"] diff --git a/Battle Pong/MainMenu.gd b/Battle Pong/MainMenu.gd index f879f3e..6b66d93 100644 --- a/Battle Pong/MainMenu.gd +++ b/Battle Pong/MainMenu.gd @@ -18,13 +18,15 @@ func _on_but_local_two_player_pressed(): func _on_but_two_re_with_images_pressed(): $"/root/GameSettings".rendering_enabled = true $"/root/GameSettings".learn_with_images = true + $"/root/GameSettings".trainings_mode_enabled = false get_tree().change_scene("res://Main.tscn") - pass # Replace with function body. + func _on_but_two_re_with_position_pressed(): $"/root/GameSettings".rendering_enabled = $vbox_two_learner/HBoxContainer/cb_rendering_enabled.is_pressed() $"/root/GameSettings".learn_with_images = false + $"/root/GameSettings".trainings_mode_enabled = false if not $"/root/GameSettings".rendering_enabled: $vbox_two_learner.hide() $lbl_game_running.show() @@ -33,7 +35,7 @@ func _on_but_two_re_with_position_pressed(): yield(VisualServer, "frame_post_draw") print("Rendering is disabled") get_tree().change_scene("res://Main.tscn") - pass # Replace with function body. + func _on_cb_rendering_enabled_pressed(): @@ -43,18 +45,23 @@ func _on_cb_rendering_enabled_pressed(): else: $lbl_game_running.show() print($"/root/GameSettings".rendering_enabled) - pass # Replace with function body. + func _on_but_trainer_with_images_pressed(): - - pass # Replace with function body. + $"/root/GameSettings".rendering_enabled = true + $"/root/GameSettings".learn_with_images = true + $"/root/GameSettings".trainings_mode_enabled = true + func _on_but_trainer_with_position_pressed(): - pass # Replace with function body. + $"/root/GameSettings".rendering_enabled = true + $"/root/GameSettings".learn_with_images = false + $"/root/GameSettings".trainings_mode_enabled = true + func _on_but_settings_pressed(): get_tree().change_scene("res://SettingsWindow.tscn") - pass # Replace with function body. + -- GitLab