Created the ability to drop items on the ground after the player dies.

制作玩家死亡后,背包物品掉在地上的功能。
This commit is contained in:
Cold-Mint 2024-06-08 23:59:24 +08:00
parent 0dd3de228e
commit 05763c25b1
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
30 changed files with 123 additions and 31 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -4,3 +4,5 @@ slogan_1,如果你想要得到爱,你就播种爱。,"If you want love, you so
slogan_2,快乐?伤心?痛苦?,Happy? Sad? Pain?,楽しいですか?悲しいですか?苦しいですか?
slogan_3,Kawaii!,Kawaii!,Kawaii!
slogan_4,魔法是想象的世界。,Magic is an imaginary world.,魔法は想像の世界です。
slogan_5,也试试Minecraft,Also try Minecraft!,Minecraftもやってみて
slogan_6,也试试Terraria,Also try Terraria!,Terrariaもやってみて
1 id zh en ja
4 slogan_2 快乐?伤心?痛苦? Happy? Sad? Pain? 楽しいですか?悲しいですか?苦しいですか?
5 slogan_3 Kawaii! Kawaii! Kawaii!
6 slogan_4 魔法是想象的世界。 Magic is an imaginary world. 魔法は想像の世界です。
7 slogan_5 也试试Minecraft! Also try Minecraft! Minecraftもやってみて!
8 slogan_6 也试试Terraria! Also try Terraria! Terrariaもやってみて!

View File

@ -2,7 +2,7 @@
importer="csv_translation"
type="Translation"
uid="uid://dbgkevd34vb0d"
uid="uid://bgfmprv2sm645"
[deps]

Binary file not shown.

Binary file not shown.

View File

@ -45,3 +45,18 @@ script = ExtResource("2_6p8mv")
[node name="StaffOfTheUndead" parent="." instance=ExtResource("3_ud0w8")]
position = Vector2(231, 116)
[node name="StaffOfTheUndead2" parent="." instance=ExtResource("3_ud0w8")]
position = Vector2(113, 149)
[node name="StaffOfTheUndead5" parent="." instance=ExtResource("3_ud0w8")]
position = Vector2(213, 177)
[node name="StaffOfTheUndead6" parent="." instance=ExtResource("3_ud0w8")]
position = Vector2(290, 167)
[node name="StaffOfTheUndead3" parent="." instance=ExtResource("3_ud0w8")]
position = Vector2(70, 88)
[node name="StaffOfTheUndead4" parent="." instance=ExtResource("3_ud0w8")]
position = Vector2(367, 85)

View File

