Code cleanup
parent
9aff213b2d
commit
b41cc14695
@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Godot.NET.Sdk/4.2.0-beta.3">
|
<Project Sdk="Godot.NET.Sdk/4.2.0-beta.3">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,78 +1,79 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace Scripts;
|
namespace Scripts;
|
||||||
|
|
||||||
[GlobalClass]
|
[GlobalClass]
|
||||||
public partial class Asteroid : Node3D {
|
public partial class Asteroid : Node3D {
|
||||||
[Export] public RigidBody3D AsteroidRb;
|
[Export] private CollisionShape3D asteroidCollisionShape;
|
||||||
[Export] private MeshInstance3D asteroidMesh;
|
[Export] private MeshInstance3D asteroidMesh;
|
||||||
[Export] private CollisionShape3D asteroidCollisionShape;
|
[Export] public RigidBody3D AsteroidRb;
|
||||||
[Export] private GpuParticlesCollisionSphere3D particleCollision;
|
[Export] private PackedScene explosion;
|
||||||
[Export] private PackedScene explosion;
|
[Export] private GpuParticlesCollisionSphere3D particleCollision;
|
||||||
|
private Vector3 rotation;
|
||||||
|
private float rotSpeed = 100f;
|
||||||
|
private float size;
|
||||||
|
|
||||||
|
private float speed;
|
||||||
|
|
||||||
private float speed;
|
public override void _EnterTree() {
|
||||||
private float rotSpeed = 100f;
|
Position = new((float)GD.RandRange(-3.7, 3.7), 0, -6.4f);
|
||||||
private float size;
|
|
||||||
private Vector3 rotation;
|
|
||||||
|
|
||||||
public override void _EnterTree() {
|
size = (float)GD.RandRange(0.5f, 1f);
|
||||||
Position = new((float)GD.RandRange(-3.7, 3.7), 0, -6.4f);
|
Vector3 scale = new(size, size, size);
|
||||||
|
asteroidMesh.Scale = scale;
|
||||||
|
AsteroidRb.Scale = scale;
|
||||||
|
asteroidCollisionShape.Scale = scale;
|
||||||
|
|
||||||
size = (float)GD.RandRange(0.5f, 1f);
|
speed = GD.Randf() * GameManager.Instance.Level * 0.1f + 1f;
|
||||||
Vector3 scale = new(size, size,size);
|
rotation = new((float)GD.RandRange(-rotSpeed, rotSpeed), (float)GD.RandRange(-rotSpeed, rotSpeed), (float)GD.RandRange(-rotSpeed, rotSpeed));
|
||||||
asteroidMesh.Scale = scale;
|
}
|
||||||
AsteroidRb.Scale = scale;
|
|
||||||
asteroidCollisionShape.Scale = scale;
|
|
||||||
|
|
||||||
speed = GD.Randf() * GameManager.Instance.Level * 0.1f + 1f;
|
public override void _Ready() { }
|
||||||
rotation = new((float)GD.RandRange(-rotSpeed, rotSpeed), (float)GD.RandRange(-rotSpeed, rotSpeed), (float)GD.RandRange(-rotSpeed, rotSpeed));
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void _Ready() {
|
public override void _PhysicsProcess(double delta) {
|
||||||
}
|
AsteroidRb.Rotate(rotation.Normalized(), (float)delta);
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta) {
|
KinematicCollision3D collision = AsteroidRb.MoveAndCollide(new(0, 0, speed * (float)delta));
|
||||||
AsteroidRb.Rotate(rotation.Normalized(), (float)delta);
|
if (collision?.GetCollider() is Node3D collider) {
|
||||||
|
Node3D parent = collider.GetParent<Node3D>();
|
||||||
|
GD.Print($"{Name} collides with {parent.Name}");
|
||||||
|
Vector3 collisionPosition = collision.GetPosition();
|
||||||
|
switch (parent) {
|
||||||
|
case Asteroid collidedAsteroid:
|
||||||
|
// collidedAsteroid.Explode(collisionPosition);
|
||||||
|
// Explode(collisionPosition);
|
||||||
|
break;
|
||||||
|
case PlayerShip:
|
||||||
|
GameManager.Instance.Lives--;
|
||||||
|
PlayerShip.Instance.Explode(collisionPosition);
|
||||||
|
Explode(collisionPosition);
|
||||||
|
break;
|
||||||
|
case GameArea:
|
||||||
|
Explode(Vector3.Zero);
|
||||||
|
break;
|
||||||
|
case LaserBeam laserBeam:
|
||||||
|
GameManager.Instance.Points++;
|
||||||
|
laserBeam.QueueFree();
|
||||||
|
Explode(collisionPosition);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
GD.Print("Asteroid collided with unknown.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
KinematicCollision3D collision = AsteroidRb.MoveAndCollide(new(0, 0, speed * (float)delta));
|
public void Explode(Vector3 exPosition) {
|
||||||
if (collision?.GetCollider() is Node3D collider) {
|
if (exPosition != Vector3.Zero) {
|
||||||
Node3D parent = collider.GetParent<Node3D>();
|
SoundManager.Instance.PlayExplosion(exPosition);
|
||||||
GD.Print($"{Name} collides with {parent.Name}");
|
if (explosion?.Instantiate() is GpuParticles3D ex) {
|
||||||
Vector3 collisionPosition = collision.GetPosition();
|
GetParent().AddChild(ex);
|
||||||
switch (parent) {
|
ex.Position = exPosition;
|
||||||
case Asteroid collidedAsteroid:
|
ex.Emitting = true;
|
||||||
// collidedAsteroid.Explode(collisionPosition);
|
}
|
||||||
// Explode(collisionPosition);
|
}
|
||||||
break;
|
|
||||||
case PlayerShip:
|
|
||||||
GameManager.Instance.Lives--;
|
|
||||||
PlayerShip.Instance.Explode(collisionPosition);
|
|
||||||
Explode(collisionPosition);
|
|
||||||
break;
|
|
||||||
case GameArea:
|
|
||||||
Explode(Vector3.Zero);
|
|
||||||
break;
|
|
||||||
case LaserBeam laserBeam:
|
|
||||||
GameManager.Instance.Points++;
|
|
||||||
laserBeam.QueueFree();
|
|
||||||
Explode(collisionPosition);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
GD.Print($"Asteroid collided with unknown.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Explode(Vector3 exPosition) {
|
GameManager.Instance.AsteroidNumber--;
|
||||||
if (exPosition != Vector3.Zero) {
|
QueueFree();
|
||||||
SoundManager.Instance.PlayExplosion(exPosition);
|
}
|
||||||
if (explosion?.Instantiate() is GpuParticles3D ex) {
|
}
|
||||||
GetParent().AddChild(ex);
|
|
||||||
ex.Position = exPosition;
|
|
||||||
ex.Emitting = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
GameManager.Instance.AsteroidNumber--;
|
|
||||||
QueueFree();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,11 +1,13 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace Scripts;
|
namespace Scripts;
|
||||||
|
|
||||||
public partial class Background : Sprite3D {
|
public partial class Background : Sprite3D {
|
||||||
[Export] private float moveVelocity = -250f;
|
[Export] private float moveVelocity = -250f;
|
||||||
public override void _Process(double delta) {
|
|
||||||
Rect2 region = RegionRect;
|
public override void _Process(double delta) {
|
||||||
region.Position += new Vector2(0, moveVelocity * (float)delta);
|
Rect2 region = RegionRect;
|
||||||
RegionRect = region;
|
region.Position += new Vector2(0, moveVelocity * (float)delta);
|
||||||
}
|
RegionRect = region;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@ -1,8 +1,7 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
public partial class Explosion : GpuParticles3D
|
public partial class Explosion : GpuParticles3D {
|
||||||
{
|
public override void _Process(double delta) {
|
||||||
public override void _Process(double delta) {
|
if (!Emitting) QueueFree();
|
||||||
if (!Emitting) QueueFree();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
@ -1,7 +1,3 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System;
|
|
||||||
|
|
||||||
public partial class GameArea : Node3D
|
public partial class GameArea : Node3D { }
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,10 +1,11 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
public partial class LaserBeam : Node3D {
|
public partial class LaserBeam : Node3D {
|
||||||
[Export] private RigidBody3D rigidBody;
|
[Export] private RigidBody3D rigidBody;
|
||||||
private float speed = 10f;
|
private float speed = 10f;
|
||||||
public override void _Ready() {
|
|
||||||
Vector3 movement = new(0f, 0f, -speed);
|
public override void _Ready() {
|
||||||
rigidBody.AddConstantForce(movement);
|
Vector3 movement = new(0f, 0f, -speed);
|
||||||
}
|
rigidBody.AddConstantForce(movement);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@ -1,101 +1,101 @@
|
|||||||
using System.Diagnostics;
|
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace Scripts;
|
namespace Scripts;
|
||||||
|
|
||||||
public partial class PlayerShip : Node3D {
|
public partial class PlayerShip : Node3D {
|
||||||
[Export] private float moveVelocity = 10f;
|
private const float jetTimerMax = 0.5f;
|
||||||
[Export] private float rotVelocity = 15f;
|
|
||||||
[Export] private Node3D jet;
|
private const float laserTimerMax = 1f;
|
||||||
[Export] public RigidBody3D PlayerRb;
|
|
||||||
[Export] private PackedScene explosion;
|
private const string PLAYER_MOVE_FORWARD = "Player_Move_Forward";
|
||||||
[Export] private GpuParticles3D gpulaser;
|
private const string PLAYER_MOVE_BACKWARDS = "Player_Move_Backwards";
|
||||||
[Export] private CpuParticles3D cpulaser;
|
private const string PLAYER_MOVE_LEFT = "Player_Move_Left";
|
||||||
[Export] private PackedScene laser;
|
private const string PLAYER_MOVE_RIGHT = "Player_Move_Right";
|
||||||
[Export] private Node3D shots;
|
private const string PLAYER_FIRE = "Player_Fire";
|
||||||
|
[Export] private CpuParticles3D cpulaser;
|
||||||
|
[Export] private PackedScene explosion;
|
||||||
|
[Export] private GpuParticles3D gpulaser;
|
||||||
|
[Export] private Node3D jet;
|
||||||
|
private float jetTimer = jetTimerMax;
|
||||||
|
[Export] private PackedScene laser;
|
||||||
|
private float laserTimer = laserTimerMax;
|
||||||
|
|
||||||
|
private Vector3 moveDir;
|
||||||
|
[Export] private float moveVelocity = 10f;
|
||||||
|
[Export] public RigidBody3D PlayerRb;
|
||||||
|
private Vector3 rotDir;
|
||||||
|
[Export] private float rotVelocity = 15f;
|
||||||
|
private bool shooting;
|
||||||
|
[Export] private Node3D shots;
|
||||||
|
|
||||||
|
public static PlayerShip Instance { get; private set; }
|
||||||
|
|
||||||
public static PlayerShip Instance { get; private set;}
|
public override void _Ready() {
|
||||||
|
Position = new(0, 0, 5);
|
||||||
private const float jetTimerMax = 0.5f;
|
Instance = this;
|
||||||
private float jetTimer = jetTimerMax;
|
}
|
||||||
|
|
||||||
private const float laserTimerMax = 1f;
|
|
||||||
private float laserTimer = laserTimerMax;
|
|
||||||
|
|
||||||
private Vector3 moveDir;
|
public override void _Process(double delta) {
|
||||||
private Vector3 rotDir;
|
moveDir = Vector3.Zero;
|
||||||
|
rotDir = Vector3.Zero;
|
||||||
private const string PLAYER_MOVE_FORWARD = "Player_Move_Forward";
|
|
||||||
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 shooting;
|
|
||||||
|
|
||||||
public override void _Ready() {
|
//Movement
|
||||||
Position = new(0, 0, 5);
|
if (Input.IsActionPressed(PLAYER_MOVE_FORWARD)) moveDir.Z -= moveVelocity;
|
||||||
Instance = this;
|
if (Input.IsActionJustPressed(PLAYER_MOVE_FORWARD)) rotDir.X = -rotVelocity;
|
||||||
}
|
if (Input.IsActionPressed(PLAYER_MOVE_BACKWARDS)) moveDir.Z += moveVelocity;
|
||||||
|
if (Input.IsActionJustPressed(PLAYER_MOVE_BACKWARDS)) rotDir.X = +rotVelocity;
|
||||||
|
if (Input.IsActionPressed(PLAYER_MOVE_LEFT)) moveDir.X -= moveVelocity;
|
||||||
|
if (Input.IsActionJustPressed(PLAYER_MOVE_LEFT)) rotDir.Z = -rotVelocity * 2;
|
||||||
|
if (Input.IsActionPressed(PLAYER_MOVE_RIGHT)) moveDir.X += moveVelocity;
|
||||||
|
if (Input.IsActionJustPressed(PLAYER_MOVE_RIGHT)) rotDir.Z = +rotVelocity * 2;
|
||||||
|
if (Input.IsActionJustReleased(PLAYER_MOVE_LEFT) || Input.IsActionJustReleased(PLAYER_MOVE_RIGHT)) rotDir = Vector3.Zero;
|
||||||
|
|
||||||
public override void _Process(double delta) {
|
//Fire
|
||||||
moveDir = Vector3.Zero;
|
if (Input.IsActionJustPressed(PLAYER_FIRE))
|
||||||
rotDir = Vector3.Zero;
|
if (laser.Instantiate() is Node3D shot) {
|
||||||
|
shot.Position = PlayerRb.Position + new Vector3(0f, 0f, 0.74f);
|
||||||
|
shots.AddChild(shot);
|
||||||
|
SoundManager.Instance.PlayLaserSound(PlayerRb.Position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Movement
|
public override void _PhysicsProcess(double delta) {
|
||||||
if (Input.IsActionPressed(PLAYER_MOVE_FORWARD)) moveDir.Z -= moveVelocity;
|
if (moveDir != Vector3.Zero) {
|
||||||
if (Input.IsActionJustPressed(PLAYER_MOVE_FORWARD)) rotDir.X = -rotVelocity;
|
jet.Visible = true;
|
||||||
if (Input.IsActionPressed(PLAYER_MOVE_BACKWARDS)) moveDir.Z += moveVelocity;
|
KinematicCollision3D collision = PlayerRb.MoveAndCollide(moveDir * (float)delta);
|
||||||
if (Input.IsActionJustPressed(PLAYER_MOVE_BACKWARDS)) rotDir.X = +rotVelocity;
|
if (collision?.GetCollider() is Node3D collider) GD.Print($"{Name} collides with {collider.GetParentNode3D().Name}");
|
||||||
if (Input.IsActionPressed(PLAYER_MOVE_LEFT)) moveDir.X -= moveVelocity;
|
}
|
||||||
if (Input.IsActionJustPressed(PLAYER_MOVE_LEFT)) rotDir.Z = -rotVelocity * 2;
|
else {
|
||||||
if (Input.IsActionPressed(PLAYER_MOVE_RIGHT)) moveDir.X += moveVelocity;
|
jet.Visible = false;
|
||||||
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
|
PlayerRb.RotationDegrees = rotDir;
|
||||||
if (Input.IsActionJustPressed(PLAYER_FIRE)) {
|
CheckBoundaries();
|
||||||
if (laser.Instantiate() is Node3D shot) {
|
}
|
||||||
shot.Position = PlayerRb.Position + new Vector3(0f, 0f, 0.74f);
|
|
||||||
shots.AddChild(shot);
|
|
||||||
SoundManager.Instance.PlayLaserSound(PlayerRb.Position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void _PhysicsProcess(double delta) {
|
private void CheckBoundaries() {
|
||||||
if (moveDir != Vector3.Zero) {
|
Vector3 correctedPos = PlayerRb.Position;
|
||||||
jet.Visible = true;
|
correctedPos.X = Position.X switch {
|
||||||
KinematicCollision3D collision = PlayerRb.MoveAndCollide(moveDir * (float)delta);
|
< -3.3f => -3.3f,
|
||||||
if (collision?.GetCollider() is Node3D collider) GD.Print($"{Name} collides with {collider.GetParentNode3D().Name}");
|
> 3.3f => 3.3f,
|
||||||
}
|
_ => correctedPos.X
|
||||||
else {
|
};
|
||||||
jet.Visible = false;
|
correctedPos.Z = Position.Z switch {
|
||||||
}
|
< -5.2f => -5.2f,
|
||||||
PlayerRb.RotationDegrees = rotDir;
|
> 5.2f => 5.2f,
|
||||||
CheckBoundaries();
|
_ => correctedPos.Z
|
||||||
}
|
};
|
||||||
|
PlayerRb.Position = correctedPos;
|
||||||
|
}
|
||||||
|
|
||||||
private void CheckBoundaries() {
|
public void Explode(Vector3 collisionPosition) {
|
||||||
Vector3 correctedPos = PlayerRb.Position;
|
if (explosion?.Instantiate() is GpuParticles3D ex) {
|
||||||
correctedPos.X = Position.X switch {
|
GetParent().AddChild(ex);
|
||||||
< -3.3f => -3.3f,
|
ex.Position = collisionPosition;
|
||||||
> 3.3f => 3.3f,
|
ex.Emitting = true;
|
||||||
_ => correctedPos.X
|
}
|
||||||
};
|
|
||||||
correctedPos.Z = Position.Z switch {
|
|
||||||
< -5.2f => -5.2f,
|
|
||||||
> 5.2f => 5.2f,
|
|
||||||
_ => correctedPos.Z
|
|
||||||
};
|
|
||||||
PlayerRb.Position = correctedPos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Explode(Vector3 collisionPosition) {
|
SoundManager.Instance.PlayExplosion(collisionPosition);
|
||||||
if (explosion?.Instantiate() is GpuParticles3D ex) {
|
GameManager.Instance.Lives--;
|
||||||
GetParent().AddChild(ex);
|
}
|
||||||
ex.Position = collisionPosition;
|
}
|
||||||
ex.Emitting = true;
|
|
||||||
}
|
|
||||||
SoundManager.Instance.PlayExplosion(collisionPosition);
|
|
||||||
GameManager.Instance.Lives--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,42 @@
|
|||||||
|
[preset.0]
|
||||||
|
|
||||||
|
name="Linux/X11"
|
||||||
|
platform="Linux/X11"
|
||||||
|
runnable=true
|
||||||
|
dedicated_server=false
|
||||||
|
custom_features=""
|
||||||
|
export_filter="all_resources"
|
||||||
|
include_filter=""
|
||||||
|
exclude_filter=""
|
||||||
|
export_path=""
|
||||||
|
encryption_include_filters=""
|
||||||
|
encryption_exclude_filters=""
|
||||||
|
encrypt_pck=false
|
||||||
|
encrypt_directory=false
|
||||||
|
|
||||||
|
[preset.0.options]
|
||||||
|
|
||||||
|
custom_template/debug=""
|
||||||
|
custom_template/release=""
|
||||||
|
debug/export_console_wrapper=1
|
||||||
|
binary_format/embed_pck=false
|
||||||
|
texture_format/bptc=true
|
||||||
|
texture_format/s3tc=true
|
||||||
|
texture_format/etc=false
|
||||||
|
texture_format/etc2=false
|
||||||
|
binary_format/architecture="x86_64"
|
||||||
|
ssh_remote_deploy/enabled=false
|
||||||
|
ssh_remote_deploy/host="user@host_ip"
|
||||||
|
ssh_remote_deploy/port="22"
|
||||||
|
ssh_remote_deploy/extra_args_ssh=""
|
||||||
|
ssh_remote_deploy/extra_args_scp=""
|
||||||
|
ssh_remote_deploy/run_script="#!/usr/bin/env bash
|
||||||
|
export DISPLAY=:0
|
||||||
|
unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"
|
||||||
|
\"{temp_dir}/{exe_name}\" {cmd_args}"
|
||||||
|
ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash
|
||||||
|
kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\")
|
||||||
|
rm -rf \"{temp_dir}\""
|
||||||
|
dotnet/include_scripts_content=false
|
||||||
|
dotnet/include_debug_symbols=true
|
||||||
|
dotnet/embed_build_outputs=false
|
||||||
Loading…
Reference in New Issue