Added Lunge Mechanic
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[gd_scene load_steps=22 format=3 uid="uid://eknn66u8gt26"]
|
||||
[gd_scene format=3 uid="uid://eknn66u8gt26"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cy22d14qd0f48" path="res://Assets/Scenes/DEVSCENES/IQEnemy.cs" id="1_p53ib"]
|
||||
[ext_resource type="Script" uid="uid://cy22d14qd0f48" path="res://Assets/Scripts/EnemyScripts/IQEnemy.cs" id="1_p53ib"]
|
||||
[ext_resource type="Texture2D" uid="uid://c0pno0ac25r7i" path="res://Assets/Sprites/knight.png" id="2_o0b1e"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_41iyt"]
|
||||
@@ -128,21 +128,22 @@ animations = [{
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_bc7hl"]
|
||||
|
||||
[node name="IQEnemy" type="CharacterBody2D"]
|
||||
[node name="IQEnemy" type="CharacterBody2D" unique_id=240625765]
|
||||
collision_layer = 8
|
||||
collision_mask = 3
|
||||
script = ExtResource("1_p53ib")
|
||||
metadata/IQ = 20
|
||||
metadata/AbilityRegenerate = true
|
||||
metadata/_edit_vertical_guides_ = [-36.0]
|
||||
metadata/AbilityLunge = true
|
||||
|
||||
[node name="Hitbox" type="CollisionShape2D" parent="."]
|
||||
[node name="Hitbox" type="CollisionShape2D" parent="." unique_id=2143062555]
|
||||
position = Vector2(0, 2)
|
||||
shape = SubResource("RectangleShape2D_41iyt")
|
||||
|
||||
[node name="VisualsAndHitboxes" type="Node2D" parent="."]
|
||||
[node name="VisualsAndHitboxes" type="Node2D" parent="." unique_id=1894404141]
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="VisualsAndHitboxes"]
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="VisualsAndHitboxes" unique_id=1301527955]
|
||||
position = Vector2(9.536743e-07, -1.9999999)
|
||||
scale = Vector2(0.99999994, 0.99999994)
|
||||
sprite_frames = SubResource("SpriteFrames_rqn21")
|
||||
@@ -150,28 +151,28 @@ autoplay = "default"
|
||||
frame = 1
|
||||
frame_progress = 0.9866207
|
||||
|
||||
[node name="GroundDetector" type="Area2D" parent="VisualsAndHitboxes"]
|
||||
[node name="GroundDetector" type="Area2D" parent="VisualsAndHitboxes" unique_id=1709439423]
|
||||
position = Vector2(1.1368684e-13, 11.000001)
|
||||
scale = Vector2(0.099999994, 0.099999994)
|
||||
collision_layer = 0
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="VisualsAndHitboxes/GroundDetector"]
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="VisualsAndHitboxes/GroundDetector" unique_id=1429561812]
|
||||
position = Vector2(0, 19.999992)
|
||||
scale = Vector2(0.99999994, 0.99999994)
|
||||
shape = SubResource("RectangleShape2D_bc7hl")
|
||||
|
||||
[node name="LedgeDetector" type="Area2D" parent="VisualsAndHitboxes"]
|
||||
[node name="LedgeDetector" type="Area2D" parent="VisualsAndHitboxes" unique_id=1421687086]
|
||||
collision_layer = 0
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="VisualsAndHitboxes/LedgeDetector"]
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="VisualsAndHitboxes/LedgeDetector" unique_id=1073584572]
|
||||
position = Vector2(11, 13)
|
||||
scale = Vector2(0.1, 0.1)
|
||||
shape = SubResource("RectangleShape2D_bc7hl")
|
||||
|
||||
[node name="WallDetector" type="Area2D" parent="VisualsAndHitboxes"]
|
||||
[node name="WallDetector" type="Area2D" parent="VisualsAndHitboxes" unique_id=1085104067]
|
||||
collision_layer = 0
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="VisualsAndHitboxes/WallDetector"]
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="VisualsAndHitboxes/WallDetector" unique_id=1699607778]
|
||||
position = Vector2(11, 9.536743e-07)
|
||||
scale = Vector2(0.1, 0.1)
|
||||
shape = SubResource("RectangleShape2D_bc7hl")
|
||||
|
||||
@@ -10,14 +10,14 @@ public partial class IQEnemy : CharacterBody2D
|
||||
// Enemy Stats
|
||||
public int IQ;
|
||||
public float HP;
|
||||
float MaxHP, RegenerationAmmount, RegenerationInterval, WalkSpeed, JumpHeight, JumpInterval, DetectionRange;
|
||||
float MaxHP, RegenerationAmmount, RegenerationInterval, WalkSpeed, JumpHeight, JumpInterval, LungeInterval, DetectionRange;
|
||||
|
||||
// Enemy Conditions
|
||||
bool GroundDetected, LedgeDetected, WallDetected, CanJump;
|
||||
bool GroundDetected, LedgeDetected, WallDetected, CanJump, CanLunge;
|
||||
String FacingDirection;
|
||||
|
||||
// Enemy Abilities
|
||||
bool AbilityJump, AbilityMove, AbilityAttack, AbilityDash, AbilityCloak, AbilityTeleport, AbilityRegenerate;
|
||||
bool AbilityJump, AbilityMove, AbilityAttack, AbilityDash, AbilityLunge, AbilityCloak, AbilityTeleport, AbilityRegenerate;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -30,6 +30,8 @@ public partial class IQEnemy : CharacterBody2D
|
||||
else AbilityAttack = true;
|
||||
if (HasMeta("AbilityDash")) AbilityDash = (bool)GetMeta("AbilityDash");
|
||||
else AbilityDash = false;
|
||||
if (HasMeta("AbilityLunge")) AbilityLunge = (bool)GetMeta("AbilityLunge");
|
||||
else AbilityLunge = false;
|
||||
if (HasMeta("AbilityCloak")) AbilityCloak = (bool)GetMeta("AbilityCloak");
|
||||
else AbilityCloak = false;
|
||||
if (HasMeta("AbilityTeleport")) AbilityTeleport = (bool)GetMeta("AbilityTeleport");
|
||||
@@ -46,6 +48,8 @@ public partial class IQEnemy : CharacterBody2D
|
||||
else JumpHeight = 250.0f;
|
||||
if (HasMeta("JumpInterval")) JumpInterval = (float)GetMeta("JumpInterval");
|
||||
else JumpInterval = 1.0f;
|
||||
if (HasMeta("LungeInterval")) LungeInterval = (float)GetMeta("LungeInterval");
|
||||
else LungeInterval = 1.0f;
|
||||
if (HasMeta("DetectionRange")) DetectionRange = (float)GetMeta("DetectionRange");
|
||||
else DetectionRange = 100.0f;
|
||||
JumpHeight *= -1;
|
||||
@@ -68,6 +72,7 @@ public partial class IQEnemy : CharacterBody2D
|
||||
LedgeDetected = false;
|
||||
WallDetected = false;
|
||||
CanJump = AbilityJump;
|
||||
CanLunge = AbilityLunge;
|
||||
|
||||
// Apply IQ based permenant modifiers
|
||||
IQ = (int)GetMeta("IQ"); // Read IQ
|
||||
@@ -89,6 +94,7 @@ public partial class IQEnemy : CharacterBody2D
|
||||
// Show current hp for testing purposes
|
||||
if (HasMeta("CurrentHP")) SetMeta("CurrentHP", HP);
|
||||
|
||||
// Cooldowns
|
||||
// Regenerate Health
|
||||
if (AbilityRegenerate){
|
||||
if (GlobalTimer % RegenerationInterval == 0) Regenerate(RegenerationAmmount);
|
||||
@@ -97,6 +103,10 @@ public partial class IQEnemy : CharacterBody2D
|
||||
if (AbilityJump){
|
||||
if (GlobalTimer % JumpInterval == 0) CanJump = true;
|
||||
}
|
||||
// Lunge Cooldown
|
||||
if (AbilityLunge){
|
||||
if (GlobalTimer % LungeInterval == 0) CanLunge = true;
|
||||
}
|
||||
|
||||
// Movement
|
||||
// Add gravity.
|
||||
@@ -133,6 +143,7 @@ public partial class IQEnemy : CharacterBody2D
|
||||
if (DistanceFromPlayerX > (30.0f / (IQ / 4))) if (VAH.Scale[0] > 0)Flip(); // left of player
|
||||
if (DistanceFromPlayerX < (-30.0f / (IQ / 4))) if (VAH.Scale[0] < 0)Flip(); // right of player
|
||||
if (DistanceFromPlayerX < (-30.0f / (IQ / 4)) && GroundDetected && GlobalPosition[1] > CurrentLevel[2].GetNode<Node2D>("Player").GlobalPosition[1]) Jump(0.0f); // Jump when player is overhead
|
||||
if (DistanceFromPlayerX > DetectionRange / 2.0f) Lunge(100.0f * VAH.Scale[0]);
|
||||
} else{ // Patrol
|
||||
if (WallDetected && GroundDetected && Velocity[1] > 0)Flip(); // Wall too high (flips when it lands on the ground in front of a wall)
|
||||
}
|
||||
@@ -175,6 +186,11 @@ public partial class IQEnemy : CharacterBody2D
|
||||
CanJump = false;}
|
||||
}
|
||||
|
||||
void Lunge(float xMagnitude){
|
||||
if (GroundDetected && CanLunge) {Velocity = new Vector2(Velocity[0] + xMagnitude, JumpHeight / 2.0f);
|
||||
CanLunge = false;}
|
||||
}
|
||||
|
||||
bool DetectsPlayer(){
|
||||
var CurrentLevel = GetTree().Root.GetChildren();
|
||||
return (GlobalPosition.DistanceTo(CurrentLevel[2].GetNode<Node2D>("Player").GlobalPosition) <= DetectionRange) ? true : false;
|
||||
|
||||
Reference in New Issue
Block a user