Sync weapon equip to hitbox damage
This commit is contained in:
@@ -18,7 +18,6 @@ config/features=PackedStringArray("4.4", "C#", "GL Compatibility")
|
|||||||
|
|
||||||
window/size/viewport_width=1920
|
window/size/viewport_width=1920
|
||||||
window/size/viewport_height=1080
|
window/size/viewport_height=1080
|
||||||
window/size/mode=3
|
|
||||||
|
|
||||||
[dotnet]
|
[dotnet]
|
||||||
|
|
||||||
|
|||||||
@@ -106,12 +106,12 @@ public partial class Enemy : CharacterBody3D, IEnemy, IProvide<IEnemyLogic>
|
|||||||
|
|
||||||
public void OnPlayerHitboxEntered(Area3D body)
|
public void OnPlayerHitboxEntered(Area3D body)
|
||||||
{
|
{
|
||||||
if (body.GetParent() is IPlayer)
|
if (body is IHitbox hitBox)
|
||||||
{
|
{
|
||||||
if (CurrentHP > 0)
|
if (CurrentHP > 0)
|
||||||
{
|
{
|
||||||
GD.Print("Enemy Hit");
|
GD.Print("Enemy Hit");
|
||||||
EnemyLogic.Input(new EnemyLogic.Input.HitByPlayer());
|
EnemyLogic.Input(new EnemyLogic.Input.HitByPlayer(hitBox.Damage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
public readonly record struct PhysicsTick(double Delta);
|
public readonly record struct PhysicsTick(double Delta);
|
||||||
|
|
||||||
public readonly record struct HitByPlayer();
|
public readonly record struct HitByPlayer(int Damage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ namespace GameJamDungeon
|
|||||||
[Meta, Id("enemy_logic_state_alive")]
|
[Meta, Id("enemy_logic_state_alive")]
|
||||||
public abstract partial record Alive : State, IGet<Input.HitByPlayer>
|
public abstract partial record Alive : State, IGet<Input.HitByPlayer>
|
||||||
{
|
{
|
||||||
public Transition On(in Input.HitByPlayer _)
|
public Transition On(in Input.HitByPlayer input)
|
||||||
{
|
{
|
||||||
var enemy = Get<IEnemy>();
|
var enemy = Get<IEnemy>();
|
||||||
var gameRepo = Get<IGameRepo>();
|
var gameRepo = Get<IGameRepo>();
|
||||||
enemy.CurrentHP -= gameRepo.EquippedWeapon.InventoryInfo.Damage;
|
enemy.CurrentHP -= input.Damage;
|
||||||
GD.Print("Current HP: " + enemy.CurrentHP);
|
GD.Print("Current HP: " + enemy.CurrentHP);
|
||||||
GD.Print($"Hit by {gameRepo.EquippedWeapon.Name}");
|
GD.Print($"Hit by {gameRepo.EquippedWeapon.Name}");
|
||||||
Output(new Output.HitByPlayer());
|
Output(new Output.HitByPlayer());
|
||||||
|
|||||||
12
src/hitbox/Hitbox.cs
Normal file
12
src/hitbox/Hitbox.cs
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
using Chickensoft.GodotNodeInterfaces;
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
public interface IHitbox : IArea3D
|
||||||
|
{
|
||||||
|
public int Damage { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class Hitbox : Area3D, IHitbox
|
||||||
|
{
|
||||||
|
public int Damage { get; set; }
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
using Chickensoft.AutoInject;
|
using Chickensoft.AutoInject;
|
||||||
|
using Chickensoft.Collections;
|
||||||
using Chickensoft.GodotNodeInterfaces;
|
using Chickensoft.GodotNodeInterfaces;
|
||||||
using Chickensoft.Introspection;
|
using Chickensoft.Introspection;
|
||||||
using Chickensoft.SaveFileBuilder;
|
using Chickensoft.SaveFileBuilder;
|
||||||
using GameJamDungeon;
|
using GameJamDungeon;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace GameJamDungeon
|
namespace GameJamDungeon
|
||||||
{
|
{
|
||||||
@@ -52,16 +54,17 @@ namespace GameJamDungeon
|
|||||||
|
|
||||||
public PlayerLogic.IBinding PlayerBinding { get; set; } = default!;
|
public PlayerLogic.IBinding PlayerBinding { get; set; } = default!;
|
||||||
|
|
||||||
[Node]
|
[Node] public IAnimationPlayer AnimationPlayer { get; set; } = default!;
|
||||||
public IAnimationPlayer AnimationPlayer { get; set; } = default!;
|
|
||||||
|
|
||||||
[Node]
|
[Node] public AnimatedSprite2D SwordSlashAnimation { get; set; } = default!;
|
||||||
public IAnimatedSprite2D SwordSlashAnimation { get; set; } = default!;
|
|
||||||
|
[Node] public IHitbox Hitbox { get; set; } = default!;
|
||||||
|
|
||||||
|
private IAutoProp<WeaponInfo> EquippedWeapon { get; set; } = default!;
|
||||||
|
|
||||||
public void Initialize()
|
public void Initialize()
|
||||||
{
|
{
|
||||||
AnimationPlayer.AnimationFinished += OnAnimationFinished;
|
AnimationPlayer.AnimationFinished += OnAnimationFinished;
|
||||||
SwordSlashAnimation.Position = GetViewport().GetVisibleRect().Size / 2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Setup()
|
public void Setup()
|
||||||
@@ -77,20 +80,15 @@ namespace GameJamDungeon
|
|||||||
PlayerLogic.Set(GameRepo);
|
PlayerLogic.Set(GameRepo);
|
||||||
PlayerLogic.Set(PlayerData);
|
PlayerLogic.Set(PlayerData);
|
||||||
|
|
||||||
|
GameRepo.SetPlayerGlobalPosition(GlobalPosition);
|
||||||
|
EquippedWeapon = new AutoProp<WeaponInfo>(WeaponInfo.Default);
|
||||||
GameRepo.PlayerGlobalPosition.Sync += OnPlayerPositionUpdated;
|
GameRepo.PlayerGlobalPosition.Sync += OnPlayerPositionUpdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPlayerPositionUpdated(Vector3 globalPosition)
|
|
||||||
{
|
|
||||||
GlobalPosition = globalPosition;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnResolved()
|
public void OnResolved()
|
||||||
{
|
{
|
||||||
PlayerBinding = PlayerLogic.Bind();
|
PlayerBinding = PlayerLogic.Bind();
|
||||||
|
|
||||||
GameRepo.SetPlayerGlobalPosition(GlobalPosition);
|
|
||||||
|
|
||||||
PlayerBinding
|
PlayerBinding
|
||||||
.Handle((in PlayerLogic.Output.MovementComputed output) =>
|
.Handle((in PlayerLogic.Output.MovementComputed output) =>
|
||||||
{
|
{
|
||||||
@@ -104,9 +102,15 @@ namespace GameJamDungeon
|
|||||||
|
|
||||||
this.Provide();
|
this.Provide();
|
||||||
PlayerLogic.Start();
|
PlayerLogic.Start();
|
||||||
|
|
||||||
|
EquippedWeapon.Sync += OnEquippedWeaponChanged;
|
||||||
|
SwordSlashAnimation.Position = GetViewport().GetVisibleRect().Size / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnReady() => SetPhysicsProcess(true);
|
public void OnReady()
|
||||||
|
{
|
||||||
|
SetPhysicsProcess(true);
|
||||||
|
}
|
||||||
|
|
||||||
public void OnPhysicsProcess(double delta)
|
public void OnPhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
@@ -145,5 +149,9 @@ namespace GameJamDungeon
|
|||||||
PlayerBinding.Dispose();
|
PlayerBinding.Dispose();
|
||||||
AnimationPlayer.AnimationFinished -= OnAnimationFinished;
|
AnimationPlayer.AnimationFinished -= OnAnimationFinished;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnEquippedWeaponChanged(WeaponInfo info) => Hitbox.Damage = info.Damage;
|
||||||
|
|
||||||
|
private void OnPlayerPositionUpdated(Vector3 globalPosition) => GlobalPosition = globalPosition;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
[gd_scene load_steps=15 format=3 uid="uid://cfecvvav8kkp6"]
|
[gd_scene load_steps=16 format=3 uid="uid://cfecvvav8kkp6"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://src/player/Player.cs" id="1_xcol5"]
|
[ext_resource type="Script" path="res://src/player/Player.cs" id="1_xcol5"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bokx3h8kfdo5i" path="res://src/player/slash_0000_Classic_30.png" id="2_la11l"]
|
[ext_resource type="Texture2D" uid="uid://bokx3h8kfdo5i" path="res://src/player/slash_0000_Classic_30.png" id="2_la11l"]
|
||||||
|
[ext_resource type="Script" path="res://src/hitbox/Hitbox.cs" id="2_lb3qc"]
|
||||||
[ext_resource type="Texture2D" uid="uid://byosr5gk51237" path="res://src/player/slash_0001_Classic_29.png" id="3_ux3f1"]
|
[ext_resource type="Texture2D" uid="uid://byosr5gk51237" path="res://src/player/slash_0001_Classic_29.png" id="3_ux3f1"]
|
||||||
[ext_resource type="Texture2D" uid="uid://nh071o6ii03j" path="res://src/player/slash_0002_Classic_28.png" id="4_gqnq0"]
|
[ext_resource type="Texture2D" uid="uid://nh071o6ii03j" path="res://src/player/slash_0002_Classic_28.png" id="4_gqnq0"]
|
||||||
[ext_resource type="Texture2D" uid="uid://bodfblud4kea3" path="res://src/player/slash_0003_Classic_27.png" id="5_eebal"]
|
[ext_resource type="Texture2D" uid="uid://bodfblud4kea3" path="res://src/player/slash_0003_Classic_27.png" id="5_eebal"]
|
||||||
@@ -29,7 +30,7 @@ tracks/0/keys = {
|
|||||||
tracks/1/type = "value"
|
tracks/1/type = "value"
|
||||||
tracks/1/imported = false
|
tracks/1/imported = false
|
||||||
tracks/1/enabled = true
|
tracks/1/enabled = true
|
||||||
tracks/1/path = NodePath("Area3D/Hitbox:disabled")
|
tracks/1/path = NodePath("Hitbox/HitboxCollision:disabled")
|
||||||
tracks/1/interp = 1
|
tracks/1/interp = 1
|
||||||
tracks/1/loop_wrap = true
|
tracks/1/loop_wrap = true
|
||||||
tracks/1/keys = {
|
tracks/1/keys = {
|
||||||
@@ -57,7 +58,7 @@ tracks/0/keys = {
|
|||||||
tracks/1/type = "value"
|
tracks/1/type = "value"
|
||||||
tracks/1/imported = false
|
tracks/1/imported = false
|
||||||
tracks/1/enabled = true
|
tracks/1/enabled = true
|
||||||
tracks/1/path = NodePath("Area3D/Hitbox:disabled")
|
tracks/1/path = NodePath("Hitbox/HitboxCollision:disabled")
|
||||||
tracks/1/interp = 1
|
tracks/1/interp = 1
|
||||||
tracks/1/loop_wrap = true
|
tracks/1/loop_wrap = true
|
||||||
tracks/1/keys = {
|
tracks/1/keys = {
|
||||||
@@ -137,13 +138,14 @@ libraries = {
|
|||||||
"": SubResource("AnimationLibrary_w8l8m")
|
"": SubResource("AnimationLibrary_w8l8m")
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Area3D" type="Area3D" parent="."]
|
[node name="Hitbox" type="Area3D" parent="."]
|
||||||
|
unique_name_in_owner = true
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -1)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -1)
|
||||||
collision_layer = 16
|
collision_layer = 16
|
||||||
collision_mask = 16
|
collision_mask = 16
|
||||||
|
script = ExtResource("2_lb3qc")
|
||||||
|
|
||||||
[node name="Hitbox" type="CollisionShape3D" parent="Area3D"]
|
[node name="HitboxCollision" type="CollisionShape3D" parent="Hitbox"]
|
||||||
unique_name_in_owner = true
|
|
||||||
shape = SubResource("BoxShape3D_wedu3")
|
shape = SubResource("BoxShape3D_wedu3")
|
||||||
disabled = true
|
disabled = true
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Chickensoft.Serialization;
|
using Chickensoft.Collections;
|
||||||
|
using Chickensoft.Serialization;
|
||||||
using Godot;
|
using Godot;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
@@ -13,7 +14,7 @@ namespace GameJamDungeon
|
|||||||
public required PlayerLogic StateMachine { get; init; }
|
public required PlayerLogic StateMachine { get; init; }
|
||||||
|
|
||||||
[Save("PlayerEquippedSword")]
|
[Save("PlayerEquippedSword")]
|
||||||
public required InventoryItemInfo EquippedWeapon { get; set; }
|
public required IAutoProp<WeaponInfo> EquippedWeapon { get; set; }
|
||||||
|
|
||||||
[Save("PlayerInventory")]
|
[Save("PlayerInventory")]
|
||||||
public required IEnumerable<InventoryItemInfo> Inventory { get; set; }
|
public required IEnumerable<InventoryItemInfo> Inventory { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user