This commit is contained in:
Daniel Flanagan 2021-12-08 16:35:37 -06:00
parent cdd3a00186
commit b091f58636
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4
24 changed files with 14800 additions and 187 deletions

View file

@ -0,0 +1,29 @@
[remap]
importer="font_data_dynamic"
type="FontData"
uid="uid://cklw0gsblqjmg"
path="res://.godot/imported/iosevkalyte-regular.ttf-a2a88ad4f5b4e12dda9997dfa2756a6e.fontdata"
[deps]
source_file="res://assets/fonts/iosevkalyte/iosevkalyte-regular.ttf"
dest_files=["res://.godot/imported/iosevkalyte-regular.ttf-a2a88ad4f5b4e12dda9997dfa2756a6e.fontdata"]
[params]
antialiased=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
force_autohinter=false
hinting=1
oversampling=0.0
compress=true
preload/char_ranges=PackedStringArray()
preload/glyph_ranges=PackedStringArray()
preload/configurations=PackedStringArray()
support_overrides/language_enabled=PackedStringArray()
support_overrides/language_disabled=PackedStringArray()
support_overrides/script_enabled=PackedStringArray()
support_overrides/script_disabled=PackedStringArray()

BIN
assets/img/panel.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 676 B

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/panel.png-13859c06a04f6a7402b47e151aade45d.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/img/panel.png"
dest_files=[ "res://.import/panel.png-13859c06a04f6a7402b47e151aade45d.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=true
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
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/spaced-dungeon-tileset.png-59e295f606be654ab4ad304c968ca581.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/img/spaced-dungeon-tileset.png"
dest_files=[ "res://.import/spaced-dungeon-tileset.png-59e295f606be654ab4ad304c968ca581.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=true
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
process/normal_map_invert_y=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

File diff suppressed because one or more lines are too long

10
objects/bar.tscn Normal file
View file

@ -0,0 +1,10 @@
[gd_scene format=2]
[node name="bar" type="ProgressBar"]
anchor_right = 1.0
anchor_bottom = 1.0
value = 50.0
percent_visible = false
__meta__ = {
"_edit_use_anchors_": false
}

View file

@ -5,16 +5,26 @@
[node name="Control" type="HBoxContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 0
size_flags_horizontal = 3
size_flags_vertical = 0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Button" type="Button" parent="."]
margin_right = 50.0
margin_bottom = 600.0
rect_min_size = Vector2( 50, 0 )
text = "Join"
[node name="Label" type="Label" parent="."]
margin_left = 54.0
margin_right = 1024.0
margin_bottom = 600.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Lobby Name"
valign = 1
[connection signal="pressed" from="Button" to="." method="_on_join_pressed"]

31
objects/peer.tscn Normal file
View file

@ -0,0 +1,31 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://scripts/objects/peer.gd" type="Script" id=1]
[ext_resource path="res://assets/img/check.png" type="Texture" id=2]
[node name="Control" type="HBoxContainer"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 3
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TextureRect" type="TextureRect" parent="."]
margin_right = 24.0
margin_bottom = 600.0
rect_min_size = Vector2( 24, 24 )
size_flags_vertical = 11
texture = ExtResource( 2 )
expand = true
stretch_mode = 6
[node name="Label" type="Label" parent="."]
margin_left = 28.0
margin_right = 1024.0
margin_bottom = 600.0
size_flags_horizontal = 3
size_flags_vertical = 11
text = "Lobby Name"
valign = 1

131
objects/player.tscn Normal file
View file

@ -0,0 +1,131 @@
[gd_scene load_steps=16 format=2]
[ext_resource path="res://assets/img/spaced-dungeon-tileset.png" type="Texture" id=1]
[ext_resource path="res://objects/bar.tscn" type="PackedScene" id=3]
[ext_resource path="res://scripts/objects/player.gd" type="Script" id=10]
[sub_resource type="AtlasTexture" id=1]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 0, 468, 18, 36 )
[sub_resource type="AtlasTexture" id=2]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 18, 468, 18, 36 )
[sub_resource type="AtlasTexture" id=3]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 36, 468, 18, 36 )
[sub_resource type="AtlasTexture" id=4]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 54, 468, 18, 36 )
[sub_resource type="AtlasTexture" id=9]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 144, 468, 18, 36 )
[sub_resource type="AtlasTexture" id=5]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 72, 468, 18, 36 )
[sub_resource type="AtlasTexture" id=6]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 90, 468, 18, 36 )
[sub_resource type="AtlasTexture" id=7]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 108, 468, 18, 36 )
[sub_resource type="AtlasTexture" id=8]
flags = 4
atlas = ExtResource( 1 )
region = Rect2( 126, 468, 18, 36 )
[sub_resource type="SpriteFrames" id=10]
animations = [ {
"frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ) ],
"loop": true,
"name": "idle",
"speed": 6.0
}, {
"frames": [ SubResource( 9 ) ],
"loop": true,
"name": "hurt",
"speed": 5.0
}, {
"frames": [ SubResource( 5 ), SubResource( 6 ), SubResource( 7 ), SubResource( 8 ) ],
"loop": true,
"name": "run",
"speed": 12.0
} ]
[sub_resource type="ConvexPolygonShape2D" id=11]
points = PoolVector2Array( -2, 4, 2, 4, 6, 1, 6, -1, 1, -4, -1, -4, -6, -1, -6, 1 )
[sub_resource type="StyleBoxFlat" id=12]
bg_color = Color( 0, 0.25098, 1, 1 )
[node name="player" type="KinematicBody2D" groups=["destructable"]]
script = ExtResource( 10 )
[node name="sprite" type="AnimatedSprite" parent="."]
modulate = Color( 0.384314, 0.796078, 1, 1 )
position = Vector2( 0, -18 )
frames = SubResource( 10 )
animation = "idle"
frame = 1
playing = true
[node name="collider" type="CollisionShape2D" parent="."]
position = Vector2( 0, -6.5 )
scale = Vector2( 1, 1.6 )
shape = SubResource( 11 )
[node name="player_name" type="Label" parent="."]
margin_left = -21.0
margin_right = 21.0
margin_bottom = 25.0
text = "player_name"
align = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="bars" type="VBoxContainer" parent="."]
margin_left = -18.0
margin_top = -26.0
margin_right = 18.0
margin_bottom = -20.0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_constants/separation = 0
alignment = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="health_bar" parent="bars" instance=ExtResource( 3 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 36.0
margin_bottom = 3.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="mana_bar" parent="bars" instance=ExtResource( 3 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_top = 3.0
margin_right = 36.0
margin_bottom = 6.0
size_flags_horizontal = 3
size_flags_vertical = 3
custom_styles/fg = SubResource( 12 )

View file

@ -8,6 +8,22 @@
config_version=4
_global_script_classes=[ {
"base": "HBoxContainer",
"class": "LobbyControl",
"language": "GDScript",
"path": "res://scripts/objects/lobby.gd"
}, {
"base": "HBoxContainer",
"class": "PeerControl",
"language": "GDScript",
"path": "res://scripts/objects/peer.gd"
} ]
_global_script_class_icons={
"LobbyControl": "",
"PeerControl": ""
}
[application]
config/name="kdt"

View file

@ -1,8 +1,7 @@
[gd_scene load_steps=4 format=2]
[gd_scene load_steps=3 format=2]
[ext_resource path="res://scripts/screens/lobby_browser.gd" type="Script" id=1]
[ext_resource path="res://assets/theme.tres" type="Theme" id=2]
[ext_resource path="res://objects/lobby.tscn" type="PackedScene" id=3]
[node name="Control" type="MarginContainer"]
anchor_right = 1.0
@ -36,7 +35,7 @@ __meta__ = {
}
[node name="back" type="Button" parent="v/head"]
margin_right = 325.0
margin_right = 490.0
margin_bottom = 50.0
grow_horizontal = 2
grow_vertical = 2
@ -50,8 +49,8 @@ __meta__ = {
}
[node name="create_lobby" type="Button" parent="v/head"]
margin_left = 329.0
margin_right = 654.0
margin_left = 494.0
margin_right = 984.0
margin_bottom = 50.0
rect_min_size = Vector2( 150, 50 )
hint_tooltip = "Create your own public lobby that any player may join"
@ -62,20 +61,8 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="join" type="Button" parent="v/head"]
margin_left = 658.0
margin_right = 984.0
margin_bottom = 50.0
rect_min_size = Vector2( 150, 50 )
hint_tooltip = "Join the highlighted lobby ID below"
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Join"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="subhead" type="HBoxContainer" parent="v"]
visible = false
margin_top = 54.0
margin_right = 984.0
margin_bottom = 85.0
@ -96,29 +83,43 @@ rect_min_size = Vector2( 150, 0 )
placeholder_text = "Your Name Here"
[node name="body" type="ScrollContainer" parent="v"]
margin_top = 89.0
margin_top = 54.0
margin_right = 984.0
margin_bottom = 560.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="lobbies" type="ItemList" parent="v/body"]
[node name="p" type="PanelContainer" parent="v/body"]
margin_right = 984.0
margin_bottom = 471.0
hint_tooltip = "You can double-click a lobby listing to join it."
margin_bottom = 506.0
size_flags_horizontal = 3
size_flags_vertical = 3
same_column_width = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Control" parent="v/body/lobbies" instance=ExtResource( 3 )]
[node name="lobbies" type="GridContainer" parent="v/body/p"]
margin_left = 7.0
margin_top = 7.0
margin_right = 977.0
margin_bottom = 499.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="zero_state" type="CenterContainer" parent="v/body/p/lobbies"]
margin_right = 970.0
margin_bottom = 492.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="Label" type="Label" parent="v/body/p/lobbies/zero_state"]
margin_left = 229.0
margin_top = 239.0
margin_right = 740.0
margin_bottom = 253.0
size_flags_horizontal = 3
size_flags_vertical = 3
text = "Looks like there are no active lobbies at the moment! Why don't you make one?"
align = 1
valign = 1
[connection signal="pressed" from="v/head/back" to="." method="_on_back_pressed"]
[connection signal="pressed" from="v/head/create_lobby" to="." method="_on_create_lobby_pressed"]
[connection signal="pressed" from="v/head/join" to="." method="_on_join_pressed"]
[connection signal="text_changed" from="v/subhead/display_name" to="." method="_on_display_name_text_changed"]
[connection signal="item_activated" from="v/body/lobbies" to="." method="_on_lobbies_item_activated"]
[connection signal="item_selected" from="v/body/lobbies" to="." method="_on_lobbies_item_selected"]
[connection signal="nothing_selected" from="v/body/lobbies" to="." method="_on_lobbies_nothing_selected"]

