camera shaking and autoswing
parent
19aaffbeab
commit
983dfba589
|
@ -165,7 +165,8 @@ namespace SupaLidlGame.Characters
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void _on_hurtbox_received_damage(float damage,
|
public virtual void _on_hurtbox_received_damage(
|
||||||
|
float damage,
|
||||||
Character inflictor,
|
Character inflictor,
|
||||||
float knockback,
|
float knockback,
|
||||||
Vector2 knockbackOrigin = default,
|
Vector2 knockbackOrigin = default,
|
||||||
|
@ -173,12 +174,14 @@ namespace SupaLidlGame.Characters
|
||||||
{
|
{
|
||||||
Health -= damage;
|
Health -= damage;
|
||||||
|
|
||||||
|
// create damage text
|
||||||
var textScene = GD.Load<PackedScene>("res://UI/FloatingText.tscn");
|
var textScene = GD.Load<PackedScene>("res://UI/FloatingText.tscn");
|
||||||
var instance = textScene.Instantiate<UI.FloatingText>();
|
var instance = textScene.Instantiate<UI.FloatingText>();
|
||||||
instance.Text = Mathf.Round(damage).ToString();
|
instance.Text = Mathf.Round(damage).ToString();
|
||||||
instance.GlobalPosition = GlobalPosition;
|
instance.GlobalPosition = GlobalPosition;
|
||||||
this.GetAncestor<TileMap>().AddChild(instance);
|
this.GetAncestor<TileMap>().AddChild(instance);
|
||||||
|
|
||||||
|
// apply knockback
|
||||||
Vector2 knockbackDir = knockbackVector;
|
Vector2 knockbackDir = knockbackVector;
|
||||||
if (knockbackDir == default)
|
if (knockbackDir == default)
|
||||||
{
|
{
|
||||||
|
@ -190,14 +193,22 @@ namespace SupaLidlGame.Characters
|
||||||
knockbackDir = knockbackOrigin.DirectionTo(GlobalPosition);
|
knockbackDir = knockbackOrigin.DirectionTo(GlobalPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
var player = GetNode<AnimationPlayer>("FlashAnimation");
|
ApplyImpulse(knockbackDir.Normalized() * knockback);
|
||||||
if (player != null)
|
|
||||||
|
// play damage animation
|
||||||
|
var anim = GetNode<AnimationPlayer>("FlashAnimation");
|
||||||
|
if (anim != null)
|
||||||
{
|
{
|
||||||
player.Stop();
|
anim.Stop();
|
||||||
player.Play("Hurt");
|
anim.Play("Hurt");
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplyImpulse(knockbackDir.Normalized() * knockback);
|
// if anyone involved is a player, shake their screen
|
||||||
|
Player plr = inflictor as Player ?? this as Player;
|
||||||
|
if (plr is not null)
|
||||||
|
{
|
||||||
|
plr.Camera.Shake(0.75f, 0.25f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using Godot;
|
using Godot;
|
||||||
|
using SupaLidlGame.Utils;
|
||||||
|
|
||||||
namespace SupaLidlGame.Characters
|
namespace SupaLidlGame.Characters
|
||||||
{
|
{
|
||||||
|
@ -7,6 +8,9 @@ namespace SupaLidlGame.Characters
|
||||||
private AnimatedSprite2D _sprite;
|
private AnimatedSprite2D _sprite;
|
||||||
private string _spriteAnim;
|
private string _spriteAnim;
|
||||||
|
|
||||||
|
[Export]
|
||||||
|
public PlayerCamera Camera { get; set; }
|
||||||
|
|
||||||
public string Animation
|
public string Animation
|
||||||
{
|
{
|
||||||
get => _sprite.Animation;
|
get => _sprite.Animation;
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
[gd_scene load_steps=26 format=3 uid="uid://b2254pup8k161"]
|
[gd_scene load_steps=27 format=3 uid="uid://b2254pup8k161"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Characters/Player.cs" id="1_flygr"]
|
[ext_resource type="Script" path="res://Characters/Player.cs" id="1_flygr"]
|
||||||
[ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="2_ngsgt"]
|
[ext_resource type="Shader" path="res://Shaders/Flash.gdshader" id="2_ngsgt"]
|
||||||
[ext_resource type="Texture2D" uid="uid://dxymfduyrbuvx" path="res://Assets/Sprites/Characters/forsen.png" id="3_ig4hs"]
|
[ext_resource type="Texture2D" uid="uid://dxymfduyrbuvx" path="res://Assets/Sprites/Characters/forsen.png" id="3_ig4hs"]
|
||||||
[ext_resource type="Script" path="res://Characters/States/Machine.cs" id="3_npkjp"]
|
[ext_resource type="Script" path="res://Characters/States/Machine.cs" id="3_npkjp"]
|
||||||
[ext_resource type="Script" path="res://Characters/States/PlayerIdleState.cs" id="4_4k4mb"]
|
[ext_resource type="Script" path="res://Characters/States/PlayerIdleState.cs" id="4_4k4mb"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://cl56eadpklnbo" path="res://Utils/PlayerCamera.tscn" id="4_ym125"]
|
||||||
[ext_resource type="Script" path="res://Characters/States/PlayerMoveState.cs" id="5_tx5rw"]
|
[ext_resource type="Script" path="res://Characters/States/PlayerMoveState.cs" id="5_tx5rw"]
|
||||||
[ext_resource type="Script" path="res://Characters/States/PlayerRollState.cs" id="6_6bgrj"]
|
[ext_resource type="Script" path="res://Characters/States/PlayerRollState.cs" id="6_6bgrj"]
|
||||||
[ext_resource type="PackedScene" uid="uid://d72ehtv1ks0e" path="res://Items/Weapons/Sword.tscn" id="7_4rxuv"]
|
[ext_resource type="PackedScene" uid="uid://d72ehtv1ks0e" path="res://Items/Weapons/Sword.tscn" id="7_4rxuv"]
|
||||||
|
@ -103,12 +104,13 @@ _data = {
|
||||||
"RESET": SubResource("Animation_k6l16")
|
"RESET": SubResource("Animation_k6l16")
|
||||||
}
|
}
|
||||||
|
|
||||||
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Sprite", "Inventory", "StateMachine")]
|
[node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("Camera", "Sprite", "Inventory", "StateMachine")]
|
||||||
texture_filter = 3
|
texture_filter = 3
|
||||||
material = SubResource("ShaderMaterial_h78y7")
|
material = SubResource("ShaderMaterial_h78y7")
|
||||||
y_sort_enabled = true
|
y_sort_enabled = true
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
script = ExtResource("1_flygr")
|
script = ExtResource("1_flygr")
|
||||||
|
Camera = NodePath("Camera2D")
|
||||||
Speed = 64.0
|
Speed = 64.0
|
||||||
Mass = 1.0
|
Mass = 1.0
|
||||||
Health = 100.0
|
Health = 100.0
|
||||||
|
@ -127,9 +129,7 @@ playing = true
|
||||||
position = Vector2(0, 8)
|
position = Vector2(0, 8)
|
||||||
shape = SubResource("RectangleShape2D_bfqew")
|
shape = SubResource("RectangleShape2D_bfqew")
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="."]
|
[node name="Camera2D" parent="." instance=ExtResource("4_ym125")]
|
||||||
current = true
|
|
||||||
zoom = Vector2(4, 4)
|
|
||||||
|
|
||||||
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("InitialState", "Character")]
|
[node name="StateMachine" type="Node" parent="." node_paths=PackedStringArray("InitialState", "Character")]
|
||||||
script = ExtResource("3_npkjp")
|
script = ExtResource("3_npkjp")
|
||||||
|
@ -167,6 +167,7 @@ horizontal_alignment = 1
|
||||||
[node name="Node" type="Node" parent="."]
|
[node name="Node" type="Node" parent="."]
|
||||||
|
|
||||||
[node name="Inventory" type="Node2D" parent="."]
|
[node name="Inventory" type="Node2D" parent="."]
|
||||||
|
position = Vector2(0, 2)
|
||||||
y_sort_enabled = true
|
y_sort_enabled = true
|
||||||
script = ExtResource("7_xyenu")
|
script = ExtResource("7_xyenu")
|
||||||
|
|
||||||
|
|
|
@ -13,38 +13,12 @@ namespace SupaLidlGame.Characters.State
|
||||||
|
|
||||||
public override CharacterState Input(InputEvent @event)
|
public override CharacterState Input(InputEvent @event)
|
||||||
{
|
{
|
||||||
/*
|
#if DEBUG
|
||||||
if (@event is InputEventKey inputEventKey)
|
|
||||||
{
|
|
||||||
GD.Print("hello");
|
|
||||||
if (inputEventKey.Keycode == Key.G)
|
|
||||||
{
|
|
||||||
GD.Print("hi");
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
if (@event.IsActionPressed("equip"))
|
if (@event.IsActionPressed("equip"))
|
||||||
{
|
{
|
||||||
Character.Inventory.SelectedItem = Character.Inventory.GetNode<Items.Item>("Sword");
|
Character.Inventory.SelectedItem = Character.Inventory.GetNode<Items.Item>("Sword");
|
||||||
//Character.Inventory.AddItem();
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
if (@event.IsActionPressed("attack1"))
|
|
||||||
{
|
|
||||||
if (Character.Inventory.SelectedItem is not null)
|
|
||||||
{
|
|
||||||
Character.UseCurrentItem();
|
|
||||||
//Character.Inventory.SelectedItem.Use();
|
|
||||||
//return AttackState;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//if (this is PlayerAttackState)
|
|
||||||
//{
|
|
||||||
// if (@event.IsActionReleased("attack1"))
|
|
||||||
// {
|
|
||||||
// return IdleState;
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
return base.Input(@event);
|
return base.Input(@event);
|
||||||
}
|
}
|
||||||
|
@ -63,6 +37,16 @@ namespace SupaLidlGame.Characters.State
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Godot.Input.IsActionPressed("attack1"))
|
||||||
|
{
|
||||||
|
if (Character.Inventory.SelectedItem is not null)
|
||||||
|
{
|
||||||
|
Character.UseCurrentItem();
|
||||||
|
//Character.Inventory.SelectedItem.Use();
|
||||||
|
//return AttackState;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return base.Process(delta);
|
return base.Process(delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,5 +24,13 @@ namespace SupaLidlGame.Extensions
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public static T GetNode<T>(this Node node, string name) where T : Node
|
||||||
|
{
|
||||||
|
return node.GetNode(name) as T;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,7 @@ namespace SupaLidlGame.Items.Weapons
|
||||||
IsParried = false;
|
IsParried = false;
|
||||||
|
|
||||||
AnimationPlayer.Stop();
|
AnimationPlayer.Stop();
|
||||||
|
IsParryable = true;
|
||||||
|
|
||||||
if (GetNode<Node2D>("Anchor").Rotation < Mathf.DegToRad(50))
|
if (GetNode<Node2D>("Anchor").Rotation < Mathf.DegToRad(50))
|
||||||
{
|
{
|
||||||
|
@ -76,7 +77,6 @@ namespace SupaLidlGame.Items.Weapons
|
||||||
public void Attack()
|
public void Attack()
|
||||||
{
|
{
|
||||||
ParryTimeOrigin = Time.GetTicksMsec();
|
ParryTimeOrigin = Time.GetTicksMsec();
|
||||||
IsParryable = true;
|
|
||||||
//RemainingAttackTime = AttackTime;
|
//RemainingAttackTime = AttackTime;
|
||||||
IsAttacking = true;
|
IsAttacking = true;
|
||||||
Hitbox.IsDisabled = false;
|
Hitbox.IsDisabled = false;
|
||||||
|
|
|
@ -50,19 +50,19 @@ resource_name = "idle"
|
||||||
|
|
||||||
[sub_resource type="Animation" id="Animation_orc8t"]
|
[sub_resource type="Animation" id="Animation_orc8t"]
|
||||||
resource_name = "use"
|
resource_name = "use"
|
||||||
length = 0.75
|
length = 1.5
|
||||||
step = 0.05
|
step = 0.05
|
||||||
tracks/0/type = "value"
|
tracks/0/type = "value"
|
||||||
tracks/0/imported = false
|
tracks/0/imported = false
|
||||||
tracks/0/enabled = true
|
tracks/0/enabled = true
|
||||||
tracks/0/path = NodePath("Anchor:rotation")
|
tracks/0/path = NodePath("Anchor:rotation")
|
||||||
tracks/0/interp = 1
|
tracks/0/interp = 1
|
||||||
tracks/0/loop_wrap = true
|
tracks/0/loop_wrap = false
|
||||||
tracks/0/keys = {
|
tracks/0/keys = {
|
||||||
"times": PackedFloat32Array(0.05, 0.1, 0.2, 0.4, 0.75),
|
"times": PackedFloat32Array(0.05, 0.1, 0.2, 0.25, 0.75, 1.5),
|
||||||
"transitions": PackedFloat32Array(1, 4, 1, 2, 1),
|
"transitions": PackedFloat32Array(1, 4, 1, 2, 4, 1),
|
||||||
"update": 0,
|
"update": 3,
|
||||||
"values": [-0.610865, -0.959931, 3.92699, 3.92699, 3.75246]
|
"values": [-0.610865, -0.959931, 3.92699, 3.92699, 3.75246, -0.785398]
|
||||||
}
|
}
|
||||||
tracks/1/type = "method"
|
tracks/1/type = "method"
|
||||||
tracks/1/imported = false
|
tracks/1/imported = false
|
||||||
|
@ -105,9 +105,9 @@ tracks/0/path = NodePath("Anchor:rotation")
|
||||||
tracks/0/interp = 1
|
tracks/0/interp = 1
|
||||||
tracks/0/loop_wrap = true
|
tracks/0/loop_wrap = true
|
||||||
tracks/0/keys = {
|
tracks/0/keys = {
|
||||||
"times": PackedFloat32Array(0.05, 0.1, 0.2, 0.4, 0.75),
|
"times": PackedFloat32Array(0.05, 0.1, 0.2, 0.25, 0.75),
|
||||||
"transitions": PackedFloat32Array(1, 4, 1, 2, 1),
|
"transitions": PackedFloat32Array(1, 4, 1, 2, 1),
|
||||||
"update": 0,
|
"update": 3,
|
||||||
"values": [3.75246, 4.10152, -0.785398, -0.785398, -0.610865]
|
"values": [3.75246, 4.10152, -0.785398, -0.785398, -0.610865]
|
||||||
}
|
}
|
||||||
tracks/1/type = "method"
|
tracks/1/type = "method"
|
||||||
|
@ -155,6 +155,7 @@ points = PackedVector2Array(-11.314, -11.314, 0, -16, 11.314, -11.314, 16, 0, 11
|
||||||
|
|
||||||
[node name="Sword" type="Node2D" node_paths=PackedStringArray("Hitbox", "AnimationPlayer", "ParryParticles")]
|
[node name="Sword" type="Node2D" node_paths=PackedStringArray("Hitbox", "AnimationPlayer", "ParryParticles")]
|
||||||
texture_filter = 3
|
texture_filter = 3
|
||||||
|
position = Vector2(2, 0)
|
||||||
y_sort_enabled = true
|
y_sort_enabled = true
|
||||||
script = ExtResource("1_mlo73")
|
script = ExtResource("1_mlo73")
|
||||||
Hitbox = NodePath("Hitbox")
|
Hitbox = NodePath("Hitbox")
|
||||||
|
@ -171,7 +172,7 @@ rotation = -1.0472
|
||||||
y_sort_enabled = true
|
y_sort_enabled = true
|
||||||
|
|
||||||
[node name="Sprite2D" type="Sprite2D" parent="Anchor"]
|
[node name="Sprite2D" type="Sprite2D" parent="Anchor"]
|
||||||
position = Vector2(0, -8)
|
position = Vector2(0, -10)
|
||||||
y_sort_enabled = true
|
y_sort_enabled = true
|
||||||
texture = ExtResource("2_rnfo4")
|
texture = ExtResource("2_rnfo4")
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
[gd_scene load_steps=8 format=3 uid="uid://dd6xy1y0m8smm"]
|
[gd_scene load_steps=9 format=3 uid="uid://dd6xy1y0m8smm"]
|
||||||
|
|
||||||
[ext_resource type="Texture2D" uid="uid://gm2pcnfg7h8j" path="res://Assets/Sprites/tileset.png" id="1_k6myx"]
|
[ext_resource type="Texture2D" uid="uid://gm2pcnfg7h8j" path="res://Assets/Sprites/tileset.png" id="1_k6myx"]
|
||||||
[ext_resource type="PackedScene" uid="uid://b2254pup8k161" path="res://Characters/Player.tscn" id="1_m35hr"]
|
[ext_resource type="PackedScene" uid="uid://b2254pup8k161" path="res://Characters/Player.tscn" id="1_m35hr"]
|
||||||
|
@ -1101,7 +1101,13 @@ texture = ExtResource("1_k6myx")
|
||||||
physics_layer_0/collision_layer = 1
|
physics_layer_0/collision_layer = 1
|
||||||
sources/0 = SubResource("TileSetAtlasSource_1pa1q")
|
sources/0 = SubResource("TileSetAtlasSource_1pa1q")
|
||||||
|
|
||||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_mq5wa"]
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_whp32"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
shader = ExtResource("4_056cf")
|
||||||
|
shader_parameter/color = null
|
||||||
|
shader_parameter/intensity = 0.0
|
||||||
|
|
||||||
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_rthg0"]
|
||||||
resource_local_to_scene = true
|
resource_local_to_scene = true
|
||||||
shader = ExtResource("4_056cf")
|
shader = ExtResource("4_056cf")
|
||||||
shader_parameter/color = null
|
shader_parameter/color = null
|
||||||
|
@ -1144,11 +1150,11 @@ position = Vector2(-81, -34)
|
||||||
motion_mode = 1
|
motion_mode = 1
|
||||||
|
|
||||||
[node name="ExampleEnemy" parent="TileMap" instance=ExtResource("2_uti3y")]
|
[node name="ExampleEnemy" parent="TileMap" instance=ExtResource("2_uti3y")]
|
||||||
material = SubResource("ShaderMaterial_mq5wa")
|
material = SubResource("ShaderMaterial_whp32")
|
||||||
position = Vector2(38, 42)
|
position = Vector2(38, 42)
|
||||||
scale = Vector2(1.00571, 1)
|
scale = Vector2(1.00571, 1)
|
||||||
|
|
||||||
[node name="ExampleEnemy2" parent="TileMap" instance=ExtResource("2_uti3y")]
|
[node name="ExampleEnemy2" parent="TileMap" instance=ExtResource("2_uti3y")]
|
||||||
material = SubResource("ShaderMaterial_mq5wa")
|
material = SubResource("ShaderMaterial_rthg0")
|
||||||
position = Vector2(190, 99)
|
position = Vector2(190, 99)
|
||||||
scale = Vector2(1.00571, 1)
|
scale = Vector2(1.00571, 1)
|
||||||
|
|
|
@ -38,8 +38,8 @@ namespace SupaLidlGame.Utils
|
||||||
{
|
{
|
||||||
Vector2 ret = Vector2.Zero;
|
Vector2 ret = Vector2.Zero;
|
||||||
var rng = new RandomNumberGenerator();
|
var rng = new RandomNumberGenerator();
|
||||||
ret.x = (rng.Randf() * 2 - 0.5f) * intensity;
|
ret.x = (rng.Randf() - 0.5f) * intensity;
|
||||||
ret.y = (rng.Randf() * 2 - 0.5f) * intensity;
|
ret.y = (rng.Randf() - 0.5f) * intensity;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue