refactor to latest godot api
parent
38bfae2aaa
commit
f0797388d8
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<RID>();
|
||||
var spaceState = GetWorld2D().DirectSpaceState;
|
||||
var exclude = new Godot.Collections.Array<Godot.Rid>();
|
||||
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<RID>();
|
||||
var exclude = new Godot.Collections.Array<Godot.Rid>();
|
||||
exclude.Add(GetRid());
|
||||
|
||||
var rayParams = new PhysicsRayQueryParameters2D
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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; }
|
||||
|
||||
/// <summary>
|
||||
/// The time frame in seconds for which the weapon will deal damage.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The value of <c>AttackTime</c> should be less than the
|
||||
/// value of <c>UseTime</c>
|
||||
/// </remarks>
|
||||
[Export]
|
||||
public double AttackTime { get; set; } = 0;
|
||||
/// <summary>
|
||||
/// The time frame in seconds for which the weapon will deal damage.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The value of <c>AttackTime</c> should be less than the
|
||||
/// value of <c>UseTime</c>
|
||||
/// </remarks>
|
||||
[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<Node2D>("Anchor").Rotation > Mathf.DegToRad(50))
|
||||
{
|
||||
anim = "use2";
|
||||
}
|
||||
if (GetNode<Node2D>("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<AudioStreamPlayer2D>("ParrySound").Play();
|
||||
}
|
||||
}
|
||||
//this.GetAncestor<TileMap>().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<AudioStreamPlayer2D>("ParrySound").Play();
|
||||
}
|
||||
}
|
||||
//this.GetAncestor<TileMap>().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<Weapon>();
|
||||
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<Weapon>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue