mirror of
https://git.tonybark.com/tonytins/legendsonline.git
synced 2025-06-25 10:24:44 -04:00
Basic TCP connections
This commit is contained in:
parent
cd3ef1c3da
commit
60d28a2879
20 changed files with 968 additions and 30 deletions
15
client/source/GameKit.gd
Normal file
15
client/source/GameKit.gd
Normal file
|
@ -0,0 +1,15 @@
|
|||
extends Node
|
||||
|
||||
const NOT_IMPLEMENTED = "This feature is not implemented"
|
||||
|
||||
func is_game_paused(is_paused):
|
||||
if is_paused == true:
|
||||
get_tree().paused = true
|
||||
else:
|
||||
get_tree().paused = false
|
||||
|
||||
func switch_scenes(is_mode):
|
||||
if is_mode == "title":
|
||||
get_tree().change_scene_to_file("res://scenes/TitleScn.tscn")
|
||||
elif is_mode == "game":
|
||||
get_tree().change_scene_to_file("res://scenes/GameScn.tscn")
|
34
client/source/GameScn.gd
Normal file
34
client/source/GameScn.gd
Normal file
|
@ -0,0 +1,34 @@
|
|||
extends Node
|
||||
|
||||
var client: StreamPeerTCP
|
||||
|
||||
func _ready() -> void:
|
||||
GameKit.is_game_paused(false)
|
||||
await get_tree().create_timer(1).timeout
|
||||
connect_to_server()
|
||||
|
||||
func _process(delta):
|
||||
if client == null:
|
||||
return
|
||||
|
||||
client.poll()
|
||||
|
||||
if client.get_status() != StreamPeerTCP.STATUS_CONNECTED:
|
||||
return
|
||||
|
||||
if Input.is_action_pressed("ui_pause"):
|
||||
GameKit.is_game_paused(true)
|
||||
$PauseScn/PauseWin.move_to_center();
|
||||
$PauseScn/PauseWin.show()
|
||||
|
||||
func connect_to_server() -> void:
|
||||
client = StreamPeerTCP.new()
|
||||
var err = client.connect_to_host("127.0.0.1", 1337)
|
||||
if err != OK:
|
||||
print(err)
|
||||
|
||||
func _on_timer_timeout() -> void:
|
||||
if client.get_status() != StreamPeerTCP.STATUS_CONNECTED:
|
||||
return
|
||||
|
||||
client.put_data("This is Legends Online.".to_utf8_buffer())
|
15
client/source/PauseScn.gd
Normal file
15
client/source/PauseScn.gd
Normal file
|
@ -0,0 +1,15 @@
|
|||
extends Control
|
||||
|
||||
func _resume_game() -> void:
|
||||
$PauseWin.hide()
|
||||
GameKit.is_game_paused(false)
|
||||
|
||||
func _on_resume_btn_pressed() -> void:
|
||||
_resume_game()
|
||||
|
||||
func _on_exit_btn_pressed() -> void:
|
||||
GameKit.is_game_paused(false)
|
||||
GameKit.switch_scenes("title")
|
||||
|
||||
func _on_pause_win_close_requested() -> void:
|
||||
_resume_game()
|
4
client/source/TitleScn.gd
Normal file
4
client/source/TitleScn.gd
Normal file
|
@ -0,0 +1,4 @@
|
|||
extends Node
|
||||
|
||||
func _on_PlayBtn_pressed():
|
||||
GameKit.switch_scenes("game")
|
Loading…
Add table
Add a link
Reference in a new issue