diff --git a/Battle Pong/GameSettings.gd b/Battle Pong/GameSettings.gd new file mode 100644 index 0000000000000000000000000000000000000000..4647f076c0f2c439d444431334d7120a494b3d49 --- /dev/null +++ b/Battle Pong/GameSettings.gd @@ -0,0 +1,159 @@ +extends Node + +export var rendering_enabled = false +export var learn_with_images = true +export var trainings_mode_enabled = false + + +var game_playtime_per_step +var game_wins_to_reset +var game_port + +var image_format +var image_heigth +var image_width + +var trainer_ip +var trainer_port +var trainer_position +var trainer_realtime_enabled + +var ball_height +var ball_width +var ball_speed_min +var ball_speed_max +var ball_speed_increment + +var player_one_length +var player_one_speed + +var player_two_length +var player_two_speed + +var path="data.json" + +var default_data = { + "game":{ + "playtime_per_step":0.1, + "wins_to_reset":21, + "port":9080 + }, + "image":{ + "format":"RGB8", + "height":60, + "width":100 + }, + "trainer":{ + "ip":"127.0.0.1", + "port":"9080", + "position":"Right", + "realtime_enabled":true + }, + "ball":{ + "height":30, + "width":30, + "speed_min":300, + "speed_max":600, + "speed_increment":50 + }, + "player_one":{ + "length":60, + "speed":300 + }, + "player_two":{ + "length":60, + "speed":300 + } + } + +var data = default_data + +# Called when the node enters the scene tree for the first time. +func _ready(): + load_data() + pass # Replace with function body. + +func load_data(): + var file = File.new() + + if not file.file_exists(path): + reset_data() + return + + file.open(path, file.READ) + var text = file.get_as_text() + data = parse_json(text) + file.close() + update_settings() + +func save_data(): + data = { + "game":{ + "playtime_per_step":$"/root/GameSettings".game_playtime_per_step, + "wins_to_reset":$"/root/GameSettings".game_wins_to_reset, + "port":$"/root/GameSettings".game_port + }, + "image":{ + "format":$"/root/GameSettings".image_format, + "height":$"/root/GameSettings".image_heigth, + "width":$"/root/GameSettings".image_width + }, + "trainer":{ + "ip":$"/root/GameSettings".trainer_ip, + "port":$"/root/GameSettings".trainer_port, + "position":$"/root/GameSettings".trainer_position, + "realtime_enabled":$"/root/GameSettings".trainer_realtime_enabled + }, + "ball":{ + "height":$"/root/GameSettings".ball_height, + "width":$"/root/GameSettings".ball_width, + "speed_min":$"/root/GameSettings".ball_speed_min, + "speed_max":$"/root/GameSettings".ball_speed_max, + "speed_increment":$"/root/GameSettings".ball_speed_increment + }, + "player_one":{ + "length":$"/root/GameSettings".player_one_length, + "speed":$"/root/GameSettings".player_one_speed + }, + "player_two":{ + "length":$"/root/GameSettings".player_two_length, + "speed":$"/root/GameSettings".player_two_speed + } + } + var file + file = File.new() + file.open(path, File.WRITE) + file.store_line(to_json(data)) + file.close() + +func reset_data(): + data = default_data.duplicate(true) + update_settings() + +func update_settings(): + game_playtime_per_step = data["game"]["playtime_per_step"] as float + game_wins_to_reset = data["game"]["wins_to_reset"] as int + game_port= data["game"]["port"] as int + + image_format = data["image"]["format"] + image_heigth = data["image"]["height"] as int + image_width = data["image"]["width"] as int + + trainer_ip = data["trainer"]["ip"] + trainer_port = data["trainer"]["port"] as int + trainer_position = data["trainer"]["position"] + trainer_realtime_enabled = data["trainer"]["realtime_enabled"] as bool + + ball_height =data["ball"]["height"] as int + ball_width = data["ball"]["width"] as int + ball_speed_min = data["ball"]["speed_min"] as int + ball_speed_max = data["ball"]["speed_max"] as int + ball_speed_increment = data["ball"]["speed_increment"] as int + + player_one_length = data["player_one"]["length"] as int + player_one_speed = data["player_one"]["speed"] as int + + player_two_length = data["player_two"]["length"] as int + player_two_speed = data["player_two"]["speed"] as int + + diff --git a/Battle Pong/GameSettings.tscn b/Battle Pong/GameSettings.tscn new file mode 100644 index 0000000000000000000000000000000000000000..efa62e8cca79ffae20ce8ca542669a1e814ae9bc --- /dev/null +++ b/Battle Pong/GameSettings.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://GameSettings.gd" type="Script" id=1] + +[node name="Node" type="Node"] +script = ExtResource( 1 ) diff --git a/Battle Pong/Main.gd b/Battle Pong/Main.gd index 0eadd60ed6a5ca2b7c9da93d72e271ea04461da9..79510193be0a063cfde55970f4c07aefe6b59537 100644 --- a/Battle Pong/Main.gd +++ b/Battle Pong/Main.gd @@ -7,10 +7,15 @@ var _server = WebSocketServer.new() var player_one_client_id var player_two_client_id + + var action_player_one = InputEventAction.new() var next_step_player_one = false +var action_trainer_one = "" + var action_player_two = InputEventAction.new() var next_step_player_two = false +var action_trainer_two = "" var Ball = preload("Ball.tscn") var ball = Ball.instance() @@ -28,11 +33,16 @@ const P1_WIN = "Player 1 won!" const P2_WIN = "Player 2 won!" var message = SPACE_TO_PLAY -export var enable_rendering = true -export var learn_with_images = true -export var playtime_per_step = 0.1 +var enable_rendering = true +var learn_with_images = true +var game_playtime_per_step = 0.1 +var max_wins = 21 func _ready(): + enable_rendering = $"/root/GameSettings".rendering_enabled + learn_with_images = $"/root/GameSettings".learn_with_images + game_playtime_per_step = $"/root/GameSettings".game_playtime_per_step + max_wins = $"/root/GameSettings".game_wins_to_reset if not enable_rendering: VisualServer.render_loop_enabled = false # disable rendering to create a massive boost if learn_with_images: @@ -51,11 +61,11 @@ func _ready(): # in a loop for each connected peer. _server.connect("data_received", self, "_on_data") # Start listening on the given port. - var err = _server.listen(PORT) - if err != OK: + var server_err = _server.listen(PORT) + if server_err != OK: print("Unable to start server") set_process(false) - + set_ball() $PlayerOne.start($StartPositionPlayerOne.position) $PlayerTwo.start($StartPositionPlayerTwo.position) @@ -84,7 +94,7 @@ func _process(delta): # Call this in _process or _physics_process. # Data transfer, and signals emission will only happen when calling this function. _server.poll() - + check_point_scored() handle_score_event() handle_game_end() @@ -148,7 +158,7 @@ func reset_paddle_positions(): func handle_game_end(): if game_done: - if score_player_one == 5: + if score_player_one >= max_wins: message = P1_WIN else: message = P2_WIN @@ -167,8 +177,6 @@ func _on_PlayerOne_hit(): pass # Replace with function body. - - func _connected(id, proto): # This is called when a new peer connects, "id" will be the assigned peer id, # "proto" will be the selected WebSocket sub-protocol (which is optional) @@ -188,12 +196,8 @@ func _disconnected(id, was_clean = false): if( player_one_client_id == id ): player_one_client_id = null #print("Player One with Client %d disconnected, clean: %s" % [id, str(was_clean)]) - if(player_two_client_id== id): + if(player_two_client_id == id): player_two_client_id = null - #print("Player Two with Client %d disconnected, clean: %s" % [id, str(was_clean)]) - #else: - #print("Client %d disconnected, clean: %s" % [id, str(was_clean)]) - func _on_data(id): @@ -203,7 +207,7 @@ func _on_data(id): #print("Got data from client %d: %s ... echoing" % [id, pkt.get_string_from_utf8()]) var data = (JSON.parse(pkt.get_string_from_utf8())).get_result() - #print(data) + print(data) if(data): for i in data: #print(i) @@ -249,15 +253,42 @@ func _on_data(id): return_value = get_return_value_as_utf8_JSON() _server.get_peer(id).put_packet(return_value) pass + if($"/root/GameSettings".trainings_mode_enabled): + if(i=="player_one_training"): + next_step_player_one = true + # is w pressed => up + #elif is s pressed => down + # else => nothing + if(Input.is_action_pressed("player_one_up")): + action_trainer_one = "up" + elif Input.is_action_pressed("player_one_down"): + action_trainer_one = "down" + else: + action_trainer_one = "nothing" + if(i=="player_two_training"): + next_step_player_two = true + # is arrow_up pressed => up + #elif is arrow_down pressed => down + # else => nothing + if(Input.is_action_pressed("player_two_up")): + action_trainer_two = "up" + elif Input.is_action_pressed("player_two_down"): + action_trainer_two = "down" + else: + action_trainer_two = "nothing" + if(next_step_player_one and next_step_player_two): + if($"/root/GameSettings".trainer_realtime_enabled): + yield(get_tree().create_timer(game_playtime_per_step), "timeout") unpause() - $PlayerOne.run(playtime_per_step) - $PlayerTwo.run(playtime_per_step) - ball.run(playtime_per_step) + $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()} + return {"PlayerOne":{"X":$PlayerOne.position.x,"Y":$PlayerOne.position.y, "TrainingAction":action_trainer_one}, "PlayerTwo":{"X":$PlayerTwo.position.x,"Y":$PlayerTwo.position.y, "TrainingAction":action_trainer_two}, "ball":ball.get_observation()} func get_return_value_as_utf8_JSON(): var observation = get_observarion() @@ -317,6 +348,7 @@ func timeout(): if(player_two_client_id): _server.get_peer(player_two_client_id).put_packet(return_value) + func pause(): #print("pause") ball.set_pause(true) @@ -328,4 +360,3 @@ func unpause(): ball.set_pause(false) $PlayerOne.set_pause(false) $PlayerTwo.set_pause(false) - diff --git a/Battle Pong/Main.tscn b/Battle Pong/Main.tscn index 804fb3c80b00779c5b5433de80de94b16fbca3dc..9240734d80fbbf9392d771bd3413eb7d67f4352e 100644 --- a/Battle Pong/Main.tscn +++ b/Battle Pong/Main.tscn @@ -27,8 +27,13 @@ __meta__ = { } [node name="DisplayMessage" type="Label" parent="."] -margin_right = 40.0 -margin_bottom = 14.0 +anchor_left = 0.5 +anchor_right = 0.5 +margin_left = 388.214 +margin_top = 43.0813 +margin_right = 638.214 +margin_bottom = 73.0813 +align = 1 __meta__ = { "_edit_use_anchors_": false } diff --git a/Battle Pong/MainMenu.gd b/Battle Pong/MainMenu.gd new file mode 100644 index 0000000000000000000000000000000000000000..d44016d220fa9325b963963a46e68c62aae7ae6a --- /dev/null +++ b/Battle Pong/MainMenu.gd @@ -0,0 +1,69 @@ +extends Control + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass + + +func _on_but_local_two_player_pressed(): + pass # Replace with function body. + + +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") + + + +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() + get_viewport().set_clear_mode(Viewport.CLEAR_MODE_ONLY_NEXT_FRAME) + # Wait until the frame has finished before getting the texture. + yield(VisualServer, "frame_post_draw") + print("Rendering is disabled") + get_tree().change_scene("res://Main.tscn") + + + +func _on_cb_rendering_enabled_pressed(): + $"/root/GameSettings".rendering_enabled = $vbox_two_learner/HBoxContainer/cb_rendering_enabled.is_pressed() + if not $"/root/GameSettings".rendering_enabled: + $vbox_two_learner.hide() + else: + $lbl_game_running.show() + print($"/root/GameSettings".rendering_enabled) + + + +func _on_but_trainer_with_images_pressed(): + $"/root/GameSettings".rendering_enabled = true + $"/root/GameSettings".learn_with_images = true + $"/root/GameSettings".trainings_mode_enabled = true + get_tree().change_scene("res://Main.tscn") + + + +func _on_but_trainer_with_position_pressed(): + $"/root/GameSettings".rendering_enabled = true + $"/root/GameSettings".learn_with_images = false + $"/root/GameSettings".trainings_mode_enabled = true + get_tree().change_scene("res://Main.tscn") + + + +func _on_but_settings_pressed(): + get_tree().change_scene("res://SettingsWindow.tscn") + diff --git a/Battle Pong/MainMenu.tscn b/Battle Pong/MainMenu.tscn new file mode 100644 index 0000000000000000000000000000000000000000..7ef8da7138ab32e18292725bc02266e405cbd1f9 --- /dev/null +++ b/Battle Pong/MainMenu.tscn @@ -0,0 +1,115 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://MainMenu.gd" type="Script" id=1] + +[node name="MainMenu" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="lbl_title" type="Label" parent="."] +anchor_left = 0.5 +anchor_right = 0.5 +margin_left = -75.5 +margin_top = 20.0 +margin_right = 75.5 +margin_bottom = 14.0 +text = "Battle Pong" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="vbox_two_learner" type="VBoxContainer" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -132.5 +margin_top = -92.0 +margin_right = 132.5 +margin_bottom = 92.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="but_local_two_player" type="Button" parent="vbox_two_learner"] +margin_right = 265.0 +margin_bottom = 20.0 +text = "Local 2 Player" + +[node name="HSeparator2" type="HSeparator" parent="vbox_two_learner"] +margin_top = 24.0 +margin_right = 265.0 +margin_bottom = 28.0 + +[node name="but_two_re_with_images" type="Button" parent="vbox_two_learner"] +margin_top = 32.0 +margin_right = 265.0 +margin_bottom = 52.0 +text = "2 RE with Images" + +[node name="HBoxContainer" type="HBoxContainer" parent="vbox_two_learner"] +margin_top = 56.0 +margin_right = 265.0 +margin_bottom = 80.0 + +[node name="but_two_re_with_position" type="Button" parent="vbox_two_learner/HBoxContainer"] +margin_right = 126.0 +margin_bottom = 24.0 +text = "2 RE with Position" + +[node name="cb_rendering_enabled" type="CheckBox" parent="vbox_two_learner/HBoxContainer"] +margin_left = 130.0 +margin_right = 265.0 +margin_bottom = 24.0 +text = "Enable rendering" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="HSeparator" type="HSeparator" parent="vbox_two_learner"] +margin_top = 84.0 +margin_right = 265.0 +margin_bottom = 88.0 + +[node name="but_trainer_with_images" type="Button" parent="vbox_two_learner"] +margin_top = 92.0 +margin_right = 265.0 +margin_bottom = 112.0 +text = "RE Trainer with Images" + +[node name="but_trainer_with_position" type="Button" parent="vbox_two_learner"] +margin_top = 116.0 +margin_right = 265.0 +margin_bottom = 136.0 +text = "RE Trainer with Position" + +[node name="but_settings" type="Button" parent="vbox_two_learner"] +margin_top = 140.0 +margin_right = 265.0 +margin_bottom = 160.0 +text = "Settings" + +[node name="lbl_game_running" type="Label" parent="."] +visible = false +anchor_left = 0.5 +anchor_right = 0.5 +margin_left = -93.5 +margin_top = 59.0 +margin_right = 93.5 +margin_bottom = 73.0 +text = "Game runs without rendering" +__meta__ = { +"_edit_use_anchors_": false +} +[connection signal="pressed" from="vbox_two_learner/but_local_two_player" to="." method="_on_but_local_two_player_pressed"] +[connection signal="pressed" from="vbox_two_learner/but_two_re_with_images" to="." method="_on_but_two_re_with_images_pressed"] +[connection signal="pressed" from="vbox_two_learner/HBoxContainer/but_two_re_with_position" to="." method="_on_but_two_re_with_position_pressed"] +[connection signal="pressed" from="vbox_two_learner/HBoxContainer/cb_rendering_enabled" to="." method="_on_cb_rendering_enabled_pressed"] +[connection signal="pressed" from="vbox_two_learner/but_trainer_with_images" to="." method="_on_but_trainer_with_images_pressed"] +[connection signal="pressed" from="vbox_two_learner/but_trainer_with_position" to="." method="_on_but_trainer_with_position_pressed"] +[connection signal="pressed" from="vbox_two_learner/but_settings" to="." method="_on_but_settings_pressed"] diff --git a/Battle Pong/SettingsWindow.gd b/Battle Pong/SettingsWindow.gd new file mode 100644 index 0000000000000000000000000000000000000000..fc400064a09ea0ab1b625ad597c89dfa41d21a38 --- /dev/null +++ b/Battle Pong/SettingsWindow.gd @@ -0,0 +1,98 @@ +extends Control + + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + + + +# Called when the node enters the scene tree for the first time. +func _ready(): + update_gui() + + +func update_gui(): + $VBoxContainer/grid_settings/vbox_game_settings/grid_game_settings/input_game_playtime_per_step.text = str($"/root/GameSettings".game_playtime_per_step) + $VBoxContainer/grid_settings/vbox_game_settings/grid_game_settings/input_game_wins_to_reset.text = str($"/root/GameSettings".game_wins_to_reset) + $VBoxContainer/grid_settings/vbox_game_settings/grid_game_settings/input_game_port.text= str($"/root/GameSettings".game_port) + + $VBoxContainer/grid_settings/vbox_image_settings/grid_image_settings/input_image_format.text = $"/root/GameSettings".image_format + $VBoxContainer/grid_settings/vbox_image_settings/grid_image_settings/input_image_height.text = str($"/root/GameSettings".image_heigth) + $VBoxContainer/grid_settings/vbox_image_settings/grid_image_settings/input_image_width.text = str($"/root/GameSettings".image_width) + + #$VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_ip.text = $"/root/GameSettings".trainer_ip + #$VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_port.text = str($"/root/GameSettings".trainer_port) + #if $"/root/GameSettings".trainer_position =="Left": + # $VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_position.pressed = false + #elif $"/root/GameSettings".trainer_position =="Right": + # $VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_position.pressed = true + + #$VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_position.text = $"/root/GameSettings".trainer_position + $VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_realtime_enabled.pressed = $"/root/GameSettings".trainer_realtime_enabled + + $VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings/input_ball_height.text = str($"/root/GameSettings".ball_height) + $VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings/input_ball_width.text = str($"/root/GameSettings".ball_width) + $VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings/input_ball_speed_min.text = str($"/root/GameSettings".ball_speed_min) + $VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings/input_ball_speed_max.text = str($"/root/GameSettings".ball_speed_max) + $VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings/input_ball_speed_increment.text = str($"/root/GameSettings".ball_speed_increment) + + $VBoxContainer/grid_settings/vbox_player_one_settings/grid_player_one_settings/input_player_one_length.text = str($"/root/GameSettings".player_one_length) + $VBoxContainer/grid_settings/vbox_player_one_settings/grid_player_one_settings/input_player_one_speed.text = str($"/root/GameSettings".player_one_speed) + + $VBoxContainer/grid_settings/vbox_player_two_settings/grid_player_two_settings/input_player_two_length.text = str($"/root/GameSettings".player_two_length) + $VBoxContainer/grid_settings/vbox_player_two_settings/grid_player_two_settings/input_player_two_speed.text = str($"/root/GameSettings".player_two_speed) + + +func _on_input_trainer_position_pressed(): + if $VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_position.is_pressed(): + $VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_position.text = "Right" + else: + $VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_position.text = "Left" + pass # Replace with function body. + + +func _on_but_save_pressed(): + $"/root/GameSettings".game_playtime_per_step = $VBoxContainer/grid_settings/vbox_game_settings/grid_game_settings/input_game_playtime_per_step.text as float + $"/root/GameSettings".game_wins_to_reset = $VBoxContainer/grid_settings/vbox_game_settings/grid_game_settings/input_game_wins_to_reset.text as int + $"/root/GameSettings".game_port = $VBoxContainer/grid_settings/vbox_game_settings/grid_game_settings/input_game_port.text as int + + $"/root/GameSettings".image_format = $VBoxContainer/grid_settings/vbox_image_settings/grid_image_settings/input_image_format.text + $"/root/GameSettings".image_heigth = $VBoxContainer/grid_settings/vbox_image_settings/grid_image_settings/input_image_height.text as int + $"/root/GameSettings".image_width = $VBoxContainer/grid_settings/vbox_image_settings/grid_image_settings/input_image_width.text as int + + #$"/root/GameSettings".trainer_ip = $VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_ip.text + #$"/root/GameSettings".trainer_port = $VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_port.text as int + $"/root/GameSettings".trainer_position = $VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_position.text + $"/root/GameSettings".trainer_realtime_enabled = $VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_realtime_enabled.pressed + + $"/root/GameSettings".ball_height = $VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings/input_ball_height.text as int + $"/root/GameSettings".ball_width = $VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings/input_ball_width.text as int + $"/root/GameSettings".ball_speed_min = $VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings/input_ball_speed_min.text as int + $"/root/GameSettings".ball_speed_max = $VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings/input_ball_speed_max.text as int + $"/root/GameSettings".ball_speed_increment = $VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings/input_ball_speed_increment.text as int + + $"/root/GameSettings".player_one_length = $VBoxContainer/grid_settings/vbox_player_one_settings/grid_player_one_settings/input_player_one_length.text as int + $"/root/GameSettings".player_one_speed = $VBoxContainer/grid_settings/vbox_player_one_settings/grid_player_one_settings/input_player_one_speed.text as int + + $"/root/GameSettings".player_two_length = $VBoxContainer/grid_settings/vbox_player_two_settings/grid_player_two_settings/input_player_two_length.text as int + $"/root/GameSettings".player_two_speed = $VBoxContainer/grid_settings/vbox_player_two_settings/grid_player_two_settings/input_player_two_speed.text as int + + $"/root/GameSettings".save_data() + + print("new values") + print($"/root/GameSettings".data) + + get_tree().change_scene("res://MainMenu.tscn") + pass # Replace with function body. + + +func _on_but_reset_pressed(): + $"/root/GameSettings".reset_data() + update_gui() + pass # Replace with function body. + + +func _on_but_cancel_pressed(): + get_tree().change_scene("res://MainMenu.tscn") + pass # Replace with function body. diff --git a/Battle Pong/SettingsWindow.tscn b/Battle Pong/SettingsWindow.tscn new file mode 100644 index 0000000000000000000000000000000000000000..c86b6595d7feefddc8e1a3a18f47013b0e56d0ed --- /dev/null +++ b/Battle Pong/SettingsWindow.tscn @@ -0,0 +1,447 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://SettingsWindow.gd" type="Script" id=1] + +[node name="Control" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="lbl_title" type="Label" parent="."] +anchor_left = 0.5 +anchor_right = 0.5 +margin_left = -46.5 +margin_top = 20.0 +margin_right = 46.5 +margin_bottom = 14.0 +text = "Game Settings" +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -141.5 +margin_top = -181.0 +margin_right = 141.5 +margin_bottom = 181.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="grid_settings" type="GridContainer" parent="VBoxContainer"] +margin_right = 347.0 +margin_bottom = 353.0 +columns = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="vbox_game_settings" type="VBoxContainer" parent="VBoxContainer/grid_settings"] +margin_right = 163.0 +margin_bottom = 105.0 + +[node name="lbl_title_game_settings" type="Label" parent="VBoxContainer/grid_settings/vbox_game_settings"] +margin_right = 163.0 +margin_bottom = 14.0 +text = "Game:" + +[node name="grid_game_settings" type="GridContainer" parent="VBoxContainer/grid_settings/vbox_game_settings"] +margin_top = 18.0 +margin_right = 163.0 +margin_bottom = 105.0 +columns = 2 + +[node name="lbl_game_playtime_per_step" type="Label" parent="VBoxContainer/grid_settings/vbox_game_settings/grid_game_settings"] +margin_right = 89.0 +margin_bottom = 31.0 +text = "Playtime/Step +(Seconds)" + +[node name="input_game_playtime_per_step" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_game_settings/grid_game_settings"] +margin_left = 93.0 +margin_right = 151.0 +margin_bottom = 31.0 + +[node name="lbl_game_wins_to_reset" type="Label" parent="VBoxContainer/grid_settings/vbox_game_settings/grid_game_settings"] +margin_top = 40.0 +margin_right = 89.0 +margin_bottom = 54.0 +text = "Wins till end" + +[node name="input_game_wins_to_reset" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_game_settings/grid_game_settings"] +margin_left = 93.0 +margin_top = 35.0 +margin_right = 151.0 +margin_bottom = 59.0 +align = 2 + +[node name="lbl_game_port" type="Label" parent="VBoxContainer/grid_settings/vbox_game_settings/grid_game_settings"] +margin_top = 68.0 +margin_right = 89.0 +margin_bottom = 82.0 +text = "Port" + +[node name="input_game_port" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_game_settings/grid_game_settings"] +margin_left = 93.0 +margin_top = 63.0 +margin_right = 151.0 +margin_bottom = 87.0 + +[node name="VSeparator" type="VSeparator" parent="VBoxContainer/grid_settings"] +margin_left = 167.0 +margin_right = 171.0 +margin_bottom = 105.0 + +[node name="vbox_image_settings" type="VBoxContainer" parent="VBoxContainer/grid_settings"] +margin_left = 175.0 +margin_right = 347.0 +margin_bottom = 105.0 + +[node name="lbl_title_image_settings" type="Label" parent="VBoxContainer/grid_settings/vbox_image_settings"] +margin_right = 172.0 +margin_bottom = 14.0 +text = "Image:" + +[node name="grid_image_settings" type="GridContainer" parent="VBoxContainer/grid_settings/vbox_image_settings"] +margin_top = 18.0 +margin_right = 172.0 +margin_bottom = 98.0 +columns = 2 + +[node name="lbl_image_format" type="Label" parent="VBoxContainer/grid_settings/vbox_image_settings/grid_image_settings"] +margin_top = 5.0 +margin_right = 45.0 +margin_bottom = 19.0 +text = "Format" + +[node name="input_image_format" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_image_settings/grid_image_settings"] +margin_left = 49.0 +margin_right = 107.0 +margin_bottom = 24.0 +hint_tooltip = "example: +RGB8 +L8 +https://docs.godotengine.org/en/stable/classes/class_image.html#enumerations" + +[node name="lbl_image_heigth" type="Label" parent="VBoxContainer/grid_settings/vbox_image_settings/grid_image_settings"] +margin_top = 33.0 +margin_right = 45.0 +margin_bottom = 47.0 +text = "Height" + +[node name="input_image_height" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_image_settings/grid_image_settings"] +margin_left = 49.0 +margin_top = 28.0 +margin_right = 107.0 +margin_bottom = 52.0 + +[node name="lbl_image_width" type="Label" parent="VBoxContainer/grid_settings/vbox_image_settings/grid_image_settings"] +margin_top = 61.0 +margin_right = 45.0 +margin_bottom = 75.0 +text = "Width" + +[node name="input_image_width" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_image_settings/grid_image_settings"] +margin_left = 49.0 +margin_top = 56.0 +margin_right = 107.0 +margin_bottom = 80.0 + +[node name="HSeparator" type="HSeparator" parent="VBoxContainer/grid_settings"] +margin_top = 109.0 +margin_right = 163.0 +margin_bottom = 113.0 + +[node name="HSeparator6" type="HSeparator" parent="VBoxContainer/grid_settings"] +margin_left = 167.0 +margin_top = 109.0 +margin_right = 171.0 +margin_bottom = 113.0 + +[node name="HSeparator5" type="HSeparator" parent="VBoxContainer/grid_settings"] +margin_left = 175.0 +margin_top = 109.0 +margin_right = 347.0 +margin_bottom = 113.0 + +[node name="vbox_trainer_settings" type="VBoxContainer" parent="VBoxContainer/grid_settings"] +margin_top = 117.0 +margin_right = 163.0 +margin_bottom = 271.0 + +[node name="lbl_title_trainer_settings" type="Label" parent="VBoxContainer/grid_settings/vbox_trainer_settings"] +margin_right = 163.0 +margin_bottom = 14.0 +text = "Trainer:" + +[node name="grid_trainer_settings" type="GridContainer" parent="VBoxContainer/grid_settings/vbox_trainer_settings"] +margin_top = 18.0 +margin_right = 163.0 +margin_bottom = 58.0 +columns = 2 + +[node name="lbl_trainer_ip" type="Label" parent="VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings"] +visible = false +margin_right = 104.0 +margin_bottom = 14.0 +text = "IP" + +[node name="input_trainer_ip" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings"] +visible = false +margin_left = 56.0 +margin_right = 160.0 +margin_bottom = 24.0 + +[node name="lbl_trainer_port" type="Label" parent="VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings"] +visible = false +margin_top = 5.0 +margin_right = 52.0 +margin_bottom = 19.0 +text = "Port" + +[node name="input_trainer_port" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings"] +visible = false +margin_right = 104.0 +margin_bottom = 24.0 + +[node name="lbl_trainer_position" type="Label" parent="VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings"] +visible = false +margin_top = 13.0 +margin_right = 83.0 +margin_bottom = 27.0 +text = "Position" + +[node name="input_trainer_position" type="CheckButton" parent="VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings"] +visible = false +margin_right = 104.0 +margin_bottom = 40.0 +text = "Left" + +[node name="lbl_trainer_realtime_enabled" type="Label" parent="VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings"] +margin_top = 13.0 +margin_right = 83.0 +margin_bottom = 27.0 +text = "Use realtime" + +[node name="input_trainer_realtime_enabled" type="CheckButton" parent="VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings"] +margin_left = 87.0 +margin_right = 163.0 +margin_bottom = 40.0 + +[node name="VSeparator2" type="VSeparator" parent="VBoxContainer/grid_settings"] +margin_left = 167.0 +margin_top = 117.0 +margin_right = 171.0 +margin_bottom = 271.0 + +[node name="vbox_ball_settings" type="VBoxContainer" parent="VBoxContainer/grid_settings"] +margin_left = 175.0 +margin_top = 117.0 +margin_right = 347.0 +margin_bottom = 271.0 + +[node name="lbl_title_ball_settings" type="Label" parent="VBoxContainer/grid_settings/vbox_ball_settings"] +margin_right = 172.0 +margin_bottom = 14.0 +text = "Ball:" + +[node name="grid_ball_settings" type="GridContainer" parent="VBoxContainer/grid_settings/vbox_ball_settings"] +margin_top = 18.0 +margin_right = 172.0 +margin_bottom = 154.0 +columns = 2 + +[node name="lbl_ball_height" type="Label" parent="VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings"] +margin_top = 5.0 +margin_right = 110.0 +margin_bottom = 19.0 +text = "Hight" + +[node name="input_ball_height" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings"] +margin_left = 114.0 +margin_right = 172.0 +margin_bottom = 24.0 + +[node name="lbl_ball_width" type="Label" parent="VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings"] +margin_top = 33.0 +margin_right = 110.0 +margin_bottom = 47.0 +text = "Width" + +[node name="input_ball_width" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings"] +margin_left = 114.0 +margin_top = 28.0 +margin_right = 172.0 +margin_bottom = 52.0 + +[node name="lbl_ball_speed_min" type="Label" parent="VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings"] +margin_top = 61.0 +margin_right = 110.0 +margin_bottom = 75.0 +text = "Speed Min" + +[node name="input_ball_speed_min" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings"] +margin_left = 114.0 +margin_top = 56.0 +margin_right = 172.0 +margin_bottom = 80.0 + +[node name="lbl_ball_speed_max" type="Label" parent="VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings"] +margin_top = 89.0 +margin_right = 110.0 +margin_bottom = 103.0 +text = "Speed Max" + +[node name="input_ball_speed_max" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings"] +margin_left = 114.0 +margin_top = 84.0 +margin_right = 172.0 +margin_bottom = 108.0 + +[node name="lbl_ball_speed_increment" type="Label" parent="VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings"] +margin_top = 117.0 +margin_right = 110.0 +margin_bottom = 131.0 +text = "Speed Increment" + +[node name="input_ball_speed_increment" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_ball_settings/grid_ball_settings"] +margin_left = 114.0 +margin_top = 112.0 +margin_right = 172.0 +margin_bottom = 136.0 + +[node name="HSeparator7" type="HSeparator" parent="VBoxContainer/grid_settings"] +margin_top = 275.0 +margin_right = 163.0 +margin_bottom = 279.0 + +[node name="VSeparator3" type="HSeparator" parent="VBoxContainer/grid_settings"] +margin_left = 167.0 +margin_top = 275.0 +margin_right = 171.0 +margin_bottom = 279.0 + +[node name="HSeparator2" type="HSeparator" parent="VBoxContainer/grid_settings"] +margin_left = 175.0 +margin_top = 275.0 +margin_right = 347.0 +margin_bottom = 279.0 + +[node name="vbox_player_one_settings" type="VBoxContainer" parent="VBoxContainer/grid_settings"] +margin_top = 283.0 +margin_right = 163.0 +margin_bottom = 353.0 + +[node name="lbl_title_player_one_settings" type="Label" parent="VBoxContainer/grid_settings/vbox_player_one_settings"] +margin_right = 163.0 +margin_bottom = 14.0 +text = "Player 1:" + +[node name="grid_player_one_settings" type="GridContainer" parent="VBoxContainer/grid_settings/vbox_player_one_settings"] +margin_top = 18.0 +margin_right = 163.0 +margin_bottom = 70.0 +columns = 2 + +[node name="lbl_player_one_length" type="Label" parent="VBoxContainer/grid_settings/vbox_player_one_settings/grid_player_one_settings"] +margin_top = 5.0 +margin_right = 43.0 +margin_bottom = 19.0 +text = "Length" + +[node name="input_player_one_length" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_player_one_settings/grid_player_one_settings"] +margin_left = 47.0 +margin_right = 105.0 +margin_bottom = 24.0 + +[node name="lbl_player_one_speed" type="Label" parent="VBoxContainer/grid_settings/vbox_player_one_settings/grid_player_one_settings"] +margin_top = 33.0 +margin_right = 43.0 +margin_bottom = 47.0 +text = "Speed" + +[node name="input_player_one_speed" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_player_one_settings/grid_player_one_settings"] +margin_left = 47.0 +margin_top = 28.0 +margin_right = 105.0 +margin_bottom = 52.0 + +[node name="VSeparator4" type="VSeparator" parent="VBoxContainer/grid_settings"] +margin_left = 167.0 +margin_top = 283.0 +margin_right = 171.0 +margin_bottom = 353.0 + +[node name="vbox_player_two_settings" type="VBoxContainer" parent="VBoxContainer/grid_settings"] +margin_left = 175.0 +margin_top = 283.0 +margin_right = 347.0 +margin_bottom = 353.0 + +[node name="lbl_title_player_two_settings" type="Label" parent="VBoxContainer/grid_settings/vbox_player_two_settings"] +margin_right = 172.0 +margin_bottom = 14.0 +text = "Player 2:" + +[node name="grid_player_two_settings" type="GridContainer" parent="VBoxContainer/grid_settings/vbox_player_two_settings"] +margin_top = 18.0 +margin_right = 172.0 +margin_bottom = 70.0 +columns = 2 + +[node name="lbl_player_two_length" type="Label" parent="VBoxContainer/grid_settings/vbox_player_two_settings/grid_player_two_settings"] +margin_top = 5.0 +margin_right = 43.0 +margin_bottom = 19.0 +text = "Length" + +[node name="input_player_two_length" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_player_two_settings/grid_player_two_settings"] +margin_left = 47.0 +margin_right = 105.0 +margin_bottom = 24.0 + +[node name="lbl_player_two_speed" type="Label" parent="VBoxContainer/grid_settings/vbox_player_two_settings/grid_player_two_settings"] +margin_top = 33.0 +margin_right = 43.0 +margin_bottom = 47.0 +text = "Speed" + +[node name="input_player_two_speed" type="LineEdit" parent="VBoxContainer/grid_settings/vbox_player_two_settings/grid_player_two_settings"] +margin_left = 47.0 +margin_top = 28.0 +margin_right = 105.0 +margin_bottom = 52.0 + +[node name="VSeparator5" type="HSeparator" parent="VBoxContainer"] +margin_top = 357.0 +margin_right = 347.0 +margin_bottom = 361.0 + +[node name="but_save" type="Button" parent="VBoxContainer"] +margin_top = 365.0 +margin_right = 347.0 +margin_bottom = 385.0 +text = "Save" + +[node name="but_cancel" type="Button" parent="VBoxContainer"] +margin_top = 389.0 +margin_right = 347.0 +margin_bottom = 409.0 +text = "Cancel" + +[node name="but_reset" type="Button" parent="VBoxContainer"] +margin_top = 413.0 +margin_right = 347.0 +margin_bottom = 433.0 +text = "Reset" +[connection signal="pressed" from="VBoxContainer/grid_settings/vbox_trainer_settings/grid_trainer_settings/input_trainer_position" to="." method="_on_input_trainer_position_pressed"] +[connection signal="pressed" from="VBoxContainer/but_save" to="." method="_on_but_save_pressed"] +[connection signal="pressed" from="VBoxContainer/but_cancel" to="." method="_on_but_cancel_pressed"] +[connection signal="pressed" from="VBoxContainer/but_reset" to="." method="_on_but_reset_pressed"] diff --git a/Battle Pong/project.godot b/Battle Pong/project.godot index e02a4732000668ff8c3cac80538bab7bf567fd7f..b008c916c34acf2d874e69bf063e1e975be65278 100644 --- a/Battle Pong/project.godot +++ b/Battle Pong/project.godot @@ -16,9 +16,13 @@ _global_script_class_icons={ [application] config/name="Battle Pong" -run/main_scene="res://Main.tscn" +run/main_scene="res://MainMenu.tscn" config/icon="res://icon.png" +[autoload] + +GameSettings="*res://GameSettings.gd" + [debug] settings/gdscript/max_call_stack=4096