From 6726982ee64932839bc7834fc58966777ed32b7f Mon Sep 17 00:00:00 2001 From: Joseph Manley Date: Mon, 4 May 2020 02:45:04 -0400 Subject: [PATCH] Client changes and tweaks --- client/nodes/entities/player.tscn | 3 ++ client/project.godot | 29 ++++++++++++ client/scenes/game.scn | Bin 1882 -> 1789 bytes client/scripts/entities/Player.gd | 42 ++++++++++++------ .../scripts/singletons/ImportantEntities.gd | 3 ++ client/scripts/systems/WorldManager.gd | 20 +++------ client/scripts/systems/chatbox.gd | 37 +++++++++++++++ server/gameserver.hpp | 2 +- 8 files changed, 109 insertions(+), 27 deletions(-) create mode 100644 client/scripts/singletons/ImportantEntities.gd create mode 100644 client/scripts/systems/chatbox.gd diff --git a/client/nodes/entities/player.tscn b/client/nodes/entities/player.tscn index 94b4467..240ff1e 100644 --- a/client/nodes/entities/player.tscn +++ b/client/nodes/entities/player.tscn @@ -33,3 +33,6 @@ valign = 1 __meta__ = { "_edit_use_anchors_": false } + +[node name="Camera" type="Camera2D" parent="."] +zoom = Vector2( 0.5, 0.5 ) diff --git a/client/project.godot b/client/project.godot index e36439a..555412c 100644 --- a/client/project.godot +++ b/client/project.godot @@ -23,9 +23,38 @@ config/icon="res://icon.png" MusicManager="*res://nodes/MusicManager.tscn" NetworkManager="*res://nodes/NetworkManager.tscn" +ImportantEntities="*res://scripts/singletons/ImportantEntities.gd" [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={ "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) diff --git a/client/scenes/game.scn b/client/scenes/game.scn index e050f0f413f9db86873ead54b0a62c3b369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VA-&6`Ra3PVwLpF)>2n_L^6AoypDjurLBy`G+53Skdb+9EabJ;;fK9 z^Z;pOofVEw0PI6Ticz|$i0c#k>k-tR+<&yNe4XntMKsgz_P_*bZ(bTxDhLIBrM-|C zbdDe__E_;QtxILaEP_sgguZHiQr*>reO=pVFEA)6+dl zQcY(Ai(kzzI6ujSNQQiLv3-R7ve*}rp-x(HW(=d(!{n*k`bFa2PM2JI36#u7s|UQg>G)SSf228c{Qd0c(U`ZfR4J^xk{-vIi~zEdVb zumFNgpm2R2R;BY~GSOrYBn~Wh$-0c~bP5uLC>~HqUhv3k%nKC@1B>lAZ?i$zG@E^% z<*+T&AoDO^rrFv~v*v*xL8I1)0SAG<0JUZe2mk>tDiuV2qz1J%@E-Jux-_3>Ncwb+iBN$2poGLsxE~CUdnnwL@?J z`7S9k|M;K}wLE#e%Ai}Aw!@+O-5k3M5jsafO!{2pr_}2_+2kMm9JC;?@@4FFvr0Lw z=fre?_?$Wv$PEzIhobcKiX8mX&dF1(|4MuVwxRlYjE2nPX`wO(>0+A-R#psd?L~@w zLj;tzcnvX><6w14q!|<$6|Ax`d3NZK%4~$ky^%@}pOmPjAuYtwJ-Zm+&&j*!%p+f! z$MQ1F%Y8W~?^5$~crH1IWQ+G=W}ElyVSef78OrFAP8Z|jO@pTu*gdZ>7FGW0W8m4# UQ^n6hzG#H-Tx|B&4^mS@LmHZN7XSbN diff --git a/client/scripts/entities/Player.gd b/client/scripts/entities/Player.gd index 280df2e..884d390 100644 --- a/client/scripts/entities/Player.gd +++ b/client/scripts/entities/Player.gd @@ -1,27 +1,43 @@ extends KinematicBody2D 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(): + $Camera.hide() set_username("") func set_username(username): - print(username) user = username $Label.text = user 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(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: + $"/root/NetworkManager".move_player(movePos.x, movePos.y) - if movePos != Vector2.ZERO: - $"/root/NetworkManager".move_player(movePos.x, movePos.y) +func lock_input(): + input_locks = input_locks + 1 +func unlock_input(): + input_locks = input_locks - 1 diff --git a/client/scripts/singletons/ImportantEntities.gd b/client/scripts/singletons/ImportantEntities.gd new file mode 100644 index 0000000..11b6f86 --- /dev/null +++ b/client/scripts/singletons/ImportantEntities.gd @@ -0,0 +1,3 @@ +extends Node + +var main_player : KinematicBody2D = null diff --git a/client/scripts/systems/WorldManager.gd b/client/scripts/systems/WorldManager.gd index 16605a0..85fc6b6 100644 --- a/client/scripts/systems/WorldManager.gd +++ b/client/scripts/systems/WorldManager.gd @@ -17,28 +17,19 @@ func _on_world_update(): var tile_data = tileUpdate.split(',') if ':' in tile_data[2]: var pos : Vector2 = $Tiles.map_to_world(Vector2(int(tile_data[0]), int(tile_data[1]))) - if 'player:' in tile_data[2]: - print(tile_data) - 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]) + var entity_data = tile_data[2].split(':') + update_entity(entity_data[1], pos, entity_data[0]) else: $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() func display_error(error): print("Error " + error) 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: var entity_location = "res://nodes/entities/" + type + ".tscn" if File.new().file_exists(entity_location): @@ -46,6 +37,9 @@ func update_entity(entity_id : String, pos : Vector2, type : String): entity = gobj.instance() add_child(entity, true) entity.set_name(str(type + "-" + entity_id)) + if type == "player": + if entity_id == $"/root/NetworkManager".username: + entity.set_main() else: display_error("Trying to load entity of type: " + type + ", but failed.") if entity: diff --git a/client/scripts/systems/chatbox.gd b/client/scripts/systems/chatbox.gd new file mode 100644 index 0000000..b699109 --- /dev/null +++ b/client/scripts/systems/chatbox.gd @@ -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() diff --git a/server/gameserver.hpp b/server/gameserver.hpp index e0e20cb..4c4f273 100644 --- a/server/gameserver.hpp +++ b/server/gameserver.hpp @@ -76,7 +76,7 @@ void Authenticate(ENetEvent* event) usernames[peer_id] = username; //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 data = ("2|" + spawn_data).c_str();