Browse Source

level selecting system

galo 1 year ago
parent
commit
f6a83f3c25
7 changed files with 69 additions and 28 deletions
  1. 6 2
      Client.gd
  2. 21 16
      Client.tscn
  3. 25 0
      Levelselect.gd
  4. 3 0
      Server.gd
  5. 10 4
      main.tscn
  6. 3 5
      ping.gd
  7. 1 1
      playersprite.tscn

+ 6 - 2
Client.gd

@@ -55,6 +55,7 @@ remote func _On_Peer_Connected():
 				if not $players.get_node(str(x)).has_node('Camera2D'):
 					var cam2d = Camera2D.new()
 					cam2d.current = true
+					cam2d.offset.y = -90
 					$players.get_node(str(x)).add_child(cam2d)
 	
 	if dummy:
@@ -171,6 +172,9 @@ remote func level_up(arg, id):
 	if not has_node("players"): return
 	$players.get_node(str(id)).level_up_anim()
 
+remote func loadlevel(arg):
+	get_parent().get_node('Levelselect').loadlevel(arg, false)
+
 #powerpick
 remote func powerpick(arg , id):
 	if has_node('PowerMenu'):
@@ -183,11 +187,11 @@ func players_choice_is(choice, idbuffer):
 	rpc_id(1,'optionpick',idbuffer, choice)
 
 remote func _On_chat_Message(arg):
-	$RichTextLabel.text += arg + "\n"
+	$Chat/RichTextLabel.text += arg + "\n"
 
 func chat_messages(arg):
 	print(arg)
-	$LineEdit.text= ''
+	$Chat/LineEdit.text= ''
 	rpc_id(1,'chat_messages', arg)
 
 var usernamelist = {}

+ 21 - 16
Client.tscn

@@ -12,18 +12,6 @@
 [node name="Client" type="Node" groups=["client"]]
 script = ExtResource( 3 )
 
-[node name="ping" type="Label" parent="."]
-margin_left = 12.1612
-margin_top = 260.304
-margin_right = 52.1612
-margin_bottom = 281.304
-custom_fonts/font = ExtResource( 8 )
-text = "ping..."
-script = ExtResource( 5 )
-__meta__ = {
-"_edit_use_anchors_": false
-}
-
 [node name="Input" type="Node" parent="."]
 script = ExtResource( 4 )
 
@@ -37,6 +25,19 @@ script = ExtResource( 6 )
 
 [node name="Debug" parent="." instance=ExtResource( 1 )]
 
+[node name="ping" type="Label" parent="Debug"]
+margin_left = 12.1612
+margin_top = 260.304
+margin_right = 52.1612
+margin_bottom = 281.304
+custom_fonts/font = ExtResource( 8 )
+text = "ping..."
+script = ExtResource( 5 )
+
+[node name="Timer" type="Timer" parent="Debug/ping"]
+wait_time = 0.5
+autostart = true
+
 [node name="Hud" type="CanvasLayer" parent="."]
 
 [node name="HBoxContainer" type="HBoxContainer" parent="Hud"]
@@ -49,7 +50,10 @@ __meta__ = {
 
 [node name="PowerMenu" parent="." instance=ExtResource( 2 )]
 
-[node name="LineEdit" type="LineEdit" parent="."]
+[node name="Chat" type="CanvasLayer" parent="."]
+layer = 7
+
+[node name="LineEdit" type="LineEdit" parent="Chat"]
 modulate = Color( 1, 1, 1, 0.627451 )
 margin_left = 480.0
 margin_top = 320.0
@@ -58,15 +62,16 @@ margin_bottom = 344.0
 align = 2
 placeholder_text = "....message"
 
-[node name="RichTextLabel" type="RichTextLabel" parent="."]
+[node name="RichTextLabel" type="RichTextLabel" parent="Chat"]
 margin_left = 480.0
 margin_top = 220.0
 margin_right = 620.0
 margin_bottom = 315.0
 
-[node name="ColorRect" type="ColorRect" parent="RichTextLabel"]
+[node name="ColorRect" type="ColorRect" parent="Chat/RichTextLabel"]
 anchor_right = 1.0
 anchor_bottom = 1.0
 color = Color( 0, 0, 0, 0.207843 )
 
-[connection signal="text_entered" from="LineEdit" to="." method="chat_messages"]
+[connection signal="timeout" from="Debug/ping/Timer" to="Debug/ping" method="_on_Timer_timeout"]
+[connection signal="text_entered" from="Chat/LineEdit" to="." method="chat_messages"]

+ 25 - 0
Levelselect.gd

@@ -0,0 +1,25 @@
+extends Node
+
+
+# Declare member variables here. Examples:
+# var a = 2
+# var b = "text"
+var levels = {}
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+	for i in get_children():
+		levels[i.name] = i
+		call_deferred('remove_child',i)
+	pass # Replace with function body.
+
+func loadlevel(arg,arg2):
+	if levels[arg].get_parent() != self: call_deferred('add_child',levels[arg])
+	if arg2: 
+		levels[arg].call_deferred('hide')
+	else:
+		levels[arg].call_deferred('show')
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+#func _process(delta):
+#	pass

+ 3 - 0
Server.gd

@@ -16,6 +16,7 @@ func _ready():
 	
 	net.connect("peer_disconnected",self,"disc")
 	net.connect("peer_connected",self,"conn")
+	get_parent().get_node('Levelselect').loadlevel('test', true)
 	pass # Replace with function body.
 
 func _process(_delta):
@@ -54,6 +55,8 @@ remote func tokenreply(token, username):
 			username = 'player' +  str(custom_multiplayer.get_network_connected_peers().size())
 		usernames_dict[api.get_rpc_sender_id()] =  str(username)
 		send_list_of_usernames(api.get_rpc_sender_id(), username)
+		
+		rpc_id(api.get_rpc_sender_id(),'loadlevel','test')
 
 func send_list_of_usernames(user, username):
 	rpc_id(user,'_on_usernames', usernames_dict)

+ 10 - 4
main.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=17 format=2]
+[gd_scene load_steps=18 format=2]
 
 [ext_resource path="res://Login.gd" type="Script" id=1]
 [ext_resource path="res://envarg.gd" type="Script" id=2]
