Add Sway and Bob

This commit is contained in:
2022-12-06 00:48:50 +01:00
parent 04a4ebc899
commit 825d86f271
26 changed files with 1513 additions and 116 deletions

BIN
Game.exr Normal file

Binary file not shown.

28
Game.exr.import Normal file
View File

@@ -0,0 +1,28 @@
[remap]
importer="2d_array_texture"
type="CompressedTexture2DArray"
uid="uid://djhovwrdokme0"
path.etc2="res://.godot/imported/Game.exr-72bd638e1628ca77f007b851e1ccfc0d.etc2.ctexarray"
path.s3tc="res://.godot/imported/Game.exr-72bd638e1628ca77f007b851e1ccfc0d.s3tc.ctexarray"
metadata={
"imported_formats": ["etc2", "s3tc"],
"vram_texture": true
}
[deps]
source_file="res://Game.exr"
dest_files=["res://.godot/imported/Game.exr-72bd638e1628ca77f007b851e1ccfc0d.etc2.ctexarray", "res://.godot/imported/Game.exr-72bd638e1628ca77f007b851e1ccfc0d.s3tc.ctexarray"]
[params]
compress/mode=2
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/channel_pack=1
mipmaps/generate=false
mipmaps/limit=-1
slices/horizontal=1
slices/vertical=1

View File

@@ -9,7 +9,7 @@ func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _process(delta): func _process(_delta):
label.text = "H Velocity: %3.2f" % [Vector2(player.velocity.x, player.velocity.z).length()] label.text = "H Velocity: %3.2f" % [Vector2(player.velocity.x, player.velocity.z).length()]
label.text += "\nV Velocity: %3.2f" % [player.velocity.y] label.text += "\nV Velocity: %3.2f" % [player.velocity.y]
label.text += "\nOn floor: %s" % player.is_on_floor() label.text += "\nOn floor: %s" % player.is_on_floor()

BIN
Game.lmbake Normal file

Binary file not shown.

View File

@@ -1,22 +1,51 @@
[gd_scene load_steps=4 format=3 uid="uid://chf6bnj13f744"] [gd_scene load_steps=8 format=3 uid="uid://cqutof7bvocqc"]
[ext_resource type="PackedScene" uid="uid://c65plp2c8ms4" path="res://player_q3/PlayerQ3.tscn" id="1"] [ext_resource type="LightmapGIData" uid="uid://k5haifo34pp6" path="res://Game.lmbake" id="2_3k1jt"]
[ext_resource type="PackedScene" uid="uid://bl7jynld7s25o" path="res://scenes/player/PlayerQ3.tscn" id="2_dhifo"]
[ext_resource type="Script" path="res://Game.gd" id="3"] [ext_resource type="Script" path="res://Game.gd" id="3"]
[ext_resource type="PackedScene" uid="uid://bke5cip8sjpoq" path="res://map/entity_0_worldspawn.tscn" id="4"] [ext_resource type="PackedScene" uid="uid://bke5cip8sjpoq" path="res://scenes/map/entity_0_worldspawn.tscn" id="3_3r3q4"]
[sub_resource type="PhysicalSkyMaterial" id="PhysicalSkyMaterial_mv01y"]
[sub_resource type="Sky" id="Sky_ybtis"]
sky_material = SubResource("PhysicalSkyMaterial_mv01y")
[sub_resource type="Environment" id="Environment_ul6y4"]
background_mode = 2
sky = SubResource("Sky_ybtis")
ambient_light_source = 3
reflected_light_source = 2
tonemap_mode = 2
tonemap_exposure = 2.0
[node name="Game" type="Node3D"] [node name="Game" type="Node3D"]
script = ExtResource("3") script = ExtResource("3")
[node name="LightmapGI" type="LightmapGI" parent="."]
visible = false
quality = 2
bounces = 6
light_data = ExtResource("2_3k1jt")
[node name="LightmapProbe" type="LightmapProbe" parent="."]
visible = false
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource("Environment_ul6y4")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(0.77938, 0.395123, -0.486256, 0.383799, 0.312364, 0.86898, 0.495243, -0.86389, 0.0918022, 0, 22.9909, 0)
light_indirect_energy = 1.5
light_bake_mode = 1
shadow_enabled = true
[node name="entity_0_worldspawn" parent="." instance=ExtResource("3_3r3q4")]
[node name="CanvasLayer" type="CanvasLayer" parent="."] [node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="Label" type="Label" parent="CanvasLayer"] [node name="Label" type="Label" parent="CanvasLayer"]
offset_right = 40.0 offset_right = 40.0
offset_bottom = 14.0 offset_bottom = 14.0
[node name="entity_0_worldspawn" parent="." instance=ExtResource("4")] [node name="PlayerQ3" parent="." instance=ExtResource("2_dhifo")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4.6672, 11.2181)
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, -0.0303989, 0.999538, 0, -0.999538, -0.0303989, 0, 25.1267, 0)
[node name="PlayerQ3" parent="." instance=ExtResource("1")]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -3.0882, 1, -0.869213)

View File

@@ -0,0 +1,20 @@
@tool
extends EditorPlugin
func _enter_tree() -> void:
add_custom_type(
"SfxrStreamPlayer", "AudioStreamPlayer", load("res://addons/godot_sfxr/SfxrStreamPlayer.gd"),
get_editor_interface().get_base_control().get_theme_icon("AudioStreamPlayer", "EditorIcons"))
add_custom_type(
"SfxrStreamPlayer2D", "AudioStreamPlayer2D", load("res://addons/godot_sfxr/SfxrStreamPlayer2D.gd"),
get_editor_interface().get_base_control().get_theme_icon("AudioStreamPlayer2D", "EditorIcons"))
add_custom_type(
"SfxrStreamPlayer3D", "AudioStreamPlayer3D", load("res://addons/godot_sfxr/SfxrStreamPlayer3D.gd"),
get_editor_interface().get_base_control().get_theme_icon("AudioStreamPlayer3D", "EditorIcons"))
func _exit_tree() -> void:
remove_custom_type("SfxrStreamPlayer")
remove_custom_type("SfxrStreamPlayer2D")
remove_custom_type("SfxrStreamPlayer3D")

View File

