pull/3/head
John Montagu, the 4th Earl of Sandvich 2023-05-28 10:57:23 -07:00
parent bcd84e8f39
commit 39d4069aa1
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
12 changed files with 153 additions and 16 deletions

View File

@ -189,6 +189,8 @@ namespace SupaLidlGame.Characters
ApplyImpulse(knockbackDir.Normalized() * knockback);
GD.Print("lol");
// play damage animation
var anim = GetNode<AnimationPlayer>("FlashAnimation");
if (anim != null)

View File

@ -167,7 +167,7 @@ namespace SupaLidlGame.Characters
CollideWithBodies = true,
From = GlobalPosition,
To = GlobalPosition + (_weightDirs[i] * 24),
CollisionMask = 1 + 8
CollisionMask = 1 + 2 + 16
};
var result = spaceState.IntersectRay(rayParams);

View File

@ -130,6 +130,7 @@ namespace SupaLidlGame.Items
{
if (child is Item item)
{
GD.Print("Adding item " + item.Name);
AddItem(item);
}
}

View File

@ -35,6 +35,9 @@ namespace SupaLidlGame.Items
[Export]
public float InitialVelocity { get; set; } = 0;
[Export]
public bool ShouldHideIdle { get; set; } = false;
public virtual bool IsParryable { get; protected set; } = false;
public bool IsParried { get; set; }
@ -51,7 +54,10 @@ namespace SupaLidlGame.Items
public override void Equip(Character character)
{
Visible = true;
if (!ShouldHideIdle || IsUsing)
{
Visible = true;
}
Character = character;
}

View File

@ -332,7 +332,7 @@ graph_offset = Vector2(0, -104.073)
radius = 20.0
height = 48.0
[node name="Node2D" type="Node2D" node_paths=PackedStringArray("Hitbox", "AnimationPlayer", "AnimationTree", "ParryParticles", "StateMachine", "Anchor")]
[node name="Sword" type="Node2D" node_paths=PackedStringArray("Hitbox", "AnimationPlayer", "AnimationTree", "ParryParticles", "StateMachine", "Anchor")]
y_sort_enabled = true
texture_filter = 3
script = ExtResource("1_mlo73")
@ -348,6 +348,7 @@ Anchor = NodePath("Anchor")
Damage = 20.0
UseTime = 0.8
Knockback = 64.0
ShouldHideIdle = true
[node name="State" type="Node" parent="." node_paths=PackedStringArray("InitialState")]
script = ExtResource("2_vwirq")

File diff suppressed because one or more lines are too long

View File

@ -32,14 +32,29 @@ namespace SupaLidlGame.State.Character
"ui_up", "ui_down");
Vector2 mousePos = Character.GetGlobalMousePosition();
Vector2 dirToMouse = Character.GlobalPosition.DirectionTo(mousePos);
bool faceToDir = !Character.Direction.IsZeroApprox();
if (Character.Inventory.SelectedItem is Items.Weapon weapon)
{
if (!weapon.IsUsing)
{
Character.Target = dirToMouse;
if (weapon.ShouldHideIdle)
{
faceToDir = true;
}
else
{
Character.Target = dirToMouse;
}
}
else
{
faceToDir = false;
}
}
else if (!Character.Direction.IsZeroApprox())
if (faceToDir)
{
Character.Target = Character.Direction;
}
@ -53,7 +68,6 @@ namespace SupaLidlGame.State.Character
{
Character.Target = dirToMouse;
}
Character.Target = dirToMouse;
Character.UseCurrentItem();
}
}

View File

@ -7,7 +7,14 @@ namespace SupaLidlGame.State.Weapon
[Export]
public RangedFireState FireState { get; set; }
public override IState<WeaponState> Enter(IState<WeaponState> prev) => null;
[Export]
public Items.Weapons.Ranged Weapon { get; set; }
public override IState<WeaponState> Enter(IState<WeaponState> prev)
{
Weapon.Visible = !Weapon.ShouldHideIdle;
return null;
}
public override WeaponState Use()
{
@ -16,7 +23,7 @@ namespace SupaLidlGame.State.Weapon
public override void Exit(IState<WeaponState> nextState)
{
Weapon.Visible = true;
}
}
}

View File

@ -39,9 +39,7 @@ namespace SupaLidlGame.State.Weapon
_useDuration = Sword.UseTime;
_attackAnimDuration = Sword.AttackAnimationDuration;
GD.Print(_attackDuration);
GD.Print(_useDuration);
GD.Print(_attackAnimDuration);
Sword.Visible = true;
return null;
}
@ -60,7 +58,7 @@ namespace SupaLidlGame.State.Weapon
{
_isAlternate = !_isAlternate;
}
return AnticipateState;
return IdleState;
}
return null;

View File

@ -18,9 +18,17 @@ namespace SupaLidlGame.State.Weapon
{
_attackCooldown = Sword.UseTime - Sword.AttackTime;
}
Sword.Visible = !Sword.ShouldHideIdle;
return null;
}
public override void Exit(IState<WeaponState> nextState)
{
Sword.Visible = true;
}
public override WeaponState Use()
{
if (_attackCooldown <= 0)

59
Utils/Spawner.cs 100644
View File

@ -0,0 +1,59 @@
using Godot;
using Godot.Collections;
using SupaLidlGame.Extensions;
namespace SupaLidlGame.Utils
{
public partial class Spawner : Node2D
{
[Export]
public Area2D SpawnArea { get; set; }
[Export]
public PackedScene Character { get; set; }
[Export]
public double SpawnTime { get; set; }
protected double _timeLeftToSpawn = 0;
public override void _Ready()
{
}
public override void _Process(double delta)
{
if ((_timeLeftToSpawn -= delta) <= 0)
{
_timeLeftToSpawn = SpawnTime;
Spawn();
}
}
public void Spawn()
{
var coll = GetNode<CollisionShape2D>("Area2D/CollisionShape2D");
var rect = coll.Shape as RectangleShape2D;
if (rect is not null)
{
Vector2 size = rect.Size / 2;
Vector2 pos = GlobalPosition;
double x1, x2, y1, y2;
x1 = pos.X - size.X;
x2 = pos.X + size.X;
y1 = pos.Y - size.Y;
y2 = pos.Y + size.Y;
float randX = (float)GD.RandRange(x1, x2);
float randY = (float)GD.RandRange(y1, y2);
Vector2 randPos = new Vector2(randX, randY);
var chr = Character.Instantiate<Characters.Character>();
chr.GlobalPosition = randPos;
this.GetAncestor<Scenes.Map>().Entities.AddChild(chr);
}
}
}
}

14
Utils/Spawner.tscn 100644
View File

@ -0,0 +1,14 @@
[gd_scene load_steps=3 format=3 uid="uid://5nvn1tw56m8e"]
[ext_resource type="Script" path="res://Utils/Spawner.cs" id="1_6sr3u"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_smmx0"]
[node name="Spawner" type="Node2D" node_paths=PackedStringArray("SpawnArea")]
script = ExtResource("1_6sr3u")
SpawnArea = NodePath("Area2D")
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("RectangleShape2D_smmx0")