Added lightning texture. Reorganized images
This commit is contained in:
@@ -2,11 +2,6 @@ class_name AbstractTeslaProjectile
|
||||
extends AbstractDirectHitProjectile
|
||||
|
||||
|
||||
const SPIKE_WIDTH = 1
|
||||
const SPIKE_MIN_LENGTH = 10.0
|
||||
const SPIKE_MAX_LENGTH = 50.0
|
||||
|
||||
|
||||
@export_range(0.01, 0.5) var jink_min_delay: float = 0.01
|
||||
@export_range(0.01, 0.5) var jink_max_delay: float = 0.01
|
||||
@export_range(0, 360) var deviation_angle: int = 0
|
||||
@@ -15,22 +10,24 @@ const SPIKE_MAX_LENGTH = 50.0
|
||||
|
||||
var _collided_foes : Array[AbstractShip] = []
|
||||
|
||||
var _is_dead := false
|
||||
var _is_expanding := true
|
||||
var _removed_point_count := 0
|
||||
|
||||
var _spikes_by_point_count : Dictionary[int, Array] = {}
|
||||
@onready var jink_timer : Timer = $JinkTimer
|
||||
@onready var life_timer : Timer = $LifeTimer
|
||||
|
||||
|
||||
@onready var jinkTimer : Timer = $JinkTimer
|
||||
@onready var lifeTimer : Timer = $LifeTimer
|
||||
|
||||
@onready var line : Line2D = $Line2D
|
||||
@onready var line_thin : Line2D = $LineThin
|
||||
@onready var line_thick : Line2D = $LineThick
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
super._ready()
|
||||
_start_jink_timer()
|
||||
|
||||
_prepare_line(line_thin)
|
||||
_prepare_line(line_thick)
|
||||
line_thin.hide()
|
||||
|
||||
|
||||
func _prepare_line(line: Line2D) -> void:
|
||||
line.reparent(get_tree().current_scene)
|
||||
line.global_position = Vector2.ZERO
|
||||
line.add_point(position)
|
||||
@@ -38,21 +35,8 @@ func _ready() -> void:
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
super._physics_process(delta)
|
||||
|
||||
if _is_dead:
|
||||
line.remove_point(0)
|
||||
_removed_point_count += 1
|
||||
|
||||
if _removed_point_count in _spikes_by_point_count:
|
||||
var lines := _spikes_by_point_count[_removed_point_count]
|
||||
for l : Line2D in lines:
|
||||
l.queue_free()
|
||||
|
||||
if line.get_point_count() == 0:
|
||||
delete()
|
||||
|
||||
if _is_expanding:
|
||||
line.add_point(position)
|
||||
line_thin.add_point(position)
|
||||
line_thick.add_point(position)
|
||||
|
||||
|
||||
func _process_hit_for_projectile(collided_body: Node2D) -> void:
|
||||
@@ -60,19 +44,22 @@ func _process_hit_for_projectile(collided_body: Node2D) -> void:
|
||||
_collided_foes.append(collided_body)
|
||||
|
||||
damage.value = floor(damage.value/2.0)
|
||||
if damage.value == 0:
|
||||
_start_fading()
|
||||
|
||||
_velocity = _apply_random_deviation(_velocity)
|
||||
_start_jink_timer()
|
||||
|
||||
|
||||
func delete() -> void:
|
||||
line.queue_free()
|
||||
line_thin.queue_free()
|
||||
line_thick.queue_free()
|
||||
super.delete()
|
||||
|
||||
|
||||
func _start_jink_timer() -> void:
|
||||
var random_delay := randf_range(jink_min_delay, jink_max_delay)
|
||||
jinkTimer.start(random_delay)
|
||||
jink_timer.start(random_delay)
|
||||
|
||||
|
||||
func _on_jink_timer_timeout() -> void:
|
||||
@@ -84,33 +71,9 @@ func _on_jink_timer_timeout() -> void:
|
||||
else:
|
||||
_velocity = _apply_random_deviation(_velocity)
|
||||
|
||||
_create_spike()
|
||||
|
||||
_start_jink_timer()
|
||||
|
||||
|
||||
func _create_spike() -> void:
|
||||
if _is_dead: return
|
||||
|
||||
var point_count := line.get_point_count()
|
||||
if not point_count in _spikes_by_point_count:
|
||||
_spikes_by_point_count[point_count] = []
|
||||
|
||||
var spike_direction := _apply_random_deviation(_velocity).normalized()
|
||||
var spike_length := randf_range(SPIKE_MIN_LENGTH, SPIKE_MAX_LENGTH)
|
||||
var second_point := position + spike_direction * spike_length
|
||||
|
||||
var spike : Line2D = line.duplicate()
|
||||
get_parent().add_child(spike)
|
||||
spike.clear_points()
|
||||
spike.add_point(position)
|
||||
spike.add_point(second_point)
|
||||
spike.width = SPIKE_WIDTH
|
||||
spike.width_curve = null
|
||||
|
||||
_spikes_by_point_count[point_count].append(spike)
|
||||
|
||||
|
||||
func _target_foe(foe: AbstractShip) -> void:
|
||||
var current_speed := _velocity.length()
|
||||
var foe_direction := position.direction_to(foe.position)
|
||||
@@ -119,13 +82,19 @@ func _target_foe(foe: AbstractShip) -> void:
|
||||
|
||||
func _apply_random_deviation(vector: Vector2) -> Vector2:
|
||||
var deviation_rad := deg_to_rad(deviation_angle)
|
||||
var random_angle := randfn(0.0, deviation_rad / 6.0)
|
||||
var random_angle := randfn(0.0, deviation_rad)
|
||||
return vector.rotated(random_angle)
|
||||
|
||||
|
||||
func _start_fading() -> void:
|
||||
line_thick.hide()
|
||||
line_thin.show()
|
||||
life_timer.start()
|
||||
|
||||
|
||||
func _on_life_timer_timeout() -> void:
|
||||
_is_dead = true
|
||||
delete()
|
||||
|
||||
|
||||
func _on_out_of_screen_timer_timeout() -> void:
|
||||
_is_expanding = false
|
||||
_start_fading()
|
||||
|
||||
Reference in New Issue
Block a user