From f0797388d85f1d5ca5109d945c0dce54d6fcd951 Mon Sep 17 00:00:00 2001 From: HumanoidSandvichDispenser Date: Sun, 29 Jan 2023 12:05:44 -0800 Subject: [PATCH] refactor to latest godot api --- Assets/Fonts/alagard.ttf.import | 1 + Characters/Character.cs | 10 +- Characters/NPC.cs | 8 +- Extensions/Vector2.cs | 13 +- Items/Weapons/Sword.cs | 306 ++++++++++++++++---------------- SupaLidlGame.csproj | 2 +- Tests/StaticMovement.cs | 9 +- Utils/PlayerCamera.cs | 4 +- project.godot | 12 +- 9 files changed, 182 insertions(+), 183 deletions(-) diff --git a/Assets/Fonts/alagard.ttf.import b/Assets/Fonts/alagard.ttf.import index 94f50ea..51abba3 100644 --- a/Assets/Fonts/alagard.ttf.import +++ b/Assets/Fonts/alagard.ttf.import @@ -18,6 +18,7 @@ generate_mipmaps=false multichannel_signed_distance_field=false msdf_pixel_range=8 msdf_size=48 +allow_system_fallback=true force_autohinter=false hinting=1 subpixel_positioning=1 diff --git a/Characters/Character.cs b/Characters/Character.cs index f729636..7f65604 100644 --- a/Characters/Character.cs +++ b/Characters/Character.cs @@ -83,7 +83,7 @@ namespace SupaLidlGame.Characters StateMachine.Process(delta); } - Sprite.FlipH = Target.x < 0; + Sprite.FlipH = Target.X < 0; DrawTarget(); } @@ -136,16 +136,16 @@ namespace SupaLidlGame.Characters protected void DrawTarget() { Vector2 target = Target; - float angle = Mathf.Atan2(target.y, Mathf.Abs(target.x)); + float angle = Mathf.Atan2(target.Y, Mathf.Abs(target.X)); Vector2 scale = Inventory.Scale; - if (target.x < 0) + if (target.X < 0) { - scale.y = -1; + scale.Y = -1; angle = Mathf.Pi - angle; } else { - scale.y = 1; + scale.Y = 1; } Inventory.Scale = scale; Inventory.Rotation = angle; diff --git a/Characters/NPC.cs b/Characters/NPC.cs index 9b2868f..a5da9ff 100644 --- a/Characters/NPC.cs +++ b/Characters/NPC.cs @@ -120,8 +120,8 @@ namespace SupaLidlGame.Characters Vector2 dir = Target.Normalized(); float dist = GlobalPosition.DistanceSquaredTo(pos); - var spaceState = GetWorld2d().DirectSpaceState; - var exclude = new Godot.Collections.Array(); + var spaceState = GetWorld2D().DirectSpaceState; + var exclude = new Godot.Collections.Array(); exclude.Add(this.GetRid()); for (int i = 0; i < 16; i++) @@ -243,7 +243,7 @@ namespace SupaLidlGame.Characters public Vector2 GetBlocking() { - var spaceState = GetWorld2d().DirectSpaceState; + var spaceState = GetWorld2D().DirectSpaceState; int rayLength = 16; float[] weights = new float[16]; Vector2[] rays = new Vector2[16]; @@ -254,7 +254,7 @@ namespace SupaLidlGame.Characters // the length determines its strength // exclude itself from raycasts - var exclude = new Godot.Collections.Array(); + var exclude = new Godot.Collections.Array(); exclude.Add(GetRid()); var rayParams = new PhysicsRayQueryParameters2D diff --git a/Extensions/Vector2.cs b/Extensions/Vector2.cs index 4a83aef..e480eb9 100644 --- a/Extensions/Vector2.cs +++ b/Extensions/Vector2.cs @@ -1,5 +1,4 @@ using Godot; -using System.Linq; namespace SupaLidlGame.Extensions { @@ -7,8 +6,8 @@ namespace SupaLidlGame.Extensions { public static Vector2 Midpoint(this Vector2 vector, Vector2 other) { - return new Vector2((vector.x + other.x) / 2, - (vector.y + other.y) / 2); + return new Vector2((vector.X + other.X) / 2, + (vector.Y + other.Y) / 2); } public static Vector2 Midpoints(params Vector2[] vectors) @@ -19,8 +18,8 @@ namespace SupaLidlGame.Extensions for (int i = 0; i < length; i++) { - x += vectors[i].x; - y += vectors[i].y; + x += vectors[i].X; + y += vectors[i].Y; } return new Vector2(x / length, y / length); @@ -28,12 +27,12 @@ namespace SupaLidlGame.Extensions public static Vector2 Counterclockwise90(this Vector2 vector) { - return new Vector2(-vector.y, vector.x); + return new Vector2(-vector.Y, vector.X); } public static Vector2 Clockwise90(this Vector2 vector) { - return new Vector2(vector.y, -vector.x); + return new Vector2(vector.Y, -vector.X); } } } diff --git a/Items/Weapons/Sword.cs b/Items/Weapons/Sword.cs index 9caa364..0db61c9 100644 --- a/Items/Weapons/Sword.cs +++ b/Items/Weapons/Sword.cs @@ -5,183 +5,183 @@ using SupaLidlGame.Extensions; namespace SupaLidlGame.Items.Weapons { - public partial class Sword : Weapon - { - public bool IsAttacking { get; protected set; } + public partial class Sword : Weapon + { + public bool IsAttacking { get; protected set; } - [Export] - public Hitbox Hitbox { get; set; } + [Export] + public Hitbox Hitbox { get; set; } - [Export] - public AnimationPlayer AnimationPlayer { get; set; } + [Export] + public AnimationPlayer AnimationPlayer { get; set; } - /// - /// The time frame in seconds for which the weapon will deal damage. - /// - /// - /// The value of AttackTime should be less than the - /// value of UseTime - /// - [Export] - public double AttackTime { get; set; } = 0; + /// + /// The time frame in seconds for which the weapon will deal damage. + /// + /// + /// The value of AttackTime should be less than the + /// value of UseTime + /// + [Export] + public double AttackTime { get; set; } = 0; - [Export] - public CPUParticles2D ParryParticles { get; set; } + [Export] + public CpuParticles2D ParryParticles { get; set; } - public override bool IsParryable { get; protected set; } + public override bool IsParryable { get; protected set; } - public override void Equip(Character character) - { - Visible = true; - base.Equip(character); - Hitbox.Faction = character.Faction; // character is null before base - } + public override void Equip(Character character) + { + Visible = true; + base.Equip(character); + Hitbox.Faction = character.Faction; // character is null before base + } - public override void Unequip(Character character) - { - Visible = false; - base.Unequip(character); - } + public override void Unequip(Character character) + { + Visible = false; + base.Unequip(character); + } - public override void Use() - { - // we can't use if we're still using the weapon - if (RemainingUseTime > 0) - { - return; - } + public override void Use() + { + // we can't use if we're still using the weapon + if (RemainingUseTime > 0) + { + return; + } - // reset state of the weapon - IsParried = false; - IsParryable = true; - ParryTimeOrigin = Time.GetTicksMsec(); + // reset state of the weapon + IsParried = false; + IsParryable = true; + ParryTimeOrigin = Time.GetTicksMsec(); - AnimationPlayer.Stop(); + AnimationPlayer.Stop(); - // play animation depending on rotation of weapon - string anim = "use"; + // play animation depending on rotation of weapon + string anim = "use"; - if (GetNode("Anchor").Rotation > Mathf.DegToRad(50)) - { - anim = "use2"; - } + if (GetNode("Anchor").Rotation > Mathf.DegToRad(50)) + { + anim = "use2"; + } - if (Character is NPC) - { - // NPCs have a slower attack - anim += "-npc"; - } + if (Character is NPC) + { + // NPCs have a slower attack + anim += "-npc"; + } - AnimationPlayer.Play(anim); + AnimationPlayer.Play(anim); - base.Use(); - } + base.Use(); + } - public override void Deuse() - { - //AnimationPlayer.Stop(); - Deattack(); - base.Deuse(); - } + public override void Deuse() + { + //AnimationPlayer.Stop(); + Deattack(); + base.Deuse(); + } - public void Attack() - { - //RemainingAttackTime = AttackTime; - IsAttacking = true; - Hitbox.IsDisabled = false; - } + public void Attack() + { + //RemainingAttackTime = AttackTime; + IsAttacking = true; + Hitbox.IsDisabled = false; + } - public void Deattack() - { - IsAttacking = false; - IsParryable = false; - Hitbox.IsDisabled = true; - ProcessHits(); - Hitbox.ResetIgnoreList(); - AnimationPlayer.PlaybackSpeed = 1; - } + public void Deattack() + { + IsAttacking = false; + IsParryable = false; + Hitbox.IsDisabled = true; + ProcessHits(); + Hitbox.ResetIgnoreList(); + AnimationPlayer.SpeedScale = 1; + } - public override void _Ready() - { - Hitbox.Damage = Damage; - } + public override void _Ready() + { + Hitbox.Damage = Damage; + } - public override void _Process(double delta) - { - /* - if (RemainingAttackTime > 0) - { - if ((RemainingAttackTime -= delta) <= 0) - { - Deattack(); - } - } - */ - base._Process(delta); - } + public override void _Process(double delta) + { + /* + if (RemainingAttackTime > 0) + { + if ((RemainingAttackTime -= delta) <= 0) + { + Deattack(); + } + } + */ + base._Process(delta); + } - public void ProcessHits() - { - if (IsParried) - { - return; - } + public void ProcessHits() + { + if (IsParried) + { + return; + } - foreach (BoundingBox box in Hitbox.Hits) - { - GD.Print("processing hit"); - if (box is Hurtbox hurtbox) - { - hurtbox.InflictDamage(Damage, Character, Knockback); - } - } - } + foreach (BoundingBox box in Hitbox.Hits) + { + GD.Print("processing hit"); + if (box is Hurtbox hurtbox) + { + hurtbox.InflictDamage(Damage, Character, Knockback); + } + } + } - public void AttemptParry(Weapon otherWeapon) - { - if (IsParryable && otherWeapon.IsParryable) - { - ParryParticles.Emitting = true; - if (ParryTimeOrigin < otherWeapon.ParryTimeOrigin) - { - // our character was parried - IsParried = true; - AnimationPlayer.PlaybackSpeed = 0.25f; - Character.Stun(1.5f); - GetNode("ParrySound").Play(); - } - } - //this.GetAncestor().AddChild(instance); - } + public void AttemptParry(Weapon otherWeapon) + { + if (IsParryable && otherWeapon.IsParryable) + { + ParryParticles.Emitting = true; + if (ParryTimeOrigin < otherWeapon.ParryTimeOrigin) + { + // our character was parried + IsParried = true; + AnimationPlayer.SpeedScale = 0.25f; + Character.Stun(1.5f); + GetNode("ParrySound").Play(); + } + } + //this.GetAncestor().AddChild(instance); + } - public override void _on_hitbox_hit(BoundingBox box) - { - if (IsParried) - { - return; - } + public override void _on_hitbox_hit(BoundingBox box) + { + if (IsParried) + { + return; + } - if (box is Hitbox hb) - { - Weapon w = hb.GetAncestor(); - if (w is not null) - { - //Vector2 a = new Vector2(2, 2) * new Vector2(5, 2); - AttemptParry(w); - } - } + if (box is Hitbox hb) + { + Weapon w = hb.GetAncestor(); + if (w is not null) + { + //Vector2 a = new Vector2(2, 2) * new Vector2(5, 2); + AttemptParry(w); + } + } - if (box is Hurtbox hurt) - { - if (hurt.GetParent() is Character c) - { - var item = c.Inventory.SelectedItem; - if (item is Weapon w) - { - AttemptParry(w); - } - } - } - } - } + if (box is Hurtbox hurt) + { + if (hurt.GetParent() is Character c) + { + var item = c.Inventory.SelectedItem; + if (item is Weapon w) + { + AttemptParry(w); + } + } + } + } + } } diff --git a/SupaLidlGame.csproj b/SupaLidlGame.csproj index cc92d09..b69301b 100644 --- a/SupaLidlGame.csproj +++ b/SupaLidlGame.csproj @@ -1,4 +1,4 @@ - + net6.0 true diff --git a/Tests/StaticMovement.cs b/Tests/StaticMovement.cs index ef04ba1..72f35f3 100644 --- a/Tests/StaticMovement.cs +++ b/Tests/StaticMovement.cs @@ -1,5 +1,4 @@ using Godot; -using System; public partial class StaticMovement : CharacterBody2D { @@ -15,22 +14,22 @@ public partial class StaticMovement : CharacterBody2D // Add the gravity. if (!IsOnFloor()) - velocity.y += gravity * (float)delta; + velocity.Y += gravity * (float)delta; // Handle Jump. if (Input.IsActionJustPressed("ui_accept") && IsOnFloor()) - velocity.y = JumpVelocity; + velocity.Y = JumpVelocity; // Get the input direction and handle the movement/deceleration. // As good practice, you should replace UI actions with custom gameplay actions. Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down"); if (direction != Vector2.Zero) { - velocity.x = direction.x * Speed; + velocity.X = direction.X * Speed; } else { - velocity.x = Mathf.MoveToward(Velocity.x, 0, Speed); + velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed); } Velocity = velocity; diff --git a/Utils/PlayerCamera.cs b/Utils/PlayerCamera.cs index 076ee23..4d6c4e6 100644 --- a/Utils/PlayerCamera.cs +++ b/Utils/PlayerCamera.cs @@ -42,8 +42,8 @@ namespace SupaLidlGame.Utils { Vector2 ret = Vector2.Zero; var rng = new RandomNumberGenerator(); - ret.x = (rng.Randf() - 0.5f) * intensity; - ret.y = (rng.Randf() - 0.5f) * intensity; + ret.X = (rng.Randf() - 0.5f) * intensity; + ret.Y = (rng.Randf() - 0.5f) * intensity; return ret; } } diff --git a/project.godot b/project.godot index dbf8aca..fb48c18 100644 --- a/project.godot +++ b/project.godot @@ -23,32 +23,32 @@ project/assembly_name="SupaLidlGame" ui_left={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":65,"physical_keycode":0,"unicode":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":65,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null) ] } ui_right={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":68,"physical_keycode":0,"unicode":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":68,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null) ] } ui_up={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":87,"physical_keycode":0,"unicode":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":87,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null) ] } ui_down={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":83,"physical_keycode":0,"unicode":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":83,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null) ] } roll={ "deadzone": 0.5, "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":3,"pressed":false,"double_click":false,"script":null) -, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"unicode":0,"echo":false,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":0,"echo":false,"script":null) ] } attack1={ @@ -58,7 +58,7 @@ attack1={ } equip={ "deadzone": 0.5, -"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"unicode":0,"echo":false,"script":null) +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":69,"key_label":0,"unicode":0,"echo":false,"script":null) ] }