refactor to latest godot api

item-info
HumanoidSandvichDispenser 2023-01-29 12:05:44 -08:00
parent 38bfae2aaa
commit f0797388d8
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
9 changed files with 182 additions and 183 deletions

View File

@ -18,6 +18,7 @@ generate_mipmaps=false
multichannel_signed_distance_field=false multichannel_signed_distance_field=false
msdf_pixel_range=8 msdf_pixel_range=8
msdf_size=48 msdf_size=48
allow_system_fallback=true
force_autohinter=false force_autohinter=false
hinting=1 hinting=1
subpixel_positioning=1 subpixel_positioning=1

View File

@ -83,7 +83,7 @@ namespace SupaLidlGame.Characters
StateMachine.Process(delta); StateMachine.Process(delta);
} }
Sprite.FlipH = Target.x < 0; Sprite.FlipH = Target.X < 0;
DrawTarget(); DrawTarget();
} }
@ -136,16 +136,16 @@ namespace SupaLidlGame.Characters
protected void DrawTarget() protected void DrawTarget()
{ {
Vector2 target = Target; 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; Vector2 scale = Inventory.Scale;
if (target.x < 0) if (target.X < 0)
{ {
scale.y = -1; scale.Y = -1;
angle = Mathf.Pi - angle; angle = Mathf.Pi - angle;
} }
else else
{ {
scale.y = 1; scale.Y = 1;
} }
Inventory.Scale = scale; Inventory.Scale = scale;
Inventory.Rotation = angle; Inventory.Rotation = angle;

View File

@ -120,8 +120,8 @@ namespace SupaLidlGame.Characters
Vector2 dir = Target.Normalized(); Vector2 dir = Target.Normalized();
float dist = GlobalPosition.DistanceSquaredTo(pos); float dist = GlobalPosition.DistanceSquaredTo(pos);
var spaceState = GetWorld2d().DirectSpaceState; var spaceState = GetWorld2D().DirectSpaceState;
var exclude = new Godot.Collections.Array<RID>(); var exclude = new Godot.Collections.Array<Godot.Rid>();
exclude.Add(this.GetRid()); exclude.Add(this.GetRid());
for (int i = 0; i < 16; i++) for (int i = 0; i < 16; i++)
@ -243,7 +243,7 @@ namespace SupaLidlGame.Characters
public Vector2 GetBlocking() public Vector2 GetBlocking()
{ {
var spaceState = GetWorld2d().DirectSpaceState; var spaceState = GetWorld2D().DirectSpaceState;
int rayLength = 16; int rayLength = 16;
float[] weights = new float[16]; float[] weights = new float[16];
Vector2[] rays = new Vector2[16]; Vector2[] rays = new Vector2[16];
@ -254,7 +254,7 @@ namespace SupaLidlGame.Characters
// the length determines its strength // the length determines its strength
// exclude itself from raycasts // exclude itself from raycasts
var exclude = new Godot.Collections.Array<RID>(); var exclude = new Godot.Collections.Array<Godot.Rid>();
exclude.Add(GetRid()); exclude.Add(GetRid());
var rayParams = new PhysicsRayQueryParameters2D var rayParams = new PhysicsRayQueryParameters2D

View File

@ -1,5 +1,4 @@
using Godot; using Godot;
using System.Linq;
namespace SupaLidlGame.Extensions namespace SupaLidlGame.Extensions
{ {
@ -7,8 +6,8 @@ namespace SupaLidlGame.Extensions
{ {
public static Vector2 Midpoint(this Vector2 vector, Vector2 other) public static Vector2 Midpoint(this Vector2 vector, Vector2 other)
{ {
return new Vector2((vector.x + other.x) / 2, return new Vector2((vector.X + other.X) / 2,
(vector.y + other.y) / 2); (vector.Y + other.Y) / 2);
} }
public static Vector2 Midpoints(params Vector2[] vectors) public static Vector2 Midpoints(params Vector2[] vectors)
@ -19,8 +18,8 @@ namespace SupaLidlGame.Extensions
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
x += vectors[i].x; x += vectors[i].X;
y += vectors[i].y; y += vectors[i].Y;
} }
return new Vector2(x / length, y / length); return new Vector2(x / length, y / length);
@ -28,12 +27,12 @@ namespace SupaLidlGame.Extensions
public static Vector2 Counterclockwise90(this Vector2 vector) 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) public static Vector2 Clockwise90(this Vector2 vector)
{ {
return new Vector2(vector.y, -vector.x); return new Vector2(vector.Y, -vector.X);
} }
} }
} }

View File

@ -5,183 +5,183 @@ using SupaLidlGame.Extensions;
namespace SupaLidlGame.Items.Weapons namespace SupaLidlGame.Items.Weapons
{ {
public partial class Sword : Weapon public partial class Sword : Weapon
{ {
public bool IsAttacking { get; protected set; } public bool IsAttacking { get; protected set; }
[Export] [Export]
public Hitbox Hitbox { get; set; } public Hitbox Hitbox { get; set; }
[Export] [Export]
public AnimationPlayer AnimationPlayer { get; set; } public AnimationPlayer AnimationPlayer { get; set; }
/// <summary> /// <summary>
/// The time frame in seconds for which the weapon will deal damage. /// The time frame in seconds for which the weapon will deal damage.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The value of <c>AttackTime</c> should be less than the /// The value of <c>AttackTime</c> should be less than the
/// value of <c>UseTime</c> /// value of <c>UseTime</c>
/// </remarks> /// </remarks>
[Export] [Export]
public double AttackTime { get; set; } = 0; public double AttackTime { get; set; } = 0;
[Export] [Export]
public CPUParticles2D ParryParticles { get; set; } 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) public override void Equip(Character character)
{ {
Visible = true; Visible = true;
base.Equip(character); base.Equip(character);
Hitbox.Faction = character.Faction; // character is null before base Hitbox.Faction = character.Faction; // character is null before base
} }
public override void Unequip(Character character) public override void Unequip(Character character)
{ {
Visible = false; Visible = false;
base.Unequip(character); base.Unequip(character);
} }
public override void Use() public override void Use()
{ {
// we can't use if we're still using the weapon // we can't use if we're still using the weapon
if (RemainingUseTime > 0) if (RemainingUseTime > 0)
{ {
return; return;
} }
// reset state of the weapon // reset state of the weapon
IsParried = false; IsParried = false;
IsParryable = true; IsParryable = true;
ParryTimeOrigin = Time.GetTicksMsec(); ParryTimeOrigin = Time.GetTicksMsec();
AnimationPlayer.Stop(); AnimationPlayer.Stop();
// play animation depending on rotation of weapon // play animation depending on rotation of weapon
string anim = "use"; string anim = "use";
if (GetNode<Node2D>("Anchor").Rotation > Mathf.DegToRad(50)) if (GetNode<Node2D>("Anchor").Rotation > Mathf.DegToRad(50))
{ {
anim = "use2"; anim = "use2";
} }
if (Character is NPC) if (Character is NPC)
{ {
// NPCs have a slower attack // NPCs have a slower attack
anim += "-npc"; anim += "-npc";
} }
AnimationPlayer.Play(anim); AnimationPlayer.Play(anim);
base.Use(); base.Use();
} }
public override void Deuse() public override void Deuse()
{ {
//AnimationPlayer.Stop(); //AnimationPlayer.Stop();
Deattack(); Deattack();
base.Deuse(); base.Deuse();
} }
public void Attack() public void Attack()
{ {
//RemainingAttackTime = AttackTime; //RemainingAttackTime = AttackTime;
IsAttacking = true; IsAttacking = true;
Hitbox.IsDisabled = false; Hitbox.IsDisabled = false;
} }
public void Deattack() public void Deattack()
{ {
IsAttacking = false; IsAttacking = false;
IsParryable = false; IsParryable = false;
Hitbox.IsDisabled = true; Hitbox.IsDisabled = true;
ProcessHits(); ProcessHits();
Hitbox.ResetIgnoreList(); Hitbox.ResetIgnoreList();
AnimationPlayer.PlaybackSpeed = 1; AnimationPlayer.SpeedScale = 1;
} }
public override void _Ready() public override void _Ready()
{ {
Hitbox.Damage = Damage; Hitbox.Damage = Damage;
} }
public override void _Process(double delta) public override void _Process(double delta)
{ {
/* /*
if (RemainingAttackTime > 0) if (RemainingAttackTime > 0)
{ {
if ((RemainingAttackTime -= delta) <= 0) if ((RemainingAttackTime -= delta) <= 0)
{ {
Deattack(); Deattack();
} }
} }
*/ */
base._Process(delta); base._Process(delta);
} }
public void ProcessHits() public void ProcessHits()
{ {
if (IsParried) if (IsParried)
{ {
return; return;
} }
foreach (BoundingBox box in Hitbox.Hits) foreach (BoundingBox box in Hitbox.Hits)
{ {
GD.Print("processing hit"); GD.Print("processing hit");
if (box is Hurtbox hurtbox) if (box is Hurtbox hurtbox)
{ {
hurtbox.InflictDamage(Damage, Character, Knockback); hurtbox.InflictDamage(Damage, Character, Knockback);
} }
} }
} }
public void AttemptParry(Weapon otherWeapon) public void AttemptParry(Weapon otherWeapon)
{ {
if (IsParryable && otherWeapon.IsParryable) if (IsParryable && otherWeapon.IsParryable)
{ {
ParryParticles.Emitting = true; ParryParticles.Emitting = true;
if (ParryTimeOrigin < otherWeapon.ParryTimeOrigin) if (ParryTimeOrigin < otherWeapon.ParryTimeOrigin)
{ {
// our character was parried // our character was parried
IsParried = true; IsParried = true;
AnimationPlayer.PlaybackSpeed = 0.25f; AnimationPlayer.SpeedScale = 0.25f;
Character.Stun(1.5f); Character.Stun(1.5f);
GetNode<AudioStreamPlayer2D>("ParrySound").Play(); GetNode<AudioStreamPlayer2D>("ParrySound").Play();
} }
} }
//this.GetAncestor<TileMap>().AddChild(instance); //this.GetAncestor<TileMap>().AddChild(instance);
} }
public override void _on_hitbox_hit(BoundingBox box) public override void _on_hitbox_hit(BoundingBox box)
{ {
if (IsParried) if (IsParried)
{ {
return; return;
} }
if (box is Hitbox hb) if (box is Hitbox hb)
{ {
Weapon w = hb.GetAncestor<Weapon>(); Weapon w = hb.GetAncestor<Weapon>();
if (w is not null) if (w is not null)
{ {
//Vector2 a = new Vector2(2, 2) * new Vector2(5, 2); //Vector2 a = new Vector2(2, 2) * new Vector2(5, 2);
AttemptParry(w); AttemptParry(w);
} }
} }
if (box is Hurtbox hurt) if (box is Hurtbox hurt)
{ {
if (hurt.GetParent() is Character c) if (hurt.GetParent() is Character c)
{ {
var item = c.Inventory.SelectedItem; var item = c.Inventory.SelectedItem;
if (item is Weapon w) if (item is Weapon w)
{ {
AttemptParry(w); AttemptParry(w);
} }
} }
} }
} }
} }
} }

