Skip to content

add net pong #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"dodge-the-creeps/rust",
"hot-reload/rust",
"net-pong/rust",
]

# Note about Jetbrains IDEs: "IDE Sync" (Refresh Cargo projects) may cause static analysis errors such as
Expand Down
21 changes: 21 additions & 0 deletions net-pong/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Asdrome

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
24 changes: 24 additions & 0 deletions net-pong/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Godot Rust Multiplayer Pong
based on https://godotengine.org/asset-library/asset/2798

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

The godot-rust Ferris icon was obtained from [their repository](https://github.com/godot-rust/assets) and its licence's details are explained [here](https://github.com/godot-rust/assets/blob/master/asset-licenses.md).

Shield: [![CC BY 4.0][cc-by-shield]][cc-by]

This work is licensed under a
[Creative Commons Attribution 4.0 International License][cc-by].

[![CC BY 4.0][cc-by-image]][cc-by]

[cc-by]: http://creativecommons.org/licenses/by/4.0/
[cc-by-image]: https://i.creativecommons.org/l/by/4.0/88x31.png
[cc-by-shield]: https://img.shields.io/badge/License-CC%20BY%204.0-lightgrey.svg

## Acknowledgments

- [Godot Engine](https://godotengine.org/)
- [Godot Rust](https://github.com/godot-rust/gdext) for their fantastic work on integrating Rust with Godot.
3 changes: 3 additions & 0 deletions net-pong/godot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Godot 4+ specific ignores
.godot/
/android/
17 changes: 17 additions & 0 deletions net-pong/godot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Pong Multiplayer

A multiplayer implementation of the classic pong game.
One of the players should press **Host**, while the other
should type in the host's IP address and press **Join**.

Language: GDScript

Renderer: Compatibility

Note: The non-multiplayer version is available [here](https://github.com/godotengine/godot-demo-projects/tree/master/2d/pong).

Check out this demo on the asset library: https://godotengine.org/asset-library/asset/2798

## Screenshots

![Screenshot](screenshots/pong_multiplayer.png)
Binary file added net-pong/godot/ball.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions net-pong/godot/ball.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[gd_scene load_steps=3 format=3 uid="uid://bjmldn1x3lpa"]

[ext_resource type="Texture2D" uid="uid://i1imfdcn7ui" path="res://ball.png" id="2"]

[sub_resource type="CircleShape2D" id="1"]
radius = 5.11969

[node name="Ball" type="Ball"]

[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2")

[node name="Shape3D" type="CollisionShape2D" parent="."]
shape = SubResource("1")
Binary file added net-pong/godot/godot-rust.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added net-pong/godot/icon.webp
Binary file not shown.
159 changes: 159 additions & 0 deletions net-pong/godot/lobby.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
[gd_scene format=3 uid="uid://f85s2avde6r4"]

[node name="Lobby" type="Control"]
layout_mode = 3
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -320.0
offset_top = -200.0
offset_right = 320.0
offset_bottom = 200.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 2
size_flags_vertical = 2

[node name="Title" type="Label" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -110.0
offset_top = -156.0
offset_right = 110.0
offset_bottom = -116.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 2
size_flags_vertical = 0
theme_override_font_sizes/font_size = 32
text = "Multiplayer Pong"
horizontal_alignment = 1
vertical_alignment = 1

[node name="LobbyPanel" type="Lobby" parent="." node_paths=PackedStringArray("address", "host_button", "join_button", "status_ok", "status_fail", "port_forward_label", "find_public_ip_button")]
address = NodePath("Address")
host_button = NodePath("HostButton")
join_button = NodePath("JoinButton")
status_ok = NodePath("StatusOk")
status_fail = NodePath("StatusFail")
port_forward_label = NodePath("PortForward")
find_public_ip_button = NodePath("FindPublicIP")
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -110.0
offset_top = -73.0
offset_right = 110.0
offset_bottom = 73.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 2
size_flags_vertical = 2

[node name="AddressLabel" type="Label" parent="LobbyPanel"]
layout_mode = 0
offset_left = 10.0
offset_top = 6.0
offset_right = 77.0
offset_bottom = 29.0
size_flags_horizontal = 2
size_flags_vertical = 0
text = "Address:"

[node name="Address" type="LineEdit" parent="LobbyPanel"]
layout_mode = 0
offset_left = 10.0
offset_top = 37.0
offset_right = 210.0
offset_bottom = 68.0
size_flags_horizontal = 2
size_flags_vertical = 2
text = "127.0.0.1"

[node name="HostButton" type="Button" parent="LobbyPanel"]
layout_mode = 0
offset_left = 10.0
offset_top = 76.0
offset_right = 90.0
offset_bottom = 107.0
size_flags_horizontal = 2
size_flags_vertical = 2
text = "Host"

[node name="JoinButton" type="Button" parent="LobbyPanel"]
layout_mode = 0
offset_left = 130.0
offset_top = 76.0
offset_right = 210.0
offset_bottom = 107.0
size_flags_horizontal = 2
size_flags_vertical = 2
text = "Join"

[node name="StatusOk" type="Label" parent="LobbyPanel"]
layout_mode = 0
offset_left = 10.0
offset_top = 114.0
offset_right = 210.0
offset_bottom = 137.0
size_flags_horizontal = 2
size_flags_vertical = 0
horizontal_alignment = 1

[node name="StatusFail" type="Label" parent="LobbyPanel"]
modulate = Color(1, 0.427451, 0.345098, 1)
layout_mode = 0
offset_left = 10.0
offset_top = 114.0
offset_right = 210.0
offset_bottom = 137.0
size_flags_horizontal = 2
size_flags_vertical = 0
horizontal_alignment = 1

[node name="PortForward" type="Label" parent="LobbyPanel"]
visible = false
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -278.0
offset_top = 91.0
offset_right = 25.0
offset_bottom = 166.0
grow_horizontal = 2
grow_vertical = 2
text = "If you want non-LAN clients to connect,
make sure the port 8910 in UDP
is forwarded on your router."

[node name="FindPublicIP" type="LinkButton" parent="LobbyPanel"]
visible = false
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = 61.0
offset_top = 118.0
offset_right = 269.0
offset_bottom = 141.0
grow_horizontal = 2
grow_vertical = 2
text = "Find your public IP address"

[connection signal="pressed" from="LobbyPanel/HostButton" to="LobbyPanel" method="_on_host_pressed"]
[connection signal="pressed" from="LobbyPanel/JoinButton" to="LobbyPanel" method="_on_join_pressed"]
[connection signal="pressed" from="LobbyPanel/FindPublicIP" to="LobbyPanel" method="_on_find_public_ip_pressed"]
Binary file added net-pong/godot/paddle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions net-pong/godot/paddle.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[gd_scene load_steps=3 format=3 uid="uid://cpw46256eirwq"]

[ext_resource type="Texture2D" uid="uid://bjw2yb853klh2" path="res://paddle.png" id="2"]

[sub_resource type="CapsuleShape2D" id="1"]
radius = 4.78568
height = 23.6064

[node name="Paddle" type="Paddle" node_paths=PackedStringArray("you_label")]
you_label = NodePath("You")

[node name="Sprite2D" type="Sprite2D" parent="."]
texture = ExtResource("2")

[node name="Shape3D" type="CollisionShape2D" parent="."]
shape = SubResource("1")

[node name="You" type="Label" parent="."]
offset_left = -26.0
offset_top = -33.0
offset_right = 27.0
offset_bottom = -19.0
size_flags_horizontal = 2
size_flags_vertical = 0
text = "You"

[connection signal="area_entered" from="." to="." method="_on_paddle_area_enter"]
92 changes: 92 additions & 0 deletions net-pong/godot/pong.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
[gd_scene load_steps=4 format=3 uid="uid://bafoh1ief0147"]

[ext_resource type="Texture2D" uid="uid://b10swafhe08oj" path="res://separator.png" id="2"]
[ext_resource type="PackedScene" uid="uid://cpw46256eirwq" path="res://paddle.tscn" id="3"]
[ext_resource type="PackedScene" uid="uid://bjmldn1x3lpa" path="res://ball.tscn" id="4"]

[node name="Pong" type="Pong" node_paths=PackedStringArray("player1", "player2", "score_left_node", "score_right_node", "winner_left", "winner_right", "exit_game", "ball")]
player1 = NodePath("Player1")
player2 = NodePath("Player2")
score_left_node = NodePath("ScoreLeft")
score_right_node = NodePath("ScoreRight")
winner_left = NodePath("WinnerLeft")
winner_right = NodePath("WinnerRight")
exit_game = NodePath("ExitGame")
ball = NodePath("Ball")

[node name="ColorRect" type="ColorRect" parent="."]
offset_right = 640.0
offset_bottom = 400.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0.141176, 0.152941, 0.164706, 1)

[node name="Separator" type="Sprite2D" parent="."]
position = Vector2(320, 200)
texture = ExtResource("2")

[node name="Player1" parent="." instance=ExtResource("3")]
left = true
modulate = Color(0, 1, 1, 1)
position = Vector2(32.49, 188.622)

[node name="Player2" parent="." instance=ExtResource("3")]
modulate = Color(1, 0, 1, 1)
position = Vector2(608.88, 188.622)

[node name="Ball" parent="." instance=ExtResource("4")]
position = Vector2(320.387, 189.525)

[node name="ScoreLeft" type="Label" parent="."]
offset_left = 240.0
offset_top = 10.0
offset_right = 280.0
offset_bottom = 30.0
size_flags_horizontal = 2
size_flags_vertical = 0
text = "0"

[node name="ScoreRight" type="Label" parent="."]
offset_left = 360.0
offset_top = 10.0
offset_right = 400.0
offset_bottom = 30.0
size_flags_horizontal = 2
size_flags_vertical = 0
text = "0"

[node name="WinnerLeft" type="Label" parent="."]
visible = false
offset_left = 190.0
offset_top = 170.0
offset_right = 267.0
offset_bottom = 184.0
size_flags_horizontal = 2
size_flags_vertical = 0
text = "The Winner!"

[node name="WinnerRight" type="Label" parent="."]
visible = false
offset_left = 380.0
offset_top = 170.0
offset_right = 457.0
offset_bottom = 184.0
size_flags_horizontal = 2
size_flags_vertical = 0
text = "The Winner!"

[node name="ExitGame" type="Button" parent="."]
visible = false
offset_left = 280.0
offset_top = 340.0
offset_right = 360.0
offset_bottom = 360.0
size_flags_horizontal = 2
size_flags_vertical = 2
text = "Exit Game"

[node name="Camera2D" type="Camera2D" parent="."]
offset = Vector2(320, 200)

[editable path="Player1"]
[editable path="Player2"]
Loading
Loading