@ -147,6 +147,7 @@ hotbar_previous={
[internationalization]
locale/translations=PackedStringArray("res://locals/DeathInfo.en.translation", "res://locals/DeathInfo.ja.translation", "res://locals/DeathInfo.zh.translation", "res://locals/InputMapping.en.translation", "res://locals/InputMapping.ja.translation", "res://locals/InputMapping.zh.translation", "res://locals/Log.en.translation", "res://locals/Log.ja.translation", "res://locals/Log.zh.translation", "res://locals/Slogan.en.translation", "res://locals/Slogan.ja.translation", "res://locals/Slogan.zh.translation", "res://locals/UI.en.translation", "res://locals/UI.ja.translation", "res://locals/UI.zh.translation", "res://locals/Weapon.en.translation", "res://locals/Weapon.ja.translation", "res://locals/Weapon.zh.translation")
locale/test="ja"
[layer_names]

View File

@ -124,7 +124,7 @@ layout_mode = 2
[node name="GodotLabel" type="Label" parent="VBoxContainer2/HBoxContainer"]
layout_mode = 2
text = "Power by"
text = "Powered by"
horizontal_alignment = 2
[node name="LinkButton" type="LinkButton" parent="VBoxContainer2/HBoxContainer"]

View File

@ -13,6 +13,7 @@ public static class SloganProvider
static SloganProvider()
{
// Calculate SloganCount From translation file
// 从翻译文件中计算口号计数
var sloganTrans = ResourceLoader.Load<OptimizedTranslation>("res://locals/Slogan.en.translation")!;
SloganCount = sloganTrans.GetTranslatedMessageList().Length;
}

View File

@ -151,7 +151,7 @@ public partial class CharacterTemplate : CharacterBody2D
//Check whether the new Hp is greater than the maximum Hp. If yes, set the current Hp to the maximum Hp. If no, set the current Hp to the new HP
//判断新的Hp是否大于最大Hp若大于那么将当前Hp设置为最大Hp否则设置为新的Hp
CurrentHp = newHp > MaxHp ? MaxHp : newHp;
Visible = true;
Show();
}
/// <summary>
@ -318,7 +318,7 @@ public partial class CharacterTemplate : CharacterBody2D
}
else
{
pickAbleItem.Visible = false;
pickAbleItem.Hide();
pickAbleItem.ProcessMode = ProcessModeEnum.Disabled;
}
@ -358,7 +358,7 @@ public partial class CharacterTemplate : CharacterBody2D
var timeSpan = DateTime.Now - _lastDamageTime;
if (timeSpan > Config.HealthBarDisplaysTime)
{
_healthBar.Visible = false;
_healthBar.Hide();
}
}
}
@ -410,7 +410,7 @@ public partial class CharacterTemplate : CharacterBody2D
}
}
_healthBar.Visible = true;
_healthBar.Show();
_healthBar.Value = CurrentHp;
}
@ -437,6 +437,7 @@ public partial class CharacterTemplate : CharacterBody2D
//Character death
//角色死亡
OnDie(damageTemplate);
ThrowAllItemOnDie();
return true;
}
@ -528,6 +529,44 @@ public partial class CharacterTemplate : CharacterBody2D
_animatedSprite2D.FlipH = FacingLeft;
}
/// <summary>
/// <para>Throw all items when the creature dies</para>
/// <para>当生物死亡后抛出所有物品</para>
/// </summary>
private void ThrowAllItemOnDie()
{
//If the item container is null, then return
//如果物品容器为null那么返回
if (_itemContainer == null)
{
return;
}
var len = _itemContainer.GetItemSlotCount();
if (len == 0)
{
return;
}
CurrentItem = null;
const float height = -Config.CellSize * 7;
const float horizontalDirection = Config.CellSize * 15;
for (var i = 0; i < len; i++)
{
//Generates a random number that controls the horizontal velocity of thrown items (range: 0.01 to 1)
//生成一个随机数,用于控制抛出物品的水平方向速度(范围为0.01到1)
var percent = GD.Randf() + 0.01f;
if (GD.Randf() > 0.5)
{
ThrowItem(i, -1, new Vector2(horizontalDirection * percent, height));
}
else
{
ThrowItem(i, -1, new Vector2(-horizontalDirection * percent, height));
}
}
}
/// <summary>
/// <para>Throw item</para>
/// <para>抛出物品</para>
@ -539,6 +578,8 @@ public partial class CharacterTemplate : CharacterBody2D
/// <param name="number">
/// <para>How many to throw</para>
/// <para>要扔几个</para>
/// <para>The amount passed into a negative number will throw all the items in the slot at once.</para>
/// <para>数量传入一个负数,将一次扔出槽内的所有物品。</para>
/// </param>
/// <param name="velocity">
///<para>The speed to be applied to the item</para>
@ -563,6 +604,11 @@ public partial class CharacterTemplate : CharacterBody2D
return;
}
if (item is not Node2D node2D)
{
return;
}
switch (item)
{
case WeaponTemplate weaponTemplate:
@ -571,7 +617,7 @@ public partial class CharacterTemplate : CharacterBody2D
return;
}
weaponTemplate.Reparent(GameSceneNodeHolder.WeaponContainer);
CallDeferred("WeaponTemplateReparent", weaponTemplate);
var timer = new Timer();
weaponTemplate.AddChild(timer);
timer.WaitTime = _itemCollisionRecoveryTime;
@ -587,13 +633,17 @@ public partial class CharacterTemplate : CharacterBody2D
};
timer.Start();
weaponTemplate.Sleeping = false;
// weaponTemplate.LinearVelocity = Vector2.Zero;
//Setting an initial speed of 0 for items here prevents the problem of throwing items too fast.
//在这里给物品设置一个为0的初始速度可防止扔出物品时速度过快的问题。
weaponTemplate.LinearVelocity = Vector2.Zero;
break;
}
node2D.ProcessMode = ProcessModeEnum.Inherit;
node2D.Show();
//We apply force to objects.
//我们给物品施加力。
switch (CurrentItem)
switch (node2D)
{
case CharacterBody2D characterBody2D:
characterBody2D.Velocity = velocity;
@ -605,9 +655,25 @@ public partial class CharacterTemplate : CharacterBody2D
//Remove items from the item container
//在物品容器内移除物品
if (number < 0)
{
itemSlotNode.RemoveItem(item.Quantity);
}
else
{
itemSlotNode.RemoveItem(number);
}
}
/// <summary>
/// <para>Replace the parent node of the weapon</para>
/// <para>替换武器的父节点</para>
/// </summary>
/// <param name="weaponTemplate"></param>
private void WeaponTemplateReparent(WeaponTemplate weaponTemplate)
{
weaponTemplate.Reparent(GameSceneNodeHolder.WeaponContainer);
}
public sealed override void _PhysicsProcess(double delta)
{

View File

@ -353,9 +353,15 @@ public partial class Player : CharacterTemplate
}
}
/// <summary>
/// <para>When the player dies</para>
/// <para>当玩家死亡的时候</para>
/// </summary>
/// <param name="damageTemplate"></param>
protected override async Task OnDie(DamageTemplate damageTemplate)
{
Visible = false;
Hide();
ProcessMode = ProcessModeEnum.Disabled;
if (EventManager.GameOverEvent == null)
{
return;

View File

@ -97,7 +97,7 @@ public partial class ItemSlotNode : MarginContainer
if (_quantityLabel != null)
{
_quantityLabel.Visible = false;
_quantityLabel.Hide();
}
}
@ -213,16 +213,16 @@ public partial class ItemSlotNode : MarginContainer
switch (quantity)
{
case null:
_quantityLabel.Visible = false;
_quantityLabel.Hide();
return;
case > 1:
//When the quantity is greater than 1, we display the quantity.
//当数量大于1时我们显示数量
_quantityLabel.Text = quantity.ToString();
_quantityLabel.Visible = true;
_quantityLabel.Show();
break;
default:
_quantityLabel.Visible = false;
_quantityLabel.Hide();
break;
}
}
@ -236,6 +236,6 @@ public partial class ItemSlotNode : MarginContainer
_iconTextureRect = GetNode<TextureRect>("BackgroundTexture/CenterContainer/IconTextureRect");
_quantityLabel = GetNode<Label>("Control/QuantityLabel");
_control = GetNode<Control>("Control");
_quantityLabel.Visible = false;
_quantityLabel.Hide();
}
}

