Skip to content

Commit

Permalink
Fix menu title, missing gun model, jump cooldown.
Browse files Browse the repository at this point in the history
- Change title from "Energy Chops" to "Energy Shot".
- Add 3 second jump cooldown to make it easier to score hits.
- Export .obj file type to include missing gun models in game.
  • Loading branch information
knightofiam committed Feb 20, 2025
1 parent c75021d commit afab9b7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
37 changes: 24 additions & 13 deletions Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ public partial class Player : CharacterBody3D
private MeshInstance3D _mesh = null!;
private Sprite3D _crosshairs = null!;
private Timer _shotTimer = null!;
private Timer _jumpTimer = null!;
private int _health = 3;
public override void _EnterTree() => SetMultiplayerAuthority (NetworkId);
private bool IsJumping() => _jumpTimer.IsStopped() && Input.IsActionJustPressed ("jump") && IsOnFloor();
private bool IsShooting() => _shotTimer.IsStopped() && Input.IsActionJustPressed ("shoot");
private void SetColor (Color color) => (_mesh.GetSurfaceOverrideMaterial (0) as StandardMaterial3D)!.AlbedoColor = color;

public override void _Ready()
Expand All @@ -27,6 +30,7 @@ public override void _Ready()
_shootingSound = GetNode <AudioStreamPlayer3D> ("ShootingSound");
_crosshairs = GetNode <Sprite3D> ("Camera3D/Crosshairs");
_shotTimer = GetNode <Timer> ("ShotTimer");
_jumpTimer = GetNode <Timer> ("JumpTimer");
HitRedTimer = GetNode <Timer> ("HitRedTimer");

if (!IsMultiplayerAuthority())
Expand All @@ -41,12 +45,19 @@ public override void _Ready()
Input.MouseMode = Input.MouseModeEnum.Captured;
}

private void Jump (ref Vector3 velocity)
{
velocity.Y = JumpVelocity;
_jumpTimer.Start();
}

public override void _PhysicsProcess (double delta)
{
if (!IsMultiplayerAuthority()) return;
var velocity = Velocity;
if (!IsOnFloor()) velocity += Gravity * (float)delta;
if (Input.IsActionJustPressed ("jump") && IsOnFloor()) velocity.Y = JumpVelocity;
if (IsJumping()) Jump (ref velocity);

var inputDir = Input.GetVector ("move_left", "move_right", "move_forward", "move_back");
var direction = (Transform.Basis * new Vector3 (inputDir.X, 0, inputDir.Y)).Normalized();

Expand All @@ -68,24 +79,24 @@ public override void _PhysicsProcess (double delta)
public override void _UnhandledInput (InputEvent @event)
{
if (!IsMultiplayerAuthority()) return;

if (Input.IsActionJustPressed ("shoot") && _shotTimer.IsStopped())
{
_shotTimer.Start();
Rpc (MethodName.PlayShootEffects);
if (!_aim.IsColliding() || _aim.GetCollider() is not Player hitPlayer || hitPlayer.NetworkId == NetworkId) return;
GD.Print ($"{Name}: I am shooting: {hitPlayer.GetMultiplayerAuthority()}");
hitPlayer.SetColor (HitColor); // This is only for the puppet.
hitPlayer.HitRedTimer.Start(); // This is only for the puppet.
hitPlayer.RpcId (hitPlayer.NetworkId, MethodName.Shot);
}

if (IsShooting()) Shoot();
if (@event is not InputEventMouseMotion motionEvent) return;
RotateY (-motionEvent.Relative.X * 0.005f);
_camera.RotateX (-motionEvent.Relative.Y * 0.005f);
_camera.Rotation = new Vector3 (Mathf.Clamp (_camera.Rotation.X, -Mathf.Pi / 2.0f, Mathf.Pi / 2.0f), _camera.Rotation.Y, _camera.Rotation.Z);
}

private void Shoot()
{
_shotTimer.Start();
Rpc (MethodName.PlayShootEffects);
if (!_aim.IsColliding() || _aim.GetCollider() is not Player hitPlayer || hitPlayer.NetworkId == NetworkId) return;
GD.Print ($"{Name}: I am shooting: {hitPlayer.GetMultiplayerAuthority()}");
hitPlayer.SetColor (HitColor); // This is only for the puppet.
hitPlayer.HitRedTimer.Start(); // This is only for the puppet.
hitPlayer.RpcId (hitPlayer.NetworkId, MethodName.Shot);
}

[Rpc (CallLocal = true)]
private void PlayShootEffects()
{
Expand Down
4 changes: 4 additions & 0 deletions Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ script = ExtResource("1_nipvj")
wait_time = 0.25
one_shot = true

[node name="JumpTimer" type="Timer" parent="."]
wait_time = 3.0
one_shot = true

[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
mesh = SubResource("CapsuleMesh_kwhax")
Expand Down
2 changes: 1 addition & 1 deletion UI.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ theme_override_constants/separation = 200
[node name="Label" type="Label" parent="MainMenu/MarginContainer/VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 200
text = "Energy Chops"
text = "Energy Shot"
horizontal_alignment = 1

[node name="MarginContainer" type="MarginContainer" parent="MainMenu/MarginContainer/VBoxContainer"]
Expand Down
4 changes: 2 additions & 2 deletions export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ advanced_options=false
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
include_filter="*.obj"
exclude_filter=""
export_path="build/energy-shot.exe"
encryption_include_filters=""
Expand Down Expand Up @@ -75,7 +75,7 @@ advanced_options=false
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
include_filter="*.obj"
exclude_filter=""
export_path="build/energy-shot.app"
encryption_include_filters=""
Expand Down

0 comments on commit afab9b7

Please sign in to comment.