View File

@ -1,4 +1,4 @@
<Project Sdk="Godot.NET.Sdk/4.0.0-beta.7"> <Project Sdk="Godot.NET.Sdk/4.0.0-beta.16">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading> <EnableDynamicLoading>true</EnableDynamicLoading>

View File

@ -1,5 +1,4 @@
using Godot; using Godot;
using System;
public partial class StaticMovement : CharacterBody2D public partial class StaticMovement : CharacterBody2D
{ {
@ -15,22 +14,22 @@ public partial class StaticMovement : CharacterBody2D
// Add the gravity. // Add the gravity.
if (!IsOnFloor()) if (!IsOnFloor())
velocity.y += gravity * (float)delta; velocity.Y += gravity * (float)delta;
// Handle Jump. // Handle Jump.
if (Input.IsActionJustPressed("ui_accept") && IsOnFloor()) if (Input.IsActionJustPressed("ui_accept") && IsOnFloor())
velocity.y = JumpVelocity; velocity.Y = JumpVelocity;
// Get the input direction and handle the movement/deceleration. // Get the input direction and handle the movement/deceleration.
// As good practice, you should replace UI actions with custom gameplay actions. // As good practice, you should replace UI actions with custom gameplay actions.
Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down"); Vector2 direction = Input.GetVector("ui_left", "ui_right", "ui_up", "ui_down");
if (direction != Vector2.Zero) if (direction != Vector2.Zero)
{ {
velocity.x = direction.x * Speed; velocity.X = direction.X * Speed;
} }
else else
{ {
velocity.x = Mathf.MoveToward(Velocity.x, 0, Speed); velocity.X = Mathf.MoveToward(Velocity.X, 0, Speed);
} }
Velocity = velocity; Velocity = velocity;

View File

@ -42,8 +42,8 @@ namespace SupaLidlGame.Utils
{ {
Vector2 ret = Vector2.Zero; Vector2 ret = Vector2.Zero;
var rng = new RandomNumberGenerator(); var rng = new RandomNumberGenerator();
ret.x = (rng.Randf() - 0.5f) * intensity; ret.X = (rng.Randf() - 0.5f) * intensity;
ret.y = (rng.Randf() - 0.5f) * intensity; ret.Y = (rng.Randf() - 0.5f) * intensity;
return ret; return ret;
} }
} }

View File

@ -23,32 +23,32 @@ project/assembly_name="SupaLidlGame"
ui_left={ ui_left={
"deadzone": 0.5, "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) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
] ]
} }
ui_right={ ui_right={
"deadzone": 0.5, "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) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
] ]
} }
ui_up={ ui_up={
"deadzone": 0.5, "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) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null)
] ]
} }
ui_down={ ui_down={
"deadzone": 0.5, "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) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
] ]
} }
roll={ roll={
"deadzone": 0.5, "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) "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={ attack1={
@ -58,7 +58,7 @@ attack1={
} }
equip={ equip={
"deadzone": 0.5, "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)
] ]
} }