View File

@ -15,7 +15,7 @@ public partial class GameOverLoaderMenuLoader : UiLoaderTemplate
public override void InitializeUi()
{
Visible = false;
Hide();
}
public override void InitializeData()
@ -34,7 +34,7 @@ public partial class GameOverLoaderMenuLoader : UiLoaderTemplate
{
var replayEvent = new GameReplayEvent();
EventManager.GameReplayEvent?.Invoke(replayEvent);
Visible = false;
Hide();
};
}
}
@ -46,7 +46,7 @@ public partial class GameOverLoaderMenuLoader : UiLoaderTemplate
return;
}
Visible = true;
Show();
_deathInfoLabel.Text = gameOverEvent.DeathInfo;
}

View File

@ -269,12 +269,12 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
{
if (_nodeBinding.GraphEdit != null)
{
_nodeBinding.GraphEdit.Visible = false;
_nodeBinding.GraphEdit.Hide();
}
if (_nodeBinding.CreateOrEditorPanel != null)
{
_nodeBinding.CreateOrEditorPanel.Visible = true;
_nodeBinding.CreateOrEditorPanel.Show();
}
if (_nodeBinding.RoomNameLineEdit != null && _defaultRoomName != null)
@ -301,7 +301,7 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
if (_nodeBinding.HBoxContainer != null)
{
_nodeBinding.HBoxContainer.Visible = false;
_nodeBinding.HBoxContainer.Hide();
}
};
}
@ -377,7 +377,7 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
{
if (_nodeBinding.SaveOrLoadPanel != null)
{
_nodeBinding.SaveOrLoadPanel.Visible = false;
_nodeBinding.SaveOrLoadPanel.Hide();
}
};
}
@ -388,7 +388,7 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
{
if (_nodeBinding.SaveOrLoadPanel != null)
{
_nodeBinding.SaveOrLoadPanel.Visible = false;
_nodeBinding.SaveOrLoadPanel.Hide();
}
};
}
@ -399,7 +399,7 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
{
if (_nodeBinding.SaveOrLoadPanel != null)
{
_nodeBinding.SaveOrLoadPanel.Visible = true;
_nodeBinding.SaveOrLoadPanel.Show();
}
if (_nodeBinding.ActionButton != null)
@ -427,7 +427,7 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
{
if (_nodeBinding.SaveOrLoadPanel != null)
{
_nodeBinding.SaveOrLoadPanel.Visible = true;
_nodeBinding.SaveOrLoadPanel.Show();
}
if (_nodeBinding.ActionButton != null)
@ -716,17 +716,17 @@ public partial class LevelGraphEditorLoader : UiLoaderTemplate
{
if (_nodeBinding.GraphEdit != null)
{
_nodeBinding.GraphEdit.Visible = true;
_nodeBinding.GraphEdit.Show();
}
if (_nodeBinding.CreateOrEditorPanel != null)
{
_nodeBinding.CreateOrEditorPanel.Visible = false;
_nodeBinding.CreateOrEditorPanel.Hide();
}
if (_nodeBinding.HBoxContainer != null)
{
_nodeBinding.HBoxContainer.Visible = true;
_nodeBinding.HBoxContainer.Show();
}
}
}

View File

@ -25,6 +25,7 @@ public partial class PlayerSpawn : Marker2D
{
if (GameSceneNodeHolder.Player != null)
{
GameSceneNodeHolder.Player.ProcessMode = ProcessModeEnum.Inherit;
GameSceneNodeHolder.Player.Position = GlobalPosition;
GameSceneNodeHolder.Player.Revive(GameSceneNodeHolder.Player.MaxHp);
return;