@@ -0,0 +1,309 @@
extends RefCounted
class_name SfxrGenerator
var params
var wave_shape: int
var repeat_time: float
var elapsed_since_repeat: float
var arpeggio_time: int
var arpeggio_multiplier: float
var period: float
var period_mult: float
var period_mult_slide: float
var period_max: float
var enable_frequency_cutoff: bool
var duty_cycle: float
var duty_cycle_slide: float
var fltw: float
var fltw_d: float
var fltdmp: float
var flthp: float
var flthp_d: float
var enable_low_pass_filter: bool
var vibrato_speed: float
var vibrato_amplitude: float
var envelope_length: Array
var envelope_punch: float
var flanger_offset: float
var flanger_offset_slide: float
var gain: float
var sample_rate: float
func init_params(stream_player) -> void:
params = stream_player
prepare_values()
# Wave shape
wave_shape = params.wave_type
# Filter
fltw = pow(params.p_lpf_freq, 3.0) * 0.1
enable_low_pass_filter = params.p_lpf_freq != 1.0
fltw_d = 1.0 + params.p_lpf_ramp * 0.0001
fltdmp = 5.0 / (1.0 + pow(params.p_lpf_resonance, 2.0) * 20.0) * (0.01 + fltw)
if (fltdmp > 0.8):
fltdmp = 0.8
flthp = pow(params.p_hpf_freq, 2.0) * 0.1
flthp_d = 1 + params.p_hpf_ramp * 0.0003
# Vibrato
vibrato_speed = pow(params.p_vib_speed, 2.0) * 0.01
vibrato_amplitude = params.p_vib_strength * 0.5
# Envelope
envelope_length = [
floor(params.p_env_attack * params.p_env_attack * 100000.0),
floor(params.p_env_sustain * params.p_env_sustain * 100000.0),
floor(params.p_env_decay * params.p_env_decay * 100000.0),
]
envelope_punch = params.p_env_punch
# Flanger
flanger_offset = pow(params.p_pha_offset, 2.0) * 1020.0
if (params.p_pha_offset < 0.0):
flanger_offset = -flanger_offset
flanger_offset_slide = pow(params.p_pha_ramp, 2.0) * 1.0
if (params.p_pha_ramp < 0.0):
flanger_offset_slide = -flanger_offset_slide
# Repeat
repeat_time = floor(pow(1 - params.p_repeat_speed, 2.0) * 20000.0 + 32.0)
if (params.p_repeat_speed == 0.0):
repeat_time = 0.0
gain = exp(params.sound_vol) - 1.0
sample_rate = params.sample_rate
func prepare_values() -> void:
elapsed_since_repeat = 0.0
period = 100.0 / (params.p_base_freq * params.p_base_freq + 0.001)
period_max = 100.0 / (params.p_freq_limit * params.p_freq_limit + 0.001)
enable_frequency_cutoff = params.p_freq_limit > 0.0
period_mult = 1.0 - pow(params.p_freq_ramp, 3.0) * 0.01
period_mult_slide = -pow(params.p_freq_dramp, 3.0) * 0.000001
duty_cycle = 0.5 - params.p_duty * 0.5
duty_cycle_slide = -params.p_duty_ramp * 0.00005
if (params.p_arp_mod >= 0.0):
arpeggio_multiplier = 1.0 - pow(params.p_arp_mod, 2.0) * 0.9
else:
arpeggio_multiplier = 1.0 + pow(params.p_arp_mod, 2.0) * 10.0
arpeggio_time = floor(pow(1.0 - params.p_arp_speed, 2.0) * 20000.0 + 32.0)
if (params.p_arp_speed == 1.0):
arpeggio_time = 0
func get_raw_buffer() -> Array:
randomize()
var fltp: float = 0.0
var fltdp: float = 0.0
var fltphp: float = 0.0
var noise_buffer_length: int = 32
var noise_buffer: Array = []
for i in noise_buffer_length:
noise_buffer.append(randf() * 2.0 - 1.0)
var envelope_stage: int = 0
var envelope_elapsed: float = 0.0
var vibrato_phase: float = 0.0
var phase: int = 0
var ipp: int = 0
var flanger_buffer_length: int = 1024
var flanger_buffer: Array = []
for i in flanger_buffer_length:
flanger_buffer.append(0.0)
var _buffer: Array = []
var sample_sum: float = 0.0
var num_summed: float = 0.0
var summands: int = floor(44100.0 / sample_rate)
var t: float = -1.0
while t < INF:
t += 1
# Repeats
elapsed_since_repeat += 1.0
if (repeat_time != 0.0 and elapsed_since_repeat >= repeat_time):
prepare_values()
# Arpeggio (single)
if (arpeggio_time != 0 and t >= arpeggio_time):
arpeggio_time = 0
period *= arpeggio_multiplier
# Frequency slide, and frequency slide slide!
period_mult += period_mult_slide
period *= period_mult
if (period > period_max):
period = period_max
if (enable_frequency_cutoff):
break
# Vibrato
var rfperiod: float = period
if (vibrato_amplitude > 0.0):
vibrato_phase += vibrato_speed
rfperiod = period * (1.0 + sin(vibrato_phase) * vibrato_amplitude)
var iperiod: int = floor(rfperiod)
if (iperiod < SfxrGlobals.OVERSAMPLING):
iperiod = SfxrGlobals.OVERSAMPLING
# Square wave duty cycle
duty_cycle = duty_cycle + duty_cycle_slide
if (duty_cycle > 0.5):
duty_cycle = 0.5
elif (duty_cycle < 0.0):
duty_cycle = 0.0
# Volume envelope
envelope_elapsed += 1.0
if (envelope_elapsed > envelope_length[envelope_stage]):
envelope_elapsed = 0.0
envelope_stage += 1.0
if (envelope_stage > 2.0):
break
if (envelope_length[envelope_stage] == 0):
continue
var env_vol: float = 0.0
var envf: float = envelope_elapsed / envelope_length[envelope_stage]
if (envelope_stage == 0.0): # Attack
env_vol = envf
elif (envelope_stage == 1.0): # Sustain
env_vol = 1.0 + (1.0 - envf) * 2.0 * envelope_punch
else: # Decay
env_vol = 1.0 - envf
# Flanger step
flanger_offset += flanger_offset_slide
var iphase: int = abs(floor(flanger_offset))
if (iphase > 1023):
iphase = 1023
if (flthp_d != 0.0):
flthp = flthp * flthp_d
if (flthp > 0.1):
flthp = 0.1
elif (flthp < 0.00001):
flthp = 0.00001
# 8x Oversampling
var sample: float = 0.0
for i in SfxrGlobals.OVERSAMPLING:
var sub_sample: float = 0.0
phase += 1
if (phase >= iperiod):
phase %= iperiod
if (wave_shape == SfxrGlobals.WAVE_SHAPES.NOISE):
for j in noise_buffer_length:
noise_buffer[i] = randf() * 2.0 - 1.0
# Base waveform
var fp: float = float(phase) / float(iperiod)
if (wave_shape == SfxrGlobals.WAVE_SHAPES.SQUARE):
if (fp < duty_cycle):
sub_sample = 0.5
else:
sub_sample = -0.5
elif (wave_shape == SfxrGlobals.WAVE_SHAPES.SAWTOOTH):
if (fp < duty_cycle):
sub_sample = -1.0 + 2.0 * fp / duty_cycle
else:
sub_sample = 1.0 - 2.0 * (fp - duty_cycle) / (1 - duty_cycle)
elif (wave_shape == SfxrGlobals.WAVE_SHAPES.SINE):
sub_sample = sin(fp * 2.0 * PI)
elif (wave_shape == SfxrGlobals.WAVE_SHAPES.NOISE):
sub_sample = noise_buffer[int(floor(phase * 32.0 / iperiod))]
else:
printerr("ERROR: Bad wave type: " + str(wave_shape))
sub_sample = 0
# Low-pass filter
var pp: float = fltp
fltw *= fltw_d
if (fltw > 0.1):
fltw = 0.1
elif (fltw < 0.0):
fltw = 0.0
if (enable_low_pass_filter):
fltdp += (sub_sample - fltp) * fltw
fltdp -= fltdp * fltdmp
else:
fltp = sub_sample
fltdp = 0.0
fltp += fltdp
# High-pass filter
fltphp += fltp - pp
fltphp -= fltphp * flthp
sub_sample = fltphp
# Flanger
flanger_buffer[ipp & 1023] = sub_sample
sub_sample += flanger_buffer[(ipp - iphase + 1024) & 1023]
ipp = (ipp + 1) & 1023
# Final accumulation and envelope application
sample += sub_sample * env_vol
# Accumulate samples appropriately for sample rate
sample_sum += sample
num_summed += 1.0
if (num_summed >= summands):
num_summed = 0.0
sample = sample_sum / summands
sample_sum = 0.0
else:
continue
sample = sample / SfxrGlobals.OVERSAMPLING * SfxrGlobals.MASTER_VOLUME
sample *= gain
sample = floor((sample + 1) * 128)
if (sample > 255):
sample = 255;
elif (sample < 0):
sample = 0
sample += 128
if sample > 255:
sample -= 255
_buffer.append(sample)
return _buffer
func build_sample(stream_player):
init_params(stream_player)
var sample: AudioStreamWAV = stream_player.stream
if (not sample):
stream_player.stream = AudioStreamWAV.new()
sample = stream_player.stream
sample.mix_rate = sample_rate
sample.data = PackedByteArray(get_raw_buffer())
return sample

View File

@@ -0,0 +1,30 @@
extends Object
class_name SfxrGlobals
enum WAVE_SHAPES {
SQUARE,
SAWTOOTH,
SINE,
NOISE,
}
enum PRESETS {
NONE,
PICKUP,
LASER,
EXPLOSION,
POWERUP,
HIT,
JUMP,
CLICK,
BLIP,
SYNTH,
RANDOM,
TONE,
MUTATE,
}
const OVERSAMPLING = 8
const MASTER_VOLUME = 1

View File

@@ -0,0 +1,119 @@
@tool
extends AudioStreamPlayer
# Wave Shape
var wave_type: int
# Envelope
var p_env_attack: float
var p_env_sustain: float
var p_env_punch: float
var p_env_decay: float
# Tone
var p_base_freq: float
var p_freq_limit: float
var p_freq_ramp: float
var p_freq_dramp: float
# Vibrato
var p_vib_strength: float
var p_vib_speed: float
# Tonal Change
var p_arp_mod: float
var p_arp_speed: float
# Square wve duty (proportion of time signal is high vs low)
var p_duty: float
var p_duty_ramp: float
# Repeat
var p_repeat_speed: float
# Flanger
var p_pha_offset: float
var p_pha_ramp: float
# Low-pass filter
var p_lpf_freq: float
var p_lpf_ramp: float
var p_lpf_resonance: float
# High-pass filter
var p_hpf_freq: float
var p_hpf_ramp: float
# Sample parameters
var sound_vol: float
var sample_rate: float
# Sfx Generation
var sfx_timer: SceneTreeTimer
##################################
# Inspector Properties
##################################
func _get_property_list() -> Array:
return SfxrStreamPlayerInterface.object_get_property_list()
func _get(property):
return SfxrStreamPlayerInterface.object_get(self, property)
func _set(property, value) -> bool:
return SfxrStreamPlayerInterface.object_set(self, property, value)
##################################
# Defaults
##################################
func _init():
SfxrStreamPlayerInterface.object_set_defaults(self)
func property_can_revert(property: String):
return SfxrStreamPlayerInterface.object_property_can_revert(property)
func property_get_revert(property: String):
return SfxrStreamPlayerInterface.object_property_get_revert(property)
##################################
# Presets
##################################
func random_preset() -> bool:
return SfxrStreamPlayerInterface.random_preset(self)
func preset_values(preset_key: int) -> bool:
return SfxrStreamPlayerInterface.preset_values(self, preset_key)
##################################
# Playback
##################################
func _on_sfx_timer_timeout(timer: SceneTreeTimer, play_after_build: bool):
SfxrStreamPlayerInterface._on_sfx_timer_timeout(self, timer, play_after_build)
func build_sfx(play_after_build: bool = false):
SfxrStreamPlayerInterface.build_sfx(self, play_after_build)
func play(from_position: float = 0.0):
if playing:
stop()
super.play(from_position)

View File

@@ -0,0 +1,119 @@
@tool
extends AudioStreamPlayer2D
# Wave Shape
var wave_type: int
# Envelope
var p_env_attack: float
var p_env_sustain: float
var p_env_punch: float
var p_env_decay: float
# Tone
var p_base_freq: float
var p_freq_limit: float
var p_freq_ramp: float
var p_freq_dramp: float
# Vibrato
var p_vib_strength: float
var p_vib_speed: float
# Tonal Change
var p_arp_mod: float
var p_arp_speed: float
# Square wve duty (proportion of time signal is high vs low)
var p_duty: float
var p_duty_ramp: float
# Repeat
var p_repeat_speed: float
# Flanger
var p_pha_offset: float
var p_pha_ramp: float
# Low-pass filter
var p_lpf_freq: float
var p_lpf_ramp: float
var p_lpf_resonance: float
# High-pass filter
var p_hpf_freq: float
var p_hpf_ramp: float
# Sample parameters
var sound_vol: float
var sample_rate: float
# Sfx Generation
var sfx_timer: SceneTreeTimer
##################################
# Inspector Properties
##################################
func _get_property_list() -> Array:
return SfxrStreamPlayerInterface.object_get_property_list()
func _get(property):
return SfxrStreamPlayerInterface.object_get(self, property)
func _set(property, value) -> bool:
return SfxrStreamPlayerInterface.object_set(self, property, value)
##################################
# Defaults
##################################
func _init():
SfxrStreamPlayerInterface.object_set_defaults(self)
func property_can_revert(property: String):
return SfxrStreamPlayerInterface.object_property_can_revert(property)
func property_get_revert(property: String):
return SfxrStreamPlayerInterface.object_property_get_revert(property)
##################################
# Presets
##################################
func random_preset() -> bool:
return SfxrStreamPlayerInterface.random_preset(self)
func preset_values(preset_key: int) -> bool:
return SfxrStreamPlayerInterface.preset_values(self, preset_key)
##################################
# Playback
##################################
func _on_sfx_timer_timeout(timer: SceneTreeTimer, play_after_build: bool):
SfxrStreamPlayerInterface._on_sfx_timer_timeout(self, timer, play_after_build)
func build_sfx(play_after_build: bool = false):
SfxrStreamPlayerInterface.build_sfx(self, play_after_build)
func play(from_position: float = 0.0):
if playing:
stop()
super.play(from_position)

View File

@@ -0,0 +1,119 @@
@tool
extends AudioStreamPlayer3D
# Wave Shape
var wave_type: int
# Envelope
var p_env_attack: float
var p_env_sustain: float
var p_env_punch: float
var p_env_decay: float
# Tone
var p_base_freq: float
var p_freq_limit: float
var p_freq_ramp: float
var p_freq_dramp: float
# Vibrato
var p_vib_strength: float
var p_vib_speed: float
# Tonal Change
var p_arp_mod: float
var p_arp_speed: float
# Square wve duty (proportion of time signal is high vs low)
var p_duty: float
var p_duty_ramp: float
# Repeat
var p_repeat_speed: float
# Flanger
var p_pha_offset: float
var p_pha_ramp: float
# Low-pass filter
var p_lpf_freq: float
var p_lpf_ramp: float
var p_lpf_resonance: float
# High-pass filter
var p_hpf_freq: float
var p_hpf_ramp: float
# Sample parameters
var sound_vol: float
var sample_rate: float
# Sfx Generation
var sfx_timer: SceneTreeTimer
##################################
# Inspector Properties
##################################
func _get_property_list() -> Array:
return SfxrStreamPlayerInterface.object_get_property_list()
func _get(property):
return SfxrStreamPlayerInterface.object_get(self, property)
func _set(property, value):
return SfxrStreamPlayerInterface.object_set(self, property, value)
##################################
# Defaults
##################################
func _init():
SfxrStreamPlayerInterface.object_set_defaults(self)
func property_can_revert(property: String):
return SfxrStreamPlayerInterface.object_property_can_revert(property)
func property_get_revert(property: String):
return SfxrStreamPlayerInterface.object_property_get_revert(property)
##################################
# Presets
##################################
func random_preset() -> bool:
return SfxrStreamPlayerInterface.random_preset(self)
func preset_values(preset_key: int) -> bool:
return SfxrStreamPlayerInterface.preset_values(self, preset_key)
##################################
# Playback
##################################
func _on_sfx_timer_timeout(timer: SceneTreeTimer, play_after_build: bool):
SfxrStreamPlayerInterface._on_sfx_timer_timeout(self, timer, play_after_build)
func build_sfx(play_after_build: bool = false):
SfxrStreamPlayerInterface.build_sfx(self, play_after_build)
func play(from_position: float = 0.0):
if playing:
stop()
super.play(from_position)

View File

@@ -0,0 +1,477 @@
extends Object
class_name SfxrStreamPlayerInterface
##################################
# Inspector Properties
##################################
const PROPERTY_MAP = {
# Sample params
"sample_params/sound_vol": {"name": "sound_vol", "hint_string": "0,1,0.000000001", "default": 0.25},
"sample_params/sample_rate": {"name": "sample_rate", "hint_string": "6000,44100,1", "default": 44100.0},
# Envelope
"envelope/attack_time": {"name": "p_env_attack", "hint_string": "0,1,0.000000001", "default": 0.0},
"envelope/sustain_time": {"name": "p_env_sustain", "hint_string": "0,1,0.000000001", "default": 0.6641},
"envelope/punch_time": {"name": "p_env_punch", "hint_string": "0,1,0.000000001", "default": 0.0},
"envelope/decay_time": {"name": "p_env_decay", "hint_string": "0,1,0.000000001", "default": 0.0},
# Frequency
"frequency/start_frequency": {"name": "p_base_freq", "hint_string": "0,1,0.000000001", "default": 0.35173364},
"frequency/min_freq_cutoff": {"name": "p_freq_limit", "hint_string": "0,1,0.000000001", "default": 0.0},
"frequency/slide": {"name": "p_freq_ramp", "hint_string": "-1,1,0.000000001", "default": 0.0},
"frequency/delta_slide": {"name": "p_freq_dramp", "hint_string": "-1,1,0.000000001", "default": 0.0},
# Vibrato
"vibrato/depth": {"name": "p_vib_strength", "hint_string": "0,1,0.000000001", "default": 0.0},
"vibrato/speed": {"name": "p_vib_speed", "hint_string": "0,1,0.000000001", "default": 0.0},
# Arpeggiation
"arpeggiation/frequency_mult": {"name": "p_arp_mod", "hint_string": "-1,1,0.000000001", "default": 0.0},
"arpeggiation/change_speed": {"name": "p_arp_speed", "hint_string": "0,1,0.000000001", "default": 0.0},
# Duty cycle
"duty_cycle/duty_cycle": {"name": "p_duty", "hint_string": "0,1,0.000000001", "default": 0.0},
"duty_cycle/sweep": {"name": "p_duty_ramp", "hint_string": "-1,1,0.000000001", "default": 0.0},
# Retrigger
"retrigger/rate": {"name": "p_repeat_speed", "hint_string": "0,1,0.000000001", "default": 0.0},
# Flanger
"flanger/offset": {"name": "p_pha_offset", "hint_string": "-1,1,0.000000001", "default": 0.0},
"flanger/sweep": {"name": "p_pha_ramp", "hint_string": "-1,1,0.000000001", "default": 0.0},
# Low-pass filter
"low_pass_filter/cutoff_frequency": {"name": "p_lpf_freq", "hint_string": "0,1,0.000000001", "default": 1.0},
"low_pass_filter/cutoff_sweep": {"name": "p_lpf_ramp", "hint_string": "-1,1,0.000000001", "default": 0.0},
"low_pass_filter/resonance": {"name": "p_lpf_resonance", "hint_string": "0,1,0.000000001", "default": 0.0},
# High-pass filter
"high_pass_filter/cutoff_frequency": {"name": "p_hpf_freq", "hint_string": "0,1,0.000000001", "default": 0.0},
"high_pass_filter/cutoff_sweep": {"name": "p_hpf_ramp", "hint_string": "-1,1,0.000000001", "default": 0.0},
}
static func object_get_property_list() -> Array:
var presets = SfxrGlobals.PRESETS.keys()
presets.pop_front()
var props = []
props.append({
"name": "SfxrStreamPlayer",
"type": TYPE_NIL,
"usage": PROPERTY_USAGE_CATEGORY | PROPERTY_USAGE_SCRIPT_VARIABLE,
})
for preset in presets:
props.append({
"name": "generators/" + str(preset).to_lower(),
"type": TYPE_BOOL,
"usage": PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE,
})
props.append({
"name": "wave/type",
"type": TYPE_INT,
"hint": PROPERTY_HINT_ENUM,
"hint_string": ",".join(PackedStringArray(SfxrGlobals.WAVE_SHAPES.keys())),
})
for property in PROPERTY_MAP:
props.append({
"name": property,
"type": TYPE_FLOAT,
"hint": PROPERTY_HINT_RANGE,
"hint_string": PROPERTY_MAP[property]["hint_string"],
})
props.append_array([
{
"name": "actions/force_rebuild",
"type": TYPE_BOOL,
"usage": PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE,
},
])
return props
static func object_get(object: Node, property: String):
if property in PROPERTY_MAP:
return object[PROPERTY_MAP[property]["name"]]
elif property == "wave/type":
return object.wave_type
static func object_set(object: Node, property: String, value) -> bool:
var auto_build = Engine.is_editor_hint() and object.is_inside_tree()
if property in PROPERTY_MAP:
object[PROPERTY_MAP[property]["name"]] = value
if auto_build:
_schedule_build_sfx(object, true)
return true
elif property == "wave/type":
object.wave_type = value
if auto_build:
_schedule_build_sfx(object, true)
return true
elif property == "actions/force_rebuild":
if value and auto_build:
build_sfx(object, true)
return true
elif property == "sfxr_generator":
if not value:
value = 0
if preset_values(object, value) and auto_build:
build_sfx(object, true)
return true
elif property.begins_with("generators/"):
property = property.replace("generators/", "").to_upper()
if preset_values(object, SfxrGlobals.PRESETS.get(property, -1)) and auto_build:
build_sfx(object, true)
return true
return false
##################################
# Defaults
##################################
static func object_set_defaults(object: Node):
object.wave_type = SfxrGlobals.WAVE_SHAPES.SAWTOOTH
for property in PROPERTY_MAP:
object[PROPERTY_MAP[property]["name"]] = PROPERTY_MAP[property]["default"]
static func object_property_can_revert(property: String):
return property in PROPERTY_MAP
static func object_property_get_revert(property: String):
return PROPERTY_MAP[property]["default"]
##################################
# Helpers
##################################
static func frnd(rrange) -> float:
return randf() * rrange
static func rndr(from, to) -> float:
return randf() * (to - from) + from
static func rnd(rmax) -> float:
return floor(randf() * (rmax + 1))
##################################
# Presets
##################################
static func _presets_pickup(object: Node):
object_set_defaults(object)
object.wave_type = SfxrGlobals.WAVE_SHAPES.SAWTOOTH
object.p_base_freq = 0.4 + frnd(0.5)
object.p_env_attack = 0
object.p_env_sustain = frnd(0.1)
object.p_env_decay = 0.1 + frnd(0.4)
object.p_env_punch = 0.3 + frnd(0.3)
if rnd(1):
object.p_arp_speed = 0.5 + frnd(0.2)
object.p_arp_mod = 0.2 + frnd(0.4)
static func _presets_laser(object: Node):
object_set_defaults(object)
object.wave_type = rnd(2)
if object.wave_type == SfxrGlobals.WAVE_SHAPES.SINE and rnd(1):
object.wave_type = rnd(1)
if rnd(2) == 0:
object.p_base_freq = 0.3 + frnd(0.6)
object.p_freq_limit = frnd(0.1)
object.p_freq_ramp = -0.35 - frnd(0.3)
else:
object.p_base_freq = 0.5 + frnd(0.5)
object.p_freq_limit = object.p_base_freq - 0.2 - frnd(0.6)
if object.p_freq_limit < 0.2:
object.p_freq_limit = 0.2
object.p_freq_ramp = -0.15 - frnd(0.2)
if object.wave_type == SfxrGlobals.WAVE_SHAPES.SAWTOOTH:
object.p_duty = 1
if rnd(1):
object.p_duty = frnd(0.5)
object.p_duty_ramp = frnd(0.2)
else:
object.p_duty = 0.4 + frnd(0.5)
object.p_duty_ramp = -frnd(0.7)
object.p_env_attack = 0
object.p_env_sustain = 0.1 + frnd(0.2)
object.p_env_decay = frnd(0.4)
if rnd(1):
object.p_env_punch = frnd(0.3)
if rnd(2) == 0:
object.p_pha_offset = frnd(0.2)
object.p_pha_ramp = -frnd(0.2)
object.p_hpf_freq = frnd(0.3)
static func _presets_explosion(object: Node):
object_set_defaults(object)
object.wave_type = SfxrGlobals.WAVE_SHAPES.NOISE
if rnd(1):
object.p_base_freq = pow(0.1 + frnd(0.4), 2)
object.p_freq_ramp = -0.1 + frnd(0.4)
else:
object.p_base_freq = pow(0.2 + frnd(0.7), 2)
object.p_freq_ramp = -0.2 - frnd(0.2)
if rnd(4) == 0:
object.p_freq_ramp = 0
if rnd(2) == 0:
object.p_repeat_speed = 0.3 + frnd(0.5)
object.p_env_attack = 0
object.p_env_sustain = 0.1 + frnd(0.3)
object.p_env_decay = frnd(0.5)
if rnd(1):
object.p_pha_offset = -0.3 + frnd(0.9)
object.p_pha_ramp = -frnd(0.3)
object.p_env_punch = 0.2 + frnd(0.6)
if rnd(1):
object.p_vib_strength = frnd(0.7)
object.p_vib_speed = frnd(0.6)
if rnd(2) == 0:
object.p_arp_speed = 0.6 + frnd(0.3)
object.p_arp_mod = 0.8 - frnd(1.6)
static func _presets_powerup(object: Node):
object_set_defaults(object)
if rnd(1):
object.wave_type = SfxrGlobals.WAVE_SHAPES.SAWTOOTH
object.p_duty = 1
else:
object.p_duty = frnd(0.6)
object.p_base_freq = 0.2 + frnd(0.3)
if rnd(1):
object.p_freq_ramp = 0.1 + frnd(0.4)
object.p_repeat_speed = 0.4 + frnd(0.4)
else:
object.p_freq_ramp = 0.05 + frnd(0.2)
if rnd(1):
object.p_vib_strength = frnd(0.7)
object.p_vib_speed = frnd(0.6)
object.p_env_attack = 0
object.p_env_sustain = frnd(0.4)
object.p_env_decay = 0.1 + frnd(0.4)
static func _presets_hit(object: Node):
object_set_defaults(object)
object.wave_type = rnd(2)
if object.wave_type == SfxrGlobals.WAVE_SHAPES.SINE:
object.wave_type = SfxrGlobals.WAVE_SHAPES.NOISE
if object.wave_type == SfxrGlobals.WAVE_SHAPES.SQUARE:
object.p_duty = frnd(0.6)
if object.wave_type == SfxrGlobals.WAVE_SHAPES.SAWTOOTH:
object.p_duty = 1
object.p_base_freq = 0.2 + frnd(0.6)
object.p_freq_ramp = -0.3 - frnd(0.4)
object.p_env_attack = 0
object.p_env_sustain = frnd(0.1)
object.p_env_decay = 0.1 + frnd(0.2)
if rnd(1):
object.p_hpf_freq = frnd(0.3)
static func _presets_jump(object: Node):
object_set_defaults(object)
object.wave_type = SfxrGlobals.WAVE_SHAPES.SQUARE
object.p_duty = frnd(0.6)
object.p_base_freq = 0.3 + frnd(0.3)
object.p_freq_ramp = 0.1 + frnd(0.2)
object.p_env_attack = 0
object.p_env_sustain = 0.1 + frnd(0.3)
object.p_env_decay = 0.1 + frnd(0.2)
if rnd(1):
object.p_hpf_freq = frnd(0.3)
if rnd(1):
object.p_lpf_freq = 1 - frnd(0.6)
static func _presets_blip(object: Node):
object_set_defaults(object)
object.wave_type = rnd(1)
if object.wave_type == SfxrGlobals.WAVE_SHAPES.SQUARE:
object.p_duty = frnd(0.6)
else:
object.p_duty = 1
object.p_base_freq = 0.2 + frnd(0.4)
object.p_env_attack = 0
object.p_env_sustain = 0.1 + frnd(0.1)
object.p_env_decay = frnd(0.2)
object.p_hpf_freq = 0.1
static func _presets_synth(object: Node):
object_set_defaults(object)
object.wave_type = rnd(1)
object.p_base_freq = [0.2723171360931539, 0.19255692561524382, 0.13615778746815113][rnd(2)]
object.p_env_attack = frnd(0.5) if rnd(4) > 3 else 0
object.p_env_sustain = frnd(1)
object.p_env_punch = frnd(1)
object.p_env_decay = frnd(0.9) + 0.1
object.p_arp_mod = [0, 0, 0, 0, -0.3162, 0.7454, 0.7454][rnd(6)]
object.p_arp_speed = frnd(0.5) + 0.4
object.p_duty = frnd(1)
object.p_duty_ramp = frnd(1) if rnd(2) == 2 else 0
object.p_lpf_freq = [1, frnd(1) * frnd(1)][rnd(1)]
object.p_lpf_ramp = rndr(-1, 1)
object.p_lpf_resonance = frnd(1)
object.p_hpf_freq = frnd(1) if rnd(3) == 3 else 0
object.p_hpf_ramp = frnd(1) if rnd(3) == 3 else 0
static func _presets_tone(object: Node):
object_set_defaults(object)
static func _presets_click(object: Node):
if rnd(1):
_presets_hit(object)
else:
_presets_explosion(object)
if rnd(1):
object.p_freq_ramp = -0.5 + frnd(1.0)
if rnd(1):
object.p_env_sustain = (frnd(0.4) + 0.2) * object.p_env_sustain
object.p_env_decay = (frnd(0.4) + 0.2) * object.p_env_decay
if rnd(3) == 0:
object.p_env_attack = frnd(0.3)
object.p_base_freq = 1 - frnd(0.25)
object.p_hpf_freq = 1 - frnd(0.1)
static func _presets_random(object: Node):
object_set_defaults(object)
object.wave_type = rnd(3)
if rnd(1):
object.p_base_freq = pow(frnd(2) - 1, 3) + 0.5
else:
object.p_base_freq = pow(frnd(1), 2)
object.p_freq_limit = 0
object.p_freq_ramp = pow(frnd(2) - 1, 5)
if object.p_base_freq > 0.7 and object.p_freq_ramp > 0.2:
object.p_freq_ramp = -object.p_freq_ramp
if object.p_base_freq < 0.2 and object.p_freq_ramp < -0.05:
object.p_freq_ramp = -object.p_freq_ramp
object.p_freq_dramp = pow(frnd(2) - 1, 3)
object.p_duty = frnd(2) - 1
object.p_duty_ramp = pow(frnd(2) - 1, 3)
object.p_vib_strength = pow(frnd(2) - 1, 3)
object.p_vib_speed = rndr(-1, 1)
object.p_env_attack = pow(rndr(-1, 1), 3)
object.p_env_sustain = pow(rndr(-1, 1), 2)
object.p_env_decay = rndr(-1, 1)
object.p_env_punch = pow(frnd(0.8), 2)
if object.p_env_attack + object.p_env_sustain + object.p_env_decay < 0.2:
object.p_env_sustain += 0.2 + frnd(0.3)
object.p_env_decay += 0.2 + frnd(0.3)
object.p_lpf_resonance = rndr(-1, 1)
object.p_lpf_freq = 1 - pow(frnd(1), 3)
object.p_lpf_ramp = pow(frnd(2) - 1, 3)
if object.p_lpf_freq < 0.1 and object.p_lpf_ramp < -0.05:
object.p_lpf_ramp = -object.p_lpf_ramp
object.p_hpf_freq = pow(frnd(1), 5)
object.p_hpf_ramp = pow(frnd(2) - 1, 5)
object.p_pha_offset = pow(frnd(2) - 1, 3)
object.p_pha_ramp = pow(frnd(2) - 1, 3)
object.p_repeat_speed = frnd(2) - 1
object.p_arp_speed = frnd(2) - 1
object.p_arp_mod = frnd(2) - 1
static func _presets_mutate(object: Node):
if rnd(1): object.p_base_freq += frnd(0.1) - 0.05
if rnd(1): object.p_freq_ramp += frnd(0.1) - 0.05
if rnd(1): object.p_freq_dramp += frnd(0.1) - 0.05
if rnd(1): object.p_duty += frnd(0.1) - 0.05
if rnd(1): object.p_duty_ramp += frnd(0.1) - 0.05
if rnd(1): object.p_vib_strength += frnd(0.1) - 0.05
if rnd(1): object.p_vib_speed += frnd(0.1) - 0.05
if rnd(1): object.p_env_attack += frnd(0.1) - 0.05
if rnd(1): object.p_env_sustain += frnd(0.1) - 0.05
if rnd(1): object.p_env_decay += frnd(0.1) - 0.05
if rnd(1): object.p_env_punch += frnd(0.1) - 0.05
if rnd(1): object.p_lpf_resonance += frnd(0.1) - 0.05
if rnd(1): object.p_lpf_freq += frnd(0.1) - 0.05
if rnd(1): object.p_lpf_ramp += frnd(0.1) - 0.05
if rnd(1): object.p_hpf_freq += frnd(0.1) - 0.05
if rnd(1): object.p_hpf_ramp += frnd(0.1) - 0.05
if rnd(1): object.p_pha_offset += frnd(0.1) - 0.05
if rnd(1): object.p_pha_ramp += frnd(0.1) - 0.05
if rnd(1): object.p_repeat_speed += frnd(0.1) - 0.05
if rnd(1): object.p_arp_speed += frnd(0.1) - 0.05
if rnd(1): object.p_arp_mod += frnd(0.1) - 0.05
static func random_preset(object: Node) -> bool:
return preset_values(object, (randi() % (len(SfxrGlobals.PRESETS) - 1)) + 1)
static func preset_values(object: Node, preset_key: int) -> bool:
if preset_key >= 0 and preset_key < len(SfxrGlobals.PRESETS):
var preset = SfxrGlobals.PRESETS.keys()[preset_key].to_lower()
match preset:
"pickup":
_presets_pickup(object)
return true
"laser":
_presets_laser(object)
return true
"explosion":
_presets_explosion(object)
return true
"powerup":
_presets_powerup(object)
return true
"hit":
_presets_hit(object)
return true
"jump":
_presets_jump(object)
return true
"click":
_presets_click(object)
return true
"blip":
_presets_blip(object)
return true
"synth":
_presets_synth(object)
return true
"random":
_presets_random(object)
return true
"tone":
_presets_tone(object)
return true
"mutate":
_presets_mutate(object)
return true
return false
##################################
# Playback
##################################
static func _schedule_build_sfx(object: Node, play_after_build: bool):
var timer: SceneTreeTimer = object.get_tree().create_timer(.5)
object.sfx_timer = timer
timer.timeout.connect(func(): object._on_sfx_timer_timeout(timer, play_after_build))
static func _on_sfx_timer_timeout(object: Node, timer: SceneTreeTimer, play_after_build: bool):
if timer == object.sfx_timer:
build_sfx(object, play_after_build)
static func build_sfx(object: Node, play_after_build: bool = false):
var sfxg = SfxrGenerator.new()
sfxg.build_sample(object)
if play_after_build:
object.play()
object.notify_property_list_changed()

