diff --git a/DungeonShooting_Godot/prefab/test/MoveComponent.tscn b/DungeonShooting_Godot/prefab/test/MoveComponent.tscn new file mode 100644 index 0000000..d73f0db --- /dev/null +++ b/DungeonShooting_Godot/prefab/test/MoveComponent.tscn @@ -0,0 +1,8 @@ +[gd_scene load_steps=2 format=2] + +[sub_resource type="RectangleShape2D" id=1] + +[node name="MoveComponent" type="KinematicBody2D"] + +[node name="Collision" type="CollisionShape2D" parent="."] +shape = SubResource( 1 ) diff --git a/DungeonShooting_Godot/project.godot b/DungeonShooting_Godot/project.godot index 4470bd7..93ab966 100644 --- a/DungeonShooting_Godot/project.godot +++ b/DungeonShooting_Godot/project.godot @@ -11,7 +11,7 @@ [application] config/name="DungeonShooting" -run/main_scene="res://scene/Room.tscn" +run/main_scene="res://scene/test/TestCommpont.tscn" config/icon="res://icon.png" [autoload] diff --git a/DungeonShooting_Godot/scene/TestNavigation.tscn b/DungeonShooting_Godot/scene/TestNavigation.tscn deleted file mode 100644 index d310e7d..0000000 --- a/DungeonShooting_Godot/scene/TestNavigation.tscn +++ /dev/null @@ -1,79 +0,0 @@ -[gd_scene load_steps=8 format=2] - -[ext_resource path="res://src/test/TestNavigation.cs" type="Script" id=1] -[ext_resource path="res://icon.png" type="Texture" id=2] -[ext_resource path="res://resource/sprite/environment/craftpix-net-248911/16x16.png" type="Texture" id=3] - - -[sub_resource type="NavigationPolygon" id=2] -vertices = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) -polygons = [ PoolIntArray( 0, 1, 2, 3 ) ] - -[sub_resource type="TileSet" id=3] -0/name = "16x16.png 0" -0/texture = ExtResource( 3 ) -0/tex_offset = Vector2( 0, 0 ) -0/modulate = Color( 1, 1, 1, 1 ) -0/region = Rect2( 0, 0, 16, 16 ) -0/tile_mode = 0 -0/occluder_offset = Vector2( 0, 0 ) -0/navigation_offset = Vector2( 0, 0 ) -0/navigation = SubResource( 2 ) -0/shape_offset = Vector2( 0, 0 ) -0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) -0/shape_one_way = false -0/shape_one_way_margin = 0.0 -0/shapes = [ ] -0/z_index = 0 - -[sub_resource type="NavigationPolygon" id=4] -vertices = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) -polygons = [ PoolIntArray( 0, 1, 2, 3 ) ] - -[sub_resource type="TileSet" id=5] -0/name = "16x16.png 0" -0/texture = ExtResource( 3 ) -0/tex_offset = Vector2( 0, 0 ) -0/modulate = Color( 1, 1, 1, 1 ) -0/region = Rect2( 32, 0, 16, 16 ) -0/tile_mode = 0 -0/occluder_offset = Vector2( 0, 0 ) -0/navigation_offset = Vector2( 0, 0 ) -0/navigation = SubResource( 4 ) -0/shape_offset = Vector2( 0, 0 ) -0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) -0/shape_one_way = false -0/shape_one_way_margin = 0.0 -0/shapes = [ ] -0/z_index = 0 - -[node name="TestNavigation" type="Node2D"] -script = ExtResource( 1 ) - -[node name="Position2D" type="Position2D" parent="."] -z_index = -3 - -[node name="Navigation2D" type="Navigation2D" parent="Position2D"] - -[node name="Node2D" type="Node2D" parent="Position2D/Navigation2D"] - -[node name="TileMap" type="TileMap" parent="Position2D/Navigation2D/Node2D"] -tile_set = SubResource( 3 ) -cell_size = Vector2( 16, 16 ) -bake_navigation = true -format = 1 -tile_data = PoolIntArray( 131074, 0, 0, 131075, 0, 0, 131076, 0, 0, 131077, 0, 0, 131078, 0, 0, 196610, 0, 0, 196611, 0, 0, 196612, 0, 0, 196613, 0, 0, 196614, 0, 0, 262146, 0, 0, 262147, 0, 0, 262148, 0, 0, 262149, 0, 0, 262150, 0, 0, 327682, 0, 0, 327683, 0, 0, 327684, 0, 0, 327685, 0, 0, 327686, 0, 0, 327699, 0, 0, 327700, 0, 0, 327701, 0, 0, 327702, 0, 0, 327703, 0, 0, 327704, 0, 0, 327705, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 393223, 0, 0, 393224, 0, 0, 393225, 0, 0, 393226, 0, 0, 393227, 0, 0, 393228, 0, 0, 393229, 0, 0, 393235, 0, 0, 393236, 0, 0, 393237, 0, 0, 393238, 0, 0, 393239, 0, 0, 393240, 0, 0, 393241, 0, 0, 458754, 0, 0, 458755, 0, 0, 458756, 0, 0, 458757, 0, 0, 458758, 0, 0, 458759, 0, 0, 458760, 0, 0, 458761, 0, 0, 458762, 0, 0, 458763, 0, 0, 458764, 0, 0, 458765, 0, 0, 458771, 0, 0, 458772, 0, 0, 458773, 0, 0, 458774, 0, 0, 458775, 0, 0, 458776, 0, 0, 458777, 0, 0, 524299, 0, 0, 524300, 0, 0, 524301, 0, 0, 524307, 0, 0, 524308, 0, 0, 524309, 0, 0, 524310, 0, 0, 524311, 0, 0, 524312, 0, 0, 524313, 0, 0, 589835, 0, 0, 589836, 0, 0, 589837, 0, 0, 589843, 0, 0, 589844, 0, 0, 589845, 0, 0, 589846, 0, 0, 589847, 0, 0, 589848, 0, 0, 589849, 0, 0, 589850, 0, 0, 589851, 0, 0, 655371, 0, 0, 655372, 0, 0, 655373, 0, 0, 655379, 0, 0, 655380, 0, 0, 655381, 0, 0, 655382, 0, 0, 655383, 0, 0, 655384, 0, 0, 655385, 0, 0, 655386, 0, 0, 655387, 0, 0, 720897, 0, 0, 720898, 0, 0, 720899, 0, 0, 720900, 0, 0, 720901, 0, 0, 720902, 0, 0, 720903, 0, 0, 720904, 0, 0, 720905, 0, 0, 720906, 0, 0, 720907, 0, 0, 720908, 0, 0, 720909, 0, 0, 720915, 0, 0, 720916, 0, 0, 720917, 0, 0, 720918, 0, 0, 720919, 0, 0, 720920, 0, 0, 720921, 0, 0, 720922, 0, 0, 720923, 0, 0, 786433, 0, 0, 786434, 0, 0, 786435, 0, 0, 786436, 0, 0, 786437, 0, 0, 786438, 0, 0, 786439, 0, 0, 786440, 0, 0, 786441, 0, 0, 786442, 0, 0, 786443, 0, 0, 786444, 0, 0, 786445, 0, 0, 786446, 0, 0, 786447, 0, 0, 786448, 0, 0, 786449, 0, 0, 786450, 0, 0, 786451, 0, 0, 786452, 0, 0, 786453, 0, 0, 786454, 0, 0, 786455, 0, 0, 786456, 0, 0, 786457, 0, 0, 786458, 0, 0, 786459, 0, 0, 851979, 0, 0, 851980, 0, 0, 851981, 0, 0, 851982, 0, 0, 851983, 0, 0, 851984, 0, 0, 851985, 0, 0, 851986, 0, 0, 851987, 0, 0, 851988, 0, 0, 851989, 0, 0, 851990, 0, 0, 851991, 0, 0, 851992, 0, 0, 851993, 0, 0, 851994, 0, 0, 851995, 0, 0, 917515, 0, 0, 917516, 0, 0, 917517, 0, 0, 917518, 0, 0, 917519, 0, 0, 917520, 0, 0, 917521, 0, 0, 917522, 0, 0, 917523, 0, 0, 917524, 0, 0, 917525, 0, 0, 917526, 0, 0, 917527, 0, 0, 917528, 0, 0, 917529, 0, 0, 917530, 0, 0, 917531, 0, 0, 983051, 0, 0, 983052, 0, 0, 983053, 0, 0, 983054, 0, 0, 983055, 0, 0, 983056, 0, 0, 983057, 0, 0, 983058, 0, 0, 983059, 0, 0, 983060, 0, 0, 983061, 0, 0, 983062, 0, 0, 983063, 0, 0, 983064, 0, 0, 983065, 0, 0, 983066, 0, 0, 983067, 0, 0 ) - -[node name="Node2D2" type="Node2D" parent="Position2D/Navigation2D"] - -[node name="TileMap" type="TileMap" parent="Position2D/Navigation2D/Node2D2"] -tile_set = SubResource( 5 ) -cell_size = Vector2( 16, 16 ) -bake_navigation = true -format = 1 -tile_data = PoolIntArray( 131088, 0, 0, 131089, 0, 0, 131090, 0, 0, 131091, 0, 0, 131092, 0, 0, 196622, 0, 0, 196623, 0, 0, 196624, 0, 0, 196628, 0, 0, 262156, 0, 0, 262157, 0, 0, 262158, 0, 0, 262164, 0, 0, 327692, 0, 0, 524302, 0, 0, 524303, 0, 0, 524304, 0, 0, 524305, 0, 0, 524306, 0, 0, 589838, 0, 0, 589839, 0, 0, 589840, 0, 0, 589841, 0, 0, 589842, 0, 0 ) - -[node name="Sprite" type="Sprite" parent="Position2D"] -position = Vector2( 33, 32 ) -scale = Vector2( 0.2, 0.2 ) -texture = ExtResource( 2 ) diff --git a/DungeonShooting_Godot/scene/test/TestCommpont.tscn b/DungeonShooting_Godot/scene/test/TestCommpont.tscn new file mode 100644 index 0000000..7046b05 --- /dev/null +++ b/DungeonShooting_Godot/scene/test/TestCommpont.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=3 format=2] + +[ext_resource path="res://icon.png" type="Texture" id=1] +[ext_resource path="res://src/test/TestPlayer.cs" type="Script" id=2] + +[node name="Node2D" type="Node2D"] + +[node name="Sprite" type="Sprite" parent="."] +position = Vector2( 200, 102 ) +scale = Vector2( 0.3, 0.3 ) +texture = ExtResource( 1 ) +script = ExtResource( 2 ) diff --git a/DungeonShooting_Godot/scene/test/TestNavigation.tscn b/DungeonShooting_Godot/scene/test/TestNavigation.tscn new file mode 100644 index 0000000..d310e7d --- /dev/null +++ b/DungeonShooting_Godot/scene/test/TestNavigation.tscn @@ -0,0 +1,79 @@ +[gd_scene load_steps=8 format=2] + +[ext_resource path="res://src/test/TestNavigation.cs" type="Script" id=1] +[ext_resource path="res://icon.png" type="Texture" id=2] +[ext_resource path="res://resource/sprite/environment/craftpix-net-248911/16x16.png" type="Texture" id=3] + + +[sub_resource type="NavigationPolygon" id=2] +vertices = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) +polygons = [ PoolIntArray( 0, 1, 2, 3 ) ] + +[sub_resource type="TileSet" id=3] +0/name = "16x16.png 0" +0/texture = ExtResource( 3 ) +0/tex_offset = Vector2( 0, 0 ) +0/modulate = Color( 1, 1, 1, 1 ) +0/region = Rect2( 0, 0, 16, 16 ) +0/tile_mode = 0 +0/occluder_offset = Vector2( 0, 0 ) +0/navigation_offset = Vector2( 0, 0 ) +0/navigation = SubResource( 2 ) +0/shape_offset = Vector2( 0, 0 ) +0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +0/shape_one_way = false +0/shape_one_way_margin = 0.0 +0/shapes = [ ] +0/z_index = 0 + +[sub_resource type="NavigationPolygon" id=4] +vertices = PoolVector2Array( 0, 0, 16, 0, 16, 16, 0, 16 ) +polygons = [ PoolIntArray( 0, 1, 2, 3 ) ] + +[sub_resource type="TileSet" id=5] +0/name = "16x16.png 0" +0/texture = ExtResource( 3 ) +0/tex_offset = Vector2( 0, 0 ) +0/modulate = Color( 1, 1, 1, 1 ) +0/region = Rect2( 32, 0, 16, 16 ) +0/tile_mode = 0 +0/occluder_offset = Vector2( 0, 0 ) +0/navigation_offset = Vector2( 0, 0 ) +0/navigation = SubResource( 4 ) +0/shape_offset = Vector2( 0, 0 ) +0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +0/shape_one_way = false +0/shape_one_way_margin = 0.0 +0/shapes = [ ] +0/z_index = 0 + +[node name="TestNavigation" type="Node2D"] +script = ExtResource( 1 ) + +[node name="Position2D" type="Position2D" parent="."] +z_index = -3 + +[node name="Navigation2D" type="Navigation2D" parent="Position2D"] + +[node name="Node2D" type="Node2D" parent="Position2D/Navigation2D"] + +[node name="TileMap" type="TileMap" parent="Position2D/Navigation2D/Node2D"] +tile_set = SubResource( 3 ) +cell_size = Vector2( 16, 16 ) +bake_navigation = true +format = 1 +tile_data = PoolIntArray( 131074, 0, 0, 131075, 0, 0, 131076, 0, 0, 131077, 0, 0, 131078, 0, 0, 196610, 0, 0, 196611, 0, 0, 196612, 0, 0, 196613, 0, 0, 196614, 0, 0, 262146, 0, 0, 262147, 0, 0, 262148, 0, 0, 262149, 0, 0, 262150, 0, 0, 327682, 0, 0, 327683, 0, 0, 327684, 0, 0, 327685, 0, 0, 327686, 0, 0, 327699, 0, 0, 327700, 0, 0, 327701, 0, 0, 327702, 0, 0, 327703, 0, 0, 327704, 0, 0, 327705, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 393223, 0, 0, 393224, 0, 0, 393225, 0, 0, 393226, 0, 0, 393227, 0, 0, 393228, 0, 0, 393229, 0, 0, 393235, 0, 0, 393236, 0, 0, 393237, 0, 0, 393238, 0, 0, 393239, 0, 0, 393240, 0, 0, 393241, 0, 0, 458754, 0, 0, 458755, 0, 0, 458756, 0, 0, 458757, 0, 0, 458758, 0, 0, 458759, 0, 0, 458760, 0, 0, 458761, 0, 0, 458762, 0, 0, 458763, 0, 0, 458764, 0, 0, 458765, 0, 0, 458771, 0, 0, 458772, 0, 0, 458773, 0, 0, 458774, 0, 0, 458775, 0, 0, 458776, 0, 0, 458777, 0, 0, 524299, 0, 0, 524300, 0, 0, 524301, 0, 0, 524307, 0, 0, 524308, 0, 0, 524309, 0, 0, 524310, 0, 0, 524311, 0, 0, 524312, 0, 0, 524313, 0, 0, 589835, 0, 0, 589836, 0, 0, 589837, 0, 0, 589843, 0, 0, 589844, 0, 0, 589845, 0, 0, 589846, 0, 0, 589847, 0, 0, 589848, 0, 0, 589849, 0, 0, 589850, 0, 0, 589851, 0, 0, 655371, 0, 0, 655372, 0, 0, 655373, 0, 0, 655379, 0, 0, 655380, 0, 0, 655381, 0, 0, 655382, 0, 0, 655383, 0, 0, 655384, 0, 0, 655385, 0, 0, 655386, 0, 0, 655387, 0, 0, 720897, 0, 0, 720898, 0, 0, 720899, 0, 0, 720900, 0, 0, 720901, 0, 0, 720902, 0, 0, 720903, 0, 0, 720904, 0, 0, 720905, 0, 0, 720906, 0, 0, 720907, 0, 0, 720908, 0, 0, 720909, 0, 0, 720915, 0, 0, 720916, 0, 0, 720917, 0, 0, 720918, 0, 0, 720919, 0, 0, 720920, 0, 0, 720921, 0, 0, 720922, 0, 0, 720923, 0, 0, 786433, 0, 0, 786434, 0, 0, 786435, 0, 0, 786436, 0, 0, 786437, 0, 0, 786438, 0, 0, 786439, 0, 0, 786440, 0, 0, 786441, 0, 0, 786442, 0, 0, 786443, 0, 0, 786444, 0, 0, 786445, 0, 0, 786446, 0, 0, 786447, 0, 0, 786448, 0, 0, 786449, 0, 0, 786450, 0, 0, 786451, 0, 0, 786452, 0, 0, 786453, 0, 0, 786454, 0, 0, 786455, 0, 0, 786456, 0, 0, 786457, 0, 0, 786458, 0, 0, 786459, 0, 0, 851979, 0, 0, 851980, 0, 0, 851981, 0, 0, 851982, 0, 0, 851983, 0, 0, 851984, 0, 0, 851985, 0, 0, 851986, 0, 0, 851987, 0, 0, 851988, 0, 0, 851989, 0, 0, 851990, 0, 0, 851991, 0, 0, 851992, 0, 0, 851993, 0, 0, 851994, 0, 0, 851995, 0, 0, 917515, 0, 0, 917516, 0, 0, 917517, 0, 0, 917518, 0, 0, 917519, 0, 0, 917520, 0, 0, 917521, 0, 0, 917522, 0, 0, 917523, 0, 0, 917524, 0, 0, 917525, 0, 0, 917526, 0, 0, 917527, 0, 0, 917528, 0, 0, 917529, 0, 0, 917530, 0, 0, 917531, 0, 0, 983051, 0, 0, 983052, 0, 0, 983053, 0, 0, 983054, 0, 0, 983055, 0, 0, 983056, 0, 0, 983057, 0, 0, 983058, 0, 0, 983059, 0, 0, 983060, 0, 0, 983061, 0, 0, 983062, 0, 0, 983063, 0, 0, 983064, 0, 0, 983065, 0, 0, 983066, 0, 0, 983067, 0, 0 ) + +[node name="Node2D2" type="Node2D" parent="Position2D/Navigation2D"] + +[node name="TileMap" type="TileMap" parent="Position2D/Navigation2D/Node2D2"] +tile_set = SubResource( 5 ) +cell_size = Vector2( 16, 16 ) +bake_navigation = true +format = 1 +tile_data = PoolIntArray( 131088, 0, 0, 131089, 0, 0, 131090, 0, 0, 131091, 0, 0, 131092, 0, 0, 196622, 0, 0, 196623, 0, 0, 196624, 0, 0, 196628, 0, 0, 262156, 0, 0, 262157, 0, 0, 262158, 0, 0, 262164, 0, 0, 327692, 0, 0, 524302, 0, 0, 524303, 0, 0, 524304, 0, 0, 524305, 0, 0, 524306, 0, 0, 589838, 0, 0, 589839, 0, 0, 589840, 0, 0, 589841, 0, 0, 589842, 0, 0 ) + +[node name="Sprite" type="Sprite" parent="Position2D"] +position = Vector2( 33, 32 ) +scale = Vector2( 0.2, 0.2 ) +texture = ExtResource( 2 ) diff --git a/DungeonShooting_Godot/src/framework/Component.cs b/DungeonShooting_Godot/src/framework/Component.cs deleted file mode 100644 index 0c0227b..0000000 --- a/DungeonShooting_Godot/src/framework/Component.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Godot; - -public abstract class Component : IComponent where TN : Node where TG : Node2D -{ - public GameObject GameObject { get; private set; } - public TN Node { get; } - - public Component(TN inst) - { - Node = inst; - } - - public abstract void Process(float delta); - - public abstract void PhysicsProcess(float delta); - - public void SetGameObject(GameObject gameObject) - { - GameObject = gameObject; - } -} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/GameObject.cs b/DungeonShooting_Godot/src/framework/GameObject.cs index e3cc636..aae59ed 100644 --- a/DungeonShooting_Godot/src/framework/GameObject.cs +++ b/DungeonShooting_Godot/src/framework/GameObject.cs @@ -1,68 +1,122 @@ using System.Collections.Generic; using Godot; -public abstract class GameObject : IProcess where T : Node2D +public class GameObject : Node, IDestroy where T : Node2D { - public Vector3 Position { get; set; } - public Vector2 Position2D { get; set; } + public float Altitude { get; set; } - public T Node; + public Vector2 Position + { + get => Node.Position; + set => Node.Position = value; + } - private List> _components = new List>(); - private bool _isDestroy = false; + public Vector2 GlobalPosition + { + get => Node.GlobalPosition; + set => Node.GlobalPosition = value; + } + + public bool Visible + { + get => Node.Visible; + set => Node.Visible = value; + } + + public bool IsDestroyed { get; private set; } + + public T Node { get; private set; } + + private List> _components = new List>(); public GameObject(T node) { + Name = "ComponentControl"; Node = node; + node.AddChild(this); } - public void AddComponent(Component component) where TN : Node + public void AddComponent(NodeComponent nodeComponent) where TN : Node { - if (!_components.Contains(component)) + if (!_components.Contains(nodeComponent)) { - component.SetGameObject(this); - Node.AddChild(component.Node); + _components.Add(nodeComponent); + nodeComponent.SetGameObject(this); + Node.AddChild(nodeComponent.Node); + nodeComponent.OnMount(); } } - public void RemoveComponent(Component component) where TN : Node + public void RemoveComponent(NodeComponent nodeComponent) where TN : Node + { + if (_components.Remove(nodeComponent)) + { + nodeComponent.SetGameObject(null); + Node.RemoveChild(nodeComponent.Node); + nodeComponent.OnUnMount(); + } + } + + public void AddComponent(Component component) + { + if (!_components.Contains(component)) + { + _components.Add(component); + component.SetGameObject(this); + component.OnMount(); + } + } + + public void RemoveComponent(Component component) { if (_components.Remove(component)) { component.SetGameObject(null); - Node.RemoveChild(component.Node); + component.OnUnMount(); } } - public void Process(float delta) + public override void _Process(float delta) { var arr = _components.ToArray(); for (int i = 0; i < arr.Length; i++) { - arr[i].Process(delta); + if (IsDestroyed) return; + var temp = arr[i]; + if (temp != null && temp.GameObject == this && temp.Enable) + { + temp._TriggerProcess(delta); + } } } - public void PhysicsProcess(float delta) + public override void _PhysicsProcess(float delta) { var arr = _components.ToArray(); for (int i = 0; i < arr.Length; i++) { - arr[i].PhysicsProcess(delta); + if (IsDestroyed) return; + var temp = arr[i]; + if (temp != null && temp.GameObject == this && temp.Enable) + { + temp._TriggerPhysicsProcess(delta); + } } } public void Destroy() { - if (_isDestroy) + if (IsDestroyed) { return; } - _isDestroy = true; - } - public bool IsDestroy() - { - return _isDestroy; + IsDestroyed = true; + Node.QueueFree(); + var arr = _components.ToArray(); + for (int i = 0; i < arr.Length; i++) + { + arr[i].Destroy(); + } } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/IComponent.cs b/DungeonShooting_Godot/src/framework/IComponent.cs index 7002919..3db06bb 100644 --- a/DungeonShooting_Godot/src/framework/IComponent.cs +++ b/DungeonShooting_Godot/src/framework/IComponent.cs @@ -1,9 +1,18 @@  using Godot; -public interface IComponent : IProcess where TN : Node2D +public interface IComponent : IProcess, IDestroy where TN : Node2D { GameObject GameObject { get; } + + Vector2 Position { get; set; } + Vector2 GlobalPosition { get; set; } + bool Visible { get; set; } + bool Enable { get; set; } + void Ready(); + void OnMount(); + void OnUnMount(); + void SetGameObject(GameObject gameObject); } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/IDestroy.cs b/DungeonShooting_Godot/src/framework/IDestroy.cs new file mode 100644 index 0000000..82d8841 --- /dev/null +++ b/DungeonShooting_Godot/src/framework/IDestroy.cs @@ -0,0 +1,16 @@ + +/// +/// 销毁接口 +/// +public interface IDestroy +{ + /// + /// 返回物体是否已经被销毁 + /// + bool IsDestroyed { get; } + + /// + /// 销毁物体接口 + /// + void Destroy(); +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/framework/NodeComponent.cs b/DungeonShooting_Godot/src/framework/NodeComponent.cs new file mode 100644 index 0000000..732d379 --- /dev/null +++ b/DungeonShooting_Godot/src/framework/NodeComponent.cs @@ -0,0 +1,16 @@ +using Godot; + +public abstract class NodeComponent : Component where TN : Node where TG : Node2D +{ + public TN Node { get; } + + public NodeComponent(TN inst) + { + Node = inst; + } + + public override void OnDestroy() + { + Node.QueueFree(); + } +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/test/TestAttackComponent.cs b/DungeonShooting_Godot/src/test/TestAttackComponent.cs new file mode 100644 index 0000000..a13eb59 --- /dev/null +++ b/DungeonShooting_Godot/src/test/TestAttackComponent.cs @@ -0,0 +1,13 @@ + +using Godot; + +public class TestAttackComponent : Component +{ + public override void Process(float delta) + { + if (Input.IsActionPressed("fire")) + { + GD.Print("点击了开火"); + } + } +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/test/TestMoveNodeComponent.cs b/DungeonShooting_Godot/src/test/TestMoveNodeComponent.cs new file mode 100644 index 0000000..46c53df --- /dev/null +++ b/DungeonShooting_Godot/src/test/TestMoveNodeComponent.cs @@ -0,0 +1,29 @@ + +using Godot; + +public class TestMoveNodeComponent : NodeComponent +{ + public TestMoveNodeComponent(KinematicBody2D inst) : base(inst) + { + + } + + public override void Process(float delta) + { + + } + + public override void PhysicsProcess(float delta) + { + var axis = Input.GetAxis("move_left", "move_right"); + if (axis != 0f) + { + Position += new Vector2(axis * 10 * delta, 0); + } + } + + public override void OnDestroy() + { + + } +} \ No newline at end of file diff --git a/DungeonShooting_Godot/src/test/TestPlayer.cs b/DungeonShooting_Godot/src/test/TestPlayer.cs new file mode 100644 index 0000000..4ff89e3 --- /dev/null +++ b/DungeonShooting_Godot/src/test/TestPlayer.cs @@ -0,0 +1,14 @@ +using Godot; + +public class TestPlayer : Sprite +{ + public GameObject GameObject { get; private set; } + + public override void _Ready() + { + GameObject = new GameObject(this); + var move = new TestMoveNodeComponent(ResourceManager.Load("res://prefab/test/MoveComponent.tscn").Instance()); + GameObject.AddComponent(move); + GameObject.AddComponent(new TestAttackComponent()); + } +} \ No newline at end of file