Lasers, AI adjustments

This commit is contained in:
ToasterPanic 2025-12-02 13:40:18 -05:00
parent 37bb98a436
commit 49fd5c0d65
6 changed files with 88 additions and 49 deletions

View file

@ -67,6 +67,7 @@ backward={
fire={ fire={
"deadzone": 0.2, "deadzone": 0.2,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(588, 29),"global_position":Vector2(597, 77),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(588, 29),"global_position":Vector2(597, 77),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":5,"axis_value":1.0,"script":null)
] ]
} }
secondary_fire={ secondary_fire={

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=3 uid="uid://bauklhpieuivd"] [gd_scene load_steps=13 format=3 uid="uid://bauklhpieuivd"]
[ext_resource type="Script" uid="uid://d0qswyhwbhdua" path="res://scripts/game.gd" id="1_u5sy4"] [ext_resource type="Script" uid="uid://d0qswyhwbhdua" path="res://scripts/game.gd" id="1_u5sy4"]
[ext_resource type="Texture2D" uid="uid://dtwo7g0ipc4k" path="res://textures/ship_1.png" id="1_uwrxv"] [ext_resource type="Texture2D" uid="uid://dtwo7g0ipc4k" path="res://textures/ship_1.png" id="1_uwrxv"]
@ -9,9 +9,7 @@
[ext_resource type="AudioStream" uid="uid://b6tyof2j3ytbv" path="res://sounds/concrete_halls.mp3" id="3_0tnpc"] [ext_resource type="AudioStream" uid="uid://b6tyof2j3ytbv" path="res://sounds/concrete_halls.mp3" id="3_0tnpc"]
[ext_resource type="AudioStream" uid="uid://b1ung55xg31l3" path="res://sounds/boost_finish.mp3" id="3_p57ef"] [ext_resource type="AudioStream" uid="uid://b1ung55xg31l3" path="res://sounds/boost_finish.mp3" id="3_p57ef"]
[ext_resource type="AudioStream" uid="uid://y7lhonymtk3t" path="res://sounds/fire.mp3" id="8_vtaks"] [ext_resource type="AudioStream" uid="uid://y7lhonymtk3t" path="res://sounds/fire.mp3" id="8_vtaks"]
[ext_resource type="Script" uid="uid://b7te10evkqwhy" path="res://scripts/laser.gd" id="10_kvpfn"]
[ext_resource type="PackedScene" uid="uid://dy6dv2tio433m" path="res://scenes/enemy.tscn" id="11_dinhu"] [ext_resource type="PackedScene" uid="uid://dy6dv2tio433m" path="res://scenes/enemy.tscn" id="11_dinhu"]
[ext_resource type="Texture2D" uid="uid://bb0v0jtreyba3" path="res://textures/laser.png" id="11_kvuet"]
[sub_resource type="CircleShape2D" id="CircleShape2D_uwrxv"] [sub_resource type="CircleShape2D" id="CircleShape2D_uwrxv"]
radius = 16.0 radius = 16.0
@ -19,20 +17,6 @@ radius = 16.0
[sub_resource type="CircleShape2D" id="CircleShape2D_lnu2h"] [sub_resource type="CircleShape2D" id="CircleShape2D_lnu2h"]
radius = 20.0 radius = 20.0
[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
[sub_resource type="CurveTexture" id="CurveTexture_ca42v"]
curve = SubResource("Curve_ir15t")
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_rysoc"]
gravity = Vector3(0, 98, 0)
alpha_curve = SubResource("CurveTexture_ca42v")
[node name="Game" type="Node2D"] [node name="Game" type="Node2D"]
script = ExtResource("1_u5sy4") script = ExtResource("1_u5sy4")
@ -85,26 +69,6 @@ rotation_smoothing_speed = 15.0
shape = SubResource("CircleShape2D_lnu2h") shape = SubResource("CircleShape2D_lnu2h")
debug_color = Color(0.9686392, 0, 0.4696517, 0.41960785) debug_color = Color(0.9686392, 0, 0.4696517, 0.41960785)
[node name="Laser" type="RigidBody2D" parent="."]
position = Vector2(77, -428)
linear_damp = 6.247
script = ExtResource("10_kvpfn")
[node name="Sprite" type="Sprite2D" parent="Laser"]
texture = ExtResource("11_kvuet")
[node name="Hitbox" type="Area2D" parent="Laser"]
[node name="CollisionShape" type="CollisionShape2D" parent="Laser/Hitbox"]
shape = SubResource("CircleShape2D_trtic")
debug_color = Color(1, 0, 0, 0.41960785)
[node name="Trail" type="GPUParticles2D" parent="Laser"]
amount = 24
texture = ExtResource("11_kvuet")
lifetime = 0.05
process_material = SubResource("ParticleProcessMaterial_rysoc")
[node name="Enemy" parent="." instance=ExtResource("11_dinhu")] [node name="Enemy" parent="." instance=ExtResource("11_dinhu")]
position = Vector2(0, -418) position = Vector2(0, -418)
@ -138,4 +102,3 @@ grow_vertical = 2
text = "DIST: 2048" text = "DIST: 2048"
[connection signal="body_shape_entered" from="Player/Hitbox" to="Player" method="_on_hitbox_body_shape_entered"] [connection signal="body_shape_entered" from="Player/Hitbox" to="Player" method="_on_hitbox_body_shape_entered"]
[connection signal="body_shape_entered" from="Laser/Hitbox" to="Laser" method="_on_hitbox_body_shape_entered"]

39
scenes/laser.tscn Normal file
View file

@ -0,0 +1,39 @@
[gd_scene load_steps=7 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
[sub_resource type="CurveTexture" id="CurveTexture_ca42v"]
curve = SubResource("Curve_ir15t")
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_rysoc"]
gravity = Vector3(0, 98, 0)
alpha_curve = SubResource("CurveTexture_ca42v")
[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")
[connection signal="body_shape_entered" from="Hitbox" to="." method="_on_hitbox_body_shape_entered"]

View file

@ -4,7 +4,9 @@ var health = 1000
var boost = 100 var boost = 100
var speed = 480 var speed = 480
var time_since_last_collision = 1 var time_since_last_collision = 1
var time_since_last_fire = 0
var boosting = false var boosting = false
var firing = true
var axis = 0 var axis = 0
var movement_axis = -1 var movement_axis = -1
@ -15,7 +17,8 @@ var ai_mode = AI_MODE_ATTACK
var AI_STATE_EVADE_OBJECT = 1 var AI_STATE_EVADE_OBJECT = 1
var AI_STATE_TRACK_ENEMY = 2 var AI_STATE_TRACK_ENEMY = 2
var AI_STATE_STATIONARY_ENEMY = 3 var AI_STATE_EVADE_ENEMY_AIM = 3
var AI_STATE_STATIONARY_ENEMY = 4
var object_to_evade = null var object_to_evade = null
var last_ai_state_before_evasion = AI_STATE_TRACK_ENEMY var last_ai_state_before_evasion = AI_STATE_TRACK_ENEMY
@ -29,6 +32,8 @@ var boost_pressed = false
var ai_tick = 0.1 var ai_tick = 0.1
@onready var player = get_parent().get_node("Player") @onready var player = get_parent().get_node("Player")
var laser_scene = preload("res://scenes/laser.tscn")
func cast(angle): func cast(angle):
$SightCast.rotation_degrees = angle $SightCast.rotation_degrees = angle
$SightCast.force_raycast_update() $SightCast.force_raycast_update()
@ -64,6 +69,9 @@ func check_front():
return 1 return 1
func _process(delta: float) -> void: func _process(delta: float) -> void:
modulate.g = health / 1000.0
modulate.b = health / 1000.0
ai_tick -= delta ai_tick -= delta
if boosting: if boosting:
@ -86,6 +94,20 @@ func _process(delta: float) -> void:
boosting = true boosting = true
$Boost.play() $Boost.play()
time_since_last_fire -= delta
if (time_since_last_fire <= 0) and firing:
time_since_last_fire = 0.25
var laser = laser_scene.instantiate()
laser.creator = self
laser.position = position
laser.rotation = rotation
get_parent().get_node("Unloadables").add_child(laser)
if time_since_last_collision <= 1: if time_since_last_collision <= 1:
time_since_last_collision += delta time_since_last_collision += delta
@ -115,11 +137,13 @@ func _process(delta: float) -> void:
else: else:
boost_pressed = false boost_pressed = false
var direction_to_player = global_position.direction_to(player.position).angle() + deg_to_rad(270)
if ai_state == AI_STATE_TRACK_ENEMY: if ai_state == AI_STATE_TRACK_ENEMY:
target_rotation = global_position.direction_to(player.position).angle() + deg_to_rad(270) target_rotation = direction_to_player
if ai_state == AI_STATE_STATIONARY_ENEMY: if ai_state == AI_STATE_STATIONARY_ENEMY:
target_rotation = global_position.direction_to(player.position).angle() + deg_to_rad(270) target_rotation = direction_to_player
movement_axis = 0 movement_axis = 0
if front_cast: if front_cast:
@ -143,8 +167,6 @@ func _process(delta: float) -> void:
if front_cast_distance > 160 * (speed / 300): if front_cast_distance > 160 * (speed / 300):
ai_state = last_ai_state_before_evasion ai_state = last_ai_state_before_evasion
print(ai_state)
func _physics_process(delta: float) -> void: func _physics_process(delta: float) -> void:
axis = 0 axis = 0
@ -176,8 +198,6 @@ func _physics_process(delta: float) -> void:
func _on_hitbox_body_shape_entered(body_rid: RID, body: Node2D, body_shape_index: int, local_shape_index: int) -> void: func _on_hitbox_body_shape_entered(body_rid: RID, body: Node2D, body_shape_index: int, local_shape_index: int) -> void:
if body.linear_velocity.length() + linear_velocity.length() > 256: if body.linear_velocity.length() + linear_velocity.length() > 256:
health -= 100
$Collision.play() $Collision.play()
time_since_last_collision = 0 time_since_last_collision = 0

View file

@ -1,17 +1,17 @@
extends RigidBody2D extends RigidBody2D
var shooter = null var creator = null
var lifetime = 0 var lifetime = 0
var has_collided = false var has_collided = false
func _process(delta: float) -> void: func _process(delta: float) -> void:
if has_collided: return if has_collided: return
linear_velocity = transform.y * -1 * 256 linear_velocity = transform.y * -1 * 2048
func _on_hitbox_body_shape_entered(body_rid: RID, body: Node2D, body_shape_index: int, local_shape_index: int) -> void: func _on_hitbox_body_shape_entered(body_rid: RID, body: Node2D, body_shape_index: int, local_shape_index: int) -> void:
if body != shooter: if body != creator:
has_collided = true has_collided = true
linear_velocity = Vector2() linear_velocity = Vector2()

View file

@ -2,16 +2,33 @@ extends RigidBody2D
var health = 1000 var health = 1000
var boost = 100 var boost = 100
var time_since_last_fire = 0
var time_since_last_collision = 1 var time_since_last_collision = 1
var camera_shake_power = 0 var camera_shake_power = 0
var boosting = false var boosting = false
var laser_scene = preload("res://scenes/laser.tscn")
func _process(delta: float) -> void: func _process(delta: float) -> void:
modulate.g = health / 1000.0 modulate.g = health / 1000.0
modulate.b = health / 1000.0 modulate.b = health / 1000.0
$Camera.offset.x = randi_range(-camera_shake_power, camera_shake_power) $Camera.offset.x = randi_range(-camera_shake_power, camera_shake_power)
$Camera.offset.y = randi_range(-camera_shake_power, camera_shake_power) $Camera.offset.y = randi_range(-camera_shake_power, camera_shake_power)
time_since_last_fire -= delta
if (time_since_last_fire <= 0) and Input.is_action_pressed("fire"):
time_since_last_fire = 0.25
var laser = laser_scene.instantiate()
laser.creator = self
laser.position = position
laser.rotation = rotation
get_parent().get_node("Unloadables").add_child(laser)
if boosting: if boosting:
if Input.is_action_pressed("boost"): if Input.is_action_pressed("boost"):
boost -= delta * 40 boost -= delta * 40
@ -67,7 +84,6 @@ func _physics_process(delta: float) -> void:
func _on_hitbox_body_shape_entered(body_rid: RID, body: Node2D, body_shape_index: int, local_shape_index: int) -> void: func _on_hitbox_body_shape_entered(body_rid: RID, body: Node2D, body_shape_index: int, local_shape_index: int) -> void:
if body.linear_velocity.length() + linear_velocity.length() > 256: if body.linear_velocity.length() + linear_velocity.length() > 256:
health -= 100
camera_shake_power = 4 camera_shake_power = 4
$Collision.play() $Collision.play()