Inventory, Weapons and refactoring

This commit is contained in:
anyreso 2024-05-07 14:21:10 +00:00
parent fa3e1f8d22
commit 39a9200e58
74 changed files with 1812 additions and 3895 deletions

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,34 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://cumv8wij5uufk"
path="res://.godot/imported/chaingun.glb-16cef2303c058492773f5f33b566245e.scn"
[deps]
source_file="res://entities/weapons/chaingun/assets/chaingun.glb"
dest_files=["res://.godot/imported/chaingun.glb-16cef2303c058492773f5f33b566245e.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1

View file

@ -0,0 +1,17 @@
[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://dkyb51bkvgamw"]
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_343cd"]
load_path = "res://.godot/imported/Flare00.png-75515c1e8df86aba86a9e55bb8ca7901.s3tc.ctex"
[resource]
transparency = 1
cull_mode = 2
shading_mode = 0
vertex_color_use_as_albedo = true
albedo_color = Color(0.860369, 0.860369, 0.860369, 1)
albedo_texture = SubResource("CompressedTexture2D_343cd")
billboard_mode = 3
billboard_keep_scale = true
particles_anim_h_frames = 1
particles_anim_v_frames = 1
particles_anim_loop = false

View file

@ -0,0 +1,27 @@
[gd_resource type="ParticleProcessMaterial" load_steps=5 format=3 uid="uid://drjuqikmi1uth"]
[sub_resource type="Gradient" id="Gradient_4bco7"]
offsets = PackedFloat32Array(0.00806452, 1)
colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 0)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_gtja2"]
gradient = SubResource("Gradient_4bco7")
[sub_resource type="Curve" id="Curve_d0rrq"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(0.980263, 0), 0.0, 0.0, 0, 0]
point_count = 2
[sub_resource type="CurveTexture" id="CurveTexture_5xpsc"]
curve = SubResource("Curve_d0rrq")
[resource]
lifetime_randomness = 1.0
emission_shape = 1
emission_sphere_radius = 0.3
spread = 180.0
gravity = Vector3(0, -2, 0)
scale_min = 0.75
scale_max = 1.5
scale_curve = SubResource("CurveTexture_5xpsc")
color = Color(5, 2, 1, 1)
color_ramp = SubResource("GradientTexture1D_gtja2")

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,34 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://bf7v57agnxtcp"
path="res://.godot/imported/tracer.glb-49c5c0f531fb5d373b2273b8c055ba52.scn"
[deps]
source_file="res://entities/weapons/chaingun/assets/tracer.glb"
dest_files=["res://.godot/imported/tracer.glb-49c5c0f531fb5d373b2273b8c055ba52.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1

View file

@ -0,0 +1,44 @@
# This file is part of open-fpsz.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
class_name ChainGun extends Node3D
@export_range(0, 250) var ammo : int = 250
@export var fire_rate : float = .1 # seconds
@export var reload_time : float = 0. # seconds
@export_category("Animations")
@export var anim_player : AnimationPlayer
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
func trigger() -> void:
# play the fire animation
anim_player.play("fire")
# init projectile
var projectile : Node3D = $ProjectileSpawner.new_projectile(
ChainGunProjectile,
owner.linear_velocity,
owner.match_participant_component
)
# add to owner of player for now
GameManager.mode.add_child(projectile)
projectile.shape_cast.add_exception(owner)
func _on_visibility_changed() -> void:
if self.visible:
anim_player.play("equip")
#self.sounds.play("equip")

View file

@ -0,0 +1,45 @@
[gd_scene load_steps=5 format=3 uid="uid://b0xql5hi0b52y"]
[ext_resource type="PackedScene" uid="uid://cumv8wij5uufk" path="res://entities/weapons/chaingun/assets/chaingun.glb" id="1_d8tdv"]
[ext_resource type="Script" path="res://entities/weapons/chaingun/chaingun.gd" id="2_qsqeh"]
[ext_resource type="Script" path="res://entities/components/projectile_spawner.gd" id="3_knyrc"]
[ext_resource type="PackedScene" uid="uid://b0sfwgilfbpx5" path="res://entities/weapons/chaingun/projectile.tscn" id="4_p63ts"]
[node name="ChainGun" node_paths=PackedStringArray("anim_player") instance=ExtResource("1_d8tdv")]
script = ExtResource("2_qsqeh")
anim_player = NodePath("AnimationPlayer")
[node name="ProjectileSpawner" type="Marker3D" parent="." index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.124544, 0.476417)
script = ExtResource("3_knyrc")
PROJECTILE = ExtResource("4_p63ts")
inheritance = 1.0
[node name="Skeleton3D" parent="Armature" index="0"]
bones/1/rotation = Quaternion(3.09086e-08, 0.707107, 0.707107, 3.09086e-08)
bones/2/rotation = Quaternion(3.09086e-08, 0.707107, 0.707107, -3.09086e-08)
bones/3/rotation = Quaternion(3.09086e-08, 0.707107, 0.707107, -3.09086e-08)
[node name="BarrelsInner" parent="Armature/Skeleton3D" index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
[node name="BarrelsOuter" parent="Armature/Skeleton3D" index="1"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
[node name="Base" parent="Armature/Skeleton3D" index="2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
[node name="Grip" parent="Armature/Skeleton3D" index="3"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.692504, 1.30946)
[node name="AnimationPlayer" parent="." index="2"]
autoplay = "idle"
[node name="Barrels" type="BoneAttachment3D" parent="." index="3"]
transform = Transform3D(-1, 0, 8.74227e-08, 8.74227e-08, 0, 1, 0, 1, 0, -2.32831e-10, 0.692504, 0.756307)
bone_name = "barrels"
bone_idx = 1
use_external_skeleton = true
external_skeleton = NodePath("../Armature/Skeleton3D")
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]

View file

@ -0,0 +1,55 @@
# This file is part of open-fpsz.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
class_name ChainGunProjectile extends Node3D
@export var speed : float = 180. # m/s
@export var lifespan : float = .5 # in seconds
@export var build_up_time : float = .6 # seconds
var shooter : MatchParticipantComponent
var velocity : Vector3 = Vector3.ZERO
@onready var shape_cast : ShapeCast3D = $ShapeCast3D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
$Timer.wait_time = lifespan
func _on_timer_timeout() -> void:
queue_free()
func _physics_process(delta : float) -> void:
global_position += velocity * delta
if shape_cast.is_colliding():
for collision_id in shape_cast.get_collision_count():
var collider : Object = shape_cast.get_collider(collision_id)
if collider is Player:
if is_multiplayer_authority():
assert(shooter)
collider.health_component.damage.rpc(18, shooter.player_id, shooter.team_id)
queue_free()
## This method is a parameterized constructor for the [ChainGunProjectile] scene of the [ChainGun]
static func new_projectile(
origin : Marker3D,
inherited_velocity : Vector3,
_shooter : MatchParticipantComponent,
scene : PackedScene
) -> ChainGunProjectile:
var projectile : ChainGunProjectile = scene.instantiate()
projectile.shooter = _shooter
projectile.transform = origin.global_transform
projectile.velocity = origin.global_basis.z.normalized() * projectile.speed + inherited_velocity
return projectile

View file

@ -0,0 +1,25 @@
[gd_scene load_steps=4 format=3 uid="uid://b0sfwgilfbpx5"]
[ext_resource type="PackedScene" uid="uid://bf7v57agnxtcp" path="res://entities/weapons/chaingun/assets/tracer.glb" id="1_p7mmn"]
[ext_resource type="Script" path="res://entities/weapons/chaingun/projectile.gd" id="2_jjfwk"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_dbodg"]
radius = 0.2
height = 2.5
[node name="ChainGunProjectile" instance=ExtResource("1_p7mmn")]
script = ExtResource("2_jjfwk")
[node name="ShapeCast3D" type="ShapeCast3D" parent="." index="0"]
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 4.29628)
shape = SubResource("CapsuleShape3D_dbodg")
target_position = Vector3(0, -3, 0)
collision_mask = 2147483653
[node name="tracerinner" parent="." index="1"]
transform = Transform3D(0.0505494, 0, 0, 0, 0.0505494, 0, 0, 0, 0.0505494, 0, 0, 2.49628)
[node name="Timer" type="Timer" parent="." index="2"]
autostart = true
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]

View file

@ -0,0 +1,34 @@
[remap]
importer="scene"
importer_version=1
type="PackedScene"
uid="uid://bbp260t2qivxk"
path="res://.godot/imported/grenade_launcher.glb-a6b40e53ec47b6674efe99dda067cfdf.scn"
[deps]
source_file="res://entities/weapons/grenade_launcher/assets/models/grenade_launcher.glb"
dest_files=["res://.godot/imported/grenade_launcher.glb-a6b40e53ec47b6674efe99dda067cfdf.scn"]
[params]
nodes/root_type=""
nodes/root_name=""
nodes/apply_root_scale=true
nodes/root_scale=1.0
meshes/ensure_tangents=true
meshes/generate_lods=true
meshes/create_shadow_meshes=true
meshes/light_baking=1
meshes/lightmap_texel_size=0.2
meshes/force_disable_compression=false
skins/use_named_skins=true
animation/import=true
animation/fps=30
animation/trimming=false
animation/remove_immutable_tracks=true
import_script/path=""
_subresources={}
gltf/naming_version=1
gltf/embedded_image_handling=1

View file

@ -0,0 +1,13 @@
[gd_resource type="StandardMaterial3D" load_steps=2 format=3 uid="uid://bbqjhgs44rnss"]
[sub_resource type="CompressedTexture2D" id="CompressedTexture2D_uiuwk"]
load_path = "res://.godot/imported/Flare00.png-75515c1e8df86aba86a9e55bb8ca7901.s3tc.ctex"
[resource]
transparency = 1
cull_mode = 2
shading_mode = 0
vertex_color_use_as_albedo = true
albedo_color = Color(0.860369, 0.860369, 0.860369, 1)
albedo_texture = SubResource("CompressedTexture2D_uiuwk")
billboard_keep_scale = true

View file

@ -0,0 +1,27 @@
[gd_resource type="ParticleProcessMaterial" load_steps=5 format=3 uid="uid://c78xg30ynapmt"]
[sub_resource type="Gradient" id="Gradient_q75yo"]
offsets = PackedFloat32Array(0.00806452, 1)
colors = PackedColorArray(1, 1, 1, 0, 1, 1, 1, 0)
[sub_resource type="GradientTexture1D" id="GradientTexture1D_gt2l8"]
gradient = SubResource("Gradient_q75yo")
[sub_resource type="Curve" id="Curve_jt11q"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(0.980263, 0), 0.0, 0.0, 0, 0]
point_count = 2
[sub_resource type="CurveTexture" id="CurveTexture_nb67t"]
curve = SubResource("Curve_jt11q")
[resource]
lifetime_randomness = 1.0
emission_shape = 1
emission_sphere_radius = 0.3
spread = 180.0
gravity = Vector3(0, -2, 0)
scale_min = 0.75
scale_max = 1.5
scale_curve = SubResource("CurveTexture_nb67t")
color = Color(5, 2, 1, 1)
color_ramp = SubResource("GradientTexture1D_gt2l8")

View file

@ -0,0 +1,15 @@
[gd_resource type="ParticleProcessMaterial" load_steps=3 format=3 uid="uid://cykwajkj5aaqx"]
[sub_resource type="Curve" id="Curve_2oi53"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 2
[sub_resource type="CurveTexture" id="CurveTexture_ml1t5"]
curve = SubResource("Curve_2oi53")
[resource]
gravity = Vector3(0, 0, 0)
scale_min = 4.0
scale_max = 4.0
scale_curve = SubResource("CurveTexture_ml1t5")
color = Color(2.5, 1, 0.5, 1)

View file

@ -0,0 +1,31 @@
[gd_resource type="ParticleProcessMaterial" load_steps=5 format=3 uid="uid://v7s5w3uw4hmb"]
[sub_resource type="Curve" id="Curve_ei0ls"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 2
[sub_resource type="Curve" id="Curve_q68ud"]
max_value = 5.0
_data = [Vector2(0, 5), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 2
[sub_resource type="Curve" id="Curve_1s1qr"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 1), 0.0, 0.0, 0, 0]
point_count = 2
[sub_resource type="CurveXYZTexture" id="CurveXYZTexture_eoauk"]
curve_x = SubResource("Curve_ei0ls")
curve_y = SubResource("Curve_q68ud")
curve_z = SubResource("Curve_1s1qr")
[resource]
particle_flag_align_y = true
emission_shape = 1
emission_sphere_radius = 0.2
spread = 180.0
initial_velocity_min = 20.0
initial_velocity_max = 25.0
gravity = Vector3(0, -19.6, 0)
scale_min = 0.2
scale_curve = SubResource("CurveXYZTexture_eoauk")
color = Color(5, 2, 1, 1)

Binary file not shown.

After

Width:  |  Height:  |  Size: 406 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://df1te2nwndirs"
path="res://.godot/imported/Circle00.png-abb71ef9f4ed014b9c4576f63601e876.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://entities/weapons/grenade_launcher/assets/textures/Circle00.png"
dest_files=["res://.godot/imported/Circle00.png-abb71ef9f4ed014b9c4576f63601e876.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 KiB

View file

@ -0,0 +1,35 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://chchhrpwmho2c"
path.s3tc="res://.godot/imported/Flare00.png-75515c1e8df86aba86a9e55bb8ca7901.s3tc.ctex"
metadata={
"imported_formats": ["s3tc_bptc"],
"vram_texture": true
}
[deps]
source_file="res://entities/weapons/grenade_launcher/assets/textures/Flare00.png"
dest_files=["res://.godot/imported/Flare00.png-75515c1e8df86aba86a9e55bb8ca7901.s3tc.ctex"]
[params]
compress/mode=2
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=true
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=0

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://bt14yn3vctir"
path="res://.godot/imported/Flare01.png-4090d4d992d997383a0becd557b43261.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://entities/weapons/grenade_launcher/assets/textures/Flare01.png"
dest_files=["res://.godot/imported/Flare01.png-4090d4d992d997383a0becd557b43261.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -0,0 +1,38 @@
class_name GrenadeLauncherProjectileExplosion extends Node3D
## The component responsible for explosion damages
@export var explosive_damage : ExplosiveDamageComponent
## The component responsible for owner identification
var shooter : MatchParticipantComponent:
set(value):
shooter = value
explosive_damage.damage_dealer = value
## This is increment by 1 when a particle emitter is finished
var _finished_count : int = 0
## Called when the node enters the scene tree for the first time.
func _ready() -> void:
for child in $Particles.get_children():
child.emitting = true
child.finished.connect(_on_finished)
## This is called by children particle nodes to destruct our
## [GrenadeLauncherProjectileExplosion] once all emitters are finished
func _on_finished() -> void:
_finished_count += 1
if _finished_count == $Particles.get_child_count():
queue_free()
## This method is a static factory constructor for the
## [GrenadeLauncherProjectileExplosion] scene of the [GrenadeLauncherProjectile].
static func new_explosion(
origin : Vector3,
_shooter : MatchParticipantComponent,
scene : PackedScene
) -> GrenadeLauncherProjectileExplosion:
var explosion : GrenadeLauncherProjectileExplosion = scene.instantiate()
explosion.position = origin
explosion.shooter = _shooter
return explosion

View file

@ -0,0 +1,56 @@
[gd_scene load_steps=9 format=3 uid="uid://bb43ae1f5j8lw"]
[ext_resource type="Script" path="res://entities/weapons/grenade_launcher/explosion.gd" id="1_xb4jo"]
[ext_resource type="PackedScene" uid="uid://qb5sf7awdeui" path="res://entities/components/explosive_damage.tscn" id="2_rq8du"]
[ext_resource type="Material" uid="uid://v7s5w3uw4hmb" path="res://entities/weapons/grenade_launcher/assets/resources/particle_process_material_sparks.tres" id="3_4u6ue"]
[ext_resource type="Material" uid="uid://bbqjhgs44rnss" path="res://entities/weapons/grenade_launcher/assets/resources/material_flare.tres" id="4_634rq"]
[ext_resource type="Material" uid="uid://cykwajkj5aaqx" path="res://entities/weapons/grenade_launcher/assets/resources/particle_process_material_flash.tres" id="5_mntrp"]
[ext_resource type="Material" uid="uid://c78xg30ynapmt" path="res://entities/weapons/grenade_launcher/assets/resources/particle_process_material_fire.tres" id="6_s25g3"]
[sub_resource type="QuadMesh" id="QuadMesh_wt5ts"]
material = ExtResource("4_634rq")
[sub_resource type="QuadMesh" id="QuadMesh_mv2qw"]
material = ExtResource("4_634rq")
[node name="GrenadeLauncherProjectileExplosion" type="Node3D" node_paths=PackedStringArray("explosive_damage")]
script = ExtResource("1_xb4jo")
explosive_damage = NodePath("ExplosiveDamage")
[node name="ExplosiveDamage" parent="." instance=ExtResource("2_rq8du")]
[node name="Particles" type="Node3D" parent="."]
[node name="Sparks" type="GPUParticles3D" parent="Particles"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00311279, 0.0152655, -0.000196457)
emitting = false
amount = 20
lifetime = 0.3
one_shot = true
explosiveness = 1.0
fixed_fps = 60
process_material = ExtResource("3_4u6ue")
draw_pass_1 = SubResource("QuadMesh_wt5ts")
[node name="Flash" type="GPUParticles3D" parent="Particles"]
emitting = false
amount = 1
lifetime = 0.1
one_shot = true
explosiveness = 1.0
fixed_fps = 60
process_material = ExtResource("5_mntrp")
draw_pass_1 = SubResource("QuadMesh_mv2qw")
[node name="Fire" type="GPUParticles3D" parent="Particles"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.00311279, 0.0152655, -0.000196457)
emitting = false
amount = 13
lifetime = 0.55
one_shot = true
explosiveness = 1.0
fixed_fps = 60
process_material = ExtResource("6_s25g3")
draw_pass_1 = SubResource("QuadMesh_wt5ts")
[editable path="ExplosiveDamage"]

View file

@ -0,0 +1,29 @@
class_name GrenadeLauncher extends Node3D
@export_range(0, 24) var ammo : int = 24
@export var fire_rate : float = 1. # seconds
@export var reload_time : float = 1. # seconds
@export_category("Animations")
@export var anim_player : AnimationPlayer
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
func trigger() -> void:
# play the fire animation
anim_player.play("fire")
# init projectile
var projectile : Node3D = $ProjectileSpawner.new_projectile(
GrenadeLauncherProjectile,
owner.linear_velocity,
owner.match_participant_component
)
# add to owner of player for now
GameManager.mode.add_child(projectile)
func _on_visibility_changed() -> void:
if self.visible:
anim_player.play("equip")
#self.sounds.play("equip")

View file

@ -0,0 +1,27 @@
[gd_scene load_steps=5 format=3 uid="uid://cstl7yxc75572"]
[ext_resource type="PackedScene" uid="uid://bbp260t2qivxk" path="res://entities/weapons/grenade_launcher/assets/models/grenade_launcher.glb" id="1_keuur"]
[ext_resource type="Script" path="res://entities/weapons/grenade_launcher/grenade_launcher.gd" id="2_38xn3"]
[ext_resource type="PackedScene" uid="uid://dak767xehqa6x" path="res://entities/weapons/grenade_launcher/projectile.tscn" id="3_rg5nk"]
[ext_resource type="Script" path="res://entities/components/projectile_spawner.gd" id="4_5h5sw"]
[node name="GrenadeLauncher" node_paths=PackedStringArray("anim_player") instance=ExtResource("1_keuur")]
script = ExtResource("2_38xn3")
anim_player = NodePath("AnimationPlayer")
[node name="ProjectileSpawner" type="Node3D" parent="." index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1)
script = ExtResource("4_5h5sw")
PROJECTILE = ExtResource("3_rg5nk")
inheritance = 0.75
[node name="barrel" parent="Armature/Skeleton3D" index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.19209e-07, 0)
[node name="grip" parent="Armature/Skeleton3D" index="1"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.082471, -0.0653242)
[node name="main" parent="Armature/Skeleton3D" index="2"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.19209e-07, 0)
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]

View file

@ -0,0 +1,57 @@
# This file is part of open-fpsz.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
class_name GrenadeLauncherProjectile extends RigidBody3D
@export_category("Parameters")
@export var EXPLOSION : PackedScene
@export var collider : CollisionShape3D
@export var speed : float = 44. # m/s
@export var lifespan : float = 1.6 # in seconds
var shooter : MatchParticipantComponent
var pending_explosion : bool = false
## Called when the node enters the scene tree for the first time.
func _ready() -> void:
$Timer.wait_time = lifespan
$Timer.start()
## This method enable collision signals to be emitted when the lifespan timer
## is finished.
func _on_timer_timeout() -> void:
max_contacts_reported = 1
set_contact_monitor(true)
## This method is responsible for spawning the projectile explosion and freeing
## it when a collision is detected once the lifespan timer is finished.
func _on_body_entered(_body : Node) -> void:
var explosion : GrenadeLauncherProjectileExplosion = \
GrenadeLauncherProjectileExplosion.new_explosion(position, shooter, EXPLOSION)
add_sibling(explosion)
queue_free()
## This method is a static factory constructor for the [GrenadeLauncherProjectile]
## scene of the [GrenadeLauncher].
static func new_projectile(
origin : Node3D,
inherited_velocity : Vector3,
_shooter : MatchParticipantComponent,
scene : PackedScene
) -> GrenadeLauncherProjectile:
var projectile : GrenadeLauncherProjectile = scene.instantiate()
projectile.shooter = _shooter
projectile.transform = origin.global_transform
projectile.linear_velocity = origin.global_basis.z.normalized() * projectile.speed + inherited_velocity
return projectile

View file

@ -0,0 +1,46 @@
[gd_scene load_steps=7 format=3 uid="uid://dak767xehqa6x"]
[ext_resource type="Script" path="res://entities/weapons/grenade_launcher/projectile.gd" id="1_i8v2u"]
[ext_resource type="PackedScene" uid="uid://bb43ae1f5j8lw" path="res://entities/weapons/grenade_launcher/explosion.tscn" id="2_cxty7"]
[ext_resource type="Script" path="res://addons/smoothing/smoothing.gd" id="3_wyge0"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_r263x"]
rough = true
bounce = 0.5
[sub_resource type="SphereShape3D" id="SphereShape3D_kipwv"]
radius = 0.062
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_miu4v"]
albedo_color = Color(0.2, 0.2, 0.2, 1)
[node name="GrenadeLauncherProjectile" type="RigidBody3D" node_paths=PackedStringArray("collider")]
collision_layer = 2147483648
collision_mask = 2147483648
mass = 5.0
physics_material_override = SubResource("PhysicsMaterial_r263x")
continuous_cd = true
script = ExtResource("1_i8v2u")
EXPLOSION = ExtResource("2_cxty7")
collider = NodePath("CollisionShape3D")
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("SphereShape3D_kipwv")
[node name="Timer" type="Timer" parent="."]
one_shot = true
[node name="Smoothing" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.000792712, 0, -0.000432983)
script = ExtResource("3_wyge0")
flags = 3
[node name="Mesh" type="CSGSphere3D" parent="Smoothing"]
radius = 0.062
radial_segments = 24
rings = 12
material = SubResource("StandardMaterial3D_miu4v")
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="body_shape_entered" from="." to="." method="_on_body_shape_entered"]
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]

View file

@ -12,7 +12,7 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
class_name Projectile extends Node3D
class_name SpaceGunProjectile extends Node3D
@export_category("Parameters")
@export var EXPLOSION : PackedScene
@ -28,7 +28,6 @@ var velocity : Vector3 = Vector3.ZERO
var shooter : MatchParticipantComponent
func _ready() -> void:
assert(shooter)
var lifespan_timer : Timer = Timer.new()
lifespan_timer.wait_time = lifespan
lifespan_timer.one_shot = true
@ -45,12 +44,9 @@ func _ready() -> void:
func self_destruct() -> void:
explode(position)
func explode(spawn_location : Vector3) -> void:
var spawned_explosion : Node = EXPLOSION.instantiate()
spawned_explosion.position = spawn_location
spawned_explosion.shooter = shooter
game.add_child(spawned_explosion)
func explode(spawn_position : Vector3) -> void:
game.add_child(SpaceGunProjectileExplosion.new_explosion(spawn_position, shooter, EXPLOSION))
queue_free()
func _physics_process(delta : float) -> void:
@ -61,5 +57,18 @@ func _physics_process(delta : float) -> void:
var contact_point : Vector3 = shape_cast.collision_result[0].point
explode(contact_point)
## This method is a parameterized constructor for the [SpaceGunProjectile] scene of the [SpaceGun]
static func new_projectile(
origin : Marker3D,
inherited_velocity : Vector3,
_shooter : MatchParticipantComponent,
scene : PackedScene
) -> SpaceGunProjectile:
var projectile : SpaceGunProjectile = scene.instantiate()
projectile.shooter = _shooter
projectile.transform = origin.global_transform
projectile.velocity = origin.global_basis.z.normalized() * projectile.speed + inherited_velocity
return projectile
func _enable_trail() -> void:
projectile_trail._trail_enabled = true

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=8 format=3 uid="uid://dn1tcakam5egs"]
[ext_resource type="Script" path="res://entities/weapons/space_gun/projectile.gd" id="1_4j1dp"]
[ext_resource type="PackedScene" uid="uid://8atq41j7wd55" path="res://entities/weapons/space_gun/projectile_explosion.tscn" id="2_llml6"]
[ext_resource type="PackedScene" path="res://entities/weapons/space_gun/projectile_explosion.tscn" id="2_llml6"]
[ext_resource type="Script" path="res://addons/smoothing/smoothing.gd" id="3_dmi64"]
[ext_resource type="Script" path="res://entities/weapons/space_gun/projectile_trail.gd" id="3_ygqbh"]

View file

@ -12,16 +12,27 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
extends Node3D
class_name SpaceGunProjectileExplosion extends Node3D
var shooter : MatchParticipantComponent
@export var explosive_damage : ExplosiveDamageComponent
@onready var fire : GPUParticles3D = $Fire
@onready var explosive_damage : ExplosiveDamageComponent = $ExplosiveDamageComponent
var explosion_effect_pending : bool = false
var shooter : MatchParticipantComponent:
set(value):
shooter = value
assert(explosive_damage)
explosive_damage.damage_dealer = value
func _ready() -> void:
assert(shooter)
explosive_damage.damage_dealer = shooter
fire.emitting = true
fire.finished.connect(func() -> void: queue_free())
## This method is a parameterized constructor for the [SpaceGunProjectileExplosion] scene of the [SpaceGunProjectile]
static func new_explosion(spawn_position : Vector3, _shooter : MatchParticipantComponent, scene : PackedScene) -> SpaceGunProjectileExplosion:
var explosion : SpaceGunProjectileExplosion = scene.instantiate()
explosion.shooter = _shooter
explosion.position = spawn_position
return explosion

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=9 format=3 uid="uid://8atq41j7wd55"]
[gd_scene load_steps=8 format=3 uid="uid://8atq41j7wd55"]
[ext_resource type="Script" path="res://entities/weapons/space_gun/projectile_explosion.gd" id="1_fp5td"]
[ext_resource type="Script" path="res://entities/components/explosive_damage_component.gd" id="2_28ymv"]
[ext_resource type="PackedScene" uid="uid://qb5sf7awdeui" path="res://entities/components/explosive_damage.tscn" id="2_js0ht"]
[sub_resource type="Curve" id="Curve_rg204"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
@ -25,12 +25,9 @@ emission_energy_multiplier = 4.0
[sub_resource type="SphereMesh" id="SphereMesh_k3pnh"]
material = SubResource("StandardMaterial3D_wpu51")
[sub_resource type="SphereShape3D" id="SphereShape3D_nj68w"]
margin = 0.05
radius = 5.0
[node name="ProjectileExplosion" type="Node3D"]
[node name="ProjectileExplosion" type="Node3D" node_paths=PackedStringArray("explosive_damage")]
script = ExtResource("1_fp5td")
explosive_damage = NodePath("ExplosiveDamage")
[node name="Fire" type="GPUParticles3D" parent="."]
emitting = false
@ -42,8 +39,6 @@ fixed_fps = 60
process_material = SubResource("ParticleProcessMaterial_3mf41")
draw_pass_1 = SubResource("SphereMesh_k3pnh")
[node name="ExplosiveDamageComponent" type="Area3D" parent="."]
script = ExtResource("2_28ymv")
[node name="ExplosiveDamage" parent="." instance=ExtResource("2_js0ht")]
[node name="CollisionShape3D" type="CollisionShape3D" parent="ExplosiveDamageComponent"]
shape = SubResource("SphereShape3D_nj68w")
[editable path="ExplosiveDamage"]

View file

@ -12,45 +12,40 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
extends Node3D
class_name SpaceGun
class_name SpaceGun extends Node3D
@export var PROJECTILE : PackedScene
@export var holder : MatchParticipantComponent
@onready var nozzle : Node3D = $Nozzle
@onready var inventory : Node3D = get_parent()
@export var fire_rate : float = 1. # seconds
@export var reload_time : float = 1. # seconds
@export var anim_player : AnimationPlayer
enum WeaponState { WEAPON_READY, WEAPON_RELOADING }
var weapon_state : WeaponState = WeaponState.WEAPON_READY
const inheritance : float = .5 # ratio
const reload_time : float = 1. # seconds
var state : WeaponState = WeaponState.WEAPON_READY
func can_fire() -> bool:
return weapon_state == WeaponState.WEAPON_READY
return state == WeaponState.WEAPON_READY
func fire_primary() -> void:
func trigger() -> void:
# check permission
if not can_fire():
return
# init projectile
var projectile : Node = PROJECTILE.instantiate()
# configure projectile
projectile.shooter = holder
projectile.transform = nozzle.global_transform
projectile.velocity = nozzle.global_basis.z.normalized() * projectile.speed
var inheritance_factor : float = clamp(inheritance, 0., 1.)
projectile.velocity += (inventory.owner.linear_velocity * inheritance_factor)
# play the fire animation
$Mesh/AnimationPlayer.play("fire")
# add projectile as sibling of the owner
inventory.owner.add_sibling(projectile)
anim_player.play("fire")
var projectile : Node3D = $ProjectileSpawner.new_projectile(
SpaceGunProjectile,
owner.linear_velocity,
owner.match_participant_component
)
# add to owner of player for now
GameManager.mode.add_child(projectile)
# ensure projectile does not collide with owner
var collider : ShapeCast3D = projectile.shape_cast
collider.add_exception(inventory.owner)
collider.add_exception(owner)
# update states
weapon_state = WeaponState.WEAPON_RELOADING
state = WeaponState.WEAPON_RELOADING
await get_tree().create_timer(reload_time).timeout
weapon_state = WeaponState.WEAPON_READY
state = WeaponState.WEAPON_READY
func _on_visibility_changed() -> void:
if self.visible:
anim_player.play("equip")
#self.sounds.play("equip")

View file

@ -1,16 +1,23 @@
[gd_scene load_steps=4 format=3 uid="uid://c8co0qa2omjmh"]
[gd_scene load_steps=5 format=3 uid="uid://c8co0qa2omjmh"]
[ext_resource type="Script" path="res://entities/weapons/space_gun/space_gun.gd" id="1_6sm4s"]
[ext_resource type="PackedScene" uid="uid://dn1tcakam5egs" path="res://entities/weapons/space_gun/projectile.tscn" id="2_wvneg"]
[ext_resource type="PackedScene" uid="uid://bjcn37ops3bro" path="res://entities/weapons/space_gun/assets/disclauncher.glb" id="3_5k2xm"]
[ext_resource type="Script" path="res://entities/components/projectile_spawner.gd" id="3_ihk6g"]
[node name="SpaceGun" type="Node3D"]
[node name="SpaceGun" type="Node3D" node_paths=PackedStringArray("anim_player")]
script = ExtResource("1_6sm4s")
anim_player = NodePath("Mesh/AnimationPlayer")
[node name="ProjectileSpawner" type="Marker3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.27)
script = ExtResource("3_ihk6g")
PROJECTILE = ExtResource("2_wvneg")
[node name="Mesh" parent="." instance=ExtResource("3_5k2xm")]
[node name="Skeleton3D" parent="Mesh/Armature" index="0"]
bones/0/rotation = Quaternion(0.707107, -5.33851e-08, -5.33851e-08, 0.707107)
bones/0/scale = Vector3(1, 1, 1)
bones/1/rotation = Quaternion(-0.707107, 5.33851e-08, 5.33851e-08, 0.707107)
bones/1/scale = Vector3(1, 1, 1)
@ -20,15 +27,17 @@ bones/3/rotation = Quaternion(-0.707107, 5.33851e-08, 5.33851e-08, 0.707107)
bones/3/scale = Vector3(1, 1, 1)
[node name="grip" parent="Mesh/Armature/Skeleton3D" index="0"]
transform = Transform3D(1, -4.26326e-14, -2.13163e-14, 2.84217e-14, 1, -3.57628e-07, 3.2684e-14, 3.57628e-07, 1, -1.42109e-14, -2.98023e-07, 2.38419e-07)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.84217e-14, 1.19209e-07, 2.38419e-07)
[node name="main" parent="Mesh/Armature/Skeleton3D" index="1"]
transform = Transform3D(1, -4.26326e-14, -2.13163e-14, 2.84217e-14, 1, -3.57628e-07, 3.2684e-14, 3.57628e-07, 1, -1.42109e-14, -2.98023e-07, 2.38419e-07)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.84217e-14, 1.19209e-07, 2.38419e-07)
[node name="sides" parent="Mesh/Armature/Skeleton3D" index="2"]
transform = Transform3D(1, -4.26326e-14, -2.13163e-14, 2.84217e-14, 1, -3.57628e-07, 3.2684e-14, 3.57628e-07, 1, -1.42109e-14, -2.98023e-07, 2.38419e-07)
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 2.84217e-14, 1.19209e-07, 2.38419e-07)
[node name="Nozzle" type="Node3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.27)
[node name="AnimationPlayer" parent="Mesh" index="1"]
autoplay = "idle"
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
[editable path="Mesh"]