View file

@ -1,7 +1,6 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=4 format=2]
[ext_resource path="res://assets/fonts/iosevkalyte/iosevkalyte-regular.ttf" type="DynamicFontData" id=1]
[ext_resource path="res://assets/theme.tres" type="Theme" id=2]
[ext_resource path="res://scripts/screens/main_menu.gd" type="Script" id=3]
[sub_resource type="DynamicFont" id=1]
@ -15,7 +14,6 @@ margin_left = 20.0
margin_top = 20.0
margin_right = -20.0
margin_bottom = -20.0
theme = ExtResource( 2 )
script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
@ -37,7 +35,6 @@ rect_min_size = Vector2( 150, 50 )
hint_tooltip = "Yeah, let's get out of here."
size_flags_horizontal = 3
size_flags_vertical = 3
theme = ExtResource( 2 )
text = "Quit"
__meta__ = {
"_edit_use_anchors_": false
@ -51,7 +48,6 @@ rect_min_size = Vector2( 150, 50 )
hint_tooltip = "This is what you came for!"
size_flags_horizontal = 3
size_flags_vertical = 3
theme = ExtResource( 2 )
text = "Multiplayer"
[node name="Singleplayer" type="Button" parent="VBoxContainer/HBoxContainer"]
@ -64,8 +60,6 @@ hint_tooltip = "This is a multiplayer tech demo, you dunce.
And no, you may not ask why the button is here."
size_flags_horizontal = 3
size_flags_vertical = 3
theme = ExtResource( 2 )
disabled = true
text = "Singleplayer"
__meta__ = {
"_edit_use_anchors_": false
@ -80,9 +74,9 @@ size_flags_vertical = 3
[node name="VBoxContainer" type="VBoxContainer" parent="VBoxContainer/Container"]
margin_left = 124.0
margin_top = 150.0
margin_top = 153.0
margin_right = 859.0
margin_bottom = 356.0
margin_bottom = 352.0
[node name="Label" type="Label" parent="VBoxContainer/Container/VBoxContainer"]
margin_right = 735.0
@ -96,19 +90,19 @@ valign = 1
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Container/VBoxContainer"]
margin_top = 185.0
margin_right = 735.0
margin_bottom = 206.0
margin_bottom = 199.0
alignment = 1
[node name="Label" type="Label" parent="VBoxContainer/Container/VBoxContainer/HBoxContainer"]
margin_left = 305.0
margin_right = 369.0
margin_bottom = 21.0
margin_left = 312.0
margin_right = 371.0
margin_bottom = 14.0
text = "made by "
[node name="LinkButton" type="LinkButton" parent="VBoxContainer/Container/VBoxContainer/HBoxContainer"]
margin_left = 373.0
margin_right = 429.0
margin_bottom = 21.0
margin_left = 375.0
margin_right = 422.0
margin_bottom = 14.0
hint_tooltip = "Open https://lyte.dev"
text = "lytedev"

View file

@ -90,11 +90,11 @@ size_flags_horizontal = 3
size_flags_vertical = 3
[node name="peers" type="VBoxContainer" parent="v/body"]
margin_right = 180.0
margin_right = 194.0
margin_bottom = 506.0
[node name="label" type="Label" parent="v/body/peers"]
margin_right = 180.0
margin_right = 194.0
margin_bottom = 21.0
text = "Players: 1"
valign = 2
@ -102,31 +102,36 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="peers" type="ItemList" parent="v/body/peers"]
[node name="p" type="PanelContainer" parent="v/body/peers"]
margin_top = 25.0
margin_right = 180.0
margin_right = 194.0
margin_bottom = 506.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="peers" type="GridContainer" parent="v/body/peers/p"]
margin_left = 7.0
margin_top = 7.0
margin_right = 187.0
margin_bottom = 474.0
rect_min_size = Vector2( 180, 0 )
size_flags_horizontal = 3
size_flags_vertical = 3
auto_height = true
icon_scale = 0.5
fixed_icon_size = Vector2( 32, 32 )
[node name="v" type="VBoxContainer" parent="v/body"]
margin_left = 184.0
margin_left = 198.0
margin_right = 984.0
margin_bottom = 506.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="chat_head" type="HBoxContainer" parent="v/body/v"]
margin_right = 800.0
margin_right = 786.0
margin_bottom = 40.0
size_flags_horizontal = 3
[node name="label" type="Label" parent="v/body/v/chat_head"]
margin_right = 628.0
margin_right = 614.0
margin_bottom = 40.0
size_flags_horizontal = 3
size_flags_vertical = 3
@ -134,17 +139,17 @@ text = "Chat"
valign = 2
[node name="auto_scroll" type="CheckButton" parent="v/body/v/chat_head"]
margin_left = 632.0
margin_right = 800.0
margin_left = 618.0
margin_right = 786.0
margin_bottom = 40.0
size_flags_horizontal = 0
size_flags_vertical = 3
size_flags_horizontal = 12
size_flags_vertical = 12
pressed = true
text = "Auto Scroll"
[node name="messages" type="TextEdit" parent="v/body/v"]
margin_top = 44.0
margin_right = 800.0
margin_right = 786.0
margin_bottom = 471.0
size_flags_horizontal = 3
size_flags_vertical = 3
@ -157,14 +162,14 @@ caret_block_mode = true
[node name="h" type="HBoxContainer" parent="v/body/v"]
margin_top = 475.0
margin_right = 800.0
margin_right = 786.0
margin_bottom = 506.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="chat" type="LineEdit" parent="v/body/v/h"]
margin_right = 688.0
margin_right = 674.0
margin_bottom = 31.0
size_flags_horizontal = 3
size_flags_vertical = 3
@ -172,8 +177,8 @@ clear_button_enabled = true
placeholder_text = "Compose a chat message here, press Enter to send"
[node name="Button" type="Button" parent="v/body/v/h"]
margin_left = 692.0
margin_right = 800.0
margin_left = 678.0
margin_right = 786.0
margin_bottom = 31.0
size_flags_vertical = 3
text = "Send Message"

