Viewport + 3D scene
This commit is contained in:
parent
901c4b773b
commit
d5cf0528f8
8 changed files with 93 additions and 59 deletions
|
|
@ -1,29 +1,36 @@
|
||||||
[gd_scene load_steps=4 format=3 uid="uid://b1m2pclbncn68"]
|
[gd_scene load_steps=4 format=3 uid="uid://dsiowq0rnacln"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://danmaku!/scaling.gd" id="1_mxxs1"]
|
[ext_resource type="PackedScene" uid="uid://cd3tqt7hr5pqs" path="res://danmaku!/Player.tscn" id="1_22cjd"]
|
||||||
[ext_resource type="PackedScene" uid="uid://cd3tqt7hr5pqs" path="res://danmaku!/player.tscn" id="2_d6n3g"]
|
[ext_resource type="Script" path="res://danmaku!/scaling.gd" id="1_o1mqp"]
|
||||||
[ext_resource type="Script" path="res://danmaku!/network_manager.gd" id="3_4fnyw"]
|
[ext_resource type="Script" path="res://danmaku!/network_manager.gd" id="2_b2dol"]
|
||||||
|
|
||||||
[node name="Board" type="AspectRatioContainer"]
|
[node name="Board" type="Control"]
|
||||||
anchors_preset = -1
|
custom_minimum_size = Vector2(607.5, 1080)
|
||||||
anchor_right = 0.263889
|
layout_mode = 3
|
||||||
anchor_bottom = 0.257716
|
anchors_preset = 0
|
||||||
offset_right = 14.0
|
offset_right = 607.5
|
||||||
offset_bottom = 27.0
|
offset_bottom = 1080.0
|
||||||
ratio = 0.5625
|
size_flags_horizontal = 0
|
||||||
script = ExtResource("1_mxxs1")
|
size_flags_vertical = 0
|
||||||
metadata/_edit_use_anchors_ = true
|
script = ExtResource("1_o1mqp")
|
||||||
|
|
||||||
[node name="ReferenceRect" type="ReferenceRect" parent="."]
|
[node name="ReferenceRect" type="ReferenceRect" parent="."]
|
||||||
layout_mode = 2
|
layout_mode = 1
|
||||||
border_color = Color(0.995542, 0.845388, 0.421763, 1)
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
border_color = Color(1, 0.80706, 0.336228, 1)
|
||||||
|
border_width = 2.0
|
||||||
editor_only = false
|
editor_only = false
|
||||||
|
|
||||||
[node name="Container" type="Node2D" parent="ReferenceRect"]
|
[node name="World" type="Node2D" parent="."]
|
||||||
scale = Vector2(1.2125, 1.2125)
|
unique_name_in_owner = true
|
||||||
|
scale = Vector2(6.75, 6.75)
|
||||||
|
|
||||||
[node name="Player" parent="ReferenceRect/Container" instance=ExtResource("2_d6n3g")]
|
[node name="Player" parent="World" instance=ExtResource("1_22cjd")]
|
||||||
|
|
||||||
[node name="NetworkManager" type="Node2D" parent="ReferenceRect/Container" node_paths=PackedStringArray("player")]
|
[node name="NetworkManager" type="Node2D" parent="World" node_paths=PackedStringArray("player")]
|
||||||
script = ExtResource("3_4fnyw")
|
script = ExtResource("2_b2dol")
|
||||||
player = NodePath("../Player")
|
player = NodePath("../Player")
|
||||||
|
|
|
||||||
28
client/danmaku!/BoardRenderer.tscn
Normal file
28
client/danmaku!/BoardRenderer.tscn
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
[gd_scene load_steps=5 format=3 uid="uid://b1m2pclbncn68"]
|
||||||
|
|
||||||
|
[ext_resource type="PackedScene" uid="uid://dsiowq0rnacln" path="res://danmaku!/Board.tscn" id="2_25dpb"]
|
||||||
|
|
||||||
|
[sub_resource type="ViewportTexture" id="ViewportTexture_0pmy2"]
|
||||||
|
viewport_path = NodePath("SubViewport")
|
||||||
|
|
||||||
|
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_foys1"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
shading_mode = 0
|
||||||
|
albedo_texture = SubResource("ViewportTexture_0pmy2")
|
||||||
|
|
||||||
|
[sub_resource type="QuadMesh" id="QuadMesh_txqb1"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
material = SubResource("StandardMaterial3D_foys1")
|
||||||
|
size = Vector2(0.563, 1)
|
||||||
|
|
||||||
|
[node name="BoardRenderer" type="Node3D"]
|
||||||
|
|
||||||
|
[node name="BoardMesh" type="MeshInstance3D" parent="."]
|
||||||
|
mesh = SubResource("QuadMesh_txqb1")
|
||||||
|
skeleton = NodePath("../SubViewport")
|
||||||
|
|
||||||
|
[node name="SubViewport" type="SubViewport" parent="."]
|
||||||
|
handle_input_locally = false
|
||||||
|
size = Vector2i(607, 1080)
|
||||||
|
|
||||||
|
[node name="Board" parent="SubViewport" instance=ExtResource("2_25dpb")]
|
||||||
|
|
@ -1,21 +1,11 @@
|
||||||
[gd_scene load_steps=2 format=3 uid="uid://3a8txh83qfu5"]
|
[gd_scene load_steps=2 format=3 uid="uid://3a8txh83qfu5"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://b1m2pclbncn68" path="res://danmaku!/Board.tscn" id="1_pv3ov"]
|
[ext_resource type="PackedScene" uid="uid://b1m2pclbncn68" path="res://danmaku!/BoardRenderer.tscn" id="1_pv3ov"]
|
||||||
|
|
||||||
[node name="Game" type="Control"]
|
[node name="Game" type="Node"]
|
||||||
layout_mode = 3
|
|
||||||
anchors_preset = 15
|
|
||||||
anchor_right = 1.0
|
|
||||||
anchor_bottom = 1.0
|
|
||||||
grow_horizontal = 2
|
|
||||||
grow_vertical = 2
|
|
||||||
|
|
||||||
[node name="Board" parent="." instance=ExtResource("1_pv3ov")]
|
[node name="BoardRenderer" parent="." instance=ExtResource("1_pv3ov")]
|
||||||
layout_mode = 1
|
|
||||||
anchors_preset = 15
|
[node name="Camera3D" type="Camera3D" parent="."]
|
||||||
anchor_right = 1.0
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.699727)
|
||||||
anchor_bottom = 1.0
|
current = true
|
||||||
offset_right = 0.0
|
|
||||||
offset_bottom = 0.0
|
|
||||||
grow_horizontal = 2
|
|
||||||
grow_vertical = 2
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ var bullets = []
|
||||||
var current_match_id = ""
|
var current_match_id = ""
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
child_exiting_tree.connect(_on_child_exiting_tree)
|
||||||
print("Attempting auth.")
|
print("Attempting auth.")
|
||||||
await attempt_auth()
|
await attempt_auth()
|
||||||
print("Attempting to create debug match.")
|
print("Attempting to create debug match.")
|
||||||
|
|
@ -31,16 +32,14 @@ func _process(delta: float) -> void:
|
||||||
|
|
||||||
bullet.position = interpolated_pos
|
bullet.position = interpolated_pos
|
||||||
|
|
||||||
#var screen_size = get_viewport().size
|
if bullet.beyond_kill_boundary(predicted_tick):
|
||||||
#bullets = bullets.filter(func(bullet):
|
bullet.queue_free()
|
||||||
# return bullet.position.x >= 0 and bullet.position.x <= screen_size.x and \
|
|
||||||
# bullet.position.y >= 0 and bullet.position.y <= screen_size.y
|
|
||||||
#)
|
|
||||||
|
|
||||||
func _on_match_state(p_state : NakamaRTAPI.MatchData):
|
func _on_match_state(p_state : NakamaRTAPI.MatchData):
|
||||||
match p_state.op_code:
|
match p_state.op_code:
|
||||||
2:
|
2:
|
||||||
var data = JSON.parse_string(p_state.data)
|
var data = JSON.parse_string(p_state.data)
|
||||||
|
|
||||||
# Set player position given server bounds-checking
|
# Set player position given server bounds-checking
|
||||||
if data["forcePlayerPos"]:
|
if data["forcePlayerPos"]:
|
||||||
player.position = Vector2(float(data["playerPos"]["x"]), float(data["playerPos"]["y"]))
|
player.position = Vector2(float(data["playerPos"]["x"]), float(data["playerPos"]["y"]))
|
||||||
|
|
@ -60,7 +59,8 @@ func _on_match_state(p_state : NakamaRTAPI.MatchData):
|
||||||
bullet.scale = Vector2(0.2, 0.2)
|
bullet.scale = Vector2(0.2, 0.2)
|
||||||
add_child(bullet)
|
add_child(bullet)
|
||||||
bullets.append(bullet)
|
bullets.append(bullet)
|
||||||
#predicted_tick = int(b["tick"])
|
predicted_tick = int(b["tick"])
|
||||||
|
delta_counter = 0
|
||||||
|
|
||||||
func attempt_auth() -> void:
|
func attempt_auth() -> void:
|
||||||
nakama_client = Nakama.create_client("defaultkey", "127.0.0.1", 7350, "http")
|
nakama_client = Nakama.create_client("defaultkey", "127.0.0.1", 7350, "http")
|
||||||
|
|
@ -91,11 +91,15 @@ func create_and_join_debug_match() -> void:
|
||||||
func predict_tick_and_broadcast(delta):
|
func predict_tick_and_broadcast(delta):
|
||||||
delta_counter += delta
|
delta_counter += delta
|
||||||
|
|
||||||
# New tick, broadcast player inputs
|
# New tick (60 tick rate), broadcast player inputs
|
||||||
if delta_counter >= 0.05:
|
var tick_time = 0.01666666666
|
||||||
|
if delta_counter >= tick_time:
|
||||||
predicted_tick += 1
|
predicted_tick += 1
|
||||||
delta_counter -= 0.05
|
delta_counter -= tick_time
|
||||||
var pos = get_node("../Player").position
|
var pos = get_node("../Player").position
|
||||||
var json_string = JSON.stringify({"x": pos.x, "y": pos.y})
|
var json_string = JSON.stringify({"x": pos.x, "y": pos.y})
|
||||||
nakama_socket.send_match_state_async(current_match_id, 0, json_string)
|
nakama_socket.send_match_state_async(current_match_id, 0, json_string)
|
||||||
bullet_lerp_factor = delta_counter / 0.05
|
bullet_lerp_factor = delta_counter / tick_time
|
||||||
|
|
||||||
|
func _on_child_exiting_tree(node: DanmakuBullet):
|
||||||
|
bullets.erase(node)
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
[gd_scene load_steps=3 format=3 uid="uid://cd3tqt7hr5pqs"]
|
[gd_scene load_steps=3 format=3 uid="uid://cd3tqt7hr5pqs"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://danmaku!/player.gd" id="1_l6typ"]
|
[ext_resource type="Script" path="res://danmaku!/player.gd" id="1_r7xhp"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bs3fntlmlqpt2" path="res://icon.svg" id="2_j7sx3"]
|
[ext_resource type="Texture2D" uid="uid://bs3fntlmlqpt2" path="res://icon.svg" id="2_04s0l"]
|
||||||
|
|
||||||
[node name="Player" type="Node2D"]
|
[node name="Player" type="Node2D"]
|
||||||
script = ExtResource("1_l6typ")
|
script = ExtResource("1_r7xhp")
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||||
scale = Vector2(0.09, 0.09)
|
scale = Vector2(0.09, 0.09)
|
||||||
texture = ExtResource("2_j7sx3")
|
texture = ExtResource("2_04s0l")
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
@tool
|
@tool
|
||||||
extends AspectRatioContainer
|
extends Control
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
var board_screen_size = $ReferenceRect.get_rect()
|
var board_screen_size = self.get_rect()
|
||||||
$ReferenceRect/Container.scale = Vector2(board_screen_size.size.x / Globals.SERVER_SIZE.x, board_screen_size.size.y / Globals.SERVER_SIZE.y)
|
%World.scale = Vector2(board_screen_size.size.x / Globals.SERVER_SIZE.x, board_screen_size.size.y / Globals.SERVER_SIZE.y)
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,11 @@ config/icon="res://icon.svg"
|
||||||
|
|
||||||
Nakama="*res://addons/com.heroiclabs.nakama/Nakama.gd"
|
Nakama="*res://addons/com.heroiclabs.nakama/Nakama.gd"
|
||||||
|
|
||||||
|
[display]
|
||||||
|
|
||||||
|
window/size/viewport_width=1920
|
||||||
|
window/size/viewport_height=1080
|
||||||
|
|
||||||
[importer_defaults]
|
[importer_defaults]
|
||||||
|
|
||||||
animation_library={
|
animation_library={
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ type BattleRoyaleMatchState struct {
|
||||||
|
|
||||||
// Run on match start, initializes game state and sets tick rate
|
// Run on match start, initializes game state and sets tick rate
|
||||||
func (m *BattleRoyaleMatch) MatchInit(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, params map[string]interface{}) (interface{}, int, string) {
|
func (m *BattleRoyaleMatch) MatchInit(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, params map[string]interface{}) (interface{}, int, string) {
|
||||||
tickRate := 20 // MatchLoop invocations per second
|
tickRate := 60 // MatchLoop invocations per second
|
||||||
state := &BattleRoyaleMatchState{
|
state := &BattleRoyaleMatchState{
|
||||||
tickRate: tickRate,
|
tickRate: tickRate,
|
||||||
presences: map[string]*PresenceState{},
|
presences: map[string]*PresenceState{},
|
||||||
|
|
@ -114,7 +114,7 @@ func (m *BattleRoyaleMatch) MatchJoin(ctx context.Context, logger runtime.Logger
|
||||||
Y: STAGE_HEIGHT - STAGE_HEIGHT*0.1,
|
Y: STAGE_HEIGHT - STAGE_HEIGHT*0.1,
|
||||||
},
|
},
|
||||||
bullets: []*C.Bullet{},
|
bullets: []*C.Bullet{},
|
||||||
updatePlayerPos: false,
|
updatePlayerPos: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -232,9 +232,9 @@ func (m *BattleRoyaleMatch) MatchLoop(ctx context.Context, logger runtime.Logger
|
||||||
var newBulletsToBroadcast = []map[string]interface{}{}
|
var newBulletsToBroadcast = []map[string]interface{}{}
|
||||||
|
|
||||||
// Test bullet spawning
|
// Test bullet spawning
|
||||||
if tick%1 == 0 {
|
if tick%10 == 0 {
|
||||||
velx := rand.Float64()*(STAGE_WIDTH/float64(lobbyState.tickRate)) + 1.0
|
velx := (rand.Float64() * STAGE_WIDTH) / float64(lobbyState.tickRate)
|
||||||
vely := rand.Float64()*(STAGE_WIDTH/float64(lobbyState.tickRate)) + 1.0
|
vely := (rand.Float64() * STAGE_WIDTH) / float64(lobbyState.tickRate)
|
||||||
vel_x_sign := 2*rand.Intn(2) - 1
|
vel_x_sign := 2*rand.Intn(2) - 1
|
||||||
vel_y_sign := 2*rand.Intn(2) - 1
|
vel_y_sign := 2*rand.Intn(2) - 1
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue