I wrote some code in C# and Raylib-cs. It should do this: When you do a click, there should be drawn a circle and a line between the center of the circle and the actual mouse position. When you do another click, the circle should move against the direction of the line.
So, my code do what I wanted to do. But at high speed values the circles look blurred on the side facing away from the direction of movement. When the circle is moving slower, it looks fine for me. Is this normal? Is there something I can do?
Here is part 1 of my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using Raylib_cs;
namespace BallGame
{
class Circle
{
// KONSTRUKTOR
public Circle(Vector2 position, int radius)
{
this.Position = position;
this.Radius = radius;
}
// PROPERTIES
public int Radius { get; set; }
public Vector2 Position { get; set; }
public Color color { get; set; }
public Vector2 Direction { get; set; }
// METHODEN
public void move(float speed, float dt)
{
this.Position += this.Direction * speed * dt;
}
}
}
Here is part 2 of my code:
using Raylib_cs;
using System.Numerics;
namespace BallGame
{
class Program
{
static void Main(string[] args)
{
//Raylib.SetConfigFlags(ConfigFlags.Msaa4xHint);
Raylib.InitWindow(1600, 1200, "Ball Game");
Raylib.SetTargetFPS(120);
Vector2 circlePos = new Vector2(-1, -1);
Vector2 mousePos = new Vector2();
List<Circle> circles = new List<Circle>();
int[] clickPositions = new int[2];
while (!Raylib.WindowShouldClose())
{
// EVENTS
if (Raylib.IsMouseButtonPressed(MouseButton.Left))
{
if (circlePos != new Vector2(-1, -1))
{
circles[^1].Direction = Vector2.Normalize(circlePos - mousePos);
circlePos = new Vector2(-1, -1);
}
else
{
// not yet a circle, first click
circlePos = Raylib.GetMousePosition();
Circle newCircle = new Circle(circlePos, 50);
circles.Add(newCircle);
}
}
// UPDATE
if (circlePos != new Vector2(-1, -1))
{
mousePos = Raylib.GetMousePosition();
}
foreach (var circle in circles)
{
circle.move(500.0f, Raylib.GetFrameTime());
}
// DRAW
Raylib.BeginDrawing();
Raylib.ClearBackground(Color.LightGray);
// Line
if (circlePos != new Vector2(-1, -1))
{
Raylib.DrawLine(Convert.ToInt32(circlePos.X),
Convert.ToInt32(circlePos.Y), Convert.ToInt32(mousePos.X),
Convert.ToInt32(mousePos.Y), Color.Black);
}
// Circle
foreach (var circle in circles)
{
Raylib.DrawCircleV(circle.Position, circle.Radius, Color.Magenta);
}
Raylib.EndDrawing();
}
}
}
}