View file

@ -33,6 +33,7 @@ func main_menu():
goto_scene("main_menu")
func start_singleplayer_game():
client.fake_singleplayer()
client.close()
goto_scene("game")

View file

@ -30,6 +30,14 @@ func _ready():
# connect("lobby_sealed", self, "lobby_sealed")
add_child(signaller)
func fake_singleplayer():
print("Faking network peer for singleplayer...")
mp.initialize(1, true)
get_tree().network_peer = mp
var peer: WebRTCPeerConnection = WebRTCPeerConnection.new()
peer.initialize()
mp.add_peer(peer, 1)
func close():
mp.close()
signaller.close()
@ -75,7 +83,9 @@ func _peer_id_set(peer_id):
func _peer_joined(peers):
for i in range(len(peers)):
var peer_id = peers[i]["peerId"]
var peer = peers[i]
if peer.has("peerId"):
var peer_id = peer["peerId"]
if not mp.has_peer(peer_id):
_create_peer(peer_id)

View file

@ -162,6 +162,9 @@ func handle_message(data: Dictionary):
"peer_left":
print("Peer Left: %s" % data)
emit_signal("peer_left", data["data"])
"ready_change":
print("Peer Ready Change")
emit_signal("peer_joined", [data])
"candidate":
print("Candidate received - Data: %s" % JSON.print(data["data"]))

