From aaf9c85be7ddccebdb3a49cbb78186593b428606 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sat, 8 Jul 2023 18:57:18 +0200 Subject: [PATCH] Moved Player entity in separate scene --- entities/Player.tscn | 81 ++++++++++++++++++++++++++++++++++++++ entities/Player3D.tscn | 34 ---------------- entities/PlayerEntity.gd | 68 -------------------------------- entities/PlayerEntity.tscn | 46 ---------------------- scenes/Game.tscn | 62 ++--------------------------- 5 files changed, 84 insertions(+), 207 deletions(-) create mode 100644 entities/Player.tscn delete mode 100644 entities/Player3D.tscn delete mode 100644 entities/PlayerEntity.gd delete mode 100644 entities/PlayerEntity.tscn diff --git a/entities/Player.tscn b/entities/Player.tscn new file mode 100644 index 0000000..f75f446 --- /dev/null +++ b/entities/Player.tscn @@ -0,0 +1,81 @@ +[gd_scene load_steps=13 format=2] + +[ext_resource path="res://entities/Player.cs" type="Script" id=1] +[ext_resource path="res://components/NavigationComponent.cs" type="Script" id=2] +[ext_resource path="res://assets/Characters/Pirate.tscn" type="PackedScene" id=4] +[ext_resource path="res://components/WorldInfoComponent.cs" type="Script" id=5] +[ext_resource path="res://utils/DebugGeometry.cs" type="Script" id=6] +[ext_resource path="res://components/MovableComponent.tscn" type="PackedScene" id=7] + +[sub_resource type="CapsuleShape" id=7] +radius = 0.3 +height = 0.2 + +[sub_resource type="BoxShape" id=26] + +[sub_resource type="CubeMesh" id=27] + +[sub_resource type="SpatialMaterial" id=28] +flags_transparent = true +albedo_color = Color( 1, 1, 1, 0.0470588 ) + +[sub_resource type="CylinderShape" id=24] +height = 0.2 + +[sub_resource type="SphereShape" id=23] +radius = 0.1 + +[node name="Player" type="KinematicBody"] +collision_layer = 0 +collision_mask = 0 +axis_lock_motion_y = true +move_lock_y = true +script = ExtResource( 1 ) + +[node name="CollisionShape" type="CollisionShape" parent="."] +transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.5, 0 ) +shape = SubResource( 7 ) + +[node name="Movable" parent="." instance=ExtResource( 7 )] + +[node name="WorldInfo" type="Node" parent="."] +script = ExtResource( 5 ) +World = NodePath("../../TileWorld") + +[node name="Navigation" type="Spatial" parent="."] +script = ExtResource( 2 ) + +[node name="PathCollisionQueryVolume" type="Area" parent="Navigation"] +transform = Transform( 0.5, 0, 0, 0, 0.5, 0, 0, 0, 2, 0, 1, 2 ) +collision_layer = 0 + +[node name="CollisionShape" type="CollisionShape" parent="Navigation/PathCollisionQueryVolume"] +shape = SubResource( 26 ) + +[node name="MeshInstance" type="MeshInstance" parent="Navigation/PathCollisionQueryVolume"] +mesh = SubResource( 27 ) +material/0 = SubResource( 28 ) + +[node name="ItemAttractorArea" type="Area" parent="."] +collision_layer = 0 +collision_mask = 8 +monitorable = false + +[node name="CollisionShape" type="CollisionShape" parent="ItemAttractorArea"] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.123516, 0 ) +shape = SubResource( 24 ) + +[node name="ItemPickupArea" type="Area" parent="."] +collision_layer = 0 +collision_mask = 8 +monitorable = false + +[node name="CollisionShape" type="CollisionShape" parent="ItemPickupArea"] +shape = SubResource( 23 ) + +[node name="Geometry" parent="." instance=ExtResource( 4 )] + +[node name="DebugGeometry" type="Spatial" parent="."] +script = ExtResource( 6 ) + +[node name="ImmediateGeometry" type="ImmediateGeometry" parent="DebugGeometry"] diff --git a/entities/Player3D.tscn b/entities/Player3D.tscn deleted file mode 100644 index 9fa5522..0000000 --- a/entities/Player3D.tscn +++ /dev/null @@ -1,34 +0,0 @@ -[gd_scene load_steps=6 format=2] - -[ext_resource path="res://entities/PlayerEntity.gd" type="Script" id=1] -[ext_resource path="res://scenes/DebugCamera.gd" type="Script" id=2] -[ext_resource path="res://components/MovableComponent.tscn" type="PackedScene" id=4] - -[sub_resource type="CapsuleMesh" id=4] -radius = 0.2 -mid_height = 0.5 -radial_segments = 16 - -[sub_resource type="CapsuleShape" id=5] -radius = 0.25 -height = 0.5 - -[node name="Player" type="KinematicBody"] -script = ExtResource( 1 ) - -[node name="Camera" type="Camera" parent="."] -transform = Transform( 1, 0, 0, 0, 0.511698, 0.859165, 0, -0.859165, 0.511698, -4.76837e-07, 7.29903, 4.46831 ) -current = true -fov = 60.0 -script = ExtResource( 2 ) - -[node name="MeshInstance" type="MeshInstance" parent="."] -transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.5, 0 ) -mesh = SubResource( 4 ) - -[node name="Collision" type="CollisionShape" parent="."] -transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.5, 0 ) -shape = SubResource( 5 ) - -[node name="Movable" parent="." instance=ExtResource( 4 )] -max_speed = 3 diff --git a/entities/PlayerEntity.gd b/entities/PlayerEntity.gd deleted file mode 100644 index e5fd676..0000000 --- a/entities/PlayerEntity.gd +++ /dev/null @@ -1,68 +0,0 @@ -extends KinematicBody - -onready var color_component = $Color -onready var tinted_sprite_component = $TintedSprite -onready var clickable_component = $Clickable -onready var movable_component = $Movable -onready var collision_component = $Collision - -onready var is_active = false - - -func _ready(): - if color_component and tinted_sprite_component: - print ("Connecting signals") - color_component.connect("color_changed", tinted_sprite_component, "set_color_tint") - - if clickable_component: - clickable_component.connect("clicked", self, "_on_entity_clicked") - - if movable_component: - movable_component.connect("position_updated", self, "_on_position_updated") - movable_component.target = self.transform.origin - movable_component.pos = self.transform.origin - - -func _process(_delta): - if is_active and color_component: - var color = Color( - (sin(float(OS.get_system_time_msecs()) / 1000.0) + 1.0) / 2.0, - (sin(float(OS.get_system_time_msecs()) / 300.0) + 1.0) / 2.0, - (sin(float(OS.get_system_time_msecs()) / 100.0) + 1.0) / 2.0 - ) - color_component.set_color(color) - pass - - -func _physics_process(_delta): - if not collision_component: - return - - if movable_component and collision_component: - if movable_component.vel.length_squared() < 0.001: - return - - var physics_velocity = move_and_slide(movable_component.vel) - movable_component.vel = physics_velocity - - -func _on_entity_clicked(): - is_active = not is_active - - -func _on_position_updated(new_position): - if not collision_component: - transform.origin = new_position - - -func set_movable_target(target): - if not movable_component == null: - movable_component.target = target - - -func _unhandled_input_disabled(event): - print ("Player unhandled input...") - if event is InputEventMouseButton and event.pressed: - assert(movable_component) - - movable_component.target = event.position diff --git a/entities/PlayerEntity.tscn b/entities/PlayerEntity.tscn deleted file mode 100644 index 7f1b94a..0000000 --- a/entities/PlayerEntity.tscn +++ /dev/null @@ -1,46 +0,0 @@ -[gd_scene load_steps=10 format=2] - -[ext_resource path="res://entities/PlayerEntity.gd" type="Script" id=1] -[ext_resource path="res://components/TintedSpriteComponent.gd" type="Script" id=2] -[ext_resource path="res://components/ColorComponent.gd" type="Script" id=3] -[ext_resource path="res://components/ClickableComponent.tscn" type="PackedScene" id=4] -[ext_resource path="res://components/MovableComponent.tscn" type="PackedScene" id=5] -[ext_resource path="res://assets/pirate.svg" type="Texture" id=6] -[ext_resource path="res://assets/white.png" type="Texture" id=8] - -[sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 40, 103 ) - -[sub_resource type="CapsuleShape2D" id=2] -radius = 46.0 -height = 122.0 - -[node name="PlayerEntity" type="KinematicBody2D"] -script = ExtResource( 1 ) - -[node name="Movable" parent="." instance=ExtResource( 5 )] - -[node name="TintedSprite" type="Sprite" parent="."] -position = Vector2( -9, 3 ) -texture = ExtResource( 6 ) -script = ExtResource( 2 ) - -[node name="Clickable" parent="." instance=ExtResource( 4 )] - -[node name="CollisionShape2D" parent="Clickable/Area2D" index="0"] -position = Vector2( 7, -8 ) -shape = SubResource( 1 ) - -[node name="Color" type="Node" parent="."] -script = ExtResource( 3 ) - -[node name="Collision" type="CollisionShape2D" parent="."] -shape = SubResource( 2 ) - -[node name="TintedSprite" type="Sprite" parent="Collision"] -visible = false -scale = Vector2( 80.6324, 216.834 ) -texture = ExtResource( 8 ) -script = ExtResource( 2 ) - -[editable path="Clickable"] diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 64b5a80..5491aa2 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -1,18 +1,13 @@ -[gd_scene load_steps=23 format=2] +[gd_scene load_steps=15 format=2] [ext_resource path="res://scenes/StreamContainer.cs" type="Script" id=1] -[ext_resource path="res://components/NavigationComponent.cs" type="Script" id=2] -[ext_resource path="res://entities/Player.cs" type="Script" id=3] -[ext_resource path="res://components/MovableComponent.tscn" type="PackedScene" id=4] +[ext_resource path="res://entities/Player.tscn" type="PackedScene" id=2] [ext_resource path="res://utils/TileHighlight.tscn" type="PackedScene" id=5] -[ext_resource path="res://components/WorldInfoComponent.cs" type="Script" id=6] [ext_resource path="res://entities/Chest.tscn" type="PackedScene" id=7] [ext_resource path="res://scenes/TileWorld.tscn" type="PackedScene" id=8] [ext_resource path="res://scenes/Game.cs" type="Script" id=9] [ext_resource path="res://scenes/DebugCamera.gd" type="Script" id=10] -[ext_resource path="res://assets/Characters/Pirate.tscn" type="PackedScene" id=11] [ext_resource path="res://ui/WorldGeneratorUI.gd" type="Script" id=12] -[ext_resource path="res://utils/DebugGeometry.cs" type="Script" id=13] [ext_resource path="res://entities/Axe.tscn" type="PackedScene" id=14] [ext_resource path="res://systems/InteractionSystem.cs" type="Script" id=15] @@ -42,16 +37,6 @@ albedo_color = Color( 1, 1, 1, 0.156863 ) [sub_resource type="BoxShape" id=9] extents = Vector3( 20, 1, 20 ) -[sub_resource type="CapsuleShape" id=7] -radius = 0.3 -height = 0.2 - -[sub_resource type="CylinderShape" id=24] -height = 0.2 - -[sub_resource type="SphereShape" id=23] -radius = 0.1 - [node name="Game" type="Spatial"] script = ExtResource( 9 ) @@ -327,48 +312,7 @@ script = ExtResource( 10 ) [node name="InteractionSystem" type="Node" parent="."] script = ExtResource( 15 ) -[node name="Player" type="KinematicBody" parent="."] -collision_mask = 0 -axis_lock_motion_y = true -move_lock_y = true -script = ExtResource( 3 ) - -[node name="CollisionShape" type="CollisionShape" parent="Player"] -transform = Transform( 1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.5, 0 ) -shape = SubResource( 7 ) - -[node name="Movable" parent="Player" instance=ExtResource( 4 )] - -[node name="WorldInfo" type="Node" parent="Player"] -script = ExtResource( 6 ) -World = NodePath("../../TileWorld") - -[node name="Navigation" type="Node" parent="Player"] -script = ExtResource( 2 ) - -[node name="ItemAttractorArea" type="Area" parent="Player"] -collision_layer = 0 -collision_mask = 8 -monitorable = false - -[node name="CollisionShape" type="CollisionShape" parent="Player/ItemAttractorArea"] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.123516, 0 ) -shape = SubResource( 24 ) - -[node name="ItemPickupArea" type="Area" parent="Player"] -collision_layer = 0 -collision_mask = 8 -monitorable = false - -[node name="CollisionShape" type="CollisionShape" parent="Player/ItemPickupArea"] -shape = SubResource( 23 ) - -[node name="Geometry" parent="Player" instance=ExtResource( 11 )] - -[node name="DebugGeometry" type="Spatial" parent="Player"] -script = ExtResource( 13 ) - -[node name="ImmediateGeometry" type="ImmediateGeometry" parent="Player/DebugGeometry"] +[node name="Player" parent="." instance=ExtResource( 2 )] [node name="Entities" type="Spatial" parent="."]