Add killbox

This commit is contained in:
Sofia 2026-07-21 01:47:31 +03:00
parent 09a20f1616
commit 15dca3d912
5 changed files with 56 additions and 1 deletions

View File

@ -1,6 +1,6 @@
[gd_resource type="MapResource" format=3 uid="uid://bsjoandgu476y"] [gd_resource type="MapResource" format=3 uid="uid://bsjoandgu476y"]
[ext_resource type="PackedScene" uid="uid://ylj40hkjsgjc" path="res://maps/diner.tscn" id="1_yteo6"] [ext_resource type="PackedScene" uid="uid://ylj40hkjsgjc" path="res://maps/diner/diner.tscn" id="1_yteo6"]
[resource] [resource]
name = "Diner" name = "Diner"

View File

@ -143,6 +143,9 @@ volumetric_fog_albedo = Color(0.8156863, 0.6392157, 0.29803923, 1)
[sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_j6hgl"] [sub_resource type="CameraAttributesPractical" id="CameraAttributesPractical_j6hgl"]
exposure_multiplier = 2.641 exposure_multiplier = 2.641
[sub_resource type="BoxShape3D" id="BoxShape3D_1cgct"]
size = Vector3(1000, 1, 1000)
[node name="diner" type="Map" unique_id=1971127396 node_paths=PackedStringArray("spawner")] [node name="diner" type="Map" unique_id=1971127396 node_paths=PackedStringArray("spawner")]
spawner = NodePath("spawner") spawner = NodePath("spawner")
local_player = ExtResource("1_wffmg") local_player = ExtResource("1_wffmg")
@ -252,3 +255,10 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
[node name="spawner" type="Node3D" parent="." unique_id=2117785064] [node name="spawner" type="Node3D" parent="." unique_id=2117785064]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.739436, 0.76123095, 5.0619516) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.739436, 0.76123095, 5.0619516)
[node name="killbox" type="Killbox" parent="." unique_id=1750431583]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -7.531834, 0)
[node name="collision_shape_3d" type="CollisionShape3D" parent="killbox" unique_id=55584443]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -3.1150565, 0)
shape = SubResource("BoxShape3D_1cgct")

32
rust/src/killbox.rs Normal file
View File

@ -0,0 +1,32 @@
use godot::{
classes::{Area3D, IArea3D},
prelude::*,
};
use crate::{net::network_manager::NetworkManager, player::IPlayer};
#[derive(GodotClass)]
#[class(base=Area3D, init)]
pub struct Killbox {
base: Base<Area3D>,
}
#[godot_api]
impl IArea3D for Killbox {
fn ready(&mut self) {
self.base()
.signals()
.body_entered()
.connect_other(self, |s, body| s.kill(body));
}
}
impl Killbox {
pub fn kill(&mut self, node: Gd<Node3D>) {
if let Ok(mut player) = node.try_dynify::<dyn IPlayer>() {
if NetworkManager::singleton().bind().is_host() {
player.dyn_bind_mut().take_damage(0, 1000, true);
}
}
}
}

View File

@ -1,6 +1,7 @@
use godot::prelude::*; use godot::prelude::*;
pub mod game_manager; pub mod game_manager;
pub mod killbox;
pub mod map; pub mod map;
pub mod map_resource; pub mod map_resource;
pub mod net; pub mod net;

View File

@ -449,6 +449,18 @@ impl NetworkManager {
get_autoload_by_name::<NetworkManager>(NETWORK_SINGLETON_NAME) get_autoload_by_name::<NetworkManager>(NETWORK_SINGLETON_NAME)
} }
pub fn is_host(&self) -> bool {
if let Some(peer) = &self.peer {
if let PeerKind::Server(_, _) = peer {
true
} else {
false
}
} else {
false
}
}
pub fn host(&mut self, port: u16) { pub fn host(&mut self, port: u16) {
if self.peer.is_none() { if self.peer.is_none() {
let mut cli = CommandLinePanel::singleton(); let mut cli = CommandLinePanel::singleton();