View file

@ -1,7 +1,9 @@
extends HBoxContainer
class_name LobbyControl
export(String) var id = "Some UUID"
export(String) var text = "Lobby" setget set_text
export(String) var display_name = "Lobby" setget set_display_name
export(int) var max_players = 20 setget set_max_players
export(int) var current_players = 1 setget set_current_players
export(bool) var locked = false
@ -10,10 +12,17 @@ func _ready():
_update_text()
func _update_text():
$Label.text = "%s (%d/%d players)" % [text, current_players, max_players]
$Label.text = "%s (%d/%d players)" % [display_name, current_players, max_players]
func set_text(t):
text = t
const keys = ["id", "display_name", "max_players", "current_players", "locked"]
func set_with_dict(dict):
if dict.has("name"): self.display_name = dict["name"]
for k in keys:
if dict.has(k):
self[k] = dict[k]
func set_display_name(t):
display_name = t
_update_text()
func set_max_players(n):
@ -23,3 +32,6 @@ func set_max_players(n):
func set_current_players(n):
current_players = n
_update_text()
func _on_join_pressed():
Global.client.signaller.join_lobby(id)

36
scripts/objects/peer.gd Normal file
View file

@ -0,0 +1,36 @@
extends HBoxContainer
class_name PeerControl
onready var ready_tex: Texture = load("res://assets/img/check.png")
onready var not_ready_tex: Texture = load("res://assets/img/cross.png")
export(String) var id = "Some UUID"
export(String) var display_name = "Lobby" setget set_display_name
export(bool) var ready = false setget set_ready
func _ready():
_update()
func _update():
$Label.text = "%s" % [display_name]
$TextureRect.texture = ready_tex if ready else not_ready_tex
$TextureRect.hint_tooltip = "Ready" if ready else "Not Ready"
const keys = ["id", "display_name", "ready"]
func set_with_dict(dict):
if dict.has("name"): self.display_name = dict["name"]
for k in keys:
if dict.has(k):
self[k] = dict[k]
func set_display_name(t):
display_name = t
_update()
func set_ready(n):
ready = n
_update()
func _on_join_pressed():
Global.client.signaller.join_lobby(id)