View File

@@ -0,0 +1,7 @@
[plugin]
name="GodotSfxr"
description="Sfx Generator. Port of jsfxr (https://sfxr.me - by Eric Fredricksen) which is a port of sfxr (https://www.drpetter.se/project_sfxr.html - by DrPetter)."
author="Tomeyro"
version="1.0"
script="GodotSfxr.gd"

View File

@@ -1,16 +0,0 @@
extends Node3D
var pos = Vector2.ZERO
var y = 0
func _ready():
pos.x = 0.3 # Replace with function body.
pos.y = -1
y = -0.5
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if(transform.basis.x != 0.3 || transform.basis.z != -1):
transform.basis.y = y + sin(1 * delta)

View File

@@ -3,7 +3,7 @@
importer="scene" importer="scene"
importer_version=1 importer_version=1
type="PackedScene" type="PackedScene"
uid="uid://cnk2fusin4ewy" uid="uid://beiad4ywiojba"
path="res://.godot/imported/Revolver.gltf-1c0c2c3864f727f53cf3435925795736.scn" path="res://.godot/imported/Revolver.gltf-1c0c2c3864f727f53cf3435925795736.scn"
[deps] [deps]

File diff suppressed because one or more lines are too long

View File

@@ -1,9 +0,0 @@
[gd_scene load_steps=2 format=3 uid="uid://p3r1q0d3ibmj"]
[ext_resource type="PackedScene" uid="uid://cnk2fusin4ewy" path="res://assets/Weapons/Gun/Revolver.gltf" id="1_gnlrs"]
[node name="Revolver" instance=ExtResource("1_gnlrs")]
transform = Transform3D(0.05, 0, 0, 0, 0.0499999, 0, 0, 0, 0.0499999, 0, 0, 0)
[node name="RootNode" parent="." index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.30501, 7.01204)

View File

@@ -1,17 +0,0 @@
[gd_scene load_steps=3 format=3 uid="uid://gnhgkfm3frvt"]
[ext_resource type="Script" path="res://player_q3/Weapon.gd" id="1_2cfte"]
[ext_resource type="PackedScene" uid="uid://p3r1q0d3ibmj" path="res://player_q3/Revolver.tscn" id="1_81137"]
[node name="RevolverFix" type="Node3D"]
script = ExtResource("1_2cfte")
MOMENTUM = Vector2(-0.08, -0.25)
ANGULAR_MOMENTUM = Vector3(-12, 7, 10)
RECOIL_COOLDOWN = 0.35
RPM = 600.0
[node name="Revolver" parent="." instance=ExtResource("1_81137")]
transform = Transform3D(0.05, 0, 0, 0, 0.017101, -0.0469845, 0, 0.0469845, 0.017101, 0, -0.526001, -0.296439)
[node name="Revolver" parent="Revolver" instance=ExtResource("1_81137")]
transform = Transform3D(0.05, 0, 0, 0, 0.0259061, 0.0427652, 0, -0.0427652, 0.0259061, 0.00365943, 0.222644, -0.251306)

View File

@@ -9,20 +9,36 @@
config_version=5 config_version=5
_global_script_classes=[{ _global_script_classes=[{
"base": "RefCounted",
"class": &"SfxrGenerator",
"language": &"GDScript",
"path": "res://addons/godot_sfxr/SfxrGenerator.gd"
}, {
"base": "Object",
"class": &"SfxrGlobals",
"language": &"GDScript",
"path": "res://addons/godot_sfxr/SfxrGlobals.gd"
}, {
"base": "Object",
"class": &"SfxrStreamPlayerInterface",
"language": &"GDScript",
"path": "res://addons/godot_sfxr/SfxrStreamPlayerInterface.gd"
}, {
"base": "Node3D", "base": "Node3D",
"class": &"Weapon", "class": &"Weapon",
"language": &"GDScript", "language": &"GDScript",
"path": "res://player_q3/Weapon.gd" "path": "res://scripts/player/Weapon.gd"
}] }]
_global_script_class_icons={ _global_script_class_icons={
"SfxrGenerator": "",
"SfxrGlobals": "",
"SfxrStreamPlayerInterface": "",
"Weapon": "" "Weapon": ""
} }
[application] [application]
config/name="Simple Q3 Controller" config/name="Scoom"
config/description="Made by @fossegutten
Movement inspired by Quake3, simplified and godotified."
run/main_scene="res://Game.tscn" run/main_scene="res://Game.tscn"
config/features=PackedStringArray("4.0") config/features=PackedStringArray("4.0")
config/icon="res://textures/icon.png" config/icon="res://textures/icon.png"
@@ -35,6 +51,10 @@ window/size/height=360
window/size/test_width=1280 window/size/test_width=1280
window/size/test_height=720 window/size/test_height=720
[editor_plugins]
enabled=PackedStringArray("res://addons/godot_sfxr/plugin.cfg")
[input] [input]
move_left={ move_left={
@@ -67,6 +87,16 @@ shoot={
"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(289, 25),"global_position":Vector2(293, 70),"factor":1.0,"button_index":1,"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(289, 25),"global_position":Vector2(293, 70),"factor":1.0,"button_index":1,"pressed":true,"double_click":false,"script":null)
] ]
} }
wheel_up={
"deadzone": 0.5,
"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":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":4,"pressed":false,"double_click":false,"script":null)
]
}
wheel_down={
"deadzone": 0.5,
"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":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":5,"pressed":false,"double_click":false,"script":null)
]
}
[physics] [physics]

