using Godot; using System; using System.Collections.Generic; public partial class Student : CharacterBody2D { public float Speed { get; set; } = 10.0f; public const float JumpVelocity = -400.0f; public int NextType = -1; private Queue PathToGo = new(); public override void _PhysicsProcess(double delta) { if (PathToGo.Count == 0) { return;// No path to follow. } Vector2 velocity = new(); var nextPoint = PathToGo.Peek(); if ((int)GlobalPosition.X == nextPoint.X && (int)GlobalPosition.Y == nextPoint.Y) { GD.Print(PathToGo.Dequeue()); } nextPoint = PathToGo.Peek(); // if ((int)GlobalPosition.X == nextPoint.X) { // // Move Y // // velocity.Y = Math.Max(Speed, Math.Abs(nextPoint.Y - GlobalPosition.Y)); // velocity.Y = Speed; // if (GlobalPosition.Y > nextPoint.Y) { // velocity.Y = -velocity.Y; // } // } else if ((int)GlobalPosition.Y == nextPoint.Y) { // // move X // // velocity.X = Math.Max(Speed, Math.Abs(nextPoint.X - GlobalPosition.X)); // velocity.X = Speed; // if (GlobalPosition.X > nextPoint.X) { // velocity.X = -velocity.X; // } // } if ((int)GlobalPosition.X == nextPoint.X) { // Move Y // velocity.Y = Math.Max(Speed, Math.Abs(nextPoint.Y - GlobalPosition.Y)); velocity.Y = Speed; if (GlobalPosition.Y > nextPoint.Y) { velocity.Y = -velocity.Y; } } else if ((int)GlobalPosition.Y == nextPoint.Y) { // move X // velocity.X = Math.Max(Speed, Math.Abs(nextPoint.X - GlobalPosition.X)); velocity.X = Speed; if (GlobalPosition.X > nextPoint.X) { velocity.X = -velocity.X; } } GlobalPosition = GlobalPosition with { X = GlobalPosition.X + velocity.X, Y = GlobalPosition.Y + velocity.Y }; // Velocity = velocity; MoveAndSlide(); } public override void _Ready() { base._Ready(); var bt = GetNode("BTPlayer"); var bb = bt.Blackboard; // bb.BindVarToProperty("Stayed", this, "Speed"); // GD.Print(bb.GetVar("Stayed")); // GD.Print($"Speed: {Speed}"); var ap = GetNode("AnimationPlayer"); ap.Autoplay = "idle_front"; ap.Play("idle_front"); } public void MoveFollowPath(List path) { foreach (var p in path) { PathToGo.Enqueue(new Vector2I(p.X * 80 + 40, p.Y * 80 + 120)); } } public void GoTo(int nType) { GD.Print($"Called with nType = {nType}"); var lab = GetParentOrNull(); if (lab == null) { return; } var block = lab.GetTypedBlock((Lab.MapNodeType)nType, GD.Randi()); MoveFollowPath(lab.GetShortestPath(lab.Point2Coord(GlobalPosition), block)); randomChangeBody(); } private void randomChangeBody() { uint bodyId = GD.Randi() % 9 + 1; var body = GetNode("parts/body"); var rp = GetNode("ResourcePreloader"); body.Texture = (Texture2D)rp.GetResource($"Body_48x48_0{bodyId}"); } }