Add a null judgment.
添加空判断。
This commit is contained in:
parent
802eb599da
commit
1c116eb820
|
@ -5,4 +5,7 @@ build_an_index,为{0}构建索引。,"Build an index for {0}."
|
||||||
add_file_index,添加文件索引{0}。,"Add file index {0}."
|
add_file_index,添加文件索引{0}。,"Add file index {0}."
|
||||||
index_updated,{0}索引已更新。,"{0} Index has been updated."
|
index_updated,{0}索引已更新。,"{0} Index has been updated."
|
||||||
no_manifest_file,位于{0}的数据包,没有清单文件,无法加载。,"Packet located in {0}, no manifest file, cannot be loaded."
|
no_manifest_file,位于{0}的数据包,没有清单文件,无法加载。,"Packet located in {0}, no manifest file, cannot be loaded."
|
||||||
duplicate_at_path_id,位于{0}路径{1}的Id({2})已被占用,无法加载。,"Id({2}) in {0} path {1} is occupied and cannot be loaded."
|
duplicate_at_path_id,位于{0}路径{1}的Id({2})已被占用,无法加载。,"Id({2}) in {0} path {1} is occupied and cannot be loaded."
|
||||||
|
duplicate_at_path_id,位于{0}路径{1}的Id({2})已被占用,无法加载。,"Id({2}) in {0} path {1} is occupied and cannot be loaded."
|
||||||
|
map_generator_is_not_set_up,未设置地图生成器。,Map generator is not set up.
|
||||||
|
map_generator_is_not_configured,地图生成器没有有效配置。,Map Generator is not configured.
|
|
Binary file not shown.
Binary file not shown.
|
@ -147,7 +147,6 @@ hotbar_previous={
|
||||||
[internationalization]
|
[internationalization]
|
||||||
|
|
||||||
locale/translations=PackedStringArray("res://locals/UI.en.translation", "res://locals/UI.zh.translation", "res://locals/Error.zh.translation", "res://locals/Error.en.translation", "res://locals/slogan.en.translation", "res://locals/slogan.zh.translation", "res://locals/Log.en.translation", "res://locals/Log.zh.translation", "res://locals/Weapon.en.translation", "res://locals/Weapon.zh.translation", "res://locals/InputMapping.en.translation", "res://locals/InputMapping.zh.translation")
|
locale/translations=PackedStringArray("res://locals/UI.en.translation", "res://locals/UI.zh.translation", "res://locals/Error.zh.translation", "res://locals/Error.en.translation", "res://locals/slogan.en.translation", "res://locals/slogan.zh.translation", "res://locals/Log.en.translation", "res://locals/Log.zh.translation", "res://locals/Weapon.en.translation", "res://locals/Weapon.zh.translation", "res://locals/InputMapping.en.translation", "res://locals/InputMapping.zh.translation")
|
||||||
locale/test="en"
|
|
||||||
|
|
||||||
[layer_names]
|
[layer_names]
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using ColdMint.scripts.inventory;
|
using ColdMint.scripts.character;
|
||||||
|
using ColdMint.scripts.inventory;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace ColdMint.scripts;
|
namespace ColdMint.scripts;
|
||||||
|
@ -7,7 +8,7 @@ namespace ColdMint.scripts;
|
||||||
/// <para>The node holder within the game scene</para>
|
/// <para>The node holder within the game scene</para>
|
||||||
/// <para>游戏场景内的节点持有者</para>
|
/// <para>游戏场景内的节点持有者</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class GameSceneNodeHolder
|
public static class GameSceneNodeHolder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Player instances within the game scene</para>
|
/// <para>Player instances within the game scene</para>
|
||||||
|
|
|
@ -32,7 +32,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
|
|
||||||
//Item containers are used to store items.
|
//Item containers are used to store items.
|
||||||
//物品容器用于存储物品。
|
//物品容器用于存储物品。
|
||||||
protected IItemContainer? _itemContainer;
|
private IItemContainer? _itemContainer;
|
||||||
|
|
||||||
|
|
||||||
public IItemContainer? ItemContainer
|
public IItemContainer? ItemContainer
|
||||||
|
|
|
@ -1,64 +1,60 @@
|
||||||
using Godot;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using ColdMint.scripts;
|
|
||||||
using ColdMint.scripts.character;
|
|
||||||
using ColdMint.scripts.damage;
|
using ColdMint.scripts.damage;
|
||||||
using ColdMint.scripts.debug;
|
|
||||||
using ColdMint.scripts.utils;
|
using ColdMint.scripts.utils;
|
||||||
using ColdMint.scripts.weapon;
|
using ColdMint.scripts.weapon;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace ColdMint.scripts.character;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>玩家角色</para>
|
/// <para>玩家角色</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class Player : CharacterTemplate
|
public partial class Player : CharacterTemplate
|
||||||
{
|
{
|
||||||
private PackedScene FloatLabelPackedScene;
|
private PackedScene? _floatLabelPackedScene;
|
||||||
|
|
||||||
protected Control FloatLabel;
|
private Control? _floatLabel;
|
||||||
|
|
||||||
//Empty object projectile
|
//Empty object projectile
|
||||||
//空的物品抛射线
|
//空的物品抛射线
|
||||||
private Vector2[] emptyVector2Array = new[] { Vector2.Zero };
|
private readonly Vector2[] _emptyVector2Array = new[] { Vector2.Zero };
|
||||||
|
|
||||||
//抛物线
|
//抛物线
|
||||||
private Line2D Parabola;
|
private Line2D? _parabola;
|
||||||
|
|
||||||
//用于检测玩家是否站在平台上的射线
|
//用于检测玩家是否站在平台上的射线
|
||||||
private RayCast2D PlatformDetectionRayCast2D;
|
private RayCast2D? _platformDetectionRayCast2D;
|
||||||
|
|
||||||
//在拾捡范围内,可拾起的物品数量
|
//在拾捡范围内,可拾起的物品数量
|
||||||
private int TotalNumberOfPickups = 0;
|
private int _totalNumberOfPickups;
|
||||||
|
|
||||||
private const float promptTextDistance = 50;
|
private const float PromptTextDistance = 50;
|
||||||
|
|
||||||
//玩家可拾捡的物品
|
//玩家可拾捡的物品
|
||||||
private Node2D PickAbleItem;
|
private Node2D? _pickAbleItem;
|
||||||
|
|
||||||
//抛出物品的飞行速度
|
//抛出物品的飞行速度
|
||||||
private float throwingVelocity = Config.CellSize * 13;
|
private float _throwingVelocity = Config.CellSize * 13;
|
||||||
|
|
||||||
//射线是否与平台碰撞
|
//射线是否与平台碰撞
|
||||||
private bool CollidingWithPlatform = false;
|
private bool _collidingWithPlatform;
|
||||||
|
|
||||||
//How long does it take for the character to recover from a collision with the platform after jumping off the platform (in seconds)
|
//How long does it take for the character to recover from a collision with the platform after jumping off the platform (in seconds)
|
||||||
//角色从平台上跳下后,多少时间后恢复与平台的碰撞(单位:秒)
|
//角色从平台上跳下后,多少时间后恢复与平台的碰撞(单位:秒)
|
||||||
private double PlatformCollisionRecoveryTime = 0.2f;
|
private double _platformCollisionRecoveryTime = 0.2f;
|
||||||
|
|
||||||
//物品被扔出后多长时间恢复与地面和平台的碰撞(单位:秒)
|
//物品被扔出后多长时间恢复与地面和平台的碰撞(单位:秒)
|
||||||
private double ItemCollisionRecoveryTime = 0.045f;
|
private readonly double _itemCollisionRecoveryTime = 0.045f;
|
||||||
|
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
base._Ready();
|
base._Ready();
|
||||||
CharacterName = TranslationServer.Translate("default_player_name");
|
CharacterName = TranslationServer.Translate("default_player_name");
|
||||||
FloatLabelPackedScene = GD.Load<PackedScene>("res://prefab/ui/FloatLabel.tscn");
|
_floatLabelPackedScene = GD.Load<PackedScene>("res://prefab/ui/FloatLabel.tscn");
|
||||||
Parabola = GetNode<Line2D>("Parabola");
|
_parabola = GetNode<Line2D>("Parabola");
|
||||||
PlatformDetectionRayCast2D = GetNode<RayCast2D>("PlatformDetectionRayCast");
|
_platformDetectionRayCast2D = GetNode<RayCast2D>("PlatformDetectionRayCast");
|
||||||
UpdateOperationTip();
|
UpdateOperationTip();
|
||||||
GameSceneNodeHolder.HealthBarUi.MaxHp = MaxHp;
|
GameSceneNodeHolder.HealthBarUi.MaxHp = MaxHp;
|
||||||
GameSceneNodeHolder.HealthBarUi.CurrentHp = CurrentHp;
|
GameSceneNodeHolder.HealthBarUi.CurrentHp = CurrentHp;
|
||||||
|
@ -71,16 +67,16 @@ public partial class Player : CharacterTemplate
|
||||||
private void UpdateOperationTip()
|
private void UpdateOperationTip()
|
||||||
{
|
{
|
||||||
var operationTipBuilder = new StringBuilder();
|
var operationTipBuilder = new StringBuilder();
|
||||||
if (TotalNumberOfPickups > 0)
|
if (_totalNumberOfPickups > 0)
|
||||||
{
|
{
|
||||||
//If there's anything around to pick up
|
//If there's anything around to pick up
|
||||||
//如果周围有能捡的东西
|
//如果周围有能捡的东西
|
||||||
if (CurrentItem == null)
|
if (CurrentItem == null)
|
||||||
{
|
{
|
||||||
if (PickAbleItem != null)
|
if (_pickAbleItem != null)
|
||||||
{
|
{
|
||||||
string name = null;
|
string? name = null;
|
||||||
if (PickAbleItem is WeaponTemplate weaponTemplate)
|
if (_pickAbleItem is WeaponTemplate weaponTemplate)
|
||||||
{
|
{
|
||||||
//When the weapon has no owner, a pick up prompt is displayed.
|
//When the weapon has no owner, a pick up prompt is displayed.
|
||||||
//当武器没有主人时,显示捡起提示。
|
//当武器没有主人时,显示捡起提示。
|
||||||
|
@ -101,13 +97,13 @@ public partial class Player : CharacterTemplate
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string pickAbleItemName = null;
|
string? pickAbleItemName = null;
|
||||||
string currentItemName = null;
|
string? currentItemName = null;
|
||||||
string mustBeThrown = TranslationServer.Translate("must_be_thrown");
|
string mustBeThrown = TranslationServer.Translate("must_be_thrown");
|
||||||
if (PickAbleItem != null)
|
if (_pickAbleItem != null)
|
||||||
{
|
{
|
||||||
//可捡的物品是武器
|
//可捡的物品是武器
|
||||||
if (PickAbleItem is WeaponTemplate weaponTemplate)
|
if (_pickAbleItem is WeaponTemplate weaponTemplate)
|
||||||
{
|
{
|
||||||
pickAbleItemName = TranslationServer.Translate(weaponTemplate.Name);
|
pickAbleItemName = TranslationServer.Translate(weaponTemplate.Name);
|
||||||
}
|
}
|
||||||
|
@ -145,7 +141,7 @@ public partial class Player : CharacterTemplate
|
||||||
operationTipBuilder.Append(' ');
|
operationTipBuilder.Append(' ');
|
||||||
operationTipBuilder.Append(TranslationServer.Translate(InputMap.ActionGetEvents("ui_up")[0].AsText()));
|
operationTipBuilder.Append(TranslationServer.Translate(InputMap.ActionGetEvents("ui_up")[0].AsText()));
|
||||||
operationTipBuilder.Append(TranslationServer.Translate("jump"));
|
operationTipBuilder.Append(TranslationServer.Translate("jump"));
|
||||||
if (CollidingWithPlatform)
|
if (_collidingWithPlatform)
|
||||||
{
|
{
|
||||||
operationTipBuilder.Append(' ');
|
operationTipBuilder.Append(' ');
|
||||||
operationTipBuilder.Append(TranslationServer.Translate(InputMap.ActionGetEvents("ui_down")[0].AsText()));
|
operationTipBuilder.Append(TranslationServer.Translate(InputMap.ActionGetEvents("ui_down")[0].AsText()));
|
||||||
|
@ -177,11 +173,11 @@ public partial class Player : CharacterTemplate
|
||||||
{
|
{
|
||||||
//When the collision state between the platform detection ray and the platform changes
|
//When the collision state between the platform detection ray and the platform changes
|
||||||
//在平台检测射线与平台碰撞状态改变时
|
//在平台检测射线与平台碰撞状态改变时
|
||||||
if (PlatformDetectionRayCast2D.IsColliding() != CollidingWithPlatform)
|
if (_platformDetectionRayCast2D != null && _platformDetectionRayCast2D.IsColliding() != _collidingWithPlatform)
|
||||||
{
|
{
|
||||||
//When the state changes, update the action hint
|
//When the state changes, update the action hint
|
||||||
//当状态改变时,更新操作提示
|
//当状态改变时,更新操作提示
|
||||||
CollidingWithPlatform = PlatformDetectionRayCast2D.IsColliding();
|
_collidingWithPlatform = _platformDetectionRayCast2D.IsColliding();
|
||||||
UpdateOperationTip();
|
UpdateOperationTip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,15 +202,15 @@ public partial class Player : CharacterTemplate
|
||||||
//捡起物品
|
//捡起物品
|
||||||
if (Input.IsActionJustPressed("pick_up"))
|
if (Input.IsActionJustPressed("pick_up"))
|
||||||
{
|
{
|
||||||
var success = PickItem(PickAbleItem);
|
var success = PickItem(_pickAbleItem);
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
PickAbleItem = null;
|
_pickAbleItem = null;
|
||||||
TotalNumberOfPickups--;
|
_totalNumberOfPickups--;
|
||||||
if (FloatLabel != null)
|
if (_floatLabel != null)
|
||||||
{
|
{
|
||||||
FloatLabel.QueueFree();
|
_floatLabel.QueueFree();
|
||||||
FloatLabel = null;
|
_floatLabel = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateOperationTip();
|
UpdateOperationTip();
|
||||||
|
@ -223,13 +219,13 @@ public partial class Player : CharacterTemplate
|
||||||
|
|
||||||
if (Input.IsActionJustPressed("ui_down"))
|
if (Input.IsActionJustPressed("ui_down"))
|
||||||
{
|
{
|
||||||
if (CollidingWithPlatform)
|
if (_collidingWithPlatform)
|
||||||
{
|
{
|
||||||
//When the character stands on the platform and presses the ui_down key, we cancel the collision between the character and the platform
|
//When the character stands on the platform and presses the ui_down key, we cancel the collision between the character and the platform
|
||||||
//当角色站在平台上按下 ui_down 键时,我们取消角色与平台的碰撞
|
//当角色站在平台上按下 ui_down 键时,我们取消角色与平台的碰撞
|
||||||
var timer = new Timer();
|
var timer = new Timer();
|
||||||
AddChild(timer);
|
AddChild(timer);
|
||||||
timer.WaitTime = PlatformCollisionRecoveryTime;
|
timer.WaitTime = _platformCollisionRecoveryTime;
|
||||||
timer.OneShot = true;
|
timer.OneShot = true;
|
||||||
timer.Start();
|
timer.Start();
|
||||||
timer.Timeout += () =>
|
timer.Timeout += () =>
|
||||||
|
@ -246,15 +242,21 @@ public partial class Player : CharacterTemplate
|
||||||
//抛出物品时,显示抛物线
|
//抛出物品时,显示抛物线
|
||||||
if (Input.IsActionPressed("throw"))
|
if (Input.IsActionPressed("throw"))
|
||||||
{
|
{
|
||||||
if (CurrentItem == null)
|
if (_parabola == null)
|
||||||
{
|
{
|
||||||
Parabola.Points = emptyVector2Array;
|
return;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (ItemMarker2D == null)
|
||||||
{
|
{
|
||||||
Parabola.Points =
|
//Cannot get the marked location of the item, then do not draw a line
|
||||||
ParabolicUtils.ComputeParabolic(ItemMarker2D.Position, GetThrowVelocity(), Gravity, 0.1f);
|
//无法获取物品的标记位置,那么不绘制线
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_parabola.Points = CurrentItem == null
|
||||||
|
? _emptyVector2Array
|
||||||
|
: ParabolicUtils.ComputeParabolic(ItemMarker2D.Position, GetThrowVelocity(), Gravity, 0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -262,15 +264,20 @@ public partial class Player : CharacterTemplate
|
||||||
//抬起手时,抛出物品
|
//抬起手时,抛出物品
|
||||||
if (Input.IsActionJustReleased("throw"))
|
if (Input.IsActionJustReleased("throw"))
|
||||||
{
|
{
|
||||||
if (CurrentItem != null)
|
if (CurrentItem == null) return;
|
||||||
|
if (_parabola != null)
|
||||||
{
|
{
|
||||||
Parabola.Points = new[] { Vector2.Zero };
|
_parabola.Points = new[] { Vector2.Zero };
|
||||||
CurrentItem.Reparent(GameSceneNodeHolder.WeaponContainer);
|
}
|
||||||
if (CurrentItem is WeaponTemplate weaponTemplate)
|
|
||||||
|
CurrentItem.Reparent(GameSceneNodeHolder.WeaponContainer);
|
||||||
|
switch (CurrentItem)
|
||||||
|
{
|
||||||
|
case WeaponTemplate weaponTemplate:
|
||||||
{
|
{
|
||||||
var timer = new Timer();
|
var timer = new Timer();
|
||||||
weaponTemplate.AddChild(timer);
|
weaponTemplate.AddChild(timer);
|
||||||
timer.WaitTime = ItemCollisionRecoveryTime;
|
timer.WaitTime = _itemCollisionRecoveryTime;
|
||||||
timer.OneShot = true;
|
timer.OneShot = true;
|
||||||
timer.Timeout += () =>
|
timer.Timeout += () =>
|
||||||
{
|
{
|
||||||
|
@ -284,23 +291,20 @@ public partial class Player : CharacterTemplate
|
||||||
timer.Start();
|
timer.Start();
|
||||||
weaponTemplate.Sleeping = false;
|
weaponTemplate.Sleeping = false;
|
||||||
weaponTemplate.LinearVelocity = Vector2.Zero;
|
weaponTemplate.LinearVelocity = Vector2.Zero;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
case CharacterBody2D characterBody2D:
|
||||||
if (CurrentItem is CharacterBody2D characterBody2D)
|
|
||||||
{
|
|
||||||
characterBody2D.Velocity = GetThrowVelocity();
|
characterBody2D.Velocity = GetThrowVelocity();
|
||||||
}
|
break;
|
||||||
|
case RigidBody2D rigidBody2D:
|
||||||
if (CurrentItem is RigidBody2D rigidBody2D)
|
|
||||||
{
|
|
||||||
rigidBody2D.LinearVelocity = GetThrowVelocity();
|
rigidBody2D.LinearVelocity = GetThrowVelocity();
|
||||||
}
|
break;
|
||||||
|
|
||||||
CurrentItem = null;
|
|
||||||
TotalNumberOfPickups++;
|
|
||||||
GameSceneNodeHolder.HotBar.RemoveItemFromItemSlotBySelectIndex(1);
|
|
||||||
UpdateOperationTip();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CurrentItem = null;
|
||||||
|
_totalNumberOfPickups++;
|
||||||
|
GameSceneNodeHolder.HotBar.RemoveItemFromItemSlotBySelectIndex(1);
|
||||||
|
UpdateOperationTip();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,13 +313,18 @@ public partial class Player : CharacterTemplate
|
||||||
{
|
{
|
||||||
//We take the mouse position, normalize it, and then multiply it by the distance the player can throw
|
//We take the mouse position, normalize it, and then multiply it by the distance the player can throw
|
||||||
//我们拿到鼠标的位置,将其归一化处理,然后乘以玩家可扔出的距离
|
//我们拿到鼠标的位置,将其归一化处理,然后乘以玩家可扔出的距离
|
||||||
return GetLocalMousePosition().Normalized() * throwingVelocity;
|
return GetLocalMousePosition().Normalized() * _throwingVelocity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
AimTheCurrentItemAtAPoint(GetGlobalMousePosition());
|
AimTheCurrentItemAtAPoint(GetGlobalMousePosition());
|
||||||
var itemMarker2DPosition = ItemMarker2D.Position;
|
var itemMarker2DPosition = Vector2.Zero;
|
||||||
|
if (ItemMarker2D != null)
|
||||||
|
{
|
||||||
|
itemMarker2DPosition = ItemMarker2D.Position;
|
||||||
|
}
|
||||||
|
|
||||||
var axis = Input.GetAxis("ui_left", "ui_right");
|
var axis = Input.GetAxis("ui_left", "ui_right");
|
||||||
switch (axis)
|
switch (axis)
|
||||||
{
|
{
|
||||||
|
@ -323,23 +332,30 @@ public partial class Player : CharacterTemplate
|
||||||
//Minus 1, we move to the left
|
//Minus 1, we move to the left
|
||||||
//-1,向左移动
|
//-1,向左移动
|
||||||
FacingLeft = true;
|
FacingLeft = true;
|
||||||
itemMarker2DPosition.X = -ReadOnlyItemMarkerOriginalX;
|
if (ItemMarker2D != null)
|
||||||
|
{
|
||||||
|
itemMarker2DPosition.X = -ReadOnlyItemMarkerOriginalX;
|
||||||
|
}
|
||||||
|
|
||||||
Flip();
|
Flip();
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
//1, move to the right
|
//1, move to the right
|
||||||
//1,向右移动
|
//1,向右移动
|
||||||
FacingLeft = false;
|
FacingLeft = false;
|
||||||
itemMarker2DPosition.X = ReadOnlyItemMarkerOriginalX;
|
if (ItemMarker2D != null)
|
||||||
|
{
|
||||||
|
itemMarker2DPosition.X = ReadOnlyItemMarkerOriginalX;
|
||||||
|
}
|
||||||
|
|
||||||
Flip();
|
Flip();
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
//0, when it's not pressed
|
|
||||||
//0,没有按下时
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemMarker2D.Position = itemMarker2DPosition;
|
if (ItemMarker2D != null)
|
||||||
|
{
|
||||||
|
ItemMarker2D.Position = itemMarker2DPosition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Flip()
|
protected override void Flip()
|
||||||
|
@ -347,12 +363,9 @@ public partial class Player : CharacterTemplate
|
||||||
base.Flip();
|
base.Flip();
|
||||||
//If there is a weapon, flip it too
|
//If there is a weapon, flip it too
|
||||||
//如果有武器的话,也要翻转
|
//如果有武器的话,也要翻转
|
||||||
if (CurrentItem != null)
|
if (CurrentItem is WeaponTemplate weapon)
|
||||||
{
|
{
|
||||||
if (CurrentItem is WeaponTemplate weapon)
|
weapon.Flip(FacingLeft);
|
||||||
{
|
|
||||||
weapon.Flip(FacingLeft);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,50 +378,42 @@ public partial class Player : CharacterTemplate
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node is not Node2D)
|
if (node is not Node2D node2D)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var node2D = node as Node2D;
|
_totalNumberOfPickups++;
|
||||||
TotalNumberOfPickups++;
|
_pickAbleItem = node2D;
|
||||||
PickAbleItem = node2D;
|
if (_floatLabelPackedScene != null)
|
||||||
if (FloatLabel != null)
|
|
||||||
{
|
{
|
||||||
FloatLabel.QueueFree();
|
//If there is a scene of floating text, then we generate floating text.
|
||||||
}
|
//如果有悬浮文本的场景,那么我们生成悬浮文本。
|
||||||
|
_floatLabel?.QueueFree();
|
||||||
FloatLabel = (Control)FloatLabelPackedScene.Instantiate();
|
_floatLabel = (Control)_floatLabelPackedScene.Instantiate();
|
||||||
var rotationDegreesNode2D = node2D.RotationDegrees;
|
var rotationDegreesNode2D = node2D.RotationDegrees;
|
||||||
var rotationDegreesNode2DAbs = Math.Abs(rotationDegreesNode2D);
|
var rotationDegreesNode2DAbs = Math.Abs(rotationDegreesNode2D);
|
||||||
if (rotationDegreesNode2DAbs > 90)
|
_floatLabel.Position = rotationDegreesNode2DAbs > 90
|
||||||
{
|
? new Vector2(0, PromptTextDistance)
|
||||||
FloatLabel.Position = new Vector2(0, promptTextDistance);
|
: new Vector2(0, -PromptTextDistance);
|
||||||
}
|
_floatLabel.RotationDegrees = 0 - rotationDegreesNode2D;
|
||||||
else
|
var label = _floatLabel.GetNode<Label>("Label");
|
||||||
{
|
if (node is WeaponTemplate weapon)
|
||||||
FloatLabel.Position = new Vector2(0, -promptTextDistance);
|
|
||||||
}
|
|
||||||
|
|
||||||
FloatLabel.RotationDegrees = 0 - rotationDegreesNode2D;
|
|
||||||
var label = FloatLabel.GetNode<Label>("Label");
|
|
||||||
if (node is WeaponTemplate weapon)
|
|
||||||
{
|
|
||||||
var stringBuilder = new StringBuilder();
|
|
||||||
if (weapon.Owner != null)
|
|
||||||
{
|
{
|
||||||
|
var stringBuilder = new StringBuilder();
|
||||||
if (weapon.Owner is CharacterTemplate characterTemplate)
|
if (weapon.Owner is CharacterTemplate characterTemplate)
|
||||||
{
|
{
|
||||||
stringBuilder.Append(characterTemplate.ReadOnlyCharacterName);
|
stringBuilder.Append(characterTemplate.ReadOnlyCharacterName);
|
||||||
stringBuilder.Append(TranslationServer.Translate("de"));
|
stringBuilder.Append(TranslationServer.Translate("de"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stringBuilder.Append(TranslationServer.Translate(weapon.Name));
|
||||||
|
label.Text = stringBuilder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
stringBuilder.Append(TranslationServer.Translate(weapon.Name));
|
node.AddChild(_floatLabel);
|
||||||
label.Text = stringBuilder.ToString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node.AddChild(FloatLabel);
|
|
||||||
UpdateOperationTip();
|
UpdateOperationTip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,18 +424,18 @@ public partial class Player : CharacterTemplate
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TotalNumberOfPickups--;
|
_totalNumberOfPickups--;
|
||||||
if (TotalNumberOfPickups == 0)
|
if (_totalNumberOfPickups == 0)
|
||||||
{
|
{
|
||||||
//Set to null if there are no more items to pick up
|
//Set to null if there are no more items to pick up
|
||||||
//如果没有可捡的物品了,设置为null
|
//如果没有可捡的物品了,设置为null
|
||||||
PickAbleItem = null;
|
_pickAbleItem = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FloatLabel != null)
|
if (_floatLabel != null)
|
||||||
{
|
{
|
||||||
FloatLabel.QueueFree();
|
_floatLabel.QueueFree();
|
||||||
FloatLabel = null;
|
_floatLabel = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateOperationTip();
|
UpdateOperationTip();
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using ColdMint.scripts.character;
|
||||||
using ColdMint.scripts.debug;
|
using ColdMint.scripts.debug;
|
||||||
using ColdMint.scripts.inventory;
|
using ColdMint.scripts.inventory;
|
||||||
using ColdMint.scripts.loader.uiLoader;
|
|
||||||
using ColdMint.scripts.map;
|
using ColdMint.scripts.map;
|
||||||
using ColdMint.scripts.map.interfaces;
|
using ColdMint.scripts.map.interfaces;
|
||||||
using ColdMint.scripts.map.room;
|
using ColdMint.scripts.map.room;
|
||||||
|
@ -9,21 +9,20 @@ using ColdMint.scripts.map.roomHolder;
|
||||||
using ColdMint.scripts.map.RoomPlacer;
|
using ColdMint.scripts.map.RoomPlacer;
|
||||||
using ColdMint.scripts.map.RoomProvider;
|
using ColdMint.scripts.map.RoomProvider;
|
||||||
using ColdMint.scripts.map.slotsMatcher;
|
using ColdMint.scripts.map.slotsMatcher;
|
||||||
using ColdMint.scripts.utils;
|
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace ColdMint.scripts.loader.sceneLoader;
|
namespace ColdMint.scripts.loader.sceneLoader;
|
||||||
|
|
||||||
public partial class GameSceneLoader : SceneLoaderTemplate
|
public partial class GameSceneLoader : SceneLoaderTemplate
|
||||||
{
|
{
|
||||||
private IMapGenerator _mapGenerator;
|
private IMapGenerator? _mapGenerator;
|
||||||
private IMapGeneratorConfig _mapGeneratorConfig;
|
private IMapGeneratorConfig? _mapGeneratorConfig;
|
||||||
|
|
||||||
public override async Task InitializeData()
|
public override Task InitializeData()
|
||||||
{
|
{
|
||||||
//加载血条场景
|
//加载血条场景
|
||||||
var healthBarUI = GetNode<HealthBarUi>("CanvasLayer/Control/VBoxContainer/HealthBarUi");
|
var healthBarUi = GetNode<HealthBarUi>("CanvasLayer/Control/VBoxContainer/HealthBarUi");
|
||||||
GameSceneNodeHolder.HealthBarUi = healthBarUI;
|
GameSceneNodeHolder.HealthBarUi = healthBarUi;
|
||||||
//加载HotBar
|
//加载HotBar
|
||||||
var hotBar = GetNode<HotBar>("CanvasLayer/Control/VBoxContainer/HotBar");
|
var hotBar = GetNode<HotBar>("CanvasLayer/Control/VBoxContainer/HotBar");
|
||||||
GameSceneNodeHolder.HotBar = hotBar;
|
GameSceneNodeHolder.HotBar = hotBar;
|
||||||
|
@ -56,10 +55,22 @@ public partial class GameSceneLoader : SceneLoaderTemplate
|
||||||
_mapGeneratorConfig = new MapGeneratorConfig(GetNode<Node2D>("MapRoot"), 1);
|
_mapGeneratorConfig = new MapGeneratorConfig(GetNode<Node2D>("MapRoot"), 1);
|
||||||
roomPlacer.MapGeneratorConfig = _mapGeneratorConfig;
|
roomPlacer.MapGeneratorConfig = _mapGeneratorConfig;
|
||||||
_mapGenerator.RoomPlacer = roomPlacer;
|
_mapGenerator.RoomPlacer = roomPlacer;
|
||||||
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task LoadScene()
|
public override async Task LoadScene()
|
||||||
{
|
{
|
||||||
|
if (_mapGenerator == null)
|
||||||
|
{
|
||||||
|
LogCat.LogError("map_generator_is_not_set_up");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_mapGeneratorConfig == null)
|
||||||
|
{
|
||||||
|
LogCat.LogError("map_generator_is_not_configured");
|
||||||
|
return;
|
||||||
|
}
|
||||||
await _mapGenerator.Generate(_mapGeneratorConfig);
|
await _mapGenerator.Generate(_mapGeneratorConfig);
|
||||||
var packedScene = GD.Load<PackedScene>("res://prefab/entitys/Character.tscn");
|
var packedScene = GD.Load<PackedScene>("res://prefab/entitys/Character.tscn");
|
||||||
//Register players in the holder
|
//Register players in the holder
|
||||||
|
|
|
@ -58,7 +58,7 @@ public partial class WeaponTemplate : RigidBody2D, IItem
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
private Vector2 _recoil;
|
private Vector2 _recoil;
|
||||||
|
|
||||||
private Area2D _area2D;
|
private Area2D? _area2D;
|
||||||
|
|
||||||
protected RayCast2D _rayCast2D;
|
protected RayCast2D _rayCast2D;
|
||||||
|
|
||||||
|
@ -135,8 +135,8 @@ public partial class WeaponTemplate : RigidBody2D, IItem
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>翻转武器</para>
|
/// <para>翻转武器</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="FacingLeft"></param>
|
/// <param name="facingLeft"></param>
|
||||||
public void Flip(bool FacingLeft)
|
public void Flip(bool facingLeft)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user