From 3ecd6c3e1bcc2f56ae61ac75c215208221a58613 Mon Sep 17 00:00:00 2001 From: ToasterPanic Date: Tue, 2 Dec 2025 14:01:24 -0500 Subject: [PATCH] Player fairness, AI adjustments --- scenes/enemy.tscn | 5 ++++- scenes/game.tscn | 6 ++++++ scenes/laser.tscn | 34 +++++++++++++++++++++------------- scripts/enemy.gd | 22 ++++++++++++++++++---- scripts/laser.gd | 8 +++++++- 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/scenes/enemy.tscn b/scenes/enemy.tscn index 429c786..f467bd0 100644 --- a/scenes/enemy.tscn +++ b/scenes/enemy.tscn @@ -43,11 +43,14 @@ shape = SubResource("CircleShape2D_uwrxv") [node name="Hitbox" type="Area2D" parent="."] -[node name="CollisionShape" type="CollisionShape2D" parent="Hitbox"] +[node name="Large" type="CollisionShape2D" parent="Hitbox"] shape = SubResource("CircleShape2D_lnu2h") debug_color = Color(0.9686392, 0, 0.4696517, 0.41960785) [node name="SightCast" type="RayCast2D" parent="."] target_position = Vector2(0, -256) +[node name="FireCast" type="RayCast2D" parent="."] +target_position = Vector2(0, -1024) + [connection signal="body_shape_entered" from="Hitbox" to="." method="_on_hitbox_body_shape_entered"] diff --git a/scenes/game.tscn b/scenes/game.tscn index b99448e..65d3947 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -72,6 +72,12 @@ debug_color = Color(0.9686392, 0, 0.4696517, 0.41960785) [node name="Enemy" parent="." instance=ExtResource("11_dinhu")] position = Vector2(0, -418) +[node name="Enemy2" parent="." instance=ExtResource("11_dinhu")] +position = Vector2(362, 397) + +[node name="Enemy3" parent="." instance=ExtResource("11_dinhu")] +position = Vector2(362, 397) + [node name="Unloadables" type="Node2D" parent="."] [node name="UI" type="CanvasLayer" parent="."] diff --git a/scenes/laser.tscn b/scenes/laser.tscn index 17d5625..92f5fe8 100644 --- a/scenes/laser.tscn +++ b/scenes/laser.tscn @@ -1,11 +1,8 @@ -[gd_scene load_steps=7 format=3 uid="uid://dgj3hd5wlaoc0"] +[gd_scene load_steps=8 format=3 uid="uid://dgj3hd5wlaoc0"] [ext_resource type="Script" uid="uid://b7te10evkqwhy" path="res://scripts/laser.gd" id="1_a7dhc"] [ext_resource type="Texture2D" uid="uid://bb0v0jtreyba3" path="res://textures/laser.png" id="2_jjj73"] -[sub_resource type="CircleShape2D" id="CircleShape2D_trtic"] -radius = 12.0 - [sub_resource type="Curve" id="Curve_ir15t"] _data = [Vector2(0, 0.5393259), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0] point_count = 2 @@ -17,23 +14,34 @@ curve = SubResource("Curve_ir15t") gravity = Vector3(0, 98, 0) alpha_curve = SubResource("CurveTexture_ca42v") +[sub_resource type="CircleShape2D" id="CircleShape2D_trtic"] +radius = 12.0 + +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_a7dhc"] +radius = 2.0 +height = 20.0 + [node name="Laser" type="RigidBody2D"] linear_damp = 6.247 script = ExtResource("1_a7dhc") -[node name="Sprite" type="Sprite2D" parent="."] -texture = ExtResource("2_jjj73") - -[node name="Hitbox" type="Area2D" parent="."] - -[node name="CollisionShape" type="CollisionShape2D" parent="Hitbox"] -shape = SubResource("CircleShape2D_trtic") -debug_color = Color(1, 0, 0, 0.41960785) - [node name="Trail" type="GPUParticles2D" parent="."] amount = 24 texture = ExtResource("2_jjj73") lifetime = 0.05 process_material = SubResource("ParticleProcessMaterial_rysoc") +[node name="Sprite" type="Sprite2D" parent="."] +texture = ExtResource("2_jjj73") + +[node name="Hitbox" type="Area2D" parent="."] + +[node name="Large" type="CollisionShape2D" parent="Hitbox"] +shape = SubResource("CircleShape2D_trtic") +debug_color = Color(1, 0, 0, 0.41960785) + +[node name="Small" type="CollisionShape2D" parent="Hitbox"] +shape = SubResource("CapsuleShape2D_a7dhc") +debug_color = Color(0.77871144, 0.126396, 0.9999997, 0.41960785) + [connection signal="body_shape_entered" from="Hitbox" to="." method="_on_hitbox_body_shape_entered"] diff --git a/scripts/enemy.gd b/scripts/enemy.gd index 6986d5e..40cff91 100644 --- a/scripts/enemy.gd +++ b/scripts/enemy.gd @@ -72,6 +72,9 @@ func _process(delta: float) -> void: modulate.g = health / 1000.0 modulate.b = health / 1000.0 + if health <= 0: + queue_free() + ai_tick -= delta if boosting: @@ -112,7 +115,7 @@ func _process(delta: float) -> void: time_since_last_collision += delta if ai_tick < 0: - ai_tick = 0.1 + ai_tick = 0.25 movement_axis = -1 @@ -130,10 +133,14 @@ func _process(delta: float) -> void: $SightCast.position.x = 0 if ai_mode == AI_MODE_ATTACK: + firing = false + if !front_cast and (player_distance > 480): boost_pressed = true - elif front_cast == player: + elif $FireCast.get_collider() == player: if player_distance > 480: boost_pressed = true + + firing = true else: boost_pressed = false @@ -142,14 +149,21 @@ func _process(delta: float) -> void: if ai_state == AI_STATE_TRACK_ENEMY: target_rotation = direction_to_player + if (player.linear_velocity.length() < 256) and (player_distance < 256): + ai_state = AI_STATE_STATIONARY_ENEMY + if ai_state == AI_STATE_STATIONARY_ENEMY: target_rotation = direction_to_player movement_axis = 0 + boost_pressed = false + + if (player.linear_velocity.length() > 256) or (player_distance > 320): + ai_state = AI_STATE_TRACK_ENEMY if front_cast: var front_cast_distance = ($SightCast.get_collision_point() - position).length() - if (front_cast_distance < 160 * (speed / 300.0)) and (front_cast_distance < player_distance): + if (front_cast_distance < 160 * (speed / 300.0)) and (front_cast_distance < player_distance) and (ai_state != AI_STATE_STATIONARY_ENEMY): if ai_state != AI_STATE_EVADE_OBJECT: last_ai_state_before_evasion = ai_state ai_state = AI_STATE_EVADE_OBJECT @@ -157,7 +171,7 @@ func _process(delta: float) -> void: object_to_evade = front_cast - target_rotation_speed = 1 + target_rotation_speed = 0.8 if ai_state == AI_STATE_EVADE_OBJECT: if not front_cast: diff --git a/scripts/laser.gd b/scripts/laser.gd index 6246088..2e6140d 100644 --- a/scripts/laser.gd +++ b/scripts/laser.gd @@ -4,6 +4,12 @@ var creator = null var lifetime = 0 var has_collided = false +func _ready() -> void: + if creator.get_name() == "Player": + $Hitbox/Small.free() + else: + $Hitbox/Large.free() + func _process(delta: float) -> void: if has_collided: return @@ -20,7 +26,7 @@ func _on_hitbox_body_shape_entered(body_rid: RID, body: Node2D, body_shape_index $Trail.visible = false if "health" in body: - body.health -= 100 + body.health -= 75 await get_tree().create_timer(1.0).timeout