Client changes and tweaks
This commit is contained in:
		@ -33,3 +33,6 @@ valign = 1
 | 
				
			|||||||
__meta__ = {
 | 
					__meta__ = {
 | 
				
			||||||
"_edit_use_anchors_": false
 | 
					"_edit_use_anchors_": false
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[node name="Camera" type="Camera2D" parent="."]
 | 
				
			||||||
 | 
					zoom = Vector2( 0.5, 0.5 )
 | 
				
			||||||
 | 
				
			|||||||
@ -23,9 +23,38 @@ config/icon="res://icon.png"
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
MusicManager="*res://nodes/MusicManager.tscn"
 | 
					MusicManager="*res://nodes/MusicManager.tscn"
 | 
				
			||||||
NetworkManager="*res://nodes/NetworkManager.tscn"
 | 
					NetworkManager="*res://nodes/NetworkManager.tscn"
 | 
				
			||||||
 | 
					ImportantEntities="*res://scripts/singletons/ImportantEntities.gd"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[input]
 | 
					[input]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ui_left={
 | 
				
			||||||
 | 
					"deadzone": 0.5,
 | 
				
			||||||
 | 
					"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
 | 
				
			||||||
 | 
					, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
 | 
				
			||||||
 | 
					, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
 | 
				
			||||||
 | 
					 ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					ui_right={
 | 
				
			||||||
 | 
					"deadzone": 0.5,
 | 
				
			||||||
 | 
					"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
 | 
				
			||||||
 | 
					, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
 | 
				
			||||||
 | 
					, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
 | 
				
			||||||
 | 
					 ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					ui_up={
 | 
				
			||||||
 | 
					"deadzone": 0.5,
 | 
				
			||||||
 | 
					"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
 | 
				
			||||||
 | 
					, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
 | 
				
			||||||
 | 
					, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
 | 
				
			||||||
 | 
					 ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					ui_down={
 | 
				
			||||||
 | 
					"deadzone": 0.5,
 | 
				
			||||||
 | 
					"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
 | 
				
			||||||
 | 
					, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
 | 
				
			||||||
 | 
					, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
 | 
				
			||||||
 | 
					 ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
send_chat_message={
 | 
					send_chat_message={
 | 
				
			||||||
"deadzone": 0.5,
 | 
					"deadzone": 0.5,
 | 
				
			||||||
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777221,"unicode":0,"echo":false,"script":null)
 | 
					"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777221,"unicode":0,"echo":false,"script":null)
 | 
				
			||||||
 | 
				
			|||||||
										
											Binary file not shown.
										
									
								
							@ -1,27 +1,43 @@
 | 
				
			|||||||
extends KinematicBody2D
 | 
					extends KinematicBody2D
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export var user : String = ""
 | 
					export var user : String = ""
 | 
				
			||||||
 | 
					var main : bool = false
 | 
				
			||||||
 | 
					var input_locks = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func set_main():
 | 
				
			||||||
 | 
						main = true
 | 
				
			||||||
 | 
						$Label.hide()
 | 
				
			||||||
 | 
						$Camera.show()
 | 
				
			||||||
 | 
						$Camera.current = true
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						$"/root/ImportantEntities".main_player = self
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _ready():
 | 
					func _ready():
 | 
				
			||||||
 | 
						$Camera.hide()
 | 
				
			||||||
	set_username("")
 | 
						set_username("")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func set_username(username):
 | 
					func set_username(username):
 | 
				
			||||||
	print(username)
 | 
					 | 
				
			||||||
	user = username
 | 
						user = username
 | 
				
			||||||
	$Label.text = user
 | 
						$Label.text = user
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func _process(delta):
 | 
					func _process(delta):
 | 
				
			||||||
	var movePos : Vector2 = Vector2(0,0)
 | 
						if main and input_locks <= 0:
 | 
				
			||||||
 | 
							var movePos : Vector2 = Vector2(0,0)
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							if(Input.is_action_just_pressed("ui_up")):
 | 
				
			||||||
 | 
								movePos.y = movePos.y - 1
 | 
				
			||||||
 | 
							if(Input.is_action_just_pressed("ui_down")):
 | 
				
			||||||
 | 
								movePos.y = movePos.y + 1
 | 
				
			||||||
 | 
							if(Input.is_action_just_pressed("ui_right")):
 | 
				
			||||||
 | 
								movePos.x = movePos.x + 1
 | 
				
			||||||
 | 
							if(Input.is_action_just_pressed("ui_left")):
 | 
				
			||||||
 | 
								movePos.x = movePos.x - 1
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	
 | 
							if movePos != Vector2.ZERO:
 | 
				
			||||||
	if(Input.is_action_just_pressed("ui_up")):
 | 
								$"/root/NetworkManager".move_player(movePos.x, movePos.y)
 | 
				
			||||||
		movePos.y = movePos.y - 1
 | 
					 | 
				
			||||||
	if(Input.is_action_just_pressed("ui_down")):
 | 
					 | 
				
			||||||
		movePos.y = movePos.y + 1
 | 
					 | 
				
			||||||
	if(Input.is_action_just_pressed("ui_right")):
 | 
					 | 
				
			||||||
		movePos.x = movePos.x + 1
 | 
					 | 
				
			||||||
	if(Input.is_action_just_pressed("ui_left")):
 | 
					 | 
				
			||||||
		movePos.x = movePos.x - 1
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if movePos != Vector2.ZERO:
 | 
					func lock_input():
 | 
				
			||||||
		$"/root/NetworkManager".move_player(movePos.x, movePos.y)
 | 
						input_locks = input_locks + 1
 | 
				
			||||||
 | 
					func unlock_input():
 | 
				
			||||||
 | 
						input_locks = input_locks - 1
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										3
									
								
								client/scripts/singletons/ImportantEntities.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								client/scripts/singletons/ImportantEntities.gd
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,3 @@
 | 
				
			|||||||
 | 
					extends Node
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var main_player : KinematicBody2D = null
 | 
				
			||||||
@ -17,28 +17,19 @@ func _on_world_update():
 | 
				
			|||||||
				var tile_data = tileUpdate.split(',')
 | 
									var tile_data = tileUpdate.split(',')
 | 
				
			||||||
				if ':' in tile_data[2]:
 | 
									if ':' in tile_data[2]:
 | 
				
			||||||
					var pos : Vector2 = $Tiles.map_to_world(Vector2(int(tile_data[0]), int(tile_data[1])))
 | 
										var pos : Vector2 = $Tiles.map_to_world(Vector2(int(tile_data[0]), int(tile_data[1])))
 | 
				
			||||||
					if 'player:' in tile_data[2]:
 | 
										var entity_data = tile_data[2].split(':')
 | 
				
			||||||
						print(tile_data)
 | 
										update_entity(entity_data[1], pos, entity_data[0])
 | 
				
			||||||
						var player_name = tile_data[2].substr(len('player:'))
 | 
					 | 
				
			||||||
						print(player_name)
 | 
					 | 
				
			||||||
						if $"/root/NetworkManager".username == player_name:
 | 
					 | 
				
			||||||
							$Player.position = pos
 | 
					 | 
				
			||||||
						else:
 | 
					 | 
				
			||||||
							update_entity(player_name, pos, "player")
 | 
					 | 
				
			||||||
					else:
 | 
					 | 
				
			||||||
						var entity_data = tile_data[2].split(':')
 | 
					 | 
				
			||||||
						update_entity(entity_data[1], pos, entity_data[0])
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
				else:
 | 
									else:
 | 
				
			||||||
					$Tiles.set_cell(int(tile_data[0]), int(tile_data[1]), int(tile_data[2]))
 | 
										$Tiles.set_cell(int(tile_data[0]), int(tile_data[1]), int(tile_data[2]))
 | 
				
			||||||
	if $Loading != null:
 | 
						if get_node_or_null("Loading") != null:
 | 
				
			||||||
		$Loading.queue_free()
 | 
							$Loading.queue_free()
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
func display_error(error):
 | 
					func display_error(error):
 | 
				
			||||||
	print("Error " + error)
 | 
						print("Error " + error)
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
func update_entity(entity_id : String, pos : Vector2, type : String):
 | 
					func update_entity(entity_id : String, pos : Vector2, type : String):
 | 
				
			||||||
	var entity : Node2D = get_node_or_null( str(type + "-" + entity_id))
 | 
						var entity : Node2D = get_node_or_null( str(type + "-" + entity_id))	
 | 
				
			||||||
	if not entity:
 | 
						if not entity:
 | 
				
			||||||
		var entity_location = "res://nodes/entities/" + type + ".tscn"
 | 
							var entity_location = "res://nodes/entities/" + type + ".tscn"
 | 
				
			||||||
		if File.new().file_exists(entity_location):
 | 
							if File.new().file_exists(entity_location):
 | 
				
			||||||
@ -46,6 +37,9 @@ func update_entity(entity_id : String, pos : Vector2, type : String):
 | 
				
			|||||||
			entity = gobj.instance()
 | 
								entity = gobj.instance()
 | 
				
			||||||
			add_child(entity, true)
 | 
								add_child(entity, true)
 | 
				
			||||||
			entity.set_name(str(type + "-" + entity_id))
 | 
								entity.set_name(str(type + "-" + entity_id))
 | 
				
			||||||
 | 
								if type == "player":
 | 
				
			||||||
 | 
									if entity_id == $"/root/NetworkManager".username:
 | 
				
			||||||
 | 
										entity.set_main()
 | 
				
			||||||
		else:
 | 
							else:
 | 
				
			||||||
			display_error("Trying to load entity of type: " + type + ", but failed.")
 | 
								display_error("Trying to load entity of type: " + type + ", but failed.")
 | 
				
			||||||
	if entity:
 | 
						if entity:
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										37
									
								
								client/scripts/systems/chatbox.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								client/scripts/systems/chatbox.gd
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,37 @@
 | 
				
			|||||||
 | 
					extends Control
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const MESSAGE_TIMEOUT : int = 17
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var locking = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _ready():
 | 
				
			||||||
 | 
						$"/root/NetworkManager".connect("chat_message_recieved", self, "_on_new_message")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _on_new_message(message):
 | 
				
			||||||
 | 
						print(message)
 | 
				
			||||||
 | 
						var message_block : Label = Label.new()
 | 
				
			||||||
 | 
						message_block.text = message
 | 
				
			||||||
 | 
						var timer = Timer.new()
 | 
				
			||||||
 | 
						timer.connect("timeout", message_block, "queue_free")
 | 
				
			||||||
 | 
						message_block.add_child(timer)
 | 
				
			||||||
 | 
						$Messages.add_child(message_block)
 | 
				
			||||||
 | 
						timer.start(MESSAGE_TIMEOUT)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func _process(delta):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if $LineEdit.has_focus() != locking:
 | 
				
			||||||
 | 
							locking = $LineEdit.has_focus()
 | 
				
			||||||
 | 
							if locking:
 | 
				
			||||||
 | 
								$"/root/ImportantEntities".main_player.lock_input()
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
 | 
								$"/root/ImportantEntities".main_player.unlock_input()
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						if(Input.is_action_just_pressed("send_chat_message")):
 | 
				
			||||||
 | 
							if $LineEdit.has_focus():
 | 
				
			||||||
 | 
								if len($LineEdit.text) > 0:
 | 
				
			||||||
 | 
									$"/root/NetworkManager".send_chat_message($LineEdit.text)
 | 
				
			||||||
 | 
									$LineEdit.text = ""
 | 
				
			||||||
 | 
								$LineEdit.release_focus()
 | 
				
			||||||
 | 
							else:
 | 
				
			||||||
 | 
								$LineEdit.grab_focus()
 | 
				
			||||||
@ -76,7 +76,7 @@ void Authenticate(ENetEvent* event)
 | 
				
			|||||||
        usernames[peer_id] = username;
 | 
					        usernames[peer_id] = username;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Spawn entity
 | 
					        //Spawn entity
 | 
				
			||||||
        std::string spawn_data = gamemap.spawn_entity(usernames[peer_id], "player", 127, 127);
 | 
					        std::string spawn_data = gamemap.spawn_entity(usernames[peer_id], "player", 128, 129);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //Tell peers about new player
 | 
					        //Tell peers about new player
 | 
				
			||||||
        data = ("2|" + spawn_data).c_str();
 | 
					        data = ("2|" + spawn_data).c_str();
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user