Implemented player controller in client
This commit is contained in:
parent
5b022e17fa
commit
9d14a42388
@ -0,0 +1,3 @@
|
||||
source_md5="8aa11b5093dfa6e5ad8586cfd48b6e88"
|
||||
dest_md5="1922a2eba76828665cd680a720666fe8"
|
||||
|
Binary file not shown.
BIN
client/art/entities/player/dev_player.aseprite
Normal file
BIN
client/art/entities/player/dev_player.aseprite
Normal file
Binary file not shown.
BIN
client/art/entities/player/dev_player.png
Normal file
BIN
client/art/entities/player/dev_player.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 545 B |
34
client/art/entities/player/dev_player.png.import
Normal file
34
client/art/entities/player/dev_player.png.import
Normal file
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="StreamTexture"
|
||||
path="res://.import/dev_player.png-a3e490acef445550df71bca0ea3173dc.stex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://art/entities/player/dev_player.png"
|
||||
dest_files=[ "res://.import/dev_player.png-a3e490acef445550df71bca0ea3173dc.stex" ]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_mode=0
|
||||
compress/bptc_ldr=0
|
||||
compress/normal_map=0
|
||||
flags/repeat=0
|
||||
flags/filter=false
|
||||
flags/mipmaps=false
|
||||
flags/anisotropic=false
|
||||
flags/srgb=2
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/HDR_as_SRGB=false
|
||||
process/invert_color=false
|
||||
stream=false
|
||||
size_limit=0
|
||||
detect_3d=true
|
||||
svg/scale=1.0
|
@ -7,7 +7,7 @@ custom_features=""
|
||||
export_filter="all_resources"
|
||||
include_filter=""
|
||||
exclude_filter=""
|
||||
export_path=""
|
||||
export_path="builds/Family.x86_64"
|
||||
patch_list=PoolStringArray( )
|
||||
script_export_mode=1
|
||||
script_encryption_key=""
|
||||
|
8
client/nodes/Systems/PlayerPuppeteer.tscn
Normal file
8
client/nodes/Systems/PlayerPuppeteer.tscn
Normal file
@ -0,0 +1,8 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://scripts/systems/PlayerPuppeteer.gd" type="Script" id=1]
|
||||
[ext_resource path="res://nodes/entities/PlayerPuppet.tscn" type="PackedScene" id=2]
|
||||
|
||||
[node name="PlayerPuppeteer" type="Node2D"]
|
||||
script = ExtResource( 1 )
|
||||
puppet_template = ExtResource( 2 )
|
21
client/nodes/entities/Player.tscn
Normal file
21
client/nodes/entities/Player.tscn
Normal file
@ -0,0 +1,21 @@
|
||||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://art/entities/player/dev_player.png" type="Texture" id=1]
|
||||
[ext_resource path="res://scripts/entities/Player.gd" type="Script" id=2]
|
||||
|
||||
[node name="Player" type="KinematicBody2D"]
|
||||
script = ExtResource( 2 )
|
||||
__meta__ = {
|
||||
"_edit_group_": true
|
||||
}
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="."]
|
||||
current = true
|
||||
zoom = Vector2( 0.5, 0.5 )
|
||||
|
||||
[node name="Line2D" type="Line2D" parent="."]
|
||||
width = 4.0
|
||||
default_color = Color( 1, 0, 0, 1 )
|
6
client/nodes/entities/PlayerPuppet.tscn
Normal file
6
client/nodes/entities/PlayerPuppet.tscn
Normal file
@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://art/entities/player/dev_player.png" type="Texture" id=1]
|
||||
|
||||
[node name="PlayerPuppet" type="Sprite"]
|
||||
texture = ExtResource( 1 )
|
File diff suppressed because it is too large
Load Diff
@ -107,6 +107,14 @@ config/icon="res://icon.png"
|
||||
Nakama="*res://addons/com.heroiclabs.nakama/Nakama.gd"
|
||||
ServerConnection="*res://scripts/singletons/ServerConnection.gd"
|
||||
|
||||
[input]
|
||||
|
||||
move_to_cursor={
|
||||
"deadzone": 0.5,
|
||||
"events": [ Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"button_mask":0,"position":Vector2( 0, 0 ),"global_position":Vector2( 0, 0 ),"factor":1.0,"button_index":1,"pressed":false,"doubleclick":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[rendering]
|
||||
|
||||
quality/driver/driver_name="GLES2"
|
||||
|
File diff suppressed because one or more lines are too long
38
client/scripts/entities/Player.gd
Normal file
38
client/scripts/entities/Player.gd
Normal file
@ -0,0 +1,38 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
signal finished_moving
|
||||
|
||||
export var base_movement_speed = 100
|
||||
export(NodePath) var world
|
||||
|
||||
onready var navigation : Navigation2D = get_node(world)
|
||||
var path : PoolVector2Array
|
||||
var move : bool = false
|
||||
|
||||
func _process(delta):
|
||||
|
||||
# Click for movement target
|
||||
if Input.is_action_just_pressed("move_to_cursor"):
|
||||
path = navigation.get_simple_path(global_position, get_global_mouse_position())
|
||||
move = true
|
||||
|
||||
if move:
|
||||
move_along_path(base_movement_speed * delta)
|
||||
|
||||
func move_along_path(distance : float):
|
||||
var start_point := global_position
|
||||
for i in range(path.size()):
|
||||
var distance_to_next := start_point.distance_to(path[0])
|
||||
if distance <= distance_to_next and distance >= 0.0:
|
||||
global_position = start_point.linear_interpolate(path[0], distance/distance_to_next)
|
||||
break
|
||||
elif distance < 0.0:
|
||||
global_position = path[0]
|
||||
emit_signal("finished_moving")
|
||||
print("DONE")
|
||||
move = false
|
||||
break
|
||||
distance -= distance_to_next
|
||||
start_point = path[0]
|
||||
path.remove(0)
|
||||
|
@ -1,6 +1,9 @@
|
||||
extends Node
|
||||
|
||||
signal tile_update(tile_data)
|
||||
signal player_joined(user_id)
|
||||
signal player_left(user_id)
|
||||
signal player_pos_update(user_id, pos)
|
||||
|
||||
const KEY := "defaultkey"
|
||||
const SERVER_ENDPOINT := "nakama.cloudsumu.com"
|
||||
@ -9,9 +12,11 @@ var _session : NakamaSession
|
||||
var _client : NakamaClient = Nakama.create_client(KEY, SERVER_ENDPOINT, 7350, "http")
|
||||
var _socket : NakamaSocket
|
||||
var _precenses : Dictionary = {}
|
||||
var _world_id
|
||||
|
||||
enum OPCODE {
|
||||
tile_update = 1
|
||||
tile_update = 1,
|
||||
update_position = 2
|
||||
}
|
||||
|
||||
func authenticate_async(email : String, password : String) -> NakamaException:
|
||||
@ -43,6 +48,7 @@ func connect_to_server_async() -> NakamaException:
|
||||
var result : NakamaAsyncResult = yield(_socket.connect_async(_session), "completed")
|
||||
if not result.is_exception():
|
||||
_socket.connect("received_match_state", self, "_on_socket_received_match_state")
|
||||
_socket.connect("received_match_presence", self, "_on_received_match_presence")
|
||||
_socket.connect("closed", self, "_on_socket_closed")
|
||||
return null
|
||||
return result.exception
|
||||
@ -57,9 +63,12 @@ func join_world_async() -> Dictionary:
|
||||
if match_join_result.is_exception():
|
||||
print("Join match error: %s - %s" % [match_join_result.exception.status_code, match_join_result.exception.message])
|
||||
return {}
|
||||
|
||||
_world_id = world.payload
|
||||
|
||||
for precense in match_join_result.presences:
|
||||
_precenses[precense.user_id] = precense
|
||||
emit_signal("player_joined", precense.user_id)
|
||||
|
||||
print("Joined matched with %s other players!" % _precenses.size())
|
||||
|
||||
@ -67,9 +76,26 @@ func join_world_async() -> Dictionary:
|
||||
|
||||
func _on_socket_closed():
|
||||
_socket = null
|
||||
|
||||
|
||||
func _on_received_match_presence(match_precense : NakamaRTAPI.MatchPresenceEvent):
|
||||
for precense in match_precense.joins:
|
||||
print("%s joined the game!" % precense.username)
|
||||
_precenses[precense.user_id] = precense
|
||||
emit_signal("player_joined", precense.user_id)
|
||||
|
||||
for precense in match_precense.leaves:
|
||||
print("%s left the game!" % precense.username)
|
||||
_precenses.erase(precense.user_id)
|
||||
emit_signal("player_left", precense.user_id)
|
||||
|
||||
func _on_socket_received_match_state(match_state: NakamaRTAPI.MatchData):
|
||||
match match_state.op_code:
|
||||
OPCODE.tile_update:
|
||||
emit_signal("tile_update", JSON.parse(match_state.data).result)
|
||||
OPCODE.update_position:
|
||||
var pos_data = JSON.parse(match_state.data).result
|
||||
emit_signal("player_pos_update", pos_data["player"], Vector2(float(pos_data["x"]), float(pos_data["y"])))
|
||||
|
||||
func send_player_position(position : Vector2) -> void:
|
||||
_socket.send_match_state_async(_world_id, OPCODE.update_position, JSON.print({X = str(position.x), Y = str(position.y)}))
|
||||
|
||||
|
31
client/scripts/systems/PlayerPuppeteer.gd
Normal file
31
client/scripts/systems/PlayerPuppeteer.gd
Normal file
@ -0,0 +1,31 @@
|
||||
extends Node2D
|
||||
|
||||
export(NodePath) var puppet_parent
|
||||
export(Resource) var puppet_template
|
||||
|
||||
onready var puppet_parent_node : Node = get_node(puppet_parent)
|
||||
|
||||
var puppets : Dictionary = {}
|
||||
|
||||
func _ready():
|
||||
ServerConnection.connect("player_joined", self, "on_player_join")
|
||||
ServerConnection.connect("player_left", self, "on_player_leave")
|
||||
ServerConnection.connect("player_pos_update", self, "on_player_pos_update")
|
||||
|
||||
|
||||
func on_player_join(user_id):
|
||||
if user_id != ServerConnection._session.user_id:
|
||||
var new_puppet : Node = puppet_template.instance()
|
||||
new_puppet.name = "Player: " + user_id
|
||||
puppet_parent_node.add_child(new_puppet)
|
||||
puppets[user_id] = new_puppet
|
||||
|
||||
func on_player_leave(user_id):
|
||||
if user_id != ServerConnection._session.user_id:
|
||||
var player_puppet : Node = puppets[user_id]
|
||||
player_puppet.queue_free()
|
||||
|
||||
func on_player_pos_update(user_id, pos):
|
||||
if user_id != ServerConnection._session.user_id:
|
||||
var player_puppet : Node2D = puppets[user_id]
|
||||
player_puppet.global_position = pos
|
Reference in New Issue
Block a user