125
scripts/objects/player.gd Normal file
View file

@ -0,0 +1,125 @@
extends KinematicBody2D
export var weight = 8
export var max_speed = 80 # ~5 tiles/sec at top speed
export var friction = 500
export var speed = 20
export var health = 100 setget set_health
export var max_health = 100 setget set_max_health
export var mana = 50 setget set_mana
export var max_mana = 100 setget set_max_mana
enum PlayerClass { WIZARD }
onready var viewport = get_viewport()
onready var sprite = $sprite
onready var collider = $collider
onready var name_displayer = $player_name
onready var display_name = name
onready var player_class = PlayerClass.WIZARD
onready var skills = []
# {
# "name": "fireball",
# "cooldown": 1,
# "cast_time": 0,
# "mana_cost": 25,
# },
# {
# name: "crate",
# cooldown: 0.5,
# cast_time: 0.5,
# mana_cost: 12,
# },
# {
# name: "pillar",
# mana_cost: 50,
# cooldown: 3,
# cast_time: 3,
# },
#]
remotesync var acceleration = Vector2.ZERO
remotesync var velocity = Vector2.ZERO
func set_health(x):
health = x
$bars/health_bar.value = x
maybe_hide_health_bar()
func set_max_health(x):
max_health = x
$bars/health_bar.max_value = x
maybe_hide_health_bar()
func set_mana(x):
mana = x
$bars/mana_bar.value = x
maybe_hide_mana_bar()
func set_max_mana(x):
max_mana = x
$bars/mana_bar.max_value = x
maybe_hide_mana_bar()
func maybe_hide_mana_bar():
if mana >= max_mana:
$bars/mana_bar.hide()
else:
$bars/mana_bar.show()
func maybe_hide_health_bar():
if health >= max_health:
$bars/health_bar.hide()
else:
$bars/health_bar.show()
func _ready():
# rset_config("acceleration", MultiplayerAPI.RPC_MODE_REMOTESYNC)
# rset_config("velocity", MultiplayerAPI.RPC_MODE_REMOTESYNC)
rset_config("position", MultiplayerAPI.RPC_MODE_SLAVE)
set_display_name(name)
func set_display_name(i_name):
display_name = i_name
if len(get_tree().get_network_connected_peers()) > 1:
name_displayer.text = display_name
else:
name_displayer.text = ""
static func int_input_action(action):
return int(Input.is_action_pressed(action))
func _physics_process(delta):
self.mana += (10*delta)
self.health += (1*delta)
_process_input()
_process_animation()
rset("velocity", move_and_slide((velocity + acceleration).clamped(max_speed), Vector2.ZERO, false, 4, 0.785398, false).move_toward(Vector2.ZERO, friction * delta))
for index in get_slide_count():
var collision = get_slide_collision(index)
if collision.collider is RigidBody2D:
collision.collider.apply_central_impulse(-collision.normal * weight)
if is_network_master():
rset_unreliable("position", position)
func _process_input():
if is_network_master():
var iv = Vector2()
# probably want to implement a "whichever one was pressed last" so that
# players move as fast as possible without having to worry about switching
# key frame perfectly
iv.x = int_input_action("ui_right") - int_input_action("ui_left")
iv.y = int_input_action("ui_down") - int_input_action("ui_up")
rset("acceleration", iv.normalized() * speed)
func _process_animation():
if velocity == Vector2.ZERO:
sprite.animation = "idle"
else:
sprite.animation = "run"
if velocity.x < 0:
sprite.flip_h = true
elif velocity.x > 0:
sprite.flip_h = false

