diff --git a/Sandbox.csproj b/Sandbox.csproj index 6d96b26..badc74b 100644 --- a/Sandbox.csproj +++ b/Sandbox.csproj @@ -1,4 +1,4 @@ - + net6.0 true diff --git a/Sandbox.csproj.old b/Sandbox.csproj.old new file mode 100644 index 0000000..6d96b26 --- /dev/null +++ b/Sandbox.csproj.old @@ -0,0 +1,9 @@ + + + net6.0 + true + + + + + \ No newline at end of file diff --git a/Scenes/Blizzard.tscn b/Scenes/Blizzard.tscn new file mode 100644 index 0000000..dd221ce --- /dev/null +++ b/Scenes/Blizzard.tscn @@ -0,0 +1,18 @@ +[gd_scene load_steps=4 format=3 uid="uid://ds2y8l8onrs4f"] + +[ext_resource type="Script" path="res://Scripts/Blizzard.cs" id="1_rqtsv"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_pd0mo"] +albedo_color = Color(0.137255, 0.447059, 0.796078, 1) + +[sub_resource type="SphereMesh" id="SphereMesh_g0pbs"] +radial_segments = 4 +rings = 1 + +[node name="Blizzard" type="Node3D"] +script = ExtResource("1_rqtsv") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.11373, 0) +material_override = SubResource("StandardMaterial3D_pd0mo") +mesh = SubResource("SphereMesh_g0pbs") diff --git a/Scenes/Main.tscn b/Scenes/Main.tscn index ea8b441..f1ba317 100644 --- a/Scenes/Main.tscn +++ b/Scenes/Main.tscn @@ -1,12 +1,12 @@ -[gd_scene load_steps=16 format=3 uid="uid://bcsgd8vxy43g2"] +[gd_scene load_steps=15 format=3 uid="uid://bcsgd8vxy43g2"] [ext_resource type="Script" path="res://Scripts/Player.cs" id="1_8dc05"] [ext_resource type="PackedScene" uid="uid://d20uxkpid4ynd" path="res://Models/vivi1.gltf" id="1_mqt2m"] +[ext_resource type="PackedScene" uid="uid://dg7731nx22ewp" path="res://Scenes/fireball.tscn" id="2_bsaqu"] +[ext_resource type="PackedScene" uid="uid://ds2y8l8onrs4f" path="res://Scenes/Blizzard.tscn" id="3_4rglj"] [ext_resource type="Script" path="res://Scripts/CameraSystem.cs" id="3_5ecw2"] [ext_resource type="PackedScene" uid="uid://c13g5orvyhy1p" path="res://Models/moogle.gltf" id="4_dckjs"] [ext_resource type="Script" path="res://Scripts/NPCFollow.cs" id="4_o5mpp"] -[ext_resource type="Texture2D" uid="uid://bwku8f676eq6j" path="res://Materials/Textures/caaf021ecac0f417e167b9184d45ae8e.png" id="6_7wayf"] -[ext_resource type="Script" path="res://Scripts/Fireball.cs" id="7_mkgs3"] [sub_resource type="BoxShape3D" id="BoxShape3D_8verc"] size = Vector3(100, 2, 100) @@ -31,17 +31,6 @@ albedo_color = Color(0.509804, 0.584314, 1, 1) [sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ultw4"] albedo_color = Color(1, 1, 0, 1) -[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_njysa"] -cull_mode = 1 -shading_mode = 0 -specular_mode = 1 -vertex_color_use_as_albedo = true -albedo_texture = ExtResource("6_7wayf") -billboard_mode = 3 -particles_anim_h_frames = 1 -particles_anim_v_frames = 1 -particles_anim_loop = false - [node name="Main" type="Node"] [node name="StaticBody3D" type="StaticBody3D" parent="."] @@ -63,6 +52,7 @@ collision_layer = 2 script = ExtResource("1_8dc05") _sensitivityHorizontal = 0.01 _sensitivityVertical = 0.01 +_projectiles = Array[PackedScene]([ExtResource("2_bsaqu"), ExtResource("3_4rglj")]) [node name="Pivot" type="Node3D" parent="Player"] transform = Transform3D(-1, 0, 8.74228e-08, 0, 1, 0, -8.74228e-08, 0, -1, 0, 0, 0) @@ -119,13 +109,3 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -1.54678, 0.383205, 4.07192) material_override = SubResource("StandardMaterial3D_ultw4") use_collision = true size = Vector3(15.0266, 4.74018, 1) - -[node name="Particles" type="Node3D" parent="."] -visible = false - -[node name="Fireball" type="CSGSphere3D" parent="Particles"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.07254, -1.49094) -radial_segments = 5 -rings = 20 -material = SubResource("StandardMaterial3D_njysa") -script = ExtResource("7_mkgs3") diff --git a/Scenes/fireball.tscn b/Scenes/fireball.tscn new file mode 100644 index 0000000..93eb07c --- /dev/null +++ b/Scenes/fireball.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=4 format=3 uid="uid://dg7731nx22ewp"] + +[ext_resource type="Script" path="res://Scripts/Fireball.cs" id="1_4ipg4"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_jxwqo"] +albedo_color = Color(0.666667, 0, 0.239216, 1) + +[sub_resource type="SphereMesh" id="SphereMesh_6bhr7"] + +[node name="Fireball" type="Node3D"] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.916843, 0) +script = ExtResource("1_4ipg4") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="."] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.00392, 0) +material_override = SubResource("StandardMaterial3D_jxwqo") +mesh = SubResource("SphereMesh_6bhr7") diff --git a/Scripts/Blizzard.cs b/Scripts/Blizzard.cs new file mode 100644 index 0000000..f09d9b1 --- /dev/null +++ b/Scripts/Blizzard.cs @@ -0,0 +1,9 @@ +using Godot; + +public partial class Blizzard : Projectile +{ + public override void _PhysicsProcess(double delta) + { + Translate(new Vector3(0, 0, -Speed)); + } +} diff --git a/Scripts/Fireball.cs b/Scripts/Fireball.cs index 099591f..ca5c562 100644 --- a/Scripts/Fireball.cs +++ b/Scripts/Fireball.cs @@ -1,10 +1,9 @@ using Godot; -public partial class Fireball : CsgSphere3D +public partial class Fireball : Projectile { - private float _speed = 80f; - - public override void _PhysicsProcess(double delta) - { - } + public override void _PhysicsProcess(double delta) + { + Translate(new Vector3(0, 0, -Speed)); + } } diff --git a/Scripts/Player.cs b/Scripts/Player.cs index 9a2d7c3..7644d7d 100644 --- a/Scripts/Player.cs +++ b/Scripts/Player.cs @@ -1,82 +1,93 @@ +using System.Linq; using Godot; +using Godot.Collections; public partial class Player : CharacterBody3D { - [Export] - private float _speed = 5.0f; - [Export] - private float _jumpVelocity = 4.5f; - [Export] - private float _sensitivityHorizontal = 0.05f; - [Export] - private float _sensitivityVertical = 0.05f; - [Export] - private float _joystickDeadZone = 0.5f; + [Export] + private float _speed = 5.0f; + [Export] + private float _jumpVelocity = 4.5f; + [Export] + private float _sensitivityHorizontal = 0.05f; + [Export] + private float _sensitivityVertical = 0.05f; + [Export] + private float _joystickDeadZone = 0.5f; + [Export] + private Array _projectiles; - private Node3D _cameraMount; - private Node3D _pivot; + private Node3D _cameraMount; + private Node3D _pivot; + private PackedScene _weaponType; - // Get the _gravity from the project settings to be synced with RigidBody nodes. - public float _gravity = ProjectSettings.GetSetting("physics/3d/default_gravity").AsSingle(); + // Get the _gravity from the project settings to be synced with RigidBody nodes. + public float _gravity = ProjectSettings.GetSetting("physics/3d/default_gravity").AsSingle(); - public override void _Ready() - { - Input.MouseMode = Input.MouseModeEnum.Captured; - _cameraMount = GetNode("/root/Main/Player/CameraMount"); - _pivot = GetNode("/root/Main/Player/Pivot"); - } + public override void _Ready() + { + Input.MouseMode = Input.MouseModeEnum.Captured; + _cameraMount = GetNode("/root/Main/Player/CameraMount"); + _pivot = GetNode("/root/Main/Player/Pivot"); + _weaponType = _projectiles.First(); + } - public override void _UnhandledInput(InputEvent @event) - { - if (Input.IsActionJustPressed("quit")) - GetTree().Quit(); - if (Input.IsActionJustPressed("shoot")) - Shoot(); - } + public override void _UnhandledInput(InputEvent @event) + { + if (Input.IsActionJustPressed("quit")) + GetTree().Quit(); + if (Input.IsActionJustPressed("shoot")) + Shoot(); + if (Input.IsActionJustPressed("switch")) + SwitchWeaponType(); + } - public override void _Input(InputEvent @event) - { - } + public override void _PhysicsProcess(double delta) + { + var gravityDelta = _gravity * (float)delta; + var velocity = CalculateMovement(Velocity, Transform, gravityDelta); - public override void _PhysicsProcess(double delta) - { - var gravityDelta = _gravity * (float)delta; - var velocity = CalculateMovement(Velocity, Transform, gravityDelta); + Velocity = velocity; + MoveAndSlide(); + } - Velocity = velocity; - MoveAndSlide(); - } + private void Shoot() + { + GD.Print("Shoot"); + var projectile = _weaponType.Instantiate(); + projectile.Position = Position; + GetParent().AddChild(projectile); + } - private void Shoot() - { - GD.Print("Shoot"); - var projectile = new Fireball(); - Owner.AddChild(projectile); - projectile.Transform = Transform; - } + private void SwitchWeaponType() + { + var index = _projectiles.IndexOf(_weaponType); + _weaponType = _projectiles[(index + 1) % _projectiles.Count]; - private Vector3 CalculateMovement(Vector3 velocity, Transform3D transform, float gravityDelta) - { - if (!IsOnFloor()) - velocity.Y -= gravityDelta; + } - if (Input.IsActionJustPressed("jump") && IsOnFloor()) - velocity.Y = _jumpVelocity; + private Vector3 CalculateMovement(Vector3 velocity, Transform3D transform, float gravityDelta) + { + if (!IsOnFloor()) + velocity.Y -= gravityDelta; - Vector2 inputDir = Input.GetVector("right", "left", "back", "forward"); - Vector3 direction = (transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized(); - if (direction != Vector3.Zero) - { - velocity.X = direction.X * _speed; - velocity.Z = direction.Z * _speed; - GetNode("Pivot").LookAt(Position + direction.Normalized(), Vector3.Up); - } - else - { - velocity.X = Mathf.MoveToward(Velocity.X, 0, _speed); - velocity.Z = Mathf.MoveToward(Velocity.Z, 0, _speed); - } + if (Input.IsActionJustPressed("jump") && IsOnFloor()) + velocity.Y = _jumpVelocity; - return velocity; - } + Vector2 inputDir = Input.GetVector("right", "left", "back", "forward"); + Vector3 direction = (transform.Basis * new Vector3(inputDir.X, 0, inputDir.Y)).Normalized(); + if (direction != Vector3.Zero) + { + velocity.X = direction.X * _speed; + velocity.Z = direction.Z * _speed; + GetNode("Pivot").LookAt(Position + direction.Normalized(), Vector3.Up); + } + else + { + velocity.X = Mathf.MoveToward(Velocity.X, 0, _speed); + velocity.Z = Mathf.MoveToward(Velocity.Z, 0, _speed); + } + + return velocity; + } } diff --git a/Scripts/Projectile.cs b/Scripts/Projectile.cs new file mode 100644 index 0000000..2f4e2a7 --- /dev/null +++ b/Scripts/Projectile.cs @@ -0,0 +1,14 @@ +using Godot; + +public partial class Projectile : Node3D +{ + [Export] + private float _projectileSpeed = 0.1f; + + public override void _Ready() + { + Speed = _projectileSpeed; + } + + public float Speed { get; private set; } +} diff --git a/Scripts/WeaponType.cs b/Scripts/WeaponType.cs new file mode 100644 index 0000000..8016611 --- /dev/null +++ b/Scripts/WeaponType.cs @@ -0,0 +1,8 @@ +namespace Sandbox.Scripts +{ + internal enum WeaponType + { + Fire = 0, + Blizzard = 1 + } +} diff --git a/project.godot b/project.godot index 3c2fd28..4b4df72 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="Sandbox" run/main_scene="res://Scenes/Main.tscn" -config/features=PackedStringArray("4.0", "C#", "Forward Plus") +config/features=PackedStringArray("4.1", "C#", "Forward Plus") [dotnet] @@ -78,3 +78,8 @@ shoot={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":90,"key_label":0,"unicode":122,"echo":false,"script":null) ] } +switch={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"key_label":0,"unicode":120,"echo":false,"script":null) +] +}