added LaserBeam with Particle and Sound

pull/23/head
Sascha 2023-10-24 14:59:04 +07:00
parent 575ba2bf5d
commit 8cde01c187
11 changed files with 103 additions and 16 deletions

@ -0,0 +1,13 @@
[gd_resource type="CapsuleMesh" load_steps=2 format=3 uid="uid://yydtguqwa6us"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ig000"]
emission_enabled = true
emission = Color(0.792157, 0.85098, 0, 1)
emission_energy_multiplier = 10.0
[resource]
material = SubResource("StandardMaterial3D_ig000")
custom_aabb = AABB(1, 1, 100, 1, 1, 100)
height = 5.0
radial_segments = 32
rings = 4

@ -0,0 +1,23 @@
[gd_resource type="ParticleProcessMaterial" load_steps=3 format=3 uid="uid://jsqnryvk0qes"]
[sub_resource type="Curve" id="Curve_h0hv8"]
_data = [Vector2(0, 1), 0.0, 0.0, 0, 0, Vector2(1, 0), 0.0, 0.0, 0, 0]
point_count = 2
[sub_resource type="CurveTexture" id="CurveTexture_i2vsr"]
curve = SubResource("Curve_h0hv8")
[resource]
particle_flag_align_y = true
direction = Vector3(0, 0, -1)
spread = 1.0
initial_velocity_min = 10.0
initial_velocity_max = 15.0
gravity = Vector3(0, 0, 0)
scale_min = 0.05
scale_max = 0.05
scale_curve = SubResource("CurveTexture_i2vsr")
collision_mode = 1
collision_friction = 0.5
collision_bounce = 0.5
collision_use_scale = true

@ -0,0 +1,13 @@
[gd_scene load_steps=3 format=3 uid="uid://ck31g3hvggoh"]
[ext_resource type="Material" uid="uid://jsqnryvk0qes" path="res://Material/LaserBeamProcess.tres" id="1_6pmub"]
[ext_resource type="CapsuleMesh" uid="uid://yydtguqwa6us" path="res://Material/LaserBeamMaterial.tres" id="2_tfobi"]
[node name="LaserBeam" type="Node3D"]
[node name="GPUParticles3D" type="GPUParticles3D" parent="."]
emitting = false
amount = 1
one_shot = true
process_material = ExtResource("1_6pmub")
draw_pass_1 = ExtResource("2_tfobi")

@ -1,4 +1,4 @@
[gd_scene load_steps=13 format=3 uid="uid://tlr55u0gn20l"]
[gd_scene load_steps=15 format=3 uid="uid://tlr55u0gn20l"]
[ext_resource type="Script" path="res://Scripts/PlayerShip.cs" id="1_cpbf1"]
[ext_resource type="PackedScene" uid="uid://d0bi42b1tkjre" path="res://Packed-Scenes/PlayerShipExplosion.tscn" id="2_13dyf"]
@ -6,6 +6,8 @@
[ext_resource type="Texture2D" uid="uid://bsoehauordi1i" path="res://Textures/vehicle_playerShip_orange_nrm.png" id="3_2vqaj"]
[ext_resource type="Texture2D" uid="uid://dd4f3mkovliof" path="res://Textures/part_jet_flare_dff.png" id="4_87x8f"]
[ext_resource type="Texture2D" uid="uid://dtiljorcwbex" path="res://Textures/part_jet_core_dff.png" id="5_034vf"]
[ext_resource type="Material" uid="uid://jsqnryvk0qes" path="res://Material/LaserBeamProcess.tres" id="7_24u2t"]
[ext_resource type="CapsuleMesh" uid="uid://yydtguqwa6us" path="res://Material/LaserBeamMaterial.tres" id="8_e60hj"]
[sub_resource type="SphereShape3D" id="SphereShape3D_330dr"]
radius = 0.87
@ -89,12 +91,13 @@ normal_enabled = true
normal_scale = 2.0
normal_texture = ExtResource("3_2vqaj")
[node name="PlayerShip" type="Node3D" node_paths=PackedStringArray("jet", "PlayerRb")]
[node name="PlayerShip" type="Node3D" node_paths=PackedStringArray("jet", "PlayerRb", "laser")]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74227e-08, 0, -1, 0, 0, 0)
script = ExtResource("1_cpbf1")
jet = NodePath("RigidBody3D/CollisionShape3D/Jet")
PlayerRb = NodePath("RigidBody3D")
explosion = ExtResource("2_13dyf")
laser = NodePath("RigidBody3D/CollisionShape3D/LaserBeam/GPUParticles3D")
[node name="RigidBody3D" type="RigidBody3D" parent="."]
mass = 100.0
@ -123,5 +126,15 @@ transform = Transform3D(1, -2.84217e-14, 3.82137e-15, 3.82137e-15, 4.37114e-08,
shaded = true
texture = ExtResource("4_87x8f")
[node name="LaserBeam" type="Node3D" parent="RigidBody3D/CollisionShape3D"]
[node name="GPUParticles3D" type="GPUParticles3D" parent="RigidBody3D/CollisionShape3D/LaserBeam"]
transform = Transform3D(-1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, -0.100476, 0)
emitting = false
amount = 20
lifetime = 5.0
process_material = ExtResource("7_24u2t")
draw_pass_1 = ExtResource("8_e60hj")
[node name="AudioListener3D" type="AudioListener3D" parent="."]
current = true

@ -72,3 +72,6 @@ transform = Transform3D(1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0)
mesh = SubResource("ArrayMesh_rks3f")
skeleton = NodePath("")
surface_material_override/0 = SubResource("StandardMaterial3D_32257")
[node name="GPUParticlesCollisionSphere3D" type="GPUParticlesCollisionSphere3D" parent="RigidBody3D"]
radius = 0.75

@ -72,3 +72,6 @@ transform = Transform3D(1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0)
mesh = SubResource("ArrayMesh_jk0jt")
skeleton = NodePath("")
surface_material_override/0 = SubResource("StandardMaterial3D_is3w3")
[node name="GPUParticlesCollisionSphere3D" type="GPUParticlesCollisionSphere3D" parent="RigidBody3D"]
radius = 0.75

@ -71,3 +71,6 @@ shape = SubResource("SphereShape3D_iq8kl")
mesh = SubResource("ArrayMesh_rnkma")
skeleton = NodePath("")
surface_material_override/0 = SubResource("StandardMaterial3D_mggxn")
[node name="GPUParticlesCollisionSphere3D" type="GPUParticlesCollisionSphere3D" parent="RigidBody3D"]
radius = 0.75

@ -1,6 +1,6 @@
[gd_scene load_steps=13 format=3 uid="uid://det8556rpxhbv"]
[gd_scene load_steps=14 format=3 uid="uid://det8556rpxhbv"]
[ext_resource type="PackedScene" uid="uid://tlr55u0gn20l" path="res://Packed-Scenes/player_ship.tscn" id="1_njb5h"]
[ext_resource type="PackedScene" uid="uid://tlr55u0gn20l" path="res://Packed-Scenes/PlayerShip.tscn" id="1_njb5h"]
[ext_resource type="Texture2D" uid="uid://cg6n1hh3lj7rn" path="res://Textures/tile_nebula_green_dff.png" id="2_43vix"]
[ext_resource type="Script" path="res://Scripts/Background.cs" id="3_imgbw"]
[ext_resource type="PackedScene" uid="uid://6dn1gjqffnt" path="res://Packed-Scenes/asteroid_01.tscn" id="5_do6ba"]
@ -10,6 +10,7 @@
[ext_resource type="AudioStream" uid="uid://bthqgu8sulv77" path="res://Sounds/music_background.wav" id="8_4ms0p"]
[ext_resource type="AudioStream" uid="uid://t0y8yw2ceskq" path="res://Sounds/explosion_asteroid.wav" id="9_2dqf6"]
[ext_resource type="Script" path="res://Scripts/GameManager.cs" id="9_rsrr5"]
[ext_resource type="AudioStream" uid="uid://dlml6o3xscxqf" path="res://Sounds/weapon_player.wav" id="11_bbedd"]
[ext_resource type="Script" path="res://Scripts/GameArea.cs" id="11_p0rh7"]
[sub_resource type="BoxShape3D" id="BoxShape3D_bw288"]
@ -63,10 +64,11 @@ offset_right = 260.0
offset_bottom = 67.0
text = "Lives: 3"
[node name="SoundManager" type="Node" parent="." node_paths=PackedStringArray("explosionSound", "backgroundMusic")]
[node name="SoundManager" type="Node" parent="." node_paths=PackedStringArray("explosionSound", "backgroundMusic", "laserSound")]
script = ExtResource("8_4ksf0")
explosionSound = NodePath("ExplosionSound")
backgroundMusic = NodePath("BackgroundMusic")
laserSound = NodePath("LaserSound")
[node name="ExplosionSound" type="AudioStreamPlayer3D" parent="SoundManager"]
stream = ExtResource("9_2dqf6")
@ -76,6 +78,9 @@ stream = ExtResource("8_4ms0p")
volume_db = -20.0
autoplay = true
[node name="LaserSound" type="AudioStreamPlayer3D" parent="SoundManager"]
stream = ExtResource("11_bbedd")
[node name="GameArea" type="Node3D" parent="."]
script = ExtResource("11_p0rh7")

@ -7,6 +7,7 @@ public partial class PlayerShip : Node3D {
[Export] private Node3D jet;
[Export] public RigidBody3D PlayerRb;
[Export] private PackedScene explosion;
[Export] private GpuParticles3D laser;
public static PlayerShip Instance { get; private set;}
@ -20,6 +21,7 @@ public partial class PlayerShip : Node3D {
private const string PLAYER_MOVE_BACKWARDS = "Player_Move_Backwards";
private const string PLAYER_MOVE_LEFT = "Player_Move_Left";
private const string PLAYER_MOVE_RIGHT = "Player_Move_Right";
private const string PLAYER_FIRE = "Player_Fire";
private bool jetActive;
private bool JetActive {
@ -50,11 +52,9 @@ public partial class PlayerShip : Node3D {
moveDir = Vector3.Zero;
rotDir = Vector3.Zero;
//Movement
if (Input.IsAnythingPressed()) JetActive = true;
// Vector2 inputVector = Input.GetVector(PLAYER_MOVE_FORWARD, PLAYER_MOVE_BACKWARDS, PLAYER_MOVE_LEFT, PLAYER_MOVE_RIGHT);
// moveDir = new Vector3(inputVector.X, 0, inputVector.Y) * moveVelocity;
if (Input.IsActionPressed(PLAYER_MOVE_FORWARD)) moveDir.Z -= moveVelocity;
if (Input.IsActionPressed(PLAYER_MOVE_BACKWARDS)) moveDir.Z += moveVelocity;
if (Input.IsActionPressed(PLAYER_MOVE_LEFT)) moveDir.X -= moveVelocity;
@ -66,6 +66,10 @@ public partial class PlayerShip : Node3D {
if (Input.IsActionJustPressed(PLAYER_MOVE_RIGHT)) rotDir.Z = +rotVelocity * 2;
if (Input.IsActionJustReleased(PLAYER_MOVE_LEFT) || Input.IsActionJustReleased(PLAYER_MOVE_RIGHT)) rotDir = Vector3.Zero;
//Fire laser
laser.Emitting = Input.IsActionPressed(PLAYER_FIRE);
if (laser.Emitting) SoundManager.Instance.PlayLaserSound(PlayerRb.Position);
}
private void HandleMovement(double delta) {
@ -73,17 +77,12 @@ public partial class PlayerShip : Node3D {
KinematicCollision3D collision = PlayerRb.MoveAndCollide(moveDir * (float)delta);
if (collision?.GetCollider() is Node3D collider) GD.Print($"{Name} collides with {collider.GetParentNode3D().Name}");
}
// Position += moveDir;
PlayerRb.RotationDegrees = rotDir;
// playerRb.Rotate(rotDir.Normalized(), rotVelocity * (float)delta);
// RotationDegrees = rotDir * (float)delta;
CheckBoundaries();
}
private void CheckBoundaries() {
Vector3 correctedPos = Position;
Vector3 correctedPos = PlayerRb.Position;
correctedPos.X = Position.X switch {
< -3.3f => -3.3f,
> 3.3f => 3.3f,
@ -94,7 +93,7 @@ public partial class PlayerShip : Node3D {
> 5.2f => 5.2f,
_ => correctedPos.Z
};
Position = correctedPos;
PlayerRb.Position = correctedPos;
}
public void Explode(Vector3 collisionPosition) {
@ -103,7 +102,6 @@ public partial class PlayerShip : Node3D {
ex.Position = collisionPosition;
ex.Emitting = true;
}
SoundManager.Instance.PlayExplosion(collisionPosition);
GameManager.Instance.Lives--;
}

@ -6,6 +6,7 @@ namespace Scripts;
public partial class SoundManager : Node {
[Export] private AudioStreamPlayer3D explosionSound;
[Export] private AudioStreamPlayer backgroundMusic;
[Export] private AudioStreamPlayer3D laserSound;
public static SoundManager Instance { get; private set; }
public override void _Ready() => Instance = this;
@ -16,4 +17,9 @@ public partial class SoundManager : Node {
explosionSound.Play();
}
public void PlayLaserSound(Vector3 position) {
laserSound.Position = position;
laserSound.PitchScale = (float)GD.RandRange(0.25f, 1.75f);
laserSound.Play();
}
}

@ -56,3 +56,10 @@ Player_Move_Right={
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":14,"pressure":0.0,"pressed":true,"script":null)
]
}
Player_Fire={
"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":32,"key_label":0,"unicode":32,"echo":false,"script":null)
, 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":4194438,"key_label":0,"unicode":48,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":false,"script":null)
]
}