Client changes and tweaks

This commit is contained in:
Layla 2020-05-04 02:45:04 -04:00
parent 0e2eb924c7
commit 6726982ee6
No known key found for this signature in database
GPG Key ID: A494D9357BA1BE31
8 changed files with 109 additions and 27 deletions

View File

@ -33,3 +33,6 @@ valign = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Camera" type="Camera2D" parent="."]
zoom = Vector2( 0.5, 0.5 )

View File

@ -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)

Binary file not shown.

View File

@ -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

View File

@ -0,0 +1,3 @@
extends Node
var main_player : KinematicBody2D = null

View File

@ -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:

View 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()

View File

@ -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();