File diff suppressed because one or more lines are too long

View File

@@ -1,8 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://c65plp2c8ms4"] [gd_scene load_steps=4 format=3 uid="uid://bl7jynld7s25o"]
[ext_resource type="Script" path="res://player_q3/PlayerQ3.gd" id="1"] [ext_resource type="Script" path="res://scripts/player/PlayerQ3.gd" id="1"]
[ext_resource type="Script" path="res://player_q3/Weapons.gd" id="2_dl1i1"] [ext_resource type="Script" path="res://scripts/player/Weapons.gd" id="2_dl1i1"]
[ext_resource type="PackedScene" uid="uid://gnhgkfm3frvt" path="res://player_q3/RevolverFix.tscn" id="3_hj857"]
[sub_resource type="CylinderShape3D" id="1"] [sub_resource type="CylinderShape3D" id="1"]
@@ -17,10 +16,11 @@ shape = SubResource("1")
[node name="Head" type="Node3D" parent="Body"] [node name="Head" type="Node3D" parent="Body"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.75, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.75, 0)
script = ExtResource("2_dl1i1")
[node name="RevolverFix" parent="Body/Head" instance=ExtResource("3_hj857")] [node name="Hand" type="Node3D" parent="Body/Head"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0.385807, -0.452879, -0.930275) script = ExtResource("2_dl1i1")
sway_left = Vector3(0, 0.1, 0)
sway_right = Vector3(0, -0.1, 0)
[node name="Camera3D" type="Camera3D" parent="Body/Head"] [node name="Camera3D" type="Camera3D" parent="Body/Head"]
current = true current = true

View File

@@ -1,12 +1,11 @@
extends Node3D extends Node3D
var weapons = []
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
weapons.append($RevolverFix as Weapon) pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
if Input.is_action_pressed("shoot"): pass
weapons[0].Shoot()

View File

@@ -0,0 +1,13 @@
[gd_scene load_steps=2 format=3 uid="uid://p3r1q0d3ibmj"]
[ext_resource type="PackedScene" uid="uid://beiad4ywiojba" path="res://assets/Weapons/Gun/Revolver.gltf" id="1_j6rkf"]
[node name="Revolver" instance=ExtResource("1_j6rkf")]
transform = Transform3D(0.05, 0, 0, 0, 0.017101, -0.0469845, 0, 0.0469845, 0.017101, 0, -0.5, -0.3)
[node name="RootNode" parent="." index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.30501, 7.01204)
[node name="Cube011" parent="RootNode" index="0"]
cast_shadow = 0
gi_lightmap_scale = 2

View File

