Tutorial Lesson 6 Reference
This commit is contained in:
parent
e39a152df2
commit
8ed8c9ed19
15 changed files with 210 additions and 0 deletions
|
|
@ -0,0 +1,4 @@
|
||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
2
workbench/sample_projects/2DMultiplayerCourse-Lesson6/.gitattributes
vendored
Normal file
2
workbench/sample_projects/2DMultiplayerCourse-Lesson6/.gitattributes
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
# Normalize EOL for all files that Git considers text files.
|
||||||
|
* text=auto eol=lf
|
||||||
3
workbench/sample_projects/2DMultiplayerCourse-Lesson6/.gitignore
vendored
Normal file
3
workbench/sample_projects/2DMultiplayerCourse-Lesson6/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Godot 4+ specific ignores
|
||||||
|
.godot/
|
||||||
|
/android/
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
extends CharacterBody2D
|
||||||
|
|
||||||
|
|
||||||
|
func _process(delta: float) -> void:
|
||||||
|
var movement_vector = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||||
|
velocity = movement_vector * 100
|
||||||
|
move_and_slide()
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
uid://d1d0h37vo3my4
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
[gd_scene load_steps=4 format=3 uid="uid://c5dfksrt3u5km"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://d1d0h37vo3my4" path="res://entities/player/player.gd" id="1_symyc"]
|
||||||
|
|
||||||
|
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_sfv1e"]
|
||||||
|
size = Vector2(18, 32)
|
||||||
|
|
||||||
|
[sub_resource type="CircleShape2D" id="CircleShape2D_sfv1e"]
|
||||||
|
|
||||||
|
[node name="Player" type="CharacterBody2D"]
|
||||||
|
script = ExtResource("1_symyc")
|
||||||
|
|
||||||
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
|
position = Vector2(0, -16)
|
||||||
|
texture = SubResource("PlaceholderTexture2D_sfv1e")
|
||||||
|
|
||||||
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||||
|
position = Vector2(0, -10)
|
||||||
|
shape = SubResource("CircleShape2D_sfv1e")
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 994 B |
|
|
@ -0,0 +1,43 @@
|
||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="texture"
|
||||||
|
type="CompressedTexture2D"
|
||||||
|
uid="uid://d2sc7ltnat61x"
|
||||||
|
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
|
||||||
|
metadata={
|
||||||
|
"vram_texture": false
|
||||||
|
}
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://icon.svg"
|
||||||
|
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
compress/mode=0
|
||||||
|
compress/high_quality=false
|
||||||
|
compress/lossy_quality=0.7
|
||||||
|
compress/uastc_level=0
|
||||||
|
compress/rdo_quality_loss=0.0
|
||||||
|
compress/hdr_compression=1
|
||||||
|
compress/normal_map=0
|
||||||
|
compress/channel_pack=0
|
||||||
|
mipmaps/generate=false
|
||||||
|
mipmaps/limit=-1
|
||||||
|
roughness/mode=0
|
||||||
|
roughness/src_normal=""
|
||||||
|
process/channel_remap/red=0
|
||||||
|
process/channel_remap/green=1
|
||||||
|
process/channel_remap/blue=2
|
||||||
|
process/channel_remap/alpha=3
|
||||||
|
process/fix_alpha_border=true
|
||||||
|
process/premult_alpha=false
|
||||||
|
process/normal_map_invert_y=false
|
||||||
|
process/hdr_as_srgb=false
|
||||||
|
process/hdr_clamp_exposure=false
|
||||||
|
process/size_limit=0
|
||||||
|
detect_3d/compress_to=1
|
||||||
|
svg/scale=1.0
|
||||||
|
editor/scale_with_editor_scale=false
|
||||||
|
editor/convert_colors_with_editor_theme=false
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
peer_ready.rpc_id(1)
|
||||||
|
|
||||||
|
|
||||||
|
@rpc("any_peer", "call_local", "reliable")
|
||||||
|
func peer_ready():
|
||||||
|
print("peer %s ready" % multiplayer.get_remote_sender_id())
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
uid://d3qlqxwt1f70r
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
[gd_scene load_steps=3 format=3 uid="uid://bw77affpadnt4"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://d3qlqxwt1f70r" path="res://main.gd" id="1_ig7tw"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://c5dfksrt3u5km" path="res://entities/player/player.tscn" id="2_0xm2m"]
|
||||||
|
|
||||||
|
[node name="Main" type="Node"]
|
||||||
|
script = ExtResource("1_ig7tw")
|
||||||
|
|
||||||
|
[node name="Player" parent="." instance=ExtResource("2_0xm2m")]
|
||||||
|
position = Vector2(278, 320)
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
; Engine configuration file.
|
||||||
|
; It's best edited using the editor UI and not directly,
|
||||||
|
; since the parameters that go here are not all obvious.
|
||||||
|
;
|
||||||
|
; Format:
|
||||||
|
; [section] ; section goes between []
|
||||||
|
; param=value ; assign values to parameters
|
||||||
|
|
||||||
|
config_version=5
|
||||||
|
|
||||||
|
[application]
|
||||||
|
|
||||||
|
config/name="2DMultiplayerCourse"
|
||||||
|
run/main_scene="uid://dgistbjkrs4hx"
|
||||||
|
config/features=PackedStringArray("4.5", "GL Compatibility")
|
||||||
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
[input]
|
||||||
|
|
||||||
|
move_left={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
move_right={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
move_up={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
move_down={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"location":0,"echo":false,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
extends Control
|
||||||
|
|
||||||
|
const PORT: int = 3000
|
||||||
|
|
||||||
|
var main_scene: PackedScene = preload("uid://bw77affpadnt4")
|
||||||
|
|
||||||
|
@onready var host_button: Button = $HBoxContainer/HostButton
|
||||||
|
@onready var join_button: Button = $HBoxContainer/JoinButton
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
host_button.pressed.connect(_on_host_pressed)
|
||||||
|
join_button.pressed.connect(_on_join_pressed)
|
||||||
|
multiplayer.connected_to_server.connect(_on_connected_to_server)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_host_pressed() -> void:
|
||||||
|
var server_peer := ENetMultiplayerPeer.new()
|
||||||
|
server_peer.create_server(PORT)
|
||||||
|
multiplayer.multiplayer_peer = server_peer
|
||||||
|
get_tree().change_scene_to_packed(main_scene)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_join_pressed() -> void:
|
||||||
|
var client_peer := ENetMultiplayerPeer.new()
|
||||||
|
client_peer.create_client("127.0.0.1", PORT)
|
||||||
|
multiplayer.multiplayer_peer = client_peer
|
||||||
|
|
||||||
|
|
||||||
|
func _on_connected_to_server():
|
||||||
|
get_tree().change_scene_to_packed(main_scene)
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
uid://cbi2s1lqp560r
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
[gd_scene load_steps=2 format=3 uid="uid://dgistbjkrs4hx"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://cbi2s1lqp560r" path="res://ui/main_menu/main_menu.gd" id="1_uhj5c"]
|
||||||
|
|
||||||
|
[node name="MainMenu" type="Control"]
|
||||||
|
layout_mode = 3
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
script = ExtResource("1_uhj5c")
|
||||||
|
|
||||||
|
[node name="HBoxContainer" type="HBoxContainer" 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 = -44.5
|
||||||
|
offset_top = -15.5
|
||||||
|
offset_right = 44.5
|
||||||
|
offset_bottom = 15.5
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
|
||||||
|
[node name="HostButton" type="Button" parent="HBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Host"
|
||||||
|
|
||||||
|
[node name="JoinButton" type="Button" parent="HBoxContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Join"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue