Tweaked settings and converted client speed to float so its smoother and more natural
This commit is contained in:
+21
-16
@@ -12,14 +12,14 @@ namespace Caisses
|
||||
const int MAX_CLIENT_SPEED = 5;
|
||||
const int MIN_CLIENT_SPEED = -5;
|
||||
|
||||
private Point _speed;
|
||||
private Point _position;
|
||||
private PointF _speed;
|
||||
private PointF _position;
|
||||
private Color _color;
|
||||
private Size _size;
|
||||
private Rectangle _area;
|
||||
|
||||
public Point Speed { get => _speed; set => _speed = value; }
|
||||
public Point Position { get => _position; set => _position = value; }
|
||||
public PointF Speed { get => _speed; set => _speed = value; }
|
||||
public PointF Position { get => _position; set => _position = value; }
|
||||
public Color Color { get => _color; set => _color = value; }
|
||||
public Size Size { get => _size; set => _size = value; }
|
||||
public Rectangle Area { get => _area; set => _area = value; }
|
||||
@@ -28,12 +28,17 @@ namespace Caisses
|
||||
{
|
||||
Random = random;
|
||||
Position = Entrance;
|
||||
Position = new Point(Random.Next(0, 100), Random.Next(0, 100));
|
||||
Speed = new Point(Random.Next(MIN_CLIENT_SPEED, MAX_CLIENT_SPEED), Random.Next(MIN_CLIENT_SPEED, MAX_CLIENT_SPEED));
|
||||
//Position = new Point(Random.Next(0, 100), Random.Next(0, 100));
|
||||
Speed = new PointF(NextFloat(MIN_CLIENT_SPEED, MAX_CLIENT_SPEED), NextFloat(MIN_CLIENT_SPEED, MAX_CLIENT_SPEED));
|
||||
Color = Color.FromArgb(ShoppingTime * 2, 0, 0);
|
||||
int clientWidth = Random.Next(20, 30);
|
||||
Size = new Size(clientWidth, clientWidth);
|
||||
}
|
||||
static float NextFloat(float min, float max)
|
||||
{
|
||||
double val = (Random.NextDouble() * (max - min) + min);
|
||||
return (float)val;
|
||||
}
|
||||
public void Update(Size area)
|
||||
{
|
||||
//base.Tick();
|
||||
@@ -47,27 +52,27 @@ namespace Caisses
|
||||
switch (State)
|
||||
{
|
||||
case ClientState.Shopping:
|
||||
g.FillEllipse(new SolidBrush(Color), new Rectangle(Position, Size));
|
||||
g.FillEllipse(new SolidBrush(Color), new RectangleF(Position, Size));
|
||||
g.DrawString(ShoppingTime.ToString(), new Font("Arial", 16), new SolidBrush(Color.White),new PointF(Position.X,Position.Y));
|
||||
break;
|
||||
case ClientState.Waiting:
|
||||
g.FillEllipse(new SolidBrush(Color.Red), new Rectangle(Position, Size));
|
||||
g.FillEllipse(new SolidBrush(Color.Red), new RectangleF(Position, Size));
|
||||
g.DrawString(WaitingTime.ToString(), new Font("Arial", 16), new SolidBrush(Color.White), new PointF(Position.X, Position.Y));
|
||||
break;
|
||||
case ClientState.Inline:
|
||||
g.FillEllipse(new SolidBrush(Color.Violet), new Rectangle(Position, Size));
|
||||
g.FillEllipse(new SolidBrush(Color.Violet), new RectangleF(Position, Size));
|
||||
break;
|
||||
case ClientState.Checkout:
|
||||
g.FillEllipse(new SolidBrush(Color.Green), new Rectangle(Position, Size));
|
||||
g.FillEllipse(new SolidBrush(Color.Green), new RectangleF(Position, Size));
|
||||
g.DrawString(CheckoutTime.ToString(), new Font("Arial", 16), new SolidBrush(Color.Black), new PointF(Position.X, Position.Y));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public Point checkBounds(Point position, Size area)
|
||||
public PointF checkBounds(PointF position, Size area)
|
||||
{
|
||||
Point newPosition = new Point(position.X,position.Y);
|
||||
PointF newPosition = new PointF(position.X,position.Y);
|
||||
/*
|
||||
if (position.X < 0)
|
||||
{
|
||||
@@ -97,10 +102,10 @@ namespace Caisses
|
||||
}
|
||||
else
|
||||
{
|
||||
int diff = Math.Abs(position.X + Speed.X);
|
||||
float diff = Math.Abs(position.X + Speed.X);
|
||||
newPosition.X = diff;
|
||||
//newPosition = new Point(0, position.Y);
|
||||
Speed = new Point(Speed.X * -1,Speed.Y);
|
||||
Speed = new PointF(Speed.X * -1,Speed.Y);
|
||||
//speed.X += -1;
|
||||
}
|
||||
if (position.Y + Speed.Y > 0 && position.Y + Size.Height + Speed.Y < area.Height)
|
||||
@@ -109,10 +114,10 @@ namespace Caisses
|
||||
}
|
||||
else
|
||||
{
|
||||
int diff = Math.Abs(position.Y + Speed.Y);
|
||||
float diff = Math.Abs(position.Y + Speed.Y);
|
||||
newPosition.Y = diff;
|
||||
//newPosition = new Point(position.X, 0);
|
||||
Speed = new Point(Speed.X,Speed.Y * -1);
|
||||
Speed = new PointF(Speed.X,Speed.Y * -1);
|
||||
//speed.Y *= -1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user