diff --git a/entities/Player.gd b/entities/Player.gd index 9ccdba5..a8f1149 100644 --- a/entities/Player.gd +++ b/entities/Player.gd @@ -60,6 +60,10 @@ func _physics_process(delta): state = PlayerState.Falling elif state != PlayerState.Dead: state = PlayerState.Alive + elif state == PlayerState.Dead: + visible = false + elif state == PlayerState.Alive: + visible = true coloring_sprite.visible = state == PlayerState.Alive diff --git a/entities/SpawnPoint.gd b/entities/SpawnPoint.gd new file mode 100644 index 0000000..a131e74 --- /dev/null +++ b/entities/SpawnPoint.gd @@ -0,0 +1,30 @@ +class_name SpawnPoint extends Node3D + +@export var player_index : int = 0 +@export var fixed_player : bool = false + +var near_players: Array = [] + +func _ready(): + var area3d = $'Area3D' + + area3d.connect("body_entered", on_player_enter) + area3d.connect("body_exited", on_player_exited) + +func on_player_enter(node: Node3D): + var player: Player = node as Player + if node == null: + return + + if not near_players.find(player): + near_players.append(player) + +func on_player_exited(node: Node3D): + var player: Player = node as Player + if node == null: + return + + near_players.erase(player) + +func is_occupied(): + return near_players.size() > 0 diff --git a/entities/SpawnPoint.tscn b/entities/SpawnPoint.tscn new file mode 100644 index 0000000..bce2ca8 --- /dev/null +++ b/entities/SpawnPoint.tscn @@ -0,0 +1,27 @@ +[gd_scene load_steps=4 format=3 uid="uid://cc521i07ajufm"] + +[ext_resource type="Script" path="res://entities/SpawnPoint.gd" id="1_l0ld5"] + +[sub_resource type="CylinderMesh" id="CylinderMesh_8id3y"] +top_radius = 0.3 +height = 0.1 +radial_segments = 5 + +[sub_resource type="CylinderShape3D" id="CylinderShape3D_1ha80"] +height = 1.0 +radius = 1.0 + +[node name="SpawnPoint" type="Node3D"] +script = ExtResource("1_l0ld5") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0239549, 0) +mesh = SubResource("CylinderMesh_8id3y") + +[node name="Area3D" type="Area3D" parent="."] +collision_layer = 0 +collision_mask = 4 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="Area3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0) +shape = SubResource("CylinderShape3D_1ha80") diff --git a/scenes/World.gd b/scenes/World.gd index 368e87c..b438eec 100644 --- a/scenes/World.gd +++ b/scenes/World.gd @@ -12,6 +12,7 @@ class_name World extends Node3D var camera_position: Vector3; var world_coloring_material: ShaderMaterial var world_plane: Plane = Plane(Vector3.UP, Vector3.ZERO) +var spawn_points: Array = Array() # Called when the node enters the scene tree for the first time. func _ready(): @@ -32,6 +33,11 @@ func _ready(): score_update_timer.connect("timeout", update_score) + find_spawn_points(level) + + for player: Player in players: + player.state = player.PlayerState.Dead + apply_world_coloring_recursive(level) # Called every frame. 'delta' is the elapsed time since the previous frame. @@ -63,7 +69,27 @@ func _process(_delta): pass func _physics_process(_delta): - world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture()) + world_coloring_material.set_shader_parameter("world_color_texture", world_coloring_viewport.get_texture()) + + for player: Player in players: + if player.state == Player.PlayerState.Dead: + var occupied = true + var spawn_point + + while occupied: + spawn_point = spawn_points.pick_random() as SpawnPoint + if not spawn_point.is_occupied(): + occupied = false + + player.global_position = spawn_point.global_position + player.state = Player.PlayerState.Alive + spawn_point.near_players.append(player) + +func find_spawn_points (node): + for child in node.get_children(): + var spawn_point = child as SpawnPoint + if spawn_point: + spawn_points.append(spawn_point) func apply_world_coloring_recursive (node): for child in node.get_children(): diff --git a/scenes/World.tscn b/scenes/World.tscn index 0e70b66..ce79a7d 100644 --- a/scenes/World.tscn +++ b/scenes/World.tscn @@ -1,12 +1,13 @@ -[gd_scene load_steps=12 format=3 uid="uid://b1nm5h3yccr16"] +[gd_scene load_steps=13 format=3 uid="uid://b1nm5h3yccr16"] [ext_resource type="Script" path="res://scenes/World.gd" id="1_gtcjp"] [ext_resource type="PackedScene" uid="uid://bfyjtfdko3l7o" path="res://entities/Player.tscn" id="2_a343a"] [ext_resource type="Texture2D" uid="uid://bnsrnuuq28p4d" path="res://assets/textures/player_draw_mask.png" id="4_dipd5"] [ext_resource type="Texture2D" uid="uid://vcebfpqo2ko7" path="res://assets/textures/player_bomb_mask.png" id="5_17c1g"] -[ext_resource type="PackedScene" uid="uid://bqgleq3w0o5wj" path="res://scenes/PixelCountComputeShader.tscn" id="6_75vqy"] +[ext_resource type="PackedScene" path="res://scenes/PixelCountComputeShader.tscn" id="6_75vqy"] [ext_resource type="PackedScene" uid="uid://7a2ma10hq0qa" path="res://scenes/PlatformA.tscn" id="6_83plb"] [ext_resource type="PackedScene" uid="uid://bnmtyc1kkt6ku" path="res://scenes/PlatformB.tscn" id="7_cld3m"] +[ext_resource type="PackedScene" uid="uid://cc521i07ajufm" path="res://entities/SpawnPoint.tscn" id="8_ykvyf"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_5gauv"] sky_energy_multiplier = 5.0 @@ -96,6 +97,7 @@ position = Vector2(530, 500) texture = ExtResource("5_17c1g") [node name="Level" type="Node3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -6.76534, 0, 5.93242) [node name="Platforms" parent="Level" instance=ExtResource("6_83plb")] @@ -103,7 +105,7 @@ texture = ExtResource("5_17c1g") transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 3.68666, 0, 5.21494) [node name="Platforms3" parent="Level" instance=ExtResource("6_83plb")] -transform = Transform3D(0.92959, 0, -0.368595, 0, 1, 0, 0.368595, 0, 0.92959, 12.3051, 0, 5.54212) +transform = Transform3D(0.768741, 0, -0.63956, 0, 1, 0, 0.63956, 0, 0.768741, 9.90471, 0, 3.31265) [node name="Platforms4" parent="Level" instance=ExtResource("6_83plb")] transform = Transform3D(-0.99988, 0, -0.0155154, 0, 1, 0, 0.0155154, 0, -0.99988, 13.9505, -4.76837e-07, -0.629952) @@ -121,4 +123,16 @@ transform = Transform3D(-0.91991, 0, -0.392128, 0, 1, 0, 0.392128, 0, -0.91991, transform = Transform3D(0.769634, 0, 0.638486, 0, 1, 0, -0.638486, 0, 0.769634, -1.18219, 0, -6.89363) [node name="Platforms9" parent="Level" instance=ExtResource("7_cld3m")] -transform = Transform3D(0.330663, 0, -0.943749, 0, 1, 0, 0.943749, 0, 0.330663, -8.54214, -9.53674e-07, -20.9801) +transform = Transform3D(0.330663, 0, -0.943749, 0, 1, 0, 0.943749, 0, 0.330663, 3.64812, -9.53674e-07, -15.7327) + +[node name="Platforms10" parent="Level" instance=ExtResource("6_83plb")] +transform = Transform3D(-0.851736, 0, 0.523971, 0, 1, 0, -0.523971, 0, -0.851736, 15.3333, 0, -12.1468) + +[node name="SpawnPointPlayer1" parent="Level" instance=ExtResource("8_ykvyf")] + +[node name="SpawnPointPlayer2" parent="Level" instance=ExtResource("8_ykvyf")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 9.48618, 0, -11.2001) +player_index = 1 + +[node name="SpawnPointPlayer3" parent="Level" instance=ExtResource("8_ykvyf")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 9.55561, 0, 3.26255)