View file

@ -1,20 +1,17 @@
extends Node2D
onready var player = preload("res://objects/player.tscn")
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
rpc("add_player", get_tree().get_network_unique_id())
func _process(delta):
pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
remotesync func add_player(peer_id):
var new_player = player.instance()
new_player.set_network_master(peer_id)
add_child(new_player)
func _on_Button_pressed():
Global.main_menu()

View file

@ -4,16 +4,17 @@ extends Control
onready var is_loaded = false
onready var lobbies = $v/body/lobbies
onready var join_button = $v/head/join
onready var lobbies_grid = $v/body/p/lobbies
onready var zero_state = $v/body/p/lobbies/zero_state
onready var lobbies_label = $v/subhead/label
onready var display_name_edit = $v/subhead/display_name
onready var lobbies_map = {}
onready var lobbies = {}
onready var lobby = preload("res://objects/lobby.tscn")
func _ready():
display_name_edit.text = Global.client.signaller.display_name
join_button.disabled = true
Global.client.signaller.connect("lobby_new", self, "_lobby_new")
Global.client.signaller.connect("lobby_delete", self, "_lobby_delete")
Global.client.signaller.connect("lobby_joined", self, "_lobby_joined")
@ -25,6 +26,23 @@ func _ready():
Global.create_lobby = false
Global.client.signaller.create_lobby()
"""
var ls = []
for n in range(200):
ls.push_back({id = n, name = n, currentPlayers = n, maxPlayers = n, locked = false})
call_deferred("_lobby_new", ls)
"""
# TODO: add search
func _input(ev):
if ev is InputEventKey and ev.pressed:
if ev.scancode == KEY_T:
var ls = []
for n in range(5):
var j = n + lobbies.size()
ls.push_back({id = j, name = j, currentPlayers = j, maxPlayers = j, locked = false})
call_deferred("_lobby_new", ls)
func _signaller_disconnected():
Global.main_menu()
@ -45,40 +63,55 @@ func _on_join_pressed():
if len(items) > 0:
Global.client.signaller.join_lobby(lobbies.get_item_metadata(items[0])["id"])
func _lobby_new(new_lobbies):
func _lobby_new(new_lobbies: Array):
# TODO: handle scrolling so that the user is never too jarred (like chat)
for lobby_index in range(len(new_lobbies)):
var lobby = new_lobbies[lobby_index]
var id = lobby["id"]
var lobby_text = "%s (%d/%d players)" % [lobby["name"], lobby["currentPlayers"], lobby["maxPlayers"]]
if lobbies_map.has(id):
print("Updated Lobby ", lobby)
var i = lobbies_map[id]
lobbies.set_item_metadata(i, lobby)
lobbies.set_item_text(i, lobby_text)
var lobby_data = new_lobbies[lobby_index]
var id = lobby_data["id"]
if lobbies.has(id):
_update_lobby(id, lobby_data)
else:
print("New Lobby ", lobby)
lobbies.add_item(lobby_text)
lobbies_map[id] = lobbies.get_item_count() - 1
lobbies.set_item_metadata(lobbies_map[id], lobby)
_add_lobby(id, lobby_data)
if Global.join_first_available_lobby:
Global.join_first_available_lobby = false
Global.client.signaller.join_lobby(id)
lobbies_label.text = "Active Lobbies: %d" % lobbies.get_item_count()
func _lobby_delete(id):
if lobbies_map.has(id):
var i = lobbies_map[id]
# TODO: this will break our current mappings due to re-order
lobbies.remove_item(i)
lobbies_label.text = "Active Lobbies: %d" % lobbies.get_item_count()
func _lobby_delete(id: String):
print("Lobby Deleted: %s" % id)
_delete_lobby(id)
func _on_lobbies_item_activated(_index):
_on_join_pressed()
func _add_lobby(id, lobby_data):
call_deferred("update_lobbies_text")
print("New Lobby ", lobby_data)
# if lobby_data.currentPlayers > 0:
var new_lobby = lobby.instance()
new_lobby.set_with_dict(lobby_data)
lobbies_grid.add_child(new_lobby)
lobbies[id] = new_lobby
func _on_lobbies_item_selected(_index):
join_button.disabled = false
func _update_lobby(id, lobby_data):
call_deferred("update_lobbies_text")
print("Updated Lobby ", lobby_data)
lobbies[id].set_with_dict(lobby_data)
func _delete_lobby(id):
call_deferred("update_lobbies_text")
if lobbies.has(id):
print("Removing lobby...")
lobbies_grid.remove_child(lobbies[id])
lobbies[id].queue_free()
lobbies.erase(id)
func update_lobbies_text():
var n = lobbies.size()
lobbies_label.text = "Active Lobbies: %d" % n
if n < 1:
if !lobbies_grid.is_a_parent_of(zero_state):
lobbies_grid.add_child(zero_state)
if n > 0:
if lobbies_grid.is_a_parent_of(zero_state):
lobbies_grid.remove_child(zero_state)
func _on_display_name_text_changed(new_text):
Global.client.signaller.set_display_name(new_text)

