added a cheat console

This commit is contained in:
2023-02-19 11:51:34 +01:00
parent da44882f06
commit e60c916ab0
5 changed files with 102 additions and 2 deletions

View File

@@ -0,0 +1,56 @@
using Godot;
public partial class console : CanvasLayer
{
public RichTextLabel textblock;
public LineEdit line;
public string error = "Not found! :(";
public override void _Ready()
{
textblock = GetNode<RichTextLabel>("panel_container/v_box_container/rich_text_label");
line = GetNode<LineEdit>("panel_container/v_box_container/line_edit");
}
public override void _Process(double delta)
{
if (Input.IsActionJustPressed("console"))
{
Visible = !Visible;
line.GrabFocus();
if (GetParent().Name == "player") GetParent<player>().allowMovement = !Visible;
}
}
public void OnLineEditTextSubmitted(string command)
{
command = command.ToLower();
line.Clear();
if (command.Length != 0) textblock.AddText("\n>" + command);
Variant args;
if (command.Split(' ').Length == 2)
{
int i = command.IndexOf(" ") + 1;
args = command.Substring(i);
Call(command.Split(' ')[0], args);
}
if (command.Split(' ').Length > 2)
{
int i = command.IndexOf(" ") + 1;
args = command.Substring(i).Split(' ');
Callv(command.Split(' ')[0], args.AsGodotArray());
}
else Call(command);
}
public void help()
{
textblock.AddText("\n============ Help ============");
textblock.AddText("\n1. consoleclear - Clears the console");
textblock.AddText("\n2. speed <value> - Multiplies the player speed by the given value");
}
public void consoleclear() => textblock.Clear();
public void speed(float multiplier)
{
if (GetParent().Name == "player") GetParent<player>().speedMultiplier = Mathf.Clamp(multiplier, 0.01f, 15f);
textblock.AddText("\nSet speed to " + Mathf.Clamp(multiplier, 0.01f, 15f));
}
}

View File

@@ -7,6 +7,7 @@ public partial class player : CharacterBody2D
[Export] public string playerName;
[Export] public int speed = 200;
public float speedMultiplier = 1;
public bool allowMovement = true;
public Vector2 movement;
public AnimatedSprite2D animatedSprite;
@@ -29,7 +30,7 @@ public partial class player : CharacterBody2D
if (allowMovement) movement = Input.GetVector("move_left", "move_right", "move_up", "move_down");
else movement = Vector2.Zero;
if (movement.Length() != 0) rotCenter.Rotation = new Vector2((float)Math.Round(movement.X, 0), (float)Math.Round(movement.Y, 0)).Angle();
MoveAndCollide(movement * speed * (float)delta);
MoveAndCollide(movement * speed * speedMultiplier * (float)delta);
}
public override void _Process(double delta)
{