mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-01-19 19:44:46 +00:00
🚚 move weapons to entities
This commit is contained in:
parent
88f7fcdeae
commit
99d47b6c20
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
[ext_resource type="PackedScene" uid="uid://4naw661fqmjg" path="res://entities/player/assets/vanguard.glb" id="1_d2ik6"]
|
||||
[ext_resource type="Script" path="res://entities/player/assets/vanguard.gd" id="2_c22xr"]
|
||||
[ext_resource type="PackedScene" uid="uid://clq4uym4arpv3" path="res://weapons/space_gun/assets/SpaceGun.glb" id="2_elp0s"]
|
||||
[ext_resource type="PackedScene" uid="uid://clq4uym4arpv3" path="res://entities/weapons/space_gun/assets/SpaceGun.glb" id="2_elp0s"]
|
||||
|
||||
[sub_resource type="Animation" id="Animation_a1qf3"]
|
||||
resource_name = "t_pose"
|
||||
|
|
|
|||
|
|
@ -12,8 +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/>.
|
||||
extends Node3D
|
||||
class_name SpaceGun
|
||||
class_name SpaceGun extends Node3D
|
||||
|
||||
@export var PROJECTILE : PackedScene
|
||||
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -1,45 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="scene"
|
||||
importer_version=1
|
||||
type="PackedScene"
|
||||
uid="uid://clq4uym4arpv3"
|
||||
path="res://.godot/imported/SpaceGun.glb-ee1e940c9dd77150eaf36c6537feefef.scn"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://weapons/space_gun/assets/SpaceGun.glb"
|
||||
dest_files=["res://.godot/imported/SpaceGun.glb-ee1e940c9dd77150eaf36c6537feefef.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={
|
||||
"materials": {
|
||||
"_defaultMat": {
|
||||
"use_external/enabled": true,
|
||||
"use_external/path": ""
|
||||
},
|
||||
"dark": {
|
||||
"use_external/enabled": true,
|
||||
"use_external/path": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
gltf/naming_version=1
|
||||
gltf/embedded_image_handling=2
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 364 KiB |
|
|
@ -1,35 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://cvtqt0k2ewd07"
|
||||
path.s3tc="res://.godot/imported/albedo.png-7f543d432ab75668956abd5bcc51a13b.s3tc.ctex"
|
||||
metadata={
|
||||
"imported_formats": ["s3tc_bptc"],
|
||||
"vram_texture": true
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://weapons/space_gun/assets/albedo.png"
|
||||
dest_files=["res://.godot/imported/albedo.png-7f543d432ab75668956abd5bcc51a13b.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
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
[gd_resource type="ShaderMaterial" format=3 uid="uid://de6t4olk7hrs1"]
|
||||
|
||||
[resource]
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 364 KiB |
|
|
@ -1,34 +0,0 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://b30y3pq4u5r0h"
|
||||
path="res://.godot/imported/albedo0.png-8dedb9e51f95ee8e69f9a00bccf9fb16.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://weapons/space_gun/assets/textures/albedo0.png"
|
||||
dest_files=["res://.godot/imported/albedo0.png-8dedb9e51f95ee8e69f9a00bccf9fb16.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
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
# 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 Projectile extends Node3D
|
||||
|
||||
@export_category("Parameters")
|
||||
@export var EXPLOSION : PackedScene
|
||||
@export var speed : float = 78.4 # m/s
|
||||
@export var lifespan : float = 5.0 # in seconds
|
||||
|
||||
@onready var shape_cast = $ShapeCast3D
|
||||
@onready var game = get_tree().get_current_scene()
|
||||
|
||||
var velocity : Vector3 = Vector3.ZERO
|
||||
|
||||
func _ready():
|
||||
var lifespan_timer = Timer.new()
|
||||
lifespan_timer.wait_time = lifespan
|
||||
lifespan_timer.one_shot = true
|
||||
lifespan_timer.autostart = true
|
||||
lifespan_timer.timeout.connect(self_destruct)
|
||||
add_child(lifespan_timer)
|
||||
|
||||
func self_destruct():
|
||||
explode(position)
|
||||
|
||||
func explode(spawn_location):
|
||||
var spawned_explosion = EXPLOSION.instantiate()
|
||||
spawned_explosion.position = spawn_location
|
||||
game.add_child(spawned_explosion)
|
||||
queue_free()
|
||||
|
||||
func _physics_process(delta):
|
||||
var previous_position = global_position
|
||||
global_position += velocity * delta
|
||||
shape_cast.target_position = to_local(previous_position)
|
||||
if shape_cast.is_colliding():
|
||||
var contact_point = shape_cast.collision_result[0].point
|
||||
explode(contact_point)
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://dn1tcakam5egs"]
|
||||
|
||||
[ext_resource type="Script" path="res://weapons/space_gun/projectile.gd" id="1_4j1dp"]
|
||||
[ext_resource type="PackedScene" uid="uid://8atq41j7wd55" path="res://weapons/space_gun/projectile_explosion.tscn" id="2_llml6"]
|
||||
[ext_resource type="Script" path="res://weapons/space_gun/projectile_trail.gd" id="3_ygqbh"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_4a265"]
|
||||
transparency = 1
|
||||
blend_mode = 1
|
||||
cull_mode = 2
|
||||
shading_mode = 0
|
||||
vertex_color_use_as_albedo = true
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_o6j55"]
|
||||
albedo_color = Color(0, 0.498039, 0.854902, 1)
|
||||
emission_enabled = true
|
||||
emission = Color(0.482353, 0.65098, 1, 1)
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_umtte"]
|
||||
radius = 0.15
|
||||
|
||||
[node name="Projectile" type="Node3D"]
|
||||
script = ExtResource("1_4j1dp")
|
||||
EXPLOSION = ExtResource("2_llml6")
|
||||
|
||||
[node name="Trail3D" type="MeshInstance3D" parent="."]
|
||||
material_override = SubResource("StandardMaterial3D_4a265")
|
||||
script = ExtResource("3_ygqbh")
|
||||
_from_width = 0.15
|
||||
_scale_acceleration = 0.5
|
||||
_lifespan = 0.25
|
||||
_start_color = Color(0, 0.498039, 0.854902, 1)
|
||||
_end_color = Color(1, 1, 1, 0)
|
||||
|
||||
[node name="Mesh" type="CSGSphere3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.2, 0, 0, 0, 1, 0, 0, 0)
|
||||
radius = 0.15
|
||||
radial_segments = 24
|
||||
rings = 8
|
||||
material = SubResource("StandardMaterial3D_o6j55")
|
||||
|
||||
[node name="ShapeCast3D" type="ShapeCast3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.2, 0, 0, 0, 1, 0, 0, 0)
|
||||
shape = SubResource("SphereShape3D_umtte")
|
||||
target_position = Vector3(0, 0, 0)
|
||||
margin = 0.1
|
||||
max_results = 1
|
||||
collision_mask = 2147483649
|
||||
debug_shape_custom_color = Color(1, 0, 0, 1)
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
# 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/>.
|
||||
extends Node3D
|
||||
|
||||
@onready var fire = $Fire
|
||||
@onready var explosive_damage : ExplosiveDamageComponent = $ExplosiveDamageComponent
|
||||
var explosion_effect_pending : bool = false
|
||||
|
||||
func _ready():
|
||||
fire.emitting = true
|
||||
fire.finished.connect(func(): queue_free())
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
[gd_scene load_steps=9 format=3 uid="uid://8atq41j7wd55"]
|
||||
|
||||
[ext_resource type="Script" path="res://weapons/space_gun/projectile_explosion.gd" id="1_fp5td"]
|
||||
[ext_resource type="PackedScene" uid="uid://ds1hekx1dq1bg" path="res://components/explosive_damage_component.tscn" id="2_d4sf4"]
|
||||
|
||||
[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]
|
||||
point_count = 2
|
||||
|
||||
[sub_resource type="CurveTexture" id="CurveTexture_08dbu"]
|
||||
curve = SubResource("Curve_rg204")
|
||||
|
||||
[sub_resource type="ParticleProcessMaterial" id="ParticleProcessMaterial_3mf41"]
|
||||
spread = 180.0
|
||||
initial_velocity_min = 12.0
|
||||
initial_velocity_max = 12.0
|
||||
scale_curve = SubResource("CurveTexture_08dbu")
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_wpu51"]
|
||||
albedo_color = Color(0.819608, 0, 0, 1)
|
||||
emission_enabled = true
|
||||
emission = Color(1, 0.254902, 0.109804, 1)
|
||||
emission_energy_multiplier = 4.0
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_k3pnh"]
|
||||
material = SubResource("StandardMaterial3D_wpu51")
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_mlo2k"]
|
||||
radius = 5.0
|
||||
|
||||
[node name="ProjectileExplosion" type="Node3D"]
|
||||
script = ExtResource("1_fp5td")
|
||||
|
||||
[node name="Fire" type="GPUParticles3D" parent="."]
|
||||
emitting = false
|
||||
amount = 24
|
||||
lifetime = 0.5
|
||||
one_shot = true
|
||||
explosiveness = 1.0
|
||||
fixed_fps = 60
|
||||
process_material = SubResource("ParticleProcessMaterial_3mf41")
|
||||
draw_pass_1 = SubResource("SphereMesh_k3pnh")
|
||||
|
||||
[node name="ExplosiveDamageComponent" parent="." instance=ExtResource("2_d4sf4")]
|
||||
damage = 35
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="ExplosiveDamageComponent"]
|
||||
shape = SubResource("SphereShape3D_mlo2k")
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
# 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 Trail3D extends MeshInstance3D
|
||||
|
||||
var _points = [] # 3D points of trail
|
||||
var _widths = [] # Calculated widths of trail
|
||||
var _lifespans = [] # Trail point lifespans
|
||||
|
||||
@export var _trail_enabled : bool = true # Is trail shown?
|
||||
|
||||
@export var _from_width : float = 0.5 # Starting width
|
||||
@export var _to_width : float = 0.0 # Ending width
|
||||
|
||||
@export_range(0.5, 1.5) var _scale_acceleration : float = 1.0 # Scaling speed
|
||||
|
||||
@export var _motion_delta : float = 0.1 # Smoothness of trail
|
||||
@export var _lifespan : float = 1.0 # Duration of trail
|
||||
|
||||
@export var _start_color : Color = Color(1.0, 1.0, 1.0, 1.0) # Start color
|
||||
@export var _end_color : Color = Color(1.0, 1.0, 1.0, 1.0) # End color
|
||||
|
||||
var _old_pos : Vector3 # Previous pos
|
||||
|
||||
func _append_point():
|
||||
_points.append(get_global_transform().origin)
|
||||
_widths.append([
|
||||
get_global_transform().basis.x * _from_width,
|
||||
get_global_transform().basis.x * _from_width - get_global_transform().basis.x * _to_width
|
||||
])
|
||||
_lifespans.append(0.0)
|
||||
|
||||
func _remove_point(i):
|
||||
_points.remove_at(i)
|
||||
_widths.remove_at(i)
|
||||
_lifespans.remove_at(i)
|
||||
|
||||
func _ready():
|
||||
_old_pos = get_global_transform().origin
|
||||
mesh = ImmediateMesh.new()
|
||||
|
||||
func _process(delta):
|
||||
if(_old_pos - get_global_transform().origin).length() > _motion_delta and _trail_enabled:
|
||||
_append_point() # Create new point
|
||||
_old_pos = get_global_transform().origin # Update previous position to current position coordinates
|
||||
|
||||
# Update the lifespan
|
||||
var p = 0
|
||||
var max_points = _points.size()
|
||||
while p < max_points:
|
||||
_lifespans[p] += delta
|
||||
if _lifespans[p] > _lifespan:
|
||||
_remove_point(p)
|
||||
p -= 1
|
||||
if (p < 0): p = 0
|
||||
|
||||
max_points = _points.size()
|
||||
p += 1
|
||||
|
||||
mesh.clear_surfaces()
|
||||
|
||||
# If less than 2 points, stop rendering trail
|
||||
if _points.size() < 2:
|
||||
return
|
||||
|
||||
# Render new mesh for each point
|
||||
mesh.surface_begin(Mesh.PRIMITIVE_TRIANGLE_STRIP)
|
||||
|
||||
for i in range(_points.size()):
|
||||
var t = float(i) / (_points.size() - 1.0)
|
||||
var curr_color = _start_color.lerp(_end_color, 1 - t)
|
||||
mesh.surface_set_color(curr_color)
|
||||
|
||||
var curr_width = _widths[i][0] - pow(1 - t, _scale_acceleration) * _widths[i][1]
|
||||
|
||||
var t0 = i / _points.size()
|
||||
var t1 = t
|
||||
|
||||
mesh.surface_set_uv(Vector2(t0, 0))
|
||||
mesh.surface_add_vertex(to_local(_points[i] + curr_width))
|
||||
mesh.surface_set_uv(Vector2(t1, 1))
|
||||
mesh.surface_add_vertex(to_local(_points[i] - curr_width))
|
||||
mesh.surface_end()
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
# 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/>.
|
||||
extends Node3D
|
||||
class_name SpaceGun
|
||||
|
||||
@export var PROJECTILE : PackedScene
|
||||
|
||||
@onready var nozzle = $Nozzle
|
||||
@onready var inventory = get_parent()
|
||||
|
||||
enum WeaponState { WEAPON_READY, WEAPON_RELOADING }
|
||||
|
||||
var weapon_state : WeaponState = WeaponState.WEAPON_READY
|
||||
|
||||
const inheritance : float = .5 # ratio
|
||||
const reload_time : float = 1. # seconds
|
||||
|
||||
func can_fire():
|
||||
return weapon_state == WeaponState.WEAPON_READY
|
||||
|
||||
func fire_primary():
|
||||
if not can_fire():
|
||||
return
|
||||
|
||||
var projectile = PROJECTILE.instantiate()
|
||||
projectile.transform = nozzle.global_transform
|
||||
projectile.velocity = nozzle.global_basis.z.normalized() * projectile.speed
|
||||
var inheritance_factor = clamp(inheritance, 0., 1.)
|
||||
projectile.velocity += (inventory.owner.linear_velocity * inheritance_factor)
|
||||
inventory.owner.add_sibling(projectile)
|
||||
var collider = projectile.shape_cast
|
||||
collider.add_exception(inventory.owner)
|
||||
weapon_state = WeaponState.WEAPON_RELOADING
|
||||
await get_tree().create_timer(reload_time).timeout
|
||||
weapon_state = WeaponState.WEAPON_READY
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue