Sound effects
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://bjihbmnkq0n3b"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://bjihbmnkq0n3b"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://bqdblby54pv2s" path="res://Assets/Bullets/arrow.png" id="1_v0wue"]
|
||||
[ext_resource type="Script" uid="uid://dqvdgdobuo2rf" path="res://Game/Bullets/bullet.gd" id="1_wft0c"]
|
||||
[ext_resource type="AudioStream" uid="uid://cirkmv7ybqqay" path="res://Assets/Sounds/Arrow impact.mp3" id="3_eecms"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_wft0c"]
|
||||
size = Vector2(3, 16)
|
||||
@ -28,3 +29,6 @@ shape = SubResource("RectangleShape2D_wft0c")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="CharacterBody2D"]
|
||||
texture = ExtResource("1_v0wue")
|
||||
|
||||
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."]
|
||||
stream = ExtResource("3_eecms")
|
||||
|
@ -12,13 +12,26 @@ var midpoint = 0
|
||||
var t = 0.0
|
||||
var duration = 0.5
|
||||
|
||||
var SFX_loudness = 1.0
|
||||
var master_volume = 1.0
|
||||
var reached_once = false
|
||||
|
||||
static var NAMES = ["Forkman", "Cobold", "Ork"]
|
||||
|
||||
func _ready() -> void:
|
||||
starterpos = global_position
|
||||
targetpos = target.global_position
|
||||
midpoint = (targetpos + starterpos) / 2
|
||||
midpoint.y -= 200 #height of the curve!
|
||||
midpoint.y -= 200 #height of the curve!
|
||||
var config = ConfigFile.new()
|
||||
var err = config.load("user://settings.cfg")
|
||||
if err == OK:
|
||||
var master_volume_raw = config.get_value("audio", "master_volume", 100.0)
|
||||
master_volume = clamp(master_volume_raw / 100.0, 0.0, 1.0)
|
||||
var sfx_volume_raw = config.get_value("audio", "sfx_volume", 100.0)
|
||||
SFX_loudness = clamp(sfx_volume_raw / 100.0, 0.0, 1.0)
|
||||
|
||||
get_node("AudioStreamPlayer2D").finished.connect(finished_end_sound)
|
||||
|
||||
func set_targe(_target : Node2D) -> void:
|
||||
target = _target
|
||||
@ -31,52 +44,63 @@ func set_hitpoint(_hitpoint: int) -> void:
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if name.contains("Rock"):
|
||||
t += delta / duration
|
||||
position = bezier(t)
|
||||
if t >= 1.0:
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").play("hit")
|
||||
var killalll = get_node("Area2D").get_overlapping_bodies()
|
||||
for i in killalll:
|
||||
for j in NAMES:
|
||||
if i.get_parent().name.contains(j):
|
||||
i.get_parent().enemy_hurt(hitpoint)
|
||||
|
||||
set_process(false)
|
||||
elif target and speed > 0:
|
||||
# Get the direction vector from the bullet to the target
|
||||
var direction = (target.get_parent().get_parent().get_position() - position).normalized()
|
||||
if not reached_once:
|
||||
if name.contains("Rock"):
|
||||
t += delta / duration
|
||||
position = bezier(t)
|
||||
if t >= 1.0:
|
||||
get_node("CharacterBody2D/AnimatedSprite2D").play("hit")
|
||||
var killalll = get_node("Area2D").get_overlapping_bodies()
|
||||
for i in killalll:
|
||||
for j in NAMES:
|
||||
if i.get_parent().name.contains(j):
|
||||
i.get_parent().enemy_hurt(hitpoint)
|
||||
target_reached()
|
||||
set_process(false)
|
||||
elif target and speed > 0:
|
||||
# Get the direction vector from the bullet to the target
|
||||
var direction = (target.get_parent().get_parent().get_position() - position).normalized()
|
||||
|
||||
# Rotate the bullet to face the target
|
||||
if name.contains("Arrow"):
|
||||
rotation = direction.angle() + deg_to_rad(90)
|
||||
# Rotate the bullet to face the target
|
||||
if name.contains("Arrow"):
|
||||
rotation = direction.angle() + deg_to_rad(90)
|
||||
|
||||
# Move the bullet towards the target
|
||||
position += direction * speed * delta
|
||||
distancetaken += (direction * speed * delta).length()
|
||||
|
||||
if position.distance_to(target.get_parent().get_parent().position) <= 5:
|
||||
target_reached()
|
||||
if distancetaken > 250:
|
||||
# Move the bullet towards the target
|
||||
position += direction * speed * delta
|
||||
distancetaken += (direction * speed * delta).length()
|
||||
|
||||
if position.distance_to(target.get_parent().get_parent().position) <= 5:
|
||||
target_reached()
|
||||
if distancetaken > 250:
|
||||
queue_free()
|
||||
else:
|
||||
queue_free()
|
||||
else:
|
||||
queue_free()
|
||||
|
||||
|
||||
|
||||
func target_reached() -> void:
|
||||
if name.contains("Arrow"): #special effects here!
|
||||
if randf() < 0.1:
|
||||
target.get_parent().set_speed(target.get_parent().get_speed() / 2)
|
||||
target.get_parent().adjust_speed_of_animation()
|
||||
pass
|
||||
if name.contains("Magic"):
|
||||
if randf() < 0.1:
|
||||
target.get_parent().set_progress(max(target.get_parent().get_progress() - 60, 0))
|
||||
if not reached_once:
|
||||
reached_once = true
|
||||
if name.contains("Arrow"): #special effects here!
|
||||
self.get_node("CharacterBody2D").get_node("Sprite2D").hide()
|
||||
if randf() < 0.1:
|
||||
target.get_parent().set_speed(target.get_parent().get_speed() / 2)
|
||||
target.get_parent().adjust_speed_of_animation()
|
||||
pass
|
||||
if name.contains("Magic"):
|
||||
self.get_node("CharacterBody2D").get_node("Sprite2D").hide()
|
||||
if randf() < 0.1:
|
||||
target.get_parent().set_progress(max(target.get_parent().get_progress() - 60, 0))
|
||||
|
||||
target.get_parent().enemy_hurt(hitpoint)
|
||||
queue_free()
|
||||
if target:
|
||||
target.get_parent().enemy_hurt(hitpoint)
|
||||
self.get_node("AudioStreamPlayer2D").volume_db = linear_to_db(master_volume * SFX_loudness)
|
||||
self.get_node("AudioStreamPlayer2D").playing = true
|
||||
|
||||
|
||||
|
||||
func finished_end_sound() -> void:
|
||||
queue_free()
|
||||
|
||||
func bezier(t: float):
|
||||
var q0 = starterpos.lerp(midpoint, t)
|
||||
var q1 = midpoint.lerp(targetpos, t)
|
||||
|
@ -1,7 +1,8 @@
|
||||
[gd_scene load_steps=7 format=3 uid="uid://caynrq7jnjlnx"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://caynrq7jnjlnx"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://mmrsjrjxv168" path="res://Assets/Bullets/magic.png" id="1_jjep1"]
|
||||
[ext_resource type="Script" uid="uid://dqvdgdobuo2rf" path="res://Game/Bullets/bullet.gd" id="1_lj5pp"]
|
||||
[ext_resource type="AudioStream" uid="uid://cw3jeq08o7cb1" path="res://Assets/Sounds/wizard impact.mp3" id="3_0itbo"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_lj5pp"]
|
||||
size = Vector2(18, 16)
|
||||
@ -66,3 +67,6 @@ autoplay = "rotation"
|
||||
[node name="Sprite2D" type="Sprite2D" parent="CharacterBody2D"]
|
||||
scale = Vector2(3, 3)
|
||||
texture = ExtResource("1_jjep1")
|
||||
|
||||
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."]
|
||||
stream = ExtResource("3_0itbo")
|
||||
|
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=11 format=3 uid="uid://cwcgq1vk643ha"]
|
||||
[gd_scene load_steps=12 format=3 uid="uid://cwcgq1vk643ha"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dqvdgdobuo2rf" path="res://Game/Bullets/bullet.gd" id="1_yml18"]
|
||||
[ext_resource type="Texture2D" uid="uid://t8y1d33eiffp" path="res://Assets/Bullets/mortarbullet (1).png" id="2_yml18"]
|
||||
@ -7,6 +7,7 @@
|
||||
[ext_resource type="Texture2D" uid="uid://crf32to6tlkux" path="res://Assets/Bullets/mortarbullet (4).png" id="5_c612l"]
|
||||
[ext_resource type="Texture2D" uid="uid://bbu8u4h7vpqwa" path="res://Assets/Bullets/mortarbullet (5).png" id="6_m5188"]
|
||||
[ext_resource type="Texture2D" uid="uid://uc2ib201l7kd" path="res://Assets/Bullets/mortarbullet (6).png" id="7_lr72h"]
|
||||
[ext_resource type="AudioStream" uid="uid://we1hnps5j60u" path="res://Assets/Sounds/mortar impact.mp3" id="8_av0br"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_yml18"]
|
||||
size = Vector2(18, 16)
|
||||
@ -64,4 +65,7 @@ autoplay = "default"
|
||||
scale = Vector2(3, 3)
|
||||
shape = SubResource("CircleShape2D_tjven")
|
||||
|
||||
[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."]
|
||||
stream = ExtResource("8_av0br")
|
||||
|
||||
[connection signal="animation_finished" from="CharacterBody2D/AnimatedSprite2D" to="." method="_on_animated_sprite_2d_animation_finished"]
|
||||
|
Reference in New Issue
Block a user