diff --git a/Assets/Scenes/DEVSCENES/EnemyTest.tscn b/Assets/Scenes/DEVSCENES/EnemyTest.tscn index 2974230..eb903f1 100644 --- a/Assets/Scenes/DEVSCENES/EnemyTest.tscn +++ b/Assets/Scenes/DEVSCENES/EnemyTest.tscn @@ -148,6 +148,7 @@ texture = ExtResource("1_q0x10") [sub_resource type="TileSet" id="TileSet_q0ben"] physics_layer_0/collision_layer = 1 +physics_layer_0/collision_mask = 0 sources/0 = SubResource("TileSetAtlasSource_e35rp") [sub_resource type="Animation" id="Animation_owkni"] @@ -227,7 +228,7 @@ _data = { [node name="Level1" type="Node2D"] [node name="PlayArea" type="TileMapLayer" parent="."] -tile_map_data = PackedByteArray("AAD//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAACAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAHAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAJAAAAAAAAAAAAAAAKAAAAAAAAAAAAAAAOAAAAAAAAAAAAAAAPAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAD//wEAAAAAAAEAAAAAAAEAAAAAAAEAAAABAAEAAAAAAAEAAAACAAEAAAAAAAEAAAADAAEAAAAAAAEAAAAEAAEAAAAAAAEAAAAFAAEAAAAAAAEAAAAGAAEAAAAAAAEAAAAHAAEAAAAAAAEAAAAIAAEAAAAAAAEAAAAJAAEAAAAAAAEAAAAKAAEAAAAAAAEAAAALAAEAAAAAAAAAAAAMAAEAAAAAAAAAAAANAAEAAAAAAAAAAAAOAAEAAAAAAAEAAAAPAAEAAAAAAAEAAAAQAAEAAAAAAAEAAAARAAEAAAAAAAAAAAA=") +tile_map_data = PackedByteArray("AAD//wAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAACAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAFAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAHAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAJAAAAAAAAAAAAAAAKAAAAAAAAAAAAAAD//wEAAAAAAAEAAAAAAAEAAAAAAAEAAAABAAEAAAAAAAEAAAACAAEAAAAAAAEAAAADAAEAAAAAAAEAAAAEAAEAAAAAAAEAAAAFAAEAAAAAAAEAAAAGAAEAAAAAAAEAAAAHAAEAAAAAAAEAAAAIAAEAAAAAAAEAAAAJAAEAAAAAAAEAAAAKAAEAAAAAAAEAAAALAAEAAAAAAAAAAAAMAAEAAAAAAAAAAAANAAEAAAAAAAAAAAAOAAEAAAAAAAAAAAAPAAEAAAAAAAAAAAAQAAEAAAAAAAAAAAARAAEAAAAAAAAAAAASAAEAAAAAAAEAAAASAAAAAAAAAAAAAAATAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAUAAEAAAAAAAEAAAATAAEAAAAAAAEAAAA=") tile_set = SubResource("TileSet_q0ben") [node name="Background" type="TileMapLayer" parent="."] @@ -239,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(248, -10) +position = Vector2(221, -26) [node name="StaticThreats" type="Node" parent="."] diff --git a/Assets/Scenes/DEVSCENES/IQEnemy.cs b/Assets/Scenes/DEVSCENES/IQEnemy.cs index 69da7ec..d1ad32c 100644 --- a/Assets/Scenes/DEVSCENES/IQEnemy.cs +++ b/Assets/Scenes/DEVSCENES/IQEnemy.cs @@ -20,6 +20,8 @@ public partial class IQEnemy : CharacterBody2D float PreviousYVelocity; bool GroundDetected; bool LedgeDetected; + bool WallDetected; + String FacingDirection; // Enemy Abilities bool AbilityJump = false; @@ -45,22 +47,26 @@ public partial class IQEnemy : CharacterBody2D if (HasMeta("RegenerationInterval")) RegenerationInterval = (float)GetMeta("RegenerationInterval"); else RegenerationInterval = 1.0f; if (HasMeta("WalkSpeed")) WalkSpeed = (float)GetMeta("WalkSpeed"); - else WalkSpeed = 10.0f; + else WalkSpeed = 20.0f; if (HasMeta("JumpHeight")) JumpHeight = (float)GetMeta("JumpHeight"); - else JumpHeight = 10.0f; + else JumpHeight = 20.0f; // Read and set stats if (HasMeta("MaxHP")) MaxHP = (float)GetMeta("MaxHP"); - // Set up ground detection - GetNode("GroundDetector").AreaEntered += OnGroundEntered; - GetNode("GroundDetector").AreaExited += OnGroundExited; + // Set up collision detection + GetNode("GroundDetector").BodyEntered += OnGroundEntered; // Ground + GetNode("GroundDetector").BodyExited += OnGroundExited; + GetNode("LedgeDetector").BodyEntered += OnLedgeEntered; // Ledge + GetNode("LedgeDetector").BodyExited += OnLedgeExited; + GetNode("WallDetector").BodyEntered += OnWallEntered; // Wall + GetNode("WallDetector").BodyExited += OnWallExited; - GetNode("LedgeDetector").AreaEntered += OnLedgeEntered; - GetNode("LedgeDetector").AreaExited += OnLedgeExited; + GroundDetected = false; + LedgeDetected = false; + WallDetected = false; - GroundDetected = true; - LedgeDetected = true; + FacingDirection = "RIGHT"; // Apply IQ based permenant modifiers IQ = (int)GetMeta("IQ"); // Read IQ @@ -86,19 +92,27 @@ public partial class IQEnemy : CharacterBody2D // Movement // Add gravity. - if (GroundDetected == false){Velocity = new Vector2(Velocity[0],-1);} + if (GroundDetected == false){Velocity = new Vector2(Velocity[0],100);} + if (IQ <= 20){ // Goomba ahh diddy blud - if (GroundDetected && LedgeDetected == false) {Flip("ANY");} - if (Scale[0] > 0){Velocity = new Vector2(WalkSpeed, Velocity[1]);} // Facing right - if (Scale[0] < 0){Velocity = new Vector2(-1 * WalkSpeed, Velocity[1]);} // Facing left + if (GroundDetected && LedgeDetected == false){Flip();} + if (WallDetected){Flip();} + // Walk + if (GroundDetected){Velocity = new Vector2(WalkSpeed * Scale[0], Velocity[1]);} } - MoveAndSlide(); + MoveAndSlide(); // Updates physics applied this frame } - void Flip(string facing){ - if (facing == "ANY") Scale = new Vector2(Scale[0] * -1,1); - if (facing == "RIGHT") Scale = new Vector2(1,1); - if (facing =="LEFT") Scale = new Vector2(-1,1); + void Flip(){ + if (FacingDirection == "RIGHT"){ + Scale = new Vector2(-1,1); + FacingDirection = "LEFT"; + } + else if (FacingDirection == "LEFT") + { + Scale = new Vector2(1,1); + FacingDirection = "RIGHT"; + } } public void Regenerate(float ammount){ @@ -116,9 +130,12 @@ public partial class IQEnemy : CharacterBody2D } // Ground Detection - public void OnGroundEntered(Area2D area){if (area.CollisionLayer == 0) GroundDetected = true;} - public void OnGroundExited(Area2D area){if (area.CollisionLayer == 0) GroundDetected = false;} + public void OnGroundEntered(Node2D body){if (body is TileMapLayer tileLayer) GroundDetected = true;} + public void OnGroundExited(Node2D body){if (body is TileMapLayer tileLayer) GroundDetected = false;} // Ledge Detection - public void OnLedgeEntered(Area2D area){if (area.CollisionLayer == 0) LedgeDetected = true;} - public void OnLedgeExited(Area2D area){if (area.CollisionLayer == 0) LedgeDetected = false;} + public void OnLedgeEntered(Node2D body){if (body is TileMapLayer tileLayer) LedgeDetected = true;} + public void OnLedgeExited(Node2D body){if (body is TileMapLayer tileLayer) LedgeDetected = false;} + // Wall Detection + public void OnWallEntered(Node2D body){if (body is TileMapLayer tileLayer) WallDetected = true;} + public void OnWallExited(Node2D body){if (body is TileMapLayer tileLayer) WallDetected = false;} } diff --git a/Assets/Scenes/DEVSCENES/IQEnemy.tscn b/Assets/Scenes/DEVSCENES/IQEnemy.tscn index 6463988..58254dd 100644 --- a/Assets/Scenes/DEVSCENES/IQEnemy.tscn +++ b/Assets/Scenes/DEVSCENES/IQEnemy.tscn @@ -137,22 +137,25 @@ 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(12, 12) +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(12, 9.536743e-07) +position = Vector2(14, 9.536743e-07) scale = Vector2(0.1, 0.1) shape = SubResource("RectangleShape2D_bc7hl")