68 lines
2.2 KiB
GDScript
68 lines
2.2 KiB
GDScript
extends Node2D
|
|
static var _sound: AudioStream
|
|
static var _shot_index := 0
|
|
var impact := false
|
|
var _age := 0.0
|
|
var _material: ShaderMaterial
|
|
|
|
static func launch(ship: Node2D, at: Vector2, direction: Vector2) -> void:
|
|
preload("res://scripts/game/weapon_camera_impulse.gd").kick(ship)
|
|
var flash := Node2D.new()
|
|
flash.set_script(load("res://scripts/game/artillery_effect.gd"))
|
|
flash.position = at
|
|
flash.rotation = direction.angle()
|
|
ship.get_parent().add_child(flash)
|
|
_shot_index += 1
|
|
_sound = load("res://assets/sounds/effects/artillery_shot%s.ogg" % ("_reverb" if _shot_index%2 else "")) as AudioStream
|
|
var audio := AudioStreamPlayer2D.new()
|
|
audio.stream = _sound
|
|
audio.bus = &"MachineGun"
|
|
audio.volume_db = -7.0
|
|
audio.pitch_scale = randf_range(0.92,1.02)
|
|
audio.max_distance = 1800
|
|
ship.get_parent().add_child(audio)
|
|
audio.global_position = at
|
|
audio.finished.connect(audio.queue_free)
|
|
audio.play()
|
|
|
|
static func hit(parent: Node, at: Vector2, direction: Vector2) -> void:
|
|
var flash := Node2D.new()
|
|
flash.set_script(load("res://scripts/game/artillery_effect.gd"))
|
|
flash.impact = true
|
|
flash.position = at
|
|
flash.rotation = direction.angle()
|
|
parent.add_child(flash)
|
|
|
|
func _ready() -> void:
|
|
z_index = 25
|
|
if not impact:
|
|
var plume := ColorRect.new()
|
|
plume.mouse_filter = Control.MOUSE_FILTER_IGNORE
|
|
plume.show_behind_parent = true
|
|
plume.position = Vector2(-25,-100)
|
|
plume.size = Vector2(260,200)
|
|
_material = ShaderMaterial.new()
|
|
_material.shader = preload("res://scripts/game/artillery_muzzle.gdshader")
|
|
_material.set_shader_parameter("seed_phase",randf()*100)
|
|
plume.material = _material
|
|
add_child(plume)
|
|
|
|
func _process(delta: float) -> void:
|
|
_age += delta
|
|
if _age >= (0.5 if impact else 1.2):
|
|
queue_free()
|
|
else:
|
|
if _material != null: _material.set_shader_parameter("age",_age)
|
|
queue_redraw()
|
|
|
|
func _draw() -> void:
|
|
var t := clampf(_age/0.5,0,1)
|
|
var reach := 90.0 if impact else 120.0
|
|
if impact:
|
|
draw_arc(Vector2.ZERO,reach*t,0,TAU,40,Color(1,0.65,0.25,(1-t)*0.6),2,true)
|
|
for i in 28:
|
|
var dir := Vector2.RIGHT.rotated(float(i)*2.39996)
|
|
if not impact: dir = Vector2.RIGHT.rotated(sin(i*2.4)*0.65)
|
|
var distance := reach*t*(0.5+float(i%5)*0.16)
|
|
draw_line(dir*distance,dir*(distance+16*(1-t)),Color(1,0.66,0.18,1-t),2*(1-t)+0.4,true)
|