Code cleanup
parent
9aff213b2d
commit
b41cc14695
@ -1,6 +1,6 @@
|
||||
<Project Sdk="Godot.NET.Sdk/4.2.0-beta.3">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,78 +1,79 @@
|
||||
using Godot;
|
||||
|
||||
namespace Scripts;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class Asteroid : Node3D {
|
||||
[Export] public RigidBody3D AsteroidRb;
|
||||
[Export] private MeshInstance3D asteroidMesh;
|
||||
[Export] private CollisionShape3D asteroidCollisionShape;
|
||||
[Export] private GpuParticlesCollisionSphere3D particleCollision;
|
||||
[Export] private PackedScene explosion;
|
||||
[Export] private CollisionShape3D asteroidCollisionShape;
|
||||
[Export] private MeshInstance3D asteroidMesh;
|
||||
[Export] public RigidBody3D AsteroidRb;
|
||||
[Export] private PackedScene explosion;
|
||||
[Export] private GpuParticlesCollisionSphere3D particleCollision;
|
||||
private Vector3 rotation;
|
||||
private float rotSpeed = 100f;
|
||||
private float size;
|
||||
|
||||
private float speed;
|
||||
|
||||
private float speed;
|
||||
private float rotSpeed = 100f;
|
||||
private float size;
|
||||
private Vector3 rotation;
|
||||
public override void _EnterTree() {
|
||||
Position = new((float)GD.RandRange(-3.7, 3.7), 0, -6.4f);
|
||||
|
||||
public override void _EnterTree() {
|
||||
Position = new((float)GD.RandRange(-3.7, 3.7), 0, -6.4f);
|
||||
size = (float)GD.RandRange(0.5f, 1f);
|
||||
Vector3 scale = new(size, size, size);
|
||||
asteroidMesh.Scale = scale;
|
||||
AsteroidRb.Scale = scale;
|
||||
asteroidCollisionShape.Scale = scale;
|
||||
|
||||
size = (float)GD.RandRange(0.5f, 1f);
|
||||
Vector3 scale = new(size, size,size);
|
||||
asteroidMesh.Scale = scale;
|
||||
AsteroidRb.Scale = scale;
|
||||
asteroidCollisionShape.Scale = scale;
|
||||
speed = GD.Randf() * GameManager.Instance.Level * 0.1f + 1f;
|
||||
rotation = new((float)GD.RandRange(-rotSpeed, rotSpeed), (float)GD.RandRange(-rotSpeed, rotSpeed), (float)GD.RandRange(-rotSpeed, rotSpeed));
|
||||
}
|
||||
|
||||
speed = GD.Randf() * GameManager.Instance.Level * 0.1f + 1f;
|
||||
rotation = new((float)GD.RandRange(-rotSpeed, rotSpeed), (float)GD.RandRange(-rotSpeed, rotSpeed), (float)GD.RandRange(-rotSpeed, rotSpeed));
|
||||
}
|
||||
public override void _Ready() { }
|
||||
|
||||
public override void _Ready() {
|
||||
}
|
||||
public override void _PhysicsProcess(double delta) {
|
||||
AsteroidRb.Rotate(rotation.Normalized(), (float)delta);
|
||||
|
||||
public override void _PhysicsProcess(double delta) {
|
||||
AsteroidRb.Rotate(rotation.Normalized(), (float)delta);
|
||||
KinematicCollision3D collision = AsteroidRb.MoveAndCollide(new(0, 0, speed * (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));
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Explode(Vector3 exPosition) {
|
||||
if (exPosition != Vector3.Zero) {
|
||||
SoundManager.Instance.PlayExplosion(exPosition);
|
||||
if (explosion?.Instantiate() is GpuParticles3D ex) {
|
||||
GetParent().AddChild(ex);
|
||||
ex.Position = exPosition;
|
||||
ex.Emitting = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Explode(Vector3 exPosition) {
|
||||
if (exPosition != Vector3.Zero) {
|
||||
SoundManager.Instance.PlayExplosion(exPosition);
|
||||
if (explosion?.Instantiate() is GpuParticles3D ex) {
|
||||
GetParent().AddChild(ex);
|
||||
ex.Position = exPosition;
|
||||
ex.Emitting = true;
|
||||
}
|
||||
}
|
||||
GameManager.Instance.AsteroidNumber--;
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
GameManager.Instance.AsteroidNumber--;
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,13 @@
|
||||
using Godot;
|
||||
|
||||
namespace Scripts;
|
||||
|
||||
public partial class Background : Sprite3D {
|
||||
[Export] private float moveVelocity = -250f;
|
||||
public override void _Process(double delta) {
|
||||
Rect2 region = RegionRect;
|
||||
region.Position += new Vector2(0, moveVelocity * (float)delta);
|
||||
RegionRect = region;
|
||||
}
|
||||
}
|
||||
[Export] private float moveVelocity = -250f;
|
||||
|
||||
public override void _Process(double delta) {
|
||||
Rect2 region = RegionRect;
|
||||
region.Position += new Vector2(0, moveVelocity * (float)delta);
|
||||
RegionRect = region;
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,7 @@
|
||||
using Godot;
|
||||
|
||||
public partial class Explosion : GpuParticles3D
|
||||
{
|
||||
public override void _Process(double delta) {
|
||||
if (!Emitting) QueueFree();
|
||||
}
|
||||
}
|
||||
public partial class Explosion : GpuParticles3D {
|
||||
public override void _Process(double delta) {
|
||||
if (!Emitting) QueueFree();
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,3 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class GameArea : Node3D
|
||||
{
|
||||
|
||||
}
|
||||
public partial class GameArea : Node3D { }
|
||||
@ -1,10 +1,11 @@
|
||||
using Godot;
|
||||
|
||||
public partial class LaserBeam : Node3D {
|
||||
[Export] private RigidBody3D rigidBody;
|
||||
private float speed = 10f;
|
||||
public override void _Ready() {
|
||||
Vector3 movement = new(0f, 0f, -speed);
|
||||
rigidBody.AddConstantForce(movement);
|
||||
}
|
||||
}
|
||||
[Export] private RigidBody3D rigidBody;
|
||||
private float speed = 10f;
|
||||
|
||||
public override void _Ready() {
|
||||
Vector3 movement = new(0f, 0f, -speed);
|
||||
rigidBody.AddConstantForce(movement);
|
||||
}
|
||||
}
|
||||
@ -1,101 +1,101 @@
|
||||
using System.Diagnostics;
|
||||
using Godot;
|
||||
|
||||
namespace Scripts;
|
||||
|
||||
public partial class PlayerShip : Node3D {
|
||||
[Export] private float moveVelocity = 10f;
|
||||
[Export] private float rotVelocity = 15f;
|
||||
[Export] private Node3D jet;
|
||||
[Export] public RigidBody3D PlayerRb;
|
||||
[Export] private PackedScene explosion;
|
||||
[Export] private GpuParticles3D gpulaser;
|
||||
[Export] private CpuParticles3D cpulaser;
|
||||
[Export] private PackedScene laser;
|
||||
[Export] private Node3D shots;
|
||||
private const float jetTimerMax = 0.5f;
|
||||
|
||||
private const float laserTimerMax = 1f;
|
||||
|
||||
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";
|
||||
[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;}
|
||||
|
||||
private const float jetTimerMax = 0.5f;
|
||||
private float jetTimer = jetTimerMax;
|
||||
|
||||
private const float laserTimerMax = 1f;
|
||||
private float laserTimer = laserTimerMax;
|
||||
public override void _Ready() {
|
||||
Position = new(0, 0, 5);
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private Vector3 moveDir;
|
||||
private Vector3 rotDir;
|
||||
|
||||
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 _Process(double delta) {
|
||||
moveDir = Vector3.Zero;
|
||||
rotDir = Vector3.Zero;
|
||||
|
||||
public override void _Ready() {
|
||||
Position = new(0, 0, 5);
|
||||
Instance = this;
|
||||
}
|
||||
//Movement
|
||||
if (Input.IsActionPressed(PLAYER_MOVE_FORWARD)) moveDir.Z -= moveVelocity;
|
||||
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) {
|
||||
moveDir = Vector3.Zero;
|
||||
rotDir = Vector3.Zero;
|
||||
//Fire
|
||||
if (Input.IsActionJustPressed(PLAYER_FIRE))
|
||||
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
|
||||
if (Input.IsActionPressed(PLAYER_MOVE_FORWARD)) moveDir.Z -= moveVelocity;
|
||||
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 _PhysicsProcess(double delta) {
|
||||
if (moveDir != Vector3.Zero) {
|
||||
jet.Visible = true;
|
||||
KinematicCollision3D collision = PlayerRb.MoveAndCollide(moveDir * (float)delta);
|
||||
if (collision?.GetCollider() is Node3D collider) GD.Print($"{Name} collides with {collider.GetParentNode3D().Name}");
|
||||
}
|
||||
else {
|
||||
jet.Visible = false;
|
||||
}
|
||||
|
||||
//Fire
|
||||
if (Input.IsActionJustPressed(PLAYER_FIRE)) {
|
||||
if (laser.Instantiate() is Node3D shot) {
|
||||
shot.Position = PlayerRb.Position + new Vector3(0f, 0f, 0.74f);
|
||||
shots.AddChild(shot);
|
||||
SoundManager.Instance.PlayLaserSound(PlayerRb.Position);
|
||||
}
|
||||
}
|
||||
}
|
||||
PlayerRb.RotationDegrees = rotDir;
|
||||
CheckBoundaries();
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta) {
|
||||
if (moveDir != Vector3.Zero) {
|
||||
jet.Visible = true;
|
||||
KinematicCollision3D collision = PlayerRb.MoveAndCollide(moveDir * (float)delta);
|
||||
if (collision?.GetCollider() is Node3D collider) GD.Print($"{Name} collides with {collider.GetParentNode3D().Name}");
|
||||
}
|
||||
else {
|
||||
jet.Visible = false;
|
||||
}
|
||||
PlayerRb.RotationDegrees = rotDir;
|
||||
CheckBoundaries();
|
||||
}
|
||||
private void CheckBoundaries() {
|
||||
Vector3 correctedPos = PlayerRb.Position;
|
||||
correctedPos.X = Position.X switch {
|
||||
< -3.3f => -3.3f,
|
||||
> 3.3f => 3.3f,
|
||||
_ => correctedPos.X
|
||||
};
|
||||
correctedPos.Z = Position.Z switch {
|
||||
< -5.2f => -5.2f,
|
||||
> 5.2f => 5.2f,
|
||||
_ => correctedPos.Z
|
||||
};
|
||||
PlayerRb.Position = correctedPos;
|
||||
}
|
||||
|
||||
private void CheckBoundaries() {
|
||||
Vector3 correctedPos = PlayerRb.Position;
|
||||
correctedPos.X = Position.X switch {
|
||||
< -3.3f => -3.3f,
|
||||
> 3.3f => 3.3f,
|
||||
_ => 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) {
|
||||
if (explosion?.Instantiate() is GpuParticles3D ex) {
|
||||
GetParent().AddChild(ex);
|
||||
ex.Position = collisionPosition;
|
||||
ex.Emitting = true;
|
||||
}
|
||||
|
||||
public void Explode(Vector3 collisionPosition) {
|
||||
if (explosion?.Instantiate() is GpuParticles3D ex) {
|
||||
GetParent().AddChild(ex);
|
||||
ex.Position = collisionPosition;
|
||||
ex.Emitting = true;
|
||||
}
|
||||
SoundManager.Instance.PlayExplosion(collisionPosition);
|
||||
GameManager.Instance.Lives--;
|
||||
}
|
||||
}
|
||||
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