Compare commits
3 Commits
7a7a1c549c
...
bf486f01d4
| Author | SHA1 | Date | |
|---|---|---|---|
| bf486f01d4 | |||
| 2dde348aa0 | |||
| d0558d918c |
@ -3,6 +3,7 @@
|
|||||||
[ext_resource type="PackedScene" uid="uid://ct70bpbca8one" path="res://scenes/player/local_player.tscn" id="1_yjvui"]
|
[ext_resource type="PackedScene" uid="uid://ct70bpbca8one" path="res://scenes/player/local_player.tscn" id="1_yjvui"]
|
||||||
[ext_resource type="PackedScene" uid="uid://kfxc0migw80o" path="res://scenes/player/remote_player.tscn" id="2_kcncr"]
|
[ext_resource type="PackedScene" uid="uid://kfxc0migw80o" path="res://scenes/player/remote_player.tscn" id="2_kcncr"]
|
||||||
[ext_resource type="PackedScene" uid="uid://dfnbc8sbufa4j" path="res://scenes/misc/ball.tscn" id="3_e0nj3"]
|
[ext_resource type="PackedScene" uid="uid://dfnbc8sbufa4j" path="res://scenes/misc/ball.tscn" id="3_e0nj3"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://c1r8nk58cci3a" path="res://scenes/misc/goal.tscn" id="4_w7til"]
|
||||||
|
|
||||||
[sub_resource type="ImageTexture" id="ImageTexture_3vyb7"]
|
[sub_resource type="ImageTexture" id="ImageTexture_3vyb7"]
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5.1396794, 3.9666176, 6.2400
|
|||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 7.244197, 3.9666176, -6.361364)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 7.244197, 3.9666176, -6.361364)
|
||||||
|
|
||||||
[node name="ball_spawner" type="Node3D" parent="." unique_id=1149426253]
|
[node name="ball_spawner" type="Node3D" parent="." unique_id=1149426253]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 5.080344, 4.78083, -9.363691)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.03390026, 4.7808294, -0.102864265)
|
||||||
|
|
||||||
[node name="killbox" type="Killbox" parent="." unique_id=1018578438]
|
[node name="killbox" type="Killbox" parent="." unique_id=1018578438]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -5.367467, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -5.367467, 0)
|
||||||
@ -64,3 +65,10 @@ collision_mask = 7
|
|||||||
|
|
||||||
[node name="collision_shape_3d" type="CollisionShape3D" parent="killbox" unique_id=447460010]
|
[node name="collision_shape_3d" type="CollisionShape3D" parent="killbox" unique_id=447460010]
|
||||||
shape = SubResource("BoxShape3D_3g557")
|
shape = SubResource("BoxShape3D_3g557")
|
||||||
|
|
||||||
|
[node name="goal" parent="." unique_id=177528504 instance=ExtResource("4_w7til")]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -12.468555, 0.0050001144, 4.4860663)
|
||||||
|
|
||||||
|
[node name="goal2" parent="." unique_id=1997661586 instance=ExtResource("4_w7til")]
|
||||||
|
team = 1
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 8.417626, 0.0050001144, -3.8839006)
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
[sub_resource type="SphereShape3D" id="SphereShape3D_1cgct"]
|
[sub_resource type="SphereShape3D" id="SphereShape3D_1cgct"]
|
||||||
|
|
||||||
[node name="ball" type="Ball" unique_id=816748600]
|
[node name="ball" type="Ball" unique_id=816748600]
|
||||||
collision_layer = 4
|
collision_layer = 12
|
||||||
collision_mask = 7
|
collision_mask = 7
|
||||||
contact_monitor = true
|
contact_monitor = true
|
||||||
max_contacts_reported = 10
|
max_contacts_reported = 10
|
||||||
|
|||||||
33
godot/scenes/misc/goal.tscn
Normal file
33
godot/scenes/misc/goal.tscn
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
[gd_scene format=3 uid="uid://c1r8nk58cci3a"]
|
||||||
|
|
||||||
|
[ext_resource type="Shader" uid="uid://bafca0fr7yxgo" path="res://shaders/goal_shader.gdshader" id="1_vdq5s"]
|
||||||
|
|
||||||
|
[sub_resource type="ShaderMaterial" id="ShaderMaterial_sxx5i"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
render_priority = 0
|
||||||
|
shader = ExtResource("1_vdq5s")
|
||||||
|
shader_parameter/goal_color = Vector3(0, 0, 0)
|
||||||
|
|
||||||
|
[sub_resource type="CylinderMesh" id="CylinderMesh_1cgct"]
|
||||||
|
resource_local_to_scene = true
|
||||||
|
material = SubResource("ShaderMaterial_sxx5i")
|
||||||
|
top_radius = 2.0
|
||||||
|
bottom_radius = 2.0
|
||||||
|
cap_top = false
|
||||||
|
cap_bottom = false
|
||||||
|
|
||||||
|
[sub_resource type="CylinderShape3D" id="CylinderShape3D_1cgct"]
|
||||||
|
radius = 2.0
|
||||||
|
|
||||||
|
[node name="goal" type="Goal" unique_id=177528504 node_paths=PackedStringArray("mesh")]
|
||||||
|
mesh = NodePath("mesh_instance_3d")
|
||||||
|
collision_layer = 8
|
||||||
|
collision_mask = 8
|
||||||
|
|
||||||
|
[node name="mesh_instance_3d" type="MeshInstance3D" parent="." unique_id=587608036]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||||
|
mesh = SubResource("CylinderMesh_1cgct")
|
||||||
|
|
||||||
|
[node name="collision_shape_3d" type="CollisionShape3D" parent="." unique_id=2021568043]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||||
|
shape = SubResource("CylinderShape3D_1cgct")
|
||||||
16
godot/shaders/goal_shader.gdshader
Normal file
16
godot/shaders/goal_shader.gdshader
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
shader_type spatial;
|
||||||
|
render_mode blend_mix, depth_draw_opaque, depth_test_default, diffuse_lambert, specular_schlick_ggx, world_vertex_coords, cull_disabled;
|
||||||
|
|
||||||
|
uniform vec3 goal_color;
|
||||||
|
|
||||||
|
void vertex() {
|
||||||
|
float height = max(0.0, (1.0 - VERTEX.y));
|
||||||
|
float boost = (sin(TIME) + 3.0)/4.0;
|
||||||
|
COLOR = vec4(goal_color * boost * height, boost * height);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fragment() {
|
||||||
|
ALBEDO = COLOR.xyz;
|
||||||
|
ALPHA = COLOR.w;
|
||||||
|
EMISSION = COLOR.xyz * 2.0;
|
||||||
|
}
|
||||||
1
godot/shaders/goal_shader.gdshader.uid
Normal file
1
godot/shaders/goal_shader.gdshader.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://bafca0fr7yxgo
|
||||||
@ -158,6 +158,8 @@ pub struct Game {
|
|||||||
pub world_ball: Option<Gd<Ball>>,
|
pub world_ball: Option<Gd<Ball>>,
|
||||||
since_last_sync: f64,
|
since_last_sync: f64,
|
||||||
|
|
||||||
|
pub goals: HashMap<u8, u16>,
|
||||||
|
|
||||||
base: Base<Node>,
|
base: Base<Node>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,6 +517,20 @@ impl Game {
|
|||||||
self.spawn_ball(None, None, None);
|
self.spawn_ball(None, None, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_goal(&mut self, teams: Vec<u8>) {
|
||||||
|
for team in &teams {
|
||||||
|
self.goals
|
||||||
|
.insert(*team, self.goals.get(&team).copied().unwrap_or(0) + 1);
|
||||||
|
}
|
||||||
|
self.run_deferred(move |_| {
|
||||||
|
if let Some(peer) = &mut NetworkManager::singleton().bind_mut().peer {
|
||||||
|
if let PeerKind::Server(peer, _) = peer {
|
||||||
|
peer.broadcast_reliable(Package::Goal(teams));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
pub fn handle_ball_pickup(&mut self, player_id: u16) {
|
pub fn handle_ball_pickup(&mut self, player_id: u16) {
|
||||||
if NetworkManager::singleton().bind_mut().is_host() {
|
if NetworkManager::singleton().bind_mut().is_host() {
|
||||||
self.despawn_ball();
|
self.despawn_ball();
|
||||||
|
|||||||
58
rust/src/goal.rs
Normal file
58
rust/src/goal.rs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
use godot::{
|
||||||
|
classes::{Area3D, IArea3D, MeshInstance3D, ShaderMaterial},
|
||||||
|
prelude::*,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::{ball::Ball, game_manager::Game, net::network_manager::NetworkManager};
|
||||||
|
|
||||||
|
#[derive(GodotClass)]
|
||||||
|
#[class(base=Area3D, init)]
|
||||||
|
pub struct Goal {
|
||||||
|
#[export]
|
||||||
|
pub team: u8,
|
||||||
|
#[export]
|
||||||
|
pub mesh: Option<Gd<MeshInstance3D>>,
|
||||||
|
|
||||||
|
base: Base<Area3D>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[godot_api]
|
||||||
|
impl IArea3D for Goal {
|
||||||
|
fn ready(&mut self) {
|
||||||
|
if let Some(game) = Game::singleton() {
|
||||||
|
if let Some(team) = game.bind().get_team(self.team)
|
||||||
|
&& let Some(mesh) = &mut self.mesh
|
||||||
|
&& let Some(mat) = mesh.get_active_material(0)
|
||||||
|
&& let Ok(mut mat) = mat.try_cast::<ShaderMaterial>()
|
||||||
|
{
|
||||||
|
mat.set_shader_parameter("goal_color", &team.bind().color.to_variant());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.base()
|
||||||
|
.signals()
|
||||||
|
.body_entered()
|
||||||
|
.connect_other(self, |s, other| s.on_enter(other));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Goal {
|
||||||
|
fn on_enter(&self, node: Gd<Node3D>) {
|
||||||
|
if let Ok(_) = node.try_cast::<Ball>() {
|
||||||
|
if let Some(mut game) = Game::singleton() {
|
||||||
|
let teams = game
|
||||||
|
.bind()
|
||||||
|
.get_teams()
|
||||||
|
.iter_shared()
|
||||||
|
.enumerate()
|
||||||
|
.map(|(id, _)| id as u8)
|
||||||
|
.filter(|id| *id != self.team)
|
||||||
|
.collect();
|
||||||
|
if NetworkManager::singleton().bind().is_host() {
|
||||||
|
game.bind_mut().respawn_ball();
|
||||||
|
game.bind_mut().handle_goal(teams);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@ use godot::prelude::*;
|
|||||||
|
|
||||||
pub mod ball;
|
pub mod ball;
|
||||||
pub mod game_manager;
|
pub mod game_manager;
|
||||||
|
pub mod goal;
|
||||||
pub mod killbox;
|
pub mod killbox;
|
||||||
pub mod map;
|
pub mod map;
|
||||||
pub mod map_resource;
|
pub mod map_resource;
|
||||||
|
|||||||
@ -275,6 +275,7 @@ pub enum Package {
|
|||||||
SpawnBall(NetTransform, NetVector3, Option<u16>),
|
SpawnBall(NetTransform, NetVector3, Option<u16>),
|
||||||
DespawnBall,
|
DespawnBall,
|
||||||
SwapWeapon(u16, WeaponType),
|
SwapWeapon(u16, WeaponType),
|
||||||
|
Goal(Vec<u8>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
|||||||
@ -171,6 +171,11 @@ impl NetworkManager {
|
|||||||
game.bind_mut().change_option(opt, value);
|
game.bind_mut().change_option(opt, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Package::Goal(teams) => {
|
||||||
|
if let Some(game) = &mut Game::singleton() {
|
||||||
|
game.bind_mut().handle_goal(teams);
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user