Rename bullet to beam and weapon to raygun
This commit is contained in:
parent
9c412ef2ed
commit
c588b7cab4
@ -1,10 +1,10 @@
|
||||
[gd_scene format=3 uid="uid://cw7duhhjebypt"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cg81784ct8gf5" path="res://mesh/raygun.tscn" id="1_ckadf"]
|
||||
[ext_resource type="PackedScene" uid="uid://ctslratcr8h6v" path="res://scenes/player/raygun_bullet.tscn" id="1_m84jv"]
|
||||
[ext_resource type="PackedScene" uid="uid://ctslratcr8h6v" path="res://scenes/player/raygun_beam.tscn" id="1_m84jv"]
|
||||
[ext_resource type="AudioStream" uid="uid://xxpkjhaovyd" path="res://assets/LaserWithRecoveryEdited.ogg" id="2_lxble"]
|
||||
|
||||
[node name="raygun" type="Weapon" unique_id=751705927 node_paths=PackedStringArray("sound_emitter", "bullet_source")]
|
||||
[node name="raygun" type="Raygun" unique_id=573018429 node_paths=PackedStringArray("sound_emitter", "bullet_source")]
|
||||
sound_emitter = NodePath("sound_emitter")
|
||||
bullet_prefab = ExtResource("1_m84jv")
|
||||
bullet_source = NodePath("bullet_source")
|
||||
|
||||
@ -15,7 +15,7 @@ top_radius = 0.2
|
||||
bottom_radius = 0.2
|
||||
height = 1.0
|
||||
|
||||
[node name="raygun_bullet" type="Bullet" unique_id=1238833478]
|
||||
[node name="raygun_beam" type="Beam" unique_id=2002340444]
|
||||
|
||||
[node name="mesh_instance_3d" type="MeshInstance3D" parent="." unique_id=1295653371]
|
||||
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, 0)
|
||||
@ -21,7 +21,7 @@ use crate::{
|
||||
},
|
||||
soldier_mesh::SoldierMesh,
|
||||
ui::cli::CommandLinePanel,
|
||||
weapon::Weapon,
|
||||
weapon::Raygun,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
@ -83,7 +83,7 @@ pub struct LocalPlayer {
|
||||
soldier_mesh: Option<Gd<SoldierMesh>>,
|
||||
|
||||
pub player_id: Option<u16>,
|
||||
pub weapon: Option<Gd<Weapon>>,
|
||||
pub weapon: Option<Gd<Raygun>>,
|
||||
|
||||
movement_dir: Vector3,
|
||||
y_speed: f32,
|
||||
@ -314,7 +314,7 @@ pub struct RemotePlayer {
|
||||
soldier_mesh: Option<Gd<SoldierMesh>>,
|
||||
|
||||
pub player_id: Option<u16>,
|
||||
pub weapon: Option<Gd<Weapon>>,
|
||||
pub weapon: Option<Gd<Raygun>>,
|
||||
|
||||
movement_dir: Vector3,
|
||||
y_speed: f32,
|
||||
|
||||
@ -6,7 +6,7 @@ use godot::{
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
use crate::weapon::Weapon;
|
||||
use crate::weapon::Raygun;
|
||||
|
||||
#[derive(GodotClass)]
|
||||
#[class(base=Node3D, init)]
|
||||
@ -43,16 +43,16 @@ impl SoldierMesh {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_raygun(&mut self) -> Option<Gd<Weapon>> {
|
||||
pub fn spawn_raygun(&mut self) -> Option<Gd<Raygun>> {
|
||||
if let Some(raygun) = &self.raygun {
|
||||
let node = raygun.instantiate_as::<Weapon>();
|
||||
let node = raygun.instantiate_as::<Raygun>();
|
||||
self.spawn_weapon(node)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_weapon(&mut self, node: Gd<Weapon>) -> Option<Gd<Weapon>> {
|
||||
fn spawn_weapon(&mut self, node: Gd<Raygun>) -> Option<Gd<Raygun>> {
|
||||
if let Some(hand) = &mut self.hand_attachment {
|
||||
hand.add_child(&node);
|
||||
Some(node)
|
||||
|
||||
@ -5,7 +5,7 @@ use godot::{
|
||||
|
||||
#[derive(GodotClass)]
|
||||
#[class(base=Node3D, init)]
|
||||
pub struct Weapon {
|
||||
pub struct Raygun {
|
||||
#[export]
|
||||
sound_emitter: Option<Gd<AudioStreamPlayer3D>>,
|
||||
#[export]
|
||||
@ -16,14 +16,14 @@ pub struct Weapon {
|
||||
base: Base<Node3D>,
|
||||
}
|
||||
|
||||
impl Weapon {
|
||||
impl Raygun {
|
||||
pub fn shoot(&mut self, to: Vector3, deal_damage: bool) {
|
||||
if let Some(emitter) = &mut self.sound_emitter {
|
||||
emitter.play();
|
||||
}
|
||||
|
||||
if let Some(prefab) = &self.bullet_prefab {
|
||||
let mut bullet = prefab.instantiate_as::<Bullet>();
|
||||
let mut bullet = prefab.instantiate_as::<Beam>();
|
||||
|
||||
if let Some(source) = &self.bullet_source {
|
||||
bullet.bind_mut().source = Some(source.get_global_position());
|
||||
@ -39,7 +39,7 @@ impl Weapon {
|
||||
|
||||
#[derive(GodotClass)]
|
||||
#[class(base=Node3D, init)]
|
||||
pub struct Bullet {
|
||||
pub struct Beam {
|
||||
pub source: Option<Vector3>,
|
||||
pub target: Option<Vector3>,
|
||||
|
||||
@ -52,7 +52,7 @@ pub struct Bullet {
|
||||
}
|
||||
|
||||
#[godot_api]
|
||||
impl INode3D for Bullet {
|
||||
impl INode3D for Beam {
|
||||
fn ready(&mut self) {
|
||||
if let (Some(target), Some(source)) = (self.target, self.source) {
|
||||
let midway_point = (target + source) / 2.;
|
||||
@ -71,13 +71,13 @@ impl INode3D for Bullet {
|
||||
}
|
||||
}
|
||||
|
||||
impl Bullet {
|
||||
impl Beam {
|
||||
fn scale(&mut self) {
|
||||
let length = Vector3::BACK * self.distance;
|
||||
let girth_scale = (Vector3::UP + Vector3::RIGHT) * self.girth;
|
||||
self.base_mut().set_scale(length + girth_scale);
|
||||
|
||||
if self.girth < 0.05 {
|
||||
if self.girth < 0.01 {
|
||||
self.base_mut().queue_free();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user