View file

@ -1,99 +1,84 @@
extends MarginContainer
onready var peers = $v/body/peers/peers
onready var peers_grid = $v/body/peers/p/peers
onready var lobby_name = $v/head/lobby_info
onready var peers_list_label = $v/body/peers/label
onready var cursors = {}
onready var chat = $v/body/v/messages
onready var chat_edit = $v/body/v/h/chat
onready var auto_scroll_chk = $v/body/v/chat_head/auto_scroll
onready var max_players = $v/head/max_players
onready var ready_up = $v/head/ready_up
onready var lock = $v/head/lock
onready var start = $v/head/start
onready var ready_tex: Texture = load("res://assets/img/check.png")
onready var not_ready_tex: Texture = load("res://assets/img/cross.png")
onready var can_start = true
onready var peers_map = {}
onready var peer = preload("res://objects/peer.tscn")
onready var peers = {}
onready var is_host = false
func _ready():
Global.client.signaller.connect("peer_joined", self, "_peer_joined")
Global.client.signaller.connect("peer_left", self, "_peer_left")
# Global.client.connect("peer_disconnected", self, "_peer_left")
Global.client.signaller.connect("lobby_left", self, "_lobby_left")
lobby_name.text = "%s" % Global.client.signaller.lobby_name
Global.client.signaller.connect("lobby_new", self, "_lobby_update")
Global.client.signaller.connect("websocket_disconnected", self, "_signaller_disconnected")
Global.client.signaller.request_peer_list()
lobby_name.text = "%s" % Global.client.signaller.lobby_name
Global.client.signaller.call_deferred("request_peer_list")
call_deferred("add_chat", "# Connected to %s" % Global.client.signaller.lobby_name)
# hide/show controls depending on whether or not we're the host
var is_host = Global.client.signaller.peer_id == 1
if is_host:
ready_up.queue_free()
else:
lobby_name.editable = false
max_players.editable = false
start.queue_free()
lock.queue_free()
func _host_suffix(id):
if id == 1:
return " (Host)"
else:
return ""
func _signaller_disconnected():
Global.main_menu()
func _lobby_update(l):
for u in l:
if !is_host:
max_players.text = str(u.maxPlayers)
lobby_name.text = u.name
print(l)
break
func _peer_joined(joined_peers):
call_deferred("update_player_count")
if Global.client.signaller.is_host(): call_deferred("update_can_start")
for peer_index in range(len(joined_peers)):
var peer = joined_peers[peer_index]
var id = peer["id"]
var peer_text = "%s%s" % [peer["name"], _host_suffix(peer["peerId"])]
if peers_map.has(id):
var i = peers_map[id]
var old_peer = peers.get_item_metadata(i)
peers.set_item_metadata(i, peer)
# announce changes?
var peer_data = joined_peers[peer_index]
var id = peer_data["id"]
if peers.has(id):
_update_peer(id, peer_data)
else:
call_deferred("add_chat", "> %s joined the lobby" % peer["name"])
var ready = false
var tex = not_ready_tex
if peerId == 1:
ready = true
tex = ready_tex
peers.add_item(peer_text, tex)
var i = peers.get_item_count() - 1
peers.set_item_metadata(i, peer)
peers_map[id] = i
if !ready: can_start = false
_add_peer(id, peer_data)
func _peer_left(ids):
func _add_peer(id, peer_data):
call_deferred("update_player_count")
var new_peer = peer.instance()
new_peer.set_with_dict(peer_data)
peers_grid.add_child(new_peer)
peers[id] = new_peer
add_chat("> %s joined the lobby" % new_peer.display_name)
func _update_peer(id, peer_data):
if peer_data.ready != peers[id].ready: add_chat("! %s is %s" % [peers[id].display_name, "now ready" if peer_data.ready else "no longer ready"])
peers[id].set_with_dict(peer_data)
# TODO: announce changes in chat?
func _peer_left(ids: Array):
call_deferred("update_player_count")
print("Peer(s) Leaving: %s" % ids)
for data in ids:
print(data)
var id = data["id"]
for i in range(peers.get_item_count()):
var md = peers.get_item_metadata(i)
if md and md.has("id") and md["id"] == id:
peers.remove_item(i)
call_deferred("add_chat", "< %s left the lobby" % md["name"])
return
func update_player_count():
peers_list_label.text = "Players: %d" % peers.get_item_count()
func _on_Button_pressed():
send_chat_message()
func _on_ready_up_toggled(button_pressed: bool):
Global.client.signaller.set_ready(button_pressed)
func _on_lobby_info_text_changed(new_text: String):
Global.client.signaller.set_lobby_name(new_text)
if peers.has(id):
call_deferred("add_chat", "< %s left the lobby" % peers[id].display_name)
peers[id].queue_free()
peers.erase(id)
remotesync func add_chat(message):
if auto_scroll_chk.pressed: call_deferred("scroll_chat_to_bottom")
@ -110,17 +95,28 @@ func preserve_chat_scroll(n, tl, fl, tc, fc):
chat.select(fl, fc, tl, tc)
chat.center_viewport_to_cursor()
func _lobby_left(_id):
Global.lobby_browser()
func _on_leave_button_pressed():
Global.lobby_browser()
func _on_TextEdit_text_entered(_new_text):
send_chat_message()
func send_chat_message():
var message = chat_edit.text
if message != "":
rpc("add_chat", "%s: %s" % [Global.client.signaller.display_name, message])
chat_edit.text = ""
func update_can_start():
var can_start = true
for p in peers:
var peer = peers[p]
if !peer.ready:
can_start = false
break
print(can_start)
if can_start: add_chat("! All players ready - game may now be started")
start.disabled = !can_start
func _lobby_left(_id): Global.lobby_browser()
func _on_leave_button_pressed(): Global.lobby_browser()
func _on_TextEdit_text_entered(_new_text): send_chat_message()
func update_player_count(): peers_list_label.text = "Players: %d" % peers.size()
func _on_Button_pressed(): send_chat_message()
func _on_ready_up_toggled(button_pressed: bool): Global.client.signaller.set_ready(button_pressed)
func _on_lobby_info_text_changed(new_text: String): Global.client.signaller.set_lobby_name(new_text)
func _signaller_disconnected(): Global.main_menu()

