Skip to content

Commit

Permalink
Fixed the pause menu on player death, Changed enemy spawning mechanics
Browse files Browse the repository at this point in the history
  • Loading branch information
StaringLongingly committed Aug 22, 2024
1 parent 3a591db commit 6982084
Show file tree
Hide file tree
Showing 166 changed files with 381 additions and 304 deletions.
9 changes: 7 additions & 2 deletions Game.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,14 @@ enemies = {
"legendary": ["Caragor", "Cavedrake"],
"rare": ["Possessed Elf", "Possessed Uruk", "Possessed Hunter Uruk"]
}
time_interval = 10.0
time_interval = 20.0
min_time_interval = 0.5
time_interval_decrease_rate = 1.0
time_interval_decrease_rate = 0.2
time_increase_rate = 0.01
base_group_spawn_size_min = 1
base_group_spawn_size_max = 3
group_size_increase_rate = 0.01
max_delay_between_enemies = 3.0

[node name="Player" type="Node2D" parent="." node_paths=PackedStringArray("hpText") groups=["Player"]]
script = ExtResource("43_00hfy")
Expand Down
2 changes: 1 addition & 1 deletion drill_break_particle.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource type="Texture2D" uid="uid://28pqirqma2y5" path="res://sprites/triangle_300px.png" id="1_udndy"]
[ext_resource type="Script" path="res://sprites/drill_particles.gd" id="2_e6ytl"]
[ext_resource type="AudioStream" uid="uid://do458i14o26by" path="res://sfx/Downloads - unknown album/00 - Downloads - LeavesTest001 058.ogg" id="3_qci8f"]
[ext_resource type="AudioStream" uid="uid://do458i14o26by" path="res://sfx/Leaves/00 - Downloads - LeavesTest001 058.ogg" id="3_qci8f"]

[sub_resource type="Curve" id="Curve_x2lov"]
max_value = 100.0
Expand Down
4 changes: 2 additions & 2 deletions drill_particle.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[ext_resource type="Texture2D" uid="uid://28pqirqma2y5" path="res://sprites/triangle_300px.png" id="1_2riw8"]
[ext_resource type="Script" path="res://sprites/drill_particles.gd" id="2_ns106"]
[ext_resource type="AudioStream" uid="uid://dy0wtlnxyi4hc" path="res://sfx/Downloads - unknown album/00 - Downloads - LeavesTest001 007.ogg" id="3_y7uaa"]
[ext_resource type="Script" path="res://scripts/Drill Particle Audio.gd" id="4_3nlwu"]

[sub_resource type="Curve" id="Curve_x2lov"]
max_value = 100.0
Expand Down Expand Up @@ -49,6 +49,6 @@ hue_variation_curve = SubResource("Curve_uxsiq")
script = ExtResource("2_ns106")

[node name="AudioStreamPlayer2D" type="AudioStreamPlayer2D" parent="."]
stream = ExtResource("3_y7uaa")
autoplay = true
max_distance = 10000.0
script = ExtResource("4_3nlwu")
43 changes: 43 additions & 0 deletions scripts/Drill Particle Audio.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
extends Node

func _ready():
# The path to the folder containing the .ogg files
var folder_path = "res://sfx/Leaves"

# Open the directory
var dir = DirAccess.open(folder_path)

if dir:
# Begin listing files in the directory
dir.list_dir_begin()
var ogg_files = []

# Iterate over all files in the directory
var file_name = dir.get_next()
while file_name != "":
ogg_files.append(file_name)
file_name = dir.get_next()

# End listing of files
dir.list_dir_end()

# Select a random .ogg file from the list
if ogg_files.size() > 0:
var random_index = randi() % ogg_files.size()
var selected_ogg = ogg_files[random_index]

print("Selected file: ", selected_ogg)

