Got most basic enemy movement working

This commit is contained in:
=
2026-01-27 08:26:35 -07:00
parent 318397ee29
commit 0506824cf1
3 changed files with 50 additions and 48 deletions

View File

@@ -240,7 +240,7 @@ tile_set = SubResource("TileSet_q0ben")
[node name="Enemies" type="Node" parent="."]
[node name="IQEnemy" parent="Enemies" instance=ExtResource("8_s63xy")]
position = Vector2(221, -26)
position = Vector2(306, -26)
[node name="StaticThreats" type="Node" parent="."]

View File

@@ -5,6 +5,7 @@ public partial class IQEnemy : CharacterBody2D
{
// Misc
float GlobalTimer;
Node2D VAH; // Shorthand refrence
// Enemy Stats
public int IQ;
@@ -54,20 +55,21 @@ public partial class IQEnemy : CharacterBody2D
// Read and set stats
if (HasMeta("MaxHP")) MaxHP = (float)GetMeta("MaxHP");
FacingDirection = "RIGHT";
VAH = GetNode<Node2D>("VisualsAndHitboxes");
// Set up collision detection
GetNode<Area2D>("GroundDetector").BodyEntered += OnGroundEntered; // Ground
GetNode<Area2D>("GroundDetector").BodyExited += OnGroundExited;
GetNode<Area2D>("LedgeDetector").BodyEntered += OnLedgeEntered; // Ledge
GetNode<Area2D>("LedgeDetector").BodyExited += OnLedgeExited;
GetNode<Area2D>("WallDetector").BodyEntered += OnWallEntered; // Wall
GetNode<Area2D>("WallDetector").BodyExited += OnWallExited;
VAH.GetNode<Area2D>("GroundDetector").BodyEntered += OnGroundEntered; // Ground
VAH.GetNode<Area2D>("GroundDetector").BodyExited += OnGroundExited;
VAH.GetNode<Area2D>("LedgeDetector").BodyEntered += OnLedgeEntered; // Ledge
VAH.GetNode<Area2D>("LedgeDetector").BodyExited += OnLedgeExited;
VAH.GetNode<Area2D>("WallDetector").BodyEntered += OnWallEntered; // Wall
VAH.GetNode<Area2D>("WallDetector").BodyExited += OnWallExited;
GroundDetected = false;
LedgeDetected = false;
WallDetected = false;
FacingDirection = "RIGHT";
// Apply IQ based permenant modifiers
IQ = (int)GetMeta("IQ"); // Read IQ
@@ -75,6 +77,9 @@ public partial class IQEnemy : CharacterBody2D
HP = MaxHP;
if (IQ >= 100 && HasMeta("RegenerationInterval")) RegenerationInterval *= 0.9f;
if (IQ >= 100 && HasMeta("RegenerationAmmount")) RegenerationAmmount *= 1.05f; // 5% increase
WalkSpeed += IQ / 20;
JumpHeight += IQ / 30;
}
public override void _Process(double delta)
@@ -97,22 +102,17 @@ public partial class IQEnemy : CharacterBody2D
if (IQ <= 20){ // Goomba ahh diddy blud
if (GroundDetected && LedgeDetected == false){Flip();}
if (WallDetected){Flip();}
// Walk
if (GroundDetected){Velocity = new Vector2(WalkSpeed * Scale[0], Velocity[1]);}
if (GroundDetected){Velocity = new Vector2(WalkSpeed * VAH.Scale[0], Velocity[1]);} // Walk
}
MoveAndSlide(); // Updates physics applied this frame
}
void Flip(){
if (FacingDirection == "RIGHT"){
Scale = new Vector2(-1,1);
FacingDirection = "LEFT";
}
else if (FacingDirection == "LEFT")
{
Scale = new Vector2(1,1);
FacingDirection = "RIGHT";
}
VAH.Scale = new Vector2(-1 * VAH.Scale[0],1);
WallDetected = false;
LedgeDetected = true;
if (FacingDirection == "RIGHT"){FacingDirection = "LEFT";}
else if (FacingDirection == "LEFT"){FacingDirection = "RIGHT";}
}
public void Regenerate(float ammount){

View File

@@ -3,8 +3,6 @@
[ext_resource type="Script" uid="uid://cy22d14qd0f48" path="res://Assets/Scenes/DEVSCENES/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_bc7hl"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_41iyt"]
[sub_resource type="AtlasTexture" id="AtlasTexture_a1e3t"]
@@ -127,6 +125,8 @@ animations = [{
"speed": 5.0
}]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_bc7hl"]
[node name="IQEnemy" type="CharacterBody2D"]
collision_layer = 8
collision_mask = 3
@@ -134,38 +134,40 @@ script = ExtResource("1_p53ib")
metadata/IQ = 20
metadata/AbilityRegenerate = true
[node name="GroundDetector" type="Area2D" parent="."]
position = Vector2(1.1368684e-13, 10.999999)
scale = Vector2(0.099999994, 0.099999994)
collision_layer = 0
[node name="CollisionShape2D" type="CollisionShape2D" parent="GroundDetector"]
scale = Vector2(0.99999994, 0.99999994)
shape = SubResource("RectangleShape2D_bc7hl")
[node name="LedgeDetector" type="Area2D" parent="."]
collision_layer = 0
[node name="CollisionShape2D" type="CollisionShape2D" parent="LedgeDetector"]
position = Vector2(14, 14)
scale = Vector2(0.1, 0.1)
shape = SubResource("RectangleShape2D_bc7hl")
[node name="WallDetector" type="Area2D" parent="."]
collision_layer = 0
[node name="CollisionShape2D" type="CollisionShape2D" parent="WallDetector"]
position = Vector2(14, 9.536743e-07)
scale = Vector2(0.1, 0.1)
shape = SubResource("RectangleShape2D_bc7hl")
[node name="Hitbox" type="CollisionShape2D" parent="."]
shape = SubResource("RectangleShape2D_41iyt")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
[node name="VisualsAndHitboxes" type="Node2D" parent="."]
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="VisualsAndHitboxes"]
position = Vector2(9.536743e-07, -1.9999999)
scale = Vector2(0.99999994, 0.99999994)
sprite_frames = SubResource("SpriteFrames_rqn21")
autoplay = "default"
frame = 1
frame_progress = 0.9866207
[node name="GroundDetector" type="Area2D" parent="VisualsAndHitboxes"]
position = Vector2(1.1368684e-13, 10.999999)
scale = Vector2(0.099999994, 0.099999994)
collision_layer = 0
[node name="CollisionShape2D" type="CollisionShape2D" parent="VisualsAndHitboxes/GroundDetector"]
scale = Vector2(0.99999994, 0.99999994)
shape = SubResource("RectangleShape2D_bc7hl")
[node name="LedgeDetector" type="Area2D" parent="VisualsAndHitboxes"]
collision_layer = 0
[node name="CollisionShape2D" type="CollisionShape2D" parent="VisualsAndHitboxes/LedgeDetector"]
position = Vector2(14, 14)
scale = Vector2(0.1, 0.1)
shape = SubResource("RectangleShape2D_bc7hl")
[node name="WallDetector" type="Area2D" parent="VisualsAndHitboxes"]
collision_layer = 0
[node name="CollisionShape2D" type="CollisionShape2D" parent="VisualsAndHitboxes/WallDetector"]
position = Vector2(14, 9.536743e-07)
scale = Vector2(0.1, 0.1)
shape = SubResource("RectangleShape2D_bc7hl")