@@ -10,26 +10,33 @@ const DRAW_TIME = 0.35
#TODO: Load gun config from file #TODO: Load gun config from file
@export var MAX_CLIP = 5 var MAX_CLIP : int
@export var DAMAGE = 25 var DAMAGE : float
@export var MOMENTUM : Vector2 var MOMENTUM : Vector2
@export var ANGULAR_MOMENTUM : Vector3 var ANGULAR_MOMENTUM : Vector3
@export var RECOIL_COOLDOWN : float var RECOIL_COOLDOWN : float
@export var RPM: float var RPM: float
var DRAW_POS : Vector3
var DRAW_ROT : Vector3
var MODEL : Node3D
var FIREMODE : int
var SHOOTING_SPEED: float var SHOOTING_SPEED: float
var can_shoot : bool
var clip = 444444 var clip = 444444
var state = DEFAULT var state = DEFAULT
func _ready(): func init():
visible = true
SHOOTING_SPEED = 60.0 / RPM SHOOTING_SPEED = 60.0 / RPM
var tween = create_tween() var tween = create_tween()
MODEL.position = DRAW_POS
MODEL.rotation = DRAW_ROT
tween.set_trans(Tween.TRANS_CIRC) tween.set_trans(Tween.TRANS_CIRC)
tween.set_ease(Tween.EASE_IN_OUT) tween.set_ease(Tween.EASE_IN_OUT)
can_shoot = true
tween.tween_callback(InitialPos).set_delay(DRAW_TIME) tween.tween_callback(InitialPos).set_delay(DRAW_TIME)
func InitialPos(): func InitialPos():
@@ -37,28 +44,34 @@ func InitialPos():
tween.set_trans(Tween.TRANS_CIRC) tween.set_trans(Tween.TRANS_CIRC)
tween.set_ease(Tween.EASE_IN_OUT) tween.set_ease(Tween.EASE_IN_OUT)
tween.set_parallel(true) tween.set_parallel(true)
tween.tween_property($Revolver, "position", Vector3.ZERO, RECOIL_COOLDOWN / 2) tween.tween_property(MODEL, "position", Vector3.ZERO, RECOIL_COOLDOWN / 2)
tween.tween_property($Revolver, "rotation", Vector3.ZERO, RECOIL_COOLDOWN / 2) tween.tween_property(MODEL, "rotation", Vector3.ZERO, RECOIL_COOLDOWN / 2)
tween.tween_callback(func(): state = INITIAL).set_delay(SHOOTING_SPEED / 2) tween.tween_callback(func(): state = INITIAL).set_delay(SHOOTING_SPEED / 2)
func Shoot(): func Shoot():
if clip > 0 && state == INITIAL: if clip > 0 && state == INITIAL && can_shoot:
if !FIREMODE:
can_shoot = false
clip -= 1 clip -= 1
state = SHOOT; state = SHOOT;
var tween = create_tween() var tween = create_tween()
tween.set_trans(Tween.TRANS_ELASTIC) tween.set_trans(Tween.TRANS_ELASTIC)
tween.set_ease(Tween.EASE_OUT) tween.set_ease(Tween.EASE_OUT)
tween.set_parallel(true) tween.set_parallel(true)
tween.tween_property($Revolver, "position", Vector3(.0, MOMENTUM.x, MOMENTUM.y), RECOIL_COOLDOWN / 2) tween.tween_property(MODEL, "position", Vector3(.0, MOMENTUM.x, MOMENTUM.y), RECOIL_COOLDOWN / 2)
var rand_rot_y = randi_range(-ANGULAR_MOMENTUM.y,ANGULAR_MOMENTUM.y) var rand_rot_y = randi_range(-ANGULAR_MOMENTUM.y,ANGULAR_MOMENTUM.y)
var rand_rot_z = randi_range(-ANGULAR_MOMENTUM.z,ANGULAR_MOMENTUM.z) var rand_rot_z = randi_range(-ANGULAR_MOMENTUM.z,ANGULAR_MOMENTUM.z)
tween.tween_property($Revolver, "rotation", Vector3(deg_to_rad(ANGULAR_MOMENTUM.x),deg_to_rad(rand_rot_y),deg_to_rad(rand_rot_z)),RECOIL_COOLDOWN /2) tween.tween_property(MODEL, "rotation", Vector3(deg_to_rad(ANGULAR_MOMENTUM.x),deg_to_rad(rand_rot_y),deg_to_rad(rand_rot_z)),RECOIL_COOLDOWN /2)
tween.tween_callback(InitialPos).set_delay(SHOOTING_SPEED / 2) tween.tween_callback(InitialPos).set_delay(SHOOTING_SPEED / 2)
return true return true
return false return false
func Release():
if !FIREMODE:
can_shoot = true
func Reload(): func Reload():
if(clip < MAX_CLIP && state == INITIAL): if(clip < MAX_CLIP && state == INITIAL):

122
scripts/player/Weapons.gd Normal file
View File

@@ -0,0 +1,122 @@
extends Node3D
const CONFIG_PATH = "user://weapons.scoom"
const REVOLVER = 0
const REST = 0
const BOB = 1
var state = 0
@onready var player_root = get_node("../../../../PlayerQ3") as CharacterBody3D
var weapons = []
var current_weapon = 0
var file_data = {
REVOLVER:
{
"HAND_POS": Vector3(0.4,-0.45,-1),
"HAND_ROT": Vector3(0,PI,0),
"MODEL": "Revolver",
"MAX_CLIP": 5,
"DAMAGE": 25,
"MOMENTUM": Vector2(0.3, -0.25),
"ANGULAR_MOMENTUM": Vector3(-60, 7, 10),
"RECOIL_COOLDOWN": 0.35,
"RPM": 120,
"DRAW_POS": Vector3(0,-0.5,-0.3),
"DRAW_ROT": Vector3(1.3, 0, 0)
}
}
var mouse_mov : Vector3
var sway_threshold = 5
var sway_lerp = 5
@export var sway_left : Vector3
@export var sway_right : Vector3
@export var sway_normal : Vector3
func _ready():
save_data(file_data)
load_data()
for i in range(0, file_data.size()):
var root = Weapon.new()
root.name = str(i)
var resource = "res://scenes/weapons/" + file_data[i].MODEL + ".tscn"
var weapon_model_resource = load(resource)
var weapon_model = weapon_model_resource.instantiate()
root.add_child(weapon_model)
root.position = file_data[i].HAND_POS
root.rotation = file_data[i].HAND_ROT
root.hide()
add_child(root)
root.MAX_CLIP = file_data[i].MAX_CLIP
root.DAMAGE = file_data[i].DAMAGE
root.MOMENTUM = file_data[i].MOMENTUM
root.ANGULAR_MOMENTUM = file_data[i].ANGULAR_MOMENTUM
root.RECOIL_COOLDOWN = file_data[i].RECOIL_COOLDOWN
root.RPM = file_data[i].RPM
root.MODEL = root.get_node(file_data[i].MODEL)
root.DRAW_POS = file_data[i].DRAW_POS
root.DRAW_ROT = file_data[i].DRAW_ROT
weapons.append(root)
weapons[current_weapon].init()
func _input(event):
if event is InputEventMouseMotion:
mouse_mov.y = clampf(-event.relative.x, -0.1, 0.1)
mouse_mov.x = clampf(event.relative.y, -0.1, 0.1)
func _unhandled_input(_event):
if weapons.size() > 1 && Input.is_action_just_released("wheel_up"):
weapons[current_weapon].hide()
current_weapon = (current_weapon + 1) % weapons.size()
weapons[current_weapon].init()
if weapons.size() > 1 && Input.is_action_just_released("wheel_down"):
weapons[current_weapon].hide()
current_weapon = (current_weapon - 1) % weapons.size()
weapons[current_weapon].init()
var time = 0
func _process(delta):
if Input.is_action_pressed("shoot"):
weapons[current_weapon].Shoot()
if Input.is_action_just_released("shoot"):
weapons[current_weapon].Release()
#SWAY
if mouse_mov != null && mouse_mov.length() > 0:
weapons[current_weapon].MODEL.rotation = weapons[current_weapon].MODEL.rotation.lerp(mouse_mov, sway_lerp * delta)
mouse_mov = Vector3.ZERO
else:
weapons[current_weapon].MODEL.rotation = weapons[current_weapon].MODEL.rotation.lerp(Vector3.ZERO, sway_lerp * delta)
#BOB
if player_root.velocity.length() > 0:
time += delta
var bobOscillate = sin(time * 4 * (2 * PI)) * 0.01
position.y = bobOscillate
bobOscillate = sin(time * 4 * (PI) + PI/4) * 0.015
position.x = bobOscillate
#else:
#position = lerp(position, Vector3.ZERO, )
func save_data(data):
var file = FileAccess.open(CONFIG_PATH, FileAccess.WRITE)
file.store_var(data)
func load_data():
var file = FileAccess.open(CONFIG_PATH, FileAccess.READ)
var data = file.get_var()
file_data = data