@@ -11,6 +11,7 @@
 [ext_resource path="res://icon.png" type="Texture" id=9]
 [ext_resource path="res://art/Untitledcxz.png" type="Texture" id=10]
 [ext_resource path="res://Textures.gd" type="Script" id=11]
+[ext_resource path="res://Levelselect.gd" type="Script" id=12]
 
 [sub_resource type="AtlasTexture" id=1]
 atlas = ExtResource( 10 )
@@ -50,7 +51,6 @@ render_target_v_flip = true
 [node name="Goblin" type="AnimatedSprite" parent="Textures/Goblin1"]
 modulate = Color( 0, 0.811765, 1, 1 )
 frames = SubResource( 5 )
-frame = 3
 playing = true
 offset = Vector2( 32, 32 )
 
@@ -62,6 +62,7 @@ render_target_v_flip = true
 
 [node name="Goblin" type="AnimatedSprite" parent="Textures/Goblin2"]
 frames = SubResource( 5 )
+frame = 1
 speed_scale = 0.8
 playing = true
 offset = Vector2( 32, 32 )
@@ -75,6 +76,7 @@ render_target_v_flip = true
 [node name="Goblin" type="AnimatedSprite" parent="Textures/Goblin3"]
 modulate = Color( 1, 0, 0, 1 )
 frames = SubResource( 5 )
+frame = 1
 speed_scale = 1.2
 playing = true
 offset = Vector2( 32, 32 )
@@ -88,6 +90,7 @@ render_target_v_flip = true
 [node name="Goblin" type="AnimatedSprite" parent="Textures/Goblin4"]
 modulate = Color( 1, 0, 0.984314, 1 )
 frames = SubResource( 5 )
+frame = 2
 speed_scale = 0.9
 playing = true
 offset = Vector2( 32, 32 )
@@ -377,9 +380,12 @@ clickable = false
 [node name="Timer" type="Timer" parent="BrowserListClient"]
 autostart = true
 
-[node name="Level" type="Node" parent="."]
+[node name="Levelselect" type="Node" parent="."]
+script = ExtResource( 12 )
 
-[node name="TileMap" type="TileMap" parent="Level"]
+[node name="test" type="Node2D" parent="Levelselect"]
+
+[node name="TileMap" type="TileMap" parent="Levelselect/test"]
 tile_set = ExtResource( 8 )
 cell_size = Vector2( 32, 32 )
 collision_layer = 2

+ 3 - 5
ping.gd

@@ -1,7 +1,5 @@
 extends Label
 
-func _ready():
-	while true:
-		yield(get_tree().create_timer(0.5),'timeout')
-		text = str(get_parent().ping)
-		get_parent().latency_test()
+func _on_Timer_timeout():
+	text = str(get_parent().get_parent().ping)
+	get_parent().get_parent().latency_test()

+ 1 - 1
playersprite.tscn

@@ -242,7 +242,7 @@ font_data = ExtResource( 5 )
 [node name="playersprite" type="AnimatedSprite"]
 frames = SubResource( 27 )
 animation = "idle"
-frame = 5
+frame = 3
 playing = true
 offset = Vector2( 3.72692, -21.0081 )
 script = SubResource( 28 )