View file

@ -131,8 +131,8 @@ class Client {
}
lobbyNew(lobby: Lobby) {
// if the client is already in a lobby, they don't care about new lobbies
if (this.lobby) return;
// if the client is already in a lobby, only send messages about their lobby
if (this.lobby && this.lobby != lobby) return;
const { id, name, maxPlayers, locked } = lobby;
this.send(
buildMessage("lobby_new", {
@ -151,6 +151,7 @@ class Client {
}
lobbyCreate(opts?: Partial<Lobby>) {
this.ready = true;
if (this.lobby) {
this.send(
`[info] cannot create lobby (already in lobby ${this.lobby.id})`,
@ -177,6 +178,7 @@ class Client {
}
lobbyLeave() {
this.ready = false;
const leavingLobby = this.lobby;
if (!leavingLobby) {
this.send(`[info] cannot leave lobby (not in a lobby)`);
@ -199,6 +201,8 @@ class Lobby {
maxPlayers: number;
locked: boolean;
_shouldNotify: boolean;
constructor(host: Client, name?: string, maxPlayers = 20) {
this.id = crypto.randomUUID();
this.hostClientId = host.id;
@ -207,6 +211,8 @@ class Lobby {
this.maxPlayers = maxPlayers;
this.locked = false;
this._shouldNotify = true;
allLobbies.set(this.id, this);
host.peerId = 1;
host.lobbyJoin(this);
@ -244,10 +250,12 @@ class Lobby {
}
notify() {
if (!this._shouldNotify) return;
allClients.forEach((client) => client.lobbyNew(this));
}
remove() {
this._shouldNotify = false;
allLobbies.delete(this.id);
allClients.forEach((client) => client.lobbyDelete(this));
this.clients.forEach((client) => {