diff --git a/godot/maps/default_map/map0.tscn b/godot/maps/default_map/map0.tscn index 0af6de5..af5222b 100644 --- a/godot/maps/default_map/map0.tscn +++ b/godot/maps/default_map/map0.tscn @@ -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://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://c1r8nk58cci3a" path="res://scenes/misc/goal.tscn" id="4_w7til"] [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) [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] 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] 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) diff --git a/godot/scenes/misc/goal.tscn b/godot/scenes/misc/goal.tscn new file mode 100644 index 0000000..939b1e3 --- /dev/null +++ b/godot/scenes/misc/goal.tscn @@ -0,0 +1,31 @@ +[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") + +[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") diff --git a/godot/shaders/goal_shader.gdshader b/godot/shaders/goal_shader.gdshader new file mode 100644 index 0000000..b00a88a --- /dev/null +++ b/godot/shaders/goal_shader.gdshader @@ -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; +} \ No newline at end of file diff --git a/godot/shaders/goal_shader.gdshader.uid b/godot/shaders/goal_shader.gdshader.uid new file mode 100644 index 0000000..ecc4513 --- /dev/null +++ b/godot/shaders/goal_shader.gdshader.uid @@ -0,0 +1 @@ +uid://bafca0fr7yxgo diff --git a/rust/src/goal.rs b/rust/src/goal.rs new file mode 100644 index 0000000..39e1e6b --- /dev/null +++ b/rust/src/goal.rs @@ -0,0 +1,34 @@ +use godot::{ + classes::{Area3D, IArea3D, MeshInstance3D, ShaderMaterial}, + prelude::*, +}; + +use crate::game_manager::Game; + +#[derive(GodotClass)] +#[class(base=Area3D, init)] +pub struct Goal { + #[export] + pub team: u8, + #[export] + pub mesh: Option>, + + base: Base, +} + +#[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::() + { + godot_print!("{}", mat); + godot_print!("{}", team.bind().color); + mat.set_shader_parameter("goal_color", &team.bind().color.to_variant()); + } + } + } +} diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 0e01a22..3e1f9f6 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -2,6 +2,7 @@ use godot::prelude::*; pub mod ball; pub mod game_manager; +pub mod goal; pub mod killbox; pub mod map; pub mod map_resource;