mirror of
https://gitlab.com/open-fpsz/open-fpsz.git
synced 2026-07-14 16:04:50 +00:00
👽 interstellar delivery
This commit is contained in:
parent
547c97bfba
commit
97c8292858
257 changed files with 7309 additions and 4637 deletions
31
entities/projectiles/arc_projectile.gd
Normal file
31
entities/projectiles/arc_projectile.gd
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# 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 ArcProjectile extends ExplosiveProjectile
|
||||
|
||||
var _g: float = ProjectSettings.get_setting("physics/3d/default_gravity") # in m/s²
|
||||
var _gravity: Vector3 = _g * ProjectSettings.get_setting("physics/3d/default_gravity_vector")
|
||||
|
||||
func _physics_process(delta : float) -> void:
|
||||
# compute motion
|
||||
var previous_global_position : Vector3 = global_position
|
||||
# apply gravity
|
||||
velocity += _gravity * delta
|
||||
# compute new position
|
||||
global_position += velocity * delta
|
||||
# handle collision
|
||||
if shape_cast:
|
||||
shape_cast.target_position = to_local(previous_global_position)
|
||||
if shape_cast.is_colliding():
|
||||
destroy(shape_cast.collision_result[0].point)
|
||||
63
entities/projectiles/damages/explosive_damage.gd
Normal file
63
entities/projectiles/damages/explosive_damage.gd
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# 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/>.
|
||||
## This class defines an explosive damage area.
|
||||
##
|
||||
## It detects nearby bodies within a radius defined by a child [CollisionShape3D]
|
||||
## or [CollisionPolygon3D] and also initiates a blast that applies impulse and
|
||||
## damages to detected bodies based on their distance from the explosion.
|
||||
class_name ExplosiveDamage extends Area3D
|
||||
|
||||
## The base amount of damage.
|
||||
@export var damage: int = 1
|
||||
## The magnitude of blast force, in Newtons.
|
||||
@export var blast_force: int = 1500
|
||||
## A factor that determines how damage decreases with distance from the explosion center.
|
||||
@export var falloff: Curve
|
||||
## The entity responsible for dealing damage.
|
||||
var source: Node = null
|
||||
# The number of physics frames to process for blast detection.
|
||||
var _blast_frames: int = 0
|
||||
|
||||
func _init() -> void:
|
||||
if not body_shape_entered.is_connected(_on_body_shape_entered):
|
||||
body_shape_entered.connect(_on_body_shape_entered)
|
||||
|
||||
# queue free area after processing few frames (enough for body detection)
|
||||
func _physics_process(_delta: float) -> void:
|
||||
_blast_frames += 1
|
||||
if _blast_frames >= 2:
|
||||
queue_free()
|
||||
|
||||
# overlapping bodies signal handler
|
||||
func _on_body_shape_entered(_body_rid: RID, body: Node, _body_shape_idx: int, local_shape_idx: int) -> void:
|
||||
# retrieve area shape
|
||||
var shape : SphereShape3D = shape_owner_get_shape(
|
||||
shape_find_owner(local_shape_idx), local_shape_idx)
|
||||
# retrieve vector from current node origin to body global center of mass
|
||||
var direction: Vector3 = (body.global_transform.origin + body.center_of_mass) - global_transform.origin
|
||||
# sample curve texture if any to get falloff value at current distance
|
||||
var weight := 1.0
|
||||
if falloff:
|
||||
weight = falloff.sample(direction.length() / shape.radius)
|
||||
# handle blast
|
||||
if body is RigidBody3D:
|
||||
var impulse: Vector3 = direction.normalized() * (1000 * weight)
|
||||
# apply body impulse based on distance from explosion origin
|
||||
body.apply_impulse(impulse, global_transform.origin)
|
||||
# handle blast damages
|
||||
if body is Player:
|
||||
# deal damage based on distance from explosion origin
|
||||
body.damage.emit(source, body, damage * weight)
|
||||
|
||||
24
entities/projectiles/explosive_projectile.gd
Normal file
24
entities/projectiles/explosive_projectile.gd
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# 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 ExplosiveProjectile extends Projectile
|
||||
|
||||
@export var EXPLOSION:PackedScene
|
||||
|
||||
func destroy(location:Vector3 = global_position) -> void:
|
||||
var explosion : Node3D = EXPLOSION.instantiate()
|
||||
add_sibling(explosion)
|
||||
explosion.global_position = location
|
||||
explosion.source = source
|
||||
queue_free()
|
||||
63
entities/projectiles/projectile.gd
Normal file
63
entities/projectiles/projectile.gd
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# 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/>.
|
||||
## This class defines a projectile.
|
||||
class_name Projectile extends Node3D
|
||||
|
||||
# @NOTE: while it's the correct fundamental constant, we're really looking
|
||||
# for « terminal velocity » here instead because earth is not a vacuum
|
||||
const _speed_of_light := 299792458 # in m/s
|
||||
|
||||
## The initial speed when launched, measured in meters per second (m/s or mps).
|
||||
@export_range(0, _speed_of_light) var speed : float = 42
|
||||
## The time before it automatically self-destructs (never by default), measured in seconds (s).
|
||||
@export var lifespan : float = 0.
|
||||
## A knockback impulse applied to bodies it collides with, in Newtons.
|
||||
@export var knockback: int
|
||||
## The base amount of damage.
|
||||
@export var damage: int
|
||||
## The [param source] that launched this projectile.
|
||||
var source: Node
|
||||
|
||||
var deflectable:bool = false
|
||||
var inheritance:Vector3 = Vector3.ZERO
|
||||
var shape_cast : ShapeCast3D = null
|
||||
var velocity:Vector3 = Vector3.ZERO
|
||||
|
||||
func _init() -> void:
|
||||
# do not inherit transform from parent
|
||||
top_level = true
|
||||
# ensure projectile has shape
|
||||
ready.connect(func() -> void:
|
||||
for child in get_children():
|
||||
if child is ShapeCast3D:
|
||||
shape_cast = child
|
||||
assert(shape_cast)
|
||||
if lifespan > 0:
|
||||
get_tree().create_timer(lifespan).timeout.connect(destroy)
|
||||
)
|
||||
|
||||
func destroy(_location: Vector3 = global_position) -> void:
|
||||
queue_free()
|
||||
|
||||
func _physics_process(delta : float) -> void:
|
||||
# compute motion
|
||||
var previous_global_position : Vector3 = global_position
|
||||
# compute new position
|
||||
global_position += velocity * delta
|
||||
# handle collision
|
||||
if shape_cast:
|
||||
shape_cast.target_position = to_local(previous_global_position)
|
||||
if shape_cast.is_colliding():
|
||||
destroy(shape_cast.collision_result[0].point)
|
||||
Loading…
Add table
Add a link
Reference in a new issue