# Load and play the selected .ogg file
var audio_stream = load(folder_path + "/" + selected_ogg) as AudioStream
print(audio_stream)
if audio_stream:
var audio_player = AudioStreamPlayer3D.new() # Use AudioStreamPlayer3D for 3D audio
audio_player.stream = audio_stream
audio_player.attenuation_model = AudioStreamPlayer3D.ATTENUATION_INVERSE_DISTANCE
audio_player.max_distance = 100000.0 # Set max distance to 100000 units
audio_player.unit_size = 1.0 # Default unit size
audio_player.play() # Autoplay the sound
add_child(audio_player)
else:
print("Failed to open directory: ", folder_path)
2 changes: 1 addition & 1 deletion scripts/Generic Consumable.gd
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func _process(delta: float) -> void:
rotation_degrees = count
position = newPosDif
var scaleMagnitude = ease((1 - abs((count - 90) / 90)), 0.4) * cachedScale.x
print(str(scaleMagnitude) + ", " + str(count))
# print(str(scaleMagnitude) + ", " + str(count))
scale = Vector2.ONE * scaleMagnitude
if count > 180:
queue_free()
Expand Down
2 changes: 1 addition & 1 deletion scripts/Generic Entity.gd
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ func _on_generic_enemy_life_drain(hpGain: float) -> void:

func death():
if isPlayer:
get_tree().reload_current_scene()
get_node("/root/Node2D/HUD/PauseMenu").restart_scene()
else:
queue_free() # Remove the enemy if HP is 0 or below
98 changes: 56 additions & 42 deletions scripts/Spawn Enemies.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,85 +4,99 @@ extends Node
@export var spawningBoundaryMin: Vector2
@export var spawningBoundaryMax: Vector2

# Exported Dictionary containing folders and their respective base chances
@export var folder_chances = {
"common": 0.7, # 70% chance initially
"rare": 0.2, # 20% chance initially
"legendary": 0.1 # 10% chance initially
"common": 0.7,
"rare": 0.2,
"legendary": 0.1
}

# Exported Dictionary containing enemy paths for each folder
@export var enemies = {
"common": [],
"rare" : [],
"rare": [],
"legendary": []
}

# Exported parameters for time-related control
@export var time_interval: float = 1.0 # Initial time between spawns in seconds
@export var min_time_interval: float = 0.2 # Minimum time interval between spawns
@export var time_interval_decrease_rate: float = 0.001 # Rate at which time_interval decreases
@export var time_increase_rate: float = 0.001 # Rate at which higher-tier chances increase
@export var time_interval: float = 1.0
@export var min_time_interval: float = 0.2
@export var time_interval_decrease_rate: float = 0.001
@export var time_increase_rate: float = 0.001

# Time tracking variable (not exported, as it's not meant to be set in the editor)
var elapsed_time = 0.0
@export var base_group_spawn_size_min: int = 3 # Base minimum enemies in a group
@export var base_group_spawn_size_max: int = 7 # Base maximum enemies in a group
@export var group_size_increase_rate: float = 0.05 # Rate at which group size increases over time

@export var min_delay_between_enemies: float = 0.1 # Minimum delay between enemies in a group
@export var max_delay_between_enemies: float = 0.3 # Maximum delay between enemies in a group

# Function to spawn an enemy
func spawn_enemy():
var selected_folder = choose_folder()

if selected_folder != "":
var enemy_path = "res://enemies/" + selected_folder + "/" + enemies[selected_folder][randi_range(0, enemies[selected_folder].size() - 1)] + ".tscn"
var enemy_scene = load(enemy_path)

if enemy_scene:
var enemy_instance = enemy_scene.instantiate()
add_child(enemy_instance)
var enemyPosition = lerp(spawningBoundaryMin, spawningBoundaryMax, randf() * 2 - 1)
print("Spawned enemy from ", selected_folder, ": ", enemy_path)
print(" Enemy Position X: " + str(enemyPosition.x).left(6), ", Y: " + str(enemyPosition.y).left(6))
print(" Time Interval: " + str(time_interval))
# else:
# print("Failed to load enemy scene from path: ", enemy_path)
else:
print("No folder selected, something went wrong.")
var elapsed_time = 0.0
var spawning = false # A flag to check if a group is currently being spawned

# Function to spawn a group of enemies with delays between each spawn
func spawn_enemy_group() -> void:
spawning = true # Set the spawning flag to true
# Calculate the current group size based on elapsed time
var current_group_spawn_size_min = base_group_spawn_size_min + int(elapsed_time * group_size_increase_rate)
var current_group_spawn_size_max = base_group_spawn_size_max + int(elapsed_time * group_size_increase_rate)
var group_size = randi_range(current_group_spawn_size_min, current_group_spawn_size_max)

for i in range(group_size):
var selected_folder = choose_folder()

if selected_folder != "":
var enemy_path = "res://enemies/" + selected_folder + "/" + enemies[selected_folder][randi_range(0, enemies[selected_folder].size() - 1)] + ".tscn"
var enemy_scene = load(enemy_path)

if enemy_scene:
var enemy_instance = enemy_scene.instantiate()
add_child(enemy_instance)
var enemyPosition = lerp(spawningBoundaryMin, spawningBoundaryMax, randf() * 2 - 1)
print("Spawned enemy from ", selected_folder, ": ", enemy_path)
print(" Enemy Position X: " + str(enemyPosition.x).left(6), ", Y: " + str(enemyPosition.y).left(6))
else:
print("No folder selected, something went wrong.")

# Add a random delay between enemies
var delay = randf_range(min_delay_between_enemies, max_delay_between_enemies)
await get_tree().create_timer(delay).timeout

spawning = false # Reset the spawning flag after the group is done

# Function to choose a folder based on the current chances
func choose_folder() -> String:
var rand_value = randi() / 4294967295.0 # Normalize by dividing by 2^32 - 1
var rand_value = randi() / 4294967295.0 # Normalize by dividing by 2^32 - 1
var cumulative_chance = 0.0

for folder in folder_chances.keys():
cumulative_chance += folder_chances[folder]
if rand_value < cumulative_chance:
return folder

return "" # Should not reach here if chances are correctly normalized
return ""

# Function to update chances and spawn rate over time
func update_chances_and_spawn_rate():
# Update folder chances over time
func update_chances_and_spawn_rate() -> void:
folder_chances["common"] = max(0.5, folder_chances["common"] - time_increase_rate)
folder_chances["rare"] = min(0.3, folder_chances["rare"] + time_increase_rate * 0.5)
folder_chances["legendary"] = min(0.2, folder_chances["legendary"] + time_increase_rate * 0.5)

# Normalize chances so they sum to 1
var total_chance = 0.0
for chance in folder_chances.values():
total_chance += chance

for folder in folder_chances.keys():
folder_chances[folder] /= total_chance

# Decrease time interval to spawn enemies more frequently
time_interval = max(min_time_interval, time_interval - time_interval_decrease_rate / 100000)
time_interval += (randf() * 2 - 1) * spawnIntervalVariation

# Main loop for spawning enemies
func _process(delta):
func _process(delta: float) -> void:
elapsed_time += delta

if elapsed_time >= time_interval:
spawn_enemy()
if elapsed_time >= time_interval and not spawning: # Check if not currently spawning
await spawn_enemy_group()
update_chances_and_spawn_rate()
elapsed_time = 0.0 # Reset the timer

# Randomize the next interval a bit more to make it less predictable
elapsed_time = 0.0
time_interval = time_interval + randi_range(-0.5, 0.5) * time_interval * 0.5
51 changes: 33 additions & 18 deletions scripts/pause_menu.gd
Original file line number Diff line number Diff line change
@@ -1,43 +1,58 @@
extends RichTextLabel

var isPaused: bool = true
var textCache
var textCache: String
@export var rectangle: ColorRect
@export var animationTime: float
var cachedBlack
var cachedLod
var LodProgress: float = 1
@export var animationTime: float = 1.0
var cachedBlack: float = 0.0
var cachedLod: float = 0.0
var LodProgress: float = 1.0

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
cachedLod = rectangle.material.get_shader_parameter("lod")
cachedBlack = rectangle.material.get_shader_parameter("black")
# Ensure rectangle and its material are available
if rectangle and rectangle.material:
reset_shader_parameters()
else:
print("Error: Rectangle or material is missing.")

textCache = text
text = ""


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if Input.is_action_just_pressed("ui_cancel"):
isPaused = !isPaused

get_tree().paused = isPaused
if isPaused:
animateShader(delta, true)
animate_shader(delta, true)
text = textCache
if Input.is_action_just_pressed("Legendary Inventory"):
get_tree().reload_current_scene()

restart_scene()
else:
animateShader(delta, false)
animate_shader(delta, false)
text = ""

func animateShader(delta: float, isIncreasing: bool):
func animate_shader(delta: float, isIncreasing: bool) -> void:
if isIncreasing:
if LodProgress < 1:
LodProgress += delta / animationTime
LodProgress = min(LodProgress + delta / animationTime, 1.0)
else:
if LodProgress > 0:
LodProgress -= delta / animationTime
clampf(LodProgress, 0, 1)
LodProgress = max(LodProgress - delta / animationTime, 0.0)

rectangle.material.set_shader_parameter("lod", cachedLod * ease(LodProgress, 0.6))
rectangle.material.set_shader_parameter("black", lerpf(1, cachedBlack, ease(LodProgress, 0.6)))

# Function to reset shader parameters and cached variables
func reset_shader_parameters() -> void:
if rectangle and rectangle.material:
cachedLod = 2
cachedBlack = 0.3
LodProgress = 1.0
else:
print("Error: Rectangle or material is missing.")

# Function to handle scene restart
func restart_scene() -> void:
reset_shader_parameters() # Ensure cached values are reset before restarting
get_tree().reload_current_scene()
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://cpsa4lrbe2xux"
path="res://.godot/imported/00 - Downloads - LeavesTest001 001.ogg-21431d29ff00233d664f7fb768ce4531.oggvorbisstr"
path="res://.godot/imported/00 - Downloads - LeavesTest001 001.ogg-ac0c483fbbb36bfe60482dc66211ff75.oggvorbisstr"

[deps]

source_file="res://sfx/Downloads - unknown album/00 - Downloads - LeavesTest001 001.ogg"
dest_files=["res://.godot/imported/00 - Downloads - LeavesTest001 001.ogg-21431d29ff00233d664f7fb768ce4531.oggvorbisstr"]
source_file="res://sfx/Leaves/00 - Downloads - LeavesTest001 001.ogg"
dest_files=["res://.godot/imported/00 - Downloads - LeavesTest001 001.ogg-ac0c483fbbb36bfe60482dc66211ff75.oggvorbisstr"]

[params]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://cjcam6wyeajy5"
path="res://.godot/imported/00 - Downloads - LeavesTest001 002.ogg-5b47deba312a520c430a5809b20b48bf.oggvorbisstr"
path="res://.godot/imported/00 - Downloads - LeavesTest001 002.ogg-15e0feafc2ca582d3696621c40b7c688.oggvorbisstr"

[deps]

source_file="res://sfx/Downloads - unknown album/00 - Downloads - LeavesTest001 002.ogg"
dest_files=["res://.godot/imported/00 - Downloads - LeavesTest001 002.ogg-5b47deba312a520c430a5809b20b48bf.oggvorbisstr"]
source_file="res://sfx/Leaves/00 - Downloads - LeavesTest001 002.ogg"
dest_files=["res://.godot/imported/00 - Downloads - LeavesTest001 002.ogg-15e0feafc2ca582d3696621c40b7c688.oggvorbisstr"]

[params]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://bpyn1pjok371p"
path="res://.godot/imported/00 - Downloads - LeavesTest001 003.ogg-5a5bec76a25a3ec567c7779a53117920.oggvorbisstr"
path="res://.godot/imported/00 - Downloads - LeavesTest001 003.ogg-c8ee336a4422eff16c266e6fc7b9a251.oggvorbisstr"

[deps]

source_file="res://sfx/Downloads - unknown album/00 - Downloads - LeavesTest001 003.ogg"
dest_files=["res://.godot/imported/00 - Downloads - LeavesTest001 003.ogg-5a5bec76a25a3ec567c7779a53117920.oggvorbisstr"]
source_file="res://sfx/Leaves/00 - Downloads - LeavesTest001 003.ogg"
dest_files=["res://.godot/imported/00 - Downloads - LeavesTest001 003.ogg-c8ee336a4422eff16c266e6fc7b9a251.oggvorbisstr"]

[params]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://bvtnivxvqgns2"
path="res://.godot/imported/00 - Downloads - LeavesTest001 004.ogg-31b1c1c49e6522e25a8c8133bd73d3ff.oggvorbisstr"
path="res://.godot/imported/00 - Downloads - LeavesTest001 004.ogg-0a84fe717c5fb6dee911e3592470725b.oggvorbisstr"

[deps]

source_file="res://sfx/Downloads - unknown album/00 - Downloads - LeavesTest001 004.ogg"
dest_files=["res://.godot/imported/00 - Downloads - LeavesTest001 004.ogg-31b1c1c49e6522e25a8c8133bd73d3ff.oggvorbisstr"]
source_file="res://sfx/Leaves/00 - Downloads - LeavesTest001 004.ogg"
dest_files=["res://.godot/imported/00 - Downloads - LeavesTest001 004.ogg-0a84fe717c5fb6dee911e3592470725b.oggvorbisstr"]

[params]

Expand Down
Loading

0 comments on commit 6982084

Please sign in to comment.