diff --git a/DungeonShooting_Godot/addons/dungeonShooting_plugin/ActivityObjectTemplate.cs b/DungeonShooting_Godot/addons/dungeonShooting_plugin/ActivityObjectTemplate.cs index be07875..1f1ba31 100644 --- a/DungeonShooting_Godot/addons/dungeonShooting_plugin/ActivityObjectTemplate.cs +++ b/DungeonShooting_Godot/addons/dungeonShooting_plugin/ActivityObjectTemplate.cs @@ -54,7 +54,7 @@ { var sd = new Sprite(); sd.Name = "ShadowSprite"; - sd.Material = ResourceManager.ShadowMaterial; + sd.Material = ResourceManager.BlendMaterial; AddChild(sd); sd.Owner = owner; } diff --git a/DungeonShooting_Godot/prefab/role/Enemy.tscn b/DungeonShooting_Godot/prefab/role/Enemy.tscn index 7e3d3d3..ab2568d 100644 --- a/DungeonShooting_Godot/prefab/role/Enemy.tscn +++ b/DungeonShooting_Godot/prefab/role/Enemy.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=2] [ext_resource path="res://prefab/role/Role.tscn" type="PackedScene" id=1] -[ext_resource path="res://resource/materlal/Shadow.gdshader" type="Shader" id=2] +[ext_resource path="res://resource/materlal/Blend.gdshader" type="Shader" id=2] [sub_resource type="ShaderMaterial" id=1] resource_local_to_scene = true diff --git a/DungeonShooting_Godot/prefab/role/Player.tscn b/DungeonShooting_Godot/prefab/role/Player.tscn index 7625613..b8da7fd 100644 --- a/DungeonShooting_Godot/prefab/role/Player.tscn +++ b/DungeonShooting_Godot/prefab/role/Player.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=4 format=2] [ext_resource path="res://prefab/role/Role.tscn" type="PackedScene" id=1] -[ext_resource path="res://resource/materlal/Shadow.gdshader" type="Shader" id=2] +[ext_resource path="res://resource/materlal/Blend.gdshader" type="Shader" id=2] [sub_resource type="ShaderMaterial" id=1] resource_local_to_scene = true diff --git a/DungeonShooting_Godot/prefab/role/Role.tscn b/DungeonShooting_Godot/prefab/role/Role.tscn index 8f97c34..3f695f1 100644 --- a/DungeonShooting_Godot/prefab/role/Role.tscn +++ b/DungeonShooting_Godot/prefab/role/Role.tscn @@ -1,10 +1,10 @@ [gd_scene load_steps=23 format=2] -[ext_resource path="res://resource/materlal/Shadow.tres" type="Material" id=1] +[ext_resource path="res://resource/materlal/Blend.tres" type="Material" id=1] [ext_resource path="res://addons/dungeonShooting_plugin/ActivityObjectTemplate.cs" type="Script" id=2] [ext_resource path="res://resource/sprite/role/role1.png" type="Texture" id=3] [ext_resource path="res://src/game/role/MountRotation.cs" type="Script" id=4] -[ext_resource path="res://resource/materlal/Shadow.gdshader" type="Shader" id=5] +[ext_resource path="res://resource/materlal/Blend.gdshader" type="Shader" id=5] [sub_resource type="ShaderMaterial" id=31] resource_local_to_scene = true @@ -129,7 +129,7 @@ position = Vector2( 0, -12 ) frames = SubResource( 6 ) animation = "idle" -frame = 2 +frame = 3 playing = true [node name="Collision" type="CollisionShape2D" parent="."] diff --git a/DungeonShooting_Godot/prefab/weapon/Weapon.tscn b/DungeonShooting_Godot/prefab/weapon/Weapon.tscn index 10ec6dc..7acefc4 100644 --- a/DungeonShooting_Godot/prefab/weapon/Weapon.tscn +++ b/DungeonShooting_Godot/prefab/weapon/Weapon.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=8 format=2] -[ext_resource path="res://resource/materlal/Shadow.tres" type="Material" id=1] -[ext_resource path="res://resource/materlal/Shadow.gdshader" type="Shader" id=2] +[ext_resource path="res://resource/materlal/Blend.tres" type="Material" id=1] +[ext_resource path="res://resource/materlal/Blend.gdshader" type="Shader" id=2] [ext_resource path="res://addons/dungeonShooting_plugin/ActivityObjectTemplate.cs" type="Script" id=3] [sub_resource type="ShaderMaterial" id=5] diff --git a/DungeonShooting_Godot/prefab/weapon/shell/ShellCase.tscn b/DungeonShooting_Godot/prefab/weapon/shell/ShellCase.tscn index 7c08e95..712c039 100644 --- a/DungeonShooting_Godot/prefab/weapon/shell/ShellCase.tscn +++ b/DungeonShooting_Godot/prefab/weapon/shell/ShellCase.tscn @@ -1,7 +1,7 @@ [gd_scene load_steps=5 format=2] [ext_resource path="res://resource/sprite/shell/shellCase.png" type="Texture" id=1] -[ext_resource path="res://resource/materlal/Shadow.tres" type="Material" id=2] +[ext_resource path="res://resource/materlal/Blend.tres" type="Material" id=2] [ext_resource path="res://addons/dungeonShooting_plugin/ActivityObjectTemplate.cs" type="Script" id=3] [sub_resource type="SpriteFrames" id=1] diff --git a/DungeonShooting_Godot/resource/materlal/Blend.gdshader b/DungeonShooting_Godot/resource/materlal/Blend.gdshader new file mode 100644 index 0000000..b3ba457 --- /dev/null +++ b/DungeonShooting_Godot/resource/materlal/Blend.gdshader @@ -0,0 +1,11 @@ +shader_type canvas_item; + +uniform vec4 shadowColor : hint_color = vec4(0.0, 0.0, 0.0, 0.8); +uniform float schedule = 1.0; +//将贴图渲染为阴影 + +void fragment() { + vec4 textureColor = texture(TEXTURE, UV); + vec4 col = mix(textureColor, shadowColor, schedule); + COLOR = mix(vec4(0.0, 0.0, 0.0, 0.0), col, textureColor.a); +} diff --git a/DungeonShooting_Godot/resource/materlal/Blend.tres b/DungeonShooting_Godot/resource/materlal/Blend.tres new file mode 100644 index 0000000..e683188 --- /dev/null +++ b/DungeonShooting_Godot/resource/materlal/Blend.tres @@ -0,0 +1,9 @@ +[gd_resource type="ShaderMaterial" load_steps=2 format=2] + +[ext_resource path="res://resource/materlal/Blend.gdshader" type="Shader" id=1] + +[resource] +resource_local_to_scene = true +shader = ExtResource( 1 ) +shader_param/shadowColor = Color( 0, 0, 0, 0.470588 ) +shader_param/schedule = 1.0 diff --git a/DungeonShooting_Godot/resource/materlal/Shadow.gdshader b/DungeonShooting_Godot/resource/materlal/Shadow.gdshader deleted file mode 100644 index b3ba457..0000000 --- a/DungeonShooting_Godot/resource/materlal/Shadow.gdshader +++ /dev/null @@ -1,11 +0,0 @@ -shader_type canvas_item; - -uniform vec4 shadowColor : hint_color = vec4(0.0, 0.0, 0.0, 0.8); -uniform float schedule = 1.0; -//将贴图渲染为阴影 - -void fragment() { - vec4 textureColor = texture(TEXTURE, UV); - vec4 col = mix(textureColor, shadowColor, schedule); - COLOR = mix(vec4(0.0, 0.0, 0.0, 0.0), col, textureColor.a); -} diff --git a/DungeonShooting_Godot/resource/materlal/Shadow.tres b/DungeonShooting_Godot/resource/materlal/Shadow.tres deleted file mode 100644 index 5b36159..0000000 --- a/DungeonShooting_Godot/resource/materlal/Shadow.tres +++ /dev/null @@ -1,9 +0,0 @@ -[gd_resource type="ShaderMaterial" load_steps=2 format=2] - -[ext_resource path="res://resource/materlal/Shadow.gdshader" type="Shader" id=1] - -[resource] -resource_local_to_scene = true -shader = ExtResource( 1 ) -shader_param/shadowColor = Color( 0, 0, 0, 0.470588 ) -shader_param/schedule = 1.0 diff --git a/DungeonShooting_Godot/src/framework/ActivityObject.cs b/DungeonShooting_Godot/src/framework/ActivityObject.cs index 8158fdd..c8d5dbc 100644 --- a/DungeonShooting_Godot/src/framework/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/ActivityObject.cs @@ -10,6 +10,11 @@ public abstract class ActivityObject : KinematicBody2D { /// + /// 当前物体类型id, 用于区分是否是同一种物体, 如果不是通过 ActivityObject.Create() 函数创建出来的对象那么 ItemId 为 null + /// + public string ItemId { get; internal set; } + + /// /// 当前物体显示的精灵图像, 节点名称必须叫 "AnimatedSprite", 类型为 AnimatedSprite /// public AnimatedSprite AnimatedSprite { get; } @@ -93,7 +98,7 @@ if (!initShadow) { initShadow = true; - ShadowSprite.Material = ResourceManager.ShadowMaterial; + ShadowSprite.Material = ResourceManager.BlendMaterial; } var anim = AnimatedSprite.Animation; @@ -224,8 +229,15 @@ root.AddChild(this); } - //注意需要延时调用 - CallDeferred(nameof(ShowShadowSprite)); + if (IsInsideTree()) + { + ShowShadowSprite(); + } + else + { + //注意需要延时调用 + CallDeferred(nameof(ShowShadowSprite)); + } } /// diff --git a/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs b/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs index 4c19b4b..ad2af6a 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/bullet/Bullet.cs @@ -24,4 +24,13 @@ /// 发射该子弹的枪对象 /// 发射该子弹的角色 void Init(CampEnum target, Weapon gun, Node2D master); +} + + +public class Bullet : ActivityObject +{ + public Bullet(string scenePath) : base(scenePath) + { + + } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/item/weapon/bullet/HighSpeedBullet.cs b/DungeonShooting_Godot/src/game/item/weapon/bullet/HighSpeedBullet.cs index 53ef711..a0121ba 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/bullet/HighSpeedBullet.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/bullet/HighSpeedBullet.cs @@ -1,72 +1,72 @@ -using Godot; - -/// -/// 高速子弹 -/// -public class HighSpeedBullet : Node2D, IBullet -{ - public CampEnum TargetCamp { get; private set; } - - public Weapon Gun { get; private set; } - - public Node2D Master { get; private set; } - - /// - /// 碰撞物体后产生的火花 - /// - [Export] public PackedScene Hit; - - //射线检测节点 - private RayCast2D RayCast2D; - private Line2D Line; - private float ca = 1; - - public void Init(CampEnum target, Weapon gun, Node2D master) - { - TargetCamp = target; - Gun = gun; - Master = master; - - //飞行距离 - var distance = MathUtils.RandRange(gun.Attribute.MinDistance, gun.Attribute.MaxDistance); - - //初始化子弹数据 - RayCast2D = GetNode("RayCast2D"); - Line = GetNode("Line"); - Modulate = Colors.White; - - // 目标点 - Vector2 targetPos = new Vector2(distance, 0); - RayCast2D.CastTo = targetPos; - RayCast2D.ForceRaycastUpdate(); - if (RayCast2D.IsColliding()) - { - //碰到物体 - Vector2 collPosition = RayCast2D.GetCollisionPoint(); - Node2D hit = Hit.Instance(); - hit.RotationDegrees = MathUtils.RandRangeInt(0, 360); - hit.GlobalPosition = collPosition; - GetTree().CurrentScene.AddChild(hit); - //划线的点坐标 - Line.SetPointPosition(1, new Vector2(Line.GlobalPosition.DistanceTo(collPosition), 0)); - } - else - { - //划线的点坐标 - Line.SetPointPosition(1, targetPos); - } - RayCast2D.Enabled = false; - } - - public override void _Process(float delta) - { - ca -= 12 * delta; - if (ca <= 0) { - QueueFree(); - return; - } - Color c = Modulate; - c.a = ca; - Modulate = c; - } -} \ No newline at end of file +// using Godot; +// +// /// +// /// 高速子弹 +// /// +// public class HighSpeedBullet : Node2D, IBullet +// { +// public CampEnum TargetCamp { get; private set; } +// +// public Weapon Gun { get; private set; } +// +// public Node2D Master { get; private set; } +// +// /// +// /// 碰撞物体后产生的火花 +// /// +// [Export] public PackedScene Hit; +// +// //射线检测节点 +// private RayCast2D RayCast2D; +// private Line2D Line; +// private float ca = 1; +// +// public void Init(CampEnum target, Weapon gun, Node2D master) +// { +// TargetCamp = target; +// Gun = gun; +// Master = master; +// +// //飞行距离 +// var distance = MathUtils.RandRange(gun.Attribute.MinDistance, gun.Attribute.MaxDistance); +// +// //初始化子弹数据 +// RayCast2D = GetNode("RayCast2D"); +// Line = GetNode("Line"); +// Modulate = Colors.White; +// +// // 目标点 +// Vector2 targetPos = new Vector2(distance, 0); +// RayCast2D.CastTo = targetPos; +// RayCast2D.ForceRaycastUpdate(); +// if (RayCast2D.IsColliding()) +// { +// //碰到物体 +// Vector2 collPosition = RayCast2D.GetCollisionPoint(); +// Node2D hit = Hit.Instance(); +// hit.RotationDegrees = MathUtils.RandRangeInt(0, 360); +// hit.GlobalPosition = collPosition; +// GetTree().CurrentScene.AddChild(hit); +// //划线的点坐标 +// Line.SetPointPosition(1, new Vector2(Line.GlobalPosition.DistanceTo(collPosition), 0)); +// } +// else +// { +// //划线的点坐标 +// Line.SetPointPosition(1, targetPos); +// } +// RayCast2D.Enabled = false; +// } +// +// public override void _Process(float delta) +// { +// ca -= 12 * delta; +// if (ca <= 0) { +// QueueFree(); +// return; +// } +// Color c = Modulate; +// c.a = ca; +// Modulate = c; +// } +// } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/item/weapon/bullet/OrdinaryBullets.cs b/DungeonShooting_Godot/src/game/item/weapon/bullet/OrdinaryBullets.cs index aa19c76..2f51ecb 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/bullet/OrdinaryBullets.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/bullet/OrdinaryBullets.cs @@ -52,7 +52,7 @@ ShadowSprite.ZIndex = -1; ShadowSprite.Texture = BulletSprite.Texture; ShadowSprite.Offset = BulletSprite.Offset; - ShadowSprite.Material = ResourceManager.ShadowMaterial; + ShadowSprite.Material = ResourceManager.BlendMaterial; AddChild(ShadowSprite); } diff --git a/DungeonShooting_Godot/src/game/manager/ResourceManager.cs b/DungeonShooting_Godot/src/game/manager/ResourceManager.cs index 33669b0..4c69cd1 100644 --- a/DungeonShooting_Godot/src/game/manager/ResourceManager.cs +++ b/DungeonShooting_Godot/src/game/manager/ResourceManager.cs @@ -4,15 +4,15 @@ public static class ResourceManager { /// - /// 2D阴影的材质 + /// 颜色混合材质 /// - public static ShaderMaterial ShadowMaterial + public static ShaderMaterial BlendMaterial { get { if (_shadowMaterial == null) { - _shadowMaterial = ResourceLoader.Load("res://resource/materlal/Shadow.tres"); + _shadowMaterial = ResourceLoader.Load(ResourcePath.resource_materlal_Blend_tres); } return _shadowMaterial; } @@ -20,15 +20,15 @@ private static ShaderMaterial _shadowMaterial; /// - /// 2D阴影的Shader + /// 颜色混合Shader /// - public static Shader ShadowShader + public static Shader BlendShader { get { if (_shadowShader == null) { - _shadowShader = ResourceLoader.Load("res://resource/materlal/Shadow.gdshader"); + _shadowShader = ResourceLoader.Load(ResourcePath.resource_materlal_Blend_gdshader); } return _shadowShader; } diff --git a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs index a6be0ca..38cffd4 100644 --- a/DungeonShooting_Godot/src/game/manager/ResourcePath.cs +++ b/DungeonShooting_Godot/src/game/manager/ResourcePath.cs @@ -7,4 +7,6 @@ public const string prefab_role_Role_tscn = "res://prefab/role/Role.tscn"; public const string prefab_role_Player_tscn = "res://prefab/role/Player.tscn"; public const string prefab_role_Enemy_tscn = "res://prefab/role/Enemy.tscn"; + public const string resource_materlal_Blend_tres = "res://resource/materlal/Blend.tres"; + public const string resource_materlal_Blend_gdshader = "res://resource/materlal/Blend.gdshader"; } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/room/RoomManager.cs b/DungeonShooting_Godot/src/game/room/RoomManager.cs index c6092bb..cdb4a49 100644 --- a/DungeonShooting_Godot/src/game/room/RoomManager.cs +++ b/DungeonShooting_Godot/src/game/room/RoomManager.cs @@ -9,6 +9,9 @@ public Node2D ObjectRoot { get; private set; } public YSort SortRoot { get; private set; } + + private Enemy _enemy; + public override void _EnterTree() { Input.MouseMode = Input.MouseModeEnum.Hidden; @@ -26,16 +29,20 @@ Player.Position = new Vector2(100, 100); Player.Name = "Player"; Player.PutDown(); - - var enemy1 = new Enemy(); - enemy1.PutDown(new Vector2(150, 150)); + + _enemy = new Enemy(); + _enemy.PutDown(new Vector2(150, 150)); + + } public override void _Ready() { //播放bgm SoundManager.PlayeMusic("intro.ogg", this, -17f); - WeaponManager.GetGun("1001").PutDown(new Vector2(100, 80)); + + _enemy.PickUpWeapon(WeaponManager.GetGun("1001")); + WeaponManager.GetGun("1001").PutDown(new Vector2(80, 100)); WeaponManager.GetGun("1001").PutDown(new Vector2(80, 80)); WeaponManager.GetGun("1002").PutDown(new Vector2(80, 120)); @@ -44,7 +51,6 @@ WeaponManager.GetGun("1003").PutDown(new Vector2(180, 80)); WeaponManager.GetGun("1003").PutDown(new Vector2(180, 180)); WeaponManager.GetGun("1002").PutDown(new Vector2(180, 120)); - } public override void _Process(float delta)