Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / activity / prop / PropActivity.cs
@小李xl 小李xl on 18 Mar 2024 1 KB 调整Prop
  1.  
  2. using Godot;
  3.  
  4. /// <summary>
  5. /// 道具基类
  6. /// </summary>
  7. public abstract partial class PropActivity : ActivityObject
  8. {
  9. /// <summary>
  10. /// 道具所属角色
  11. /// </summary>
  12. public Role Master { get; set; }
  13.  
  14. /// <summary>
  15. /// 当道具被拾起时调用 (在 Master 赋值之后调用)
  16. /// </summary>
  17. public abstract void OnPickUpItem();
  18.  
  19. /// <summary>
  20. /// 当道具被移除时调用 (在 Master 置为 null 之前调用)
  21. /// </summary>
  22. public abstract void OnRemoveItem();
  23.  
  24. public override void OnInit()
  25. {
  26. ThrowCollisionMask = PhysicsLayer.Wall;
  27. }
  28.  
  29. /// <summary>
  30. /// 触发扔掉道具效果, 并不会管道具是否在道具背包中
  31. /// </summary>
  32. /// <param name="master">触发扔掉该道具的的角色</param>
  33. public void ThrowProp(Role master)
  34. {
  35. ThrowProp(master, master.GlobalPosition);
  36. }
  37. /// <summary>
  38. /// 触发扔掉道具效果, 并不会管道具是否在道具背包中
  39. /// </summary>
  40. /// <param name="master">触发扔掉该道具的的角色</param>
  41. /// <param name="startPosition">投抛起始位置</param>
  42. public void ThrowProp(Role master, Vector2 startPosition)
  43. {
  44. //阴影偏移
  45. ShadowOffset = new Vector2(0, 2);
  46. GlobalRotation = 0;
  47. var startHeight = 8;
  48. Throw(startPosition, startHeight, 0, Vector2.Zero, 0);
  49.  
  50. //继承role的移动速度
  51. InheritVelocity(master);
  52. }
  53. }