changed speed value code

This commit is contained in:
2023-02-19 12:54:13 +01:00
parent 6e7c6b94f4
commit 6e8dcba561
2 changed files with 5 additions and 6 deletions

View File

@@ -51,7 +51,7 @@ public partial class console : CanvasLayer
public void consoleclear() => textblock.Clear(); public void consoleclear() => textblock.Clear();
public void speed(float multiplier) public void speed(float multiplier)
{ {
if (GetParent().Name == "player") GetParent<player>().speedMultiplier = Mathf.Clamp(multiplier, 0.01f, 15f); if (GetParent().Name == "player") GetParent<player>().speed = Mathf.Clamp(multiplier, 0.01f, 15f);
textblock.AddText("\nSet speed to " + Mathf.Clamp(multiplier, 0.01f, 15f)); textblock.AddText("\nSet speed to " + Mathf.Clamp(multiplier, 0.01f, 15f));
} }
public void playername(string name) public void playername(string name)

View File

@@ -6,8 +6,7 @@ public partial class player : CharacterBody2D
{ {
[Export] public string playerName; [Export] public string playerName;
[Export] public int speed = 200; [Export] public float speed = 1;
public float speedMultiplier = 1;
public bool allowMovement = true; public bool allowMovement = true;
public Vector2 movement; public Vector2 movement;
public AnimatedSprite2D animatedSprite; public AnimatedSprite2D animatedSprite;
@@ -33,7 +32,7 @@ public partial class player : CharacterBody2D
if (allowMovement) movement = Input.GetVector("move_left", "move_right", "move_up", "move_down"); if (allowMovement) movement = Input.GetVector("move_left", "move_right", "move_up", "move_down");
else movement = Vector2.Zero; 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(); if (movement.Length() != 0) rotCenter.Rotation = new Vector2((float)Math.Round(movement.X, 0), (float)Math.Round(movement.Y, 0)).Angle();
MoveAndCollide(movement * speed * speedMultiplier * (float)delta); MoveAndCollide(movement * speed * 200 * (float)delta);
} }
public override void _Process(double delta) public override void _Process(double delta)
{ {
@@ -58,14 +57,14 @@ public partial class player : CharacterBody2D
{ {
animatedSprite.Animation = "move_side"; animatedSprite.Animation = "move_side";
animatedSprite.FlipH = movement.X < 0.5; animatedSprite.FlipH = movement.X < 0.5;
animatedSprite.SpeedScale = Math.Abs(movement.X * speed / 150); animatedSprite.SpeedScale = Math.Abs(movement.X * speed * 1.3f);
} }
else if (Math.Round(movement.Y, 0) != 0) else if (Math.Round(movement.Y, 0) != 0)
{ {
if (movement.Y > 0.05) animatedSprite.Animation = "move_down"; if (movement.Y > 0.05) animatedSprite.Animation = "move_down";
if (movement.Y < 0.05) animatedSprite.Animation = "move_up"; if (movement.Y < 0.05) animatedSprite.Animation = "move_up";
animatedSprite.FlipH = false; animatedSprite.FlipH = false;
animatedSprite.SpeedScale = Math.Abs(movement.Y * speed / 150); animatedSprite.SpeedScale = Math.Abs(movement.Y * speed * 1.3f);
} }
} }
} }