138 lines
5.1 KiB
C#
138 lines
5.1 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
using Excavator.Entities;
|
|||
|
|
|||
|
namespace Excavator.DrawingObjects
|
|||
|
{
|
|||
|
public class DrawingMash
|
|||
|
{
|
|||
|
public EntityMash? EntityMash { get; protected set; }
|
|||
|
public int _pictureWidth;
|
|||
|
public int _pictureHeight;
|
|||
|
protected int _startPosX;
|
|||
|
protected int _startPosY;
|
|||
|
protected readonly int _mashWidth = 150;
|
|||
|
protected readonly int _mashHeight = 95;
|
|||
|
public int GetPosX => _startPosX;
|
|||
|
public int GetPosY => _startPosY;
|
|||
|
public int GetWidth => _mashWidth;
|
|||
|
public int GetHeight => _mashHeight;
|
|||
|
public DrawingMash(int speed, double weight, Color bodyColor, int width, int height)
|
|||
|
{
|
|||
|
if (width < _mashWidth || height < _mashHeight)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
_pictureWidth = width;
|
|||
|
_pictureHeight = height;
|
|||
|
EntityMash = new EntityMash(speed, weight, bodyColor);
|
|||
|
}
|
|||
|
protected DrawingMash(int speed, double weight, Color bodyColor, int width, int height, int mashWidth, int mashHeight)
|
|||
|
{
|
|||
|
if (width < _mashWidth || height < _mashHeight)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
_pictureWidth = width;
|
|||
|
_pictureHeight = height;
|
|||
|
_mashWidth = mashWidth;
|
|||
|
_mashHeight = mashHeight;
|
|||
|
EntityMash = new EntityMash(speed, weight, bodyColor);
|
|||
|
}
|
|||
|
public void SetPosition(int x, int y)
|
|||
|
{
|
|||
|
if (x > _pictureWidth || y > _pictureHeight)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
_startPosX = x;
|
|||
|
_startPosY = y;
|
|||
|
}
|
|||
|
public void MoveTransport(DirectionType direction)
|
|||
|
{
|
|||
|
if (!CanMove(direction) || EntityMash == null)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
switch (direction)
|
|||
|
{
|
|||
|
case DirectionType.Left:
|
|||
|
if (_startPosX - EntityMash.Step > -50)
|
|||
|
{
|
|||
|
_startPosX -= (int)EntityMash.Step;
|
|||
|
}
|
|||
|
break;
|
|||
|
case DirectionType.Up:
|
|||
|
if (_startPosY - EntityMash.Step > -35)
|
|||
|
{
|
|||
|
_startPosY -= (int)EntityMash.Step;
|
|||
|
}
|
|||
|
break;
|
|||
|
case DirectionType.Right:
|
|||
|
if (_startPosX + _mashWidth + EntityMash.Step < _pictureWidth + 14)
|
|||
|
{
|
|||
|
_startPosX += (int)EntityMash.Step;
|
|||
|
}
|
|||
|
break;
|
|||
|
case DirectionType.Down:
|
|||
|
if (_startPosY + _mashHeight + EntityMash.Step < _pictureHeight)
|
|||
|
{
|
|||
|
_startPosY += (int)EntityMash.Step;
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
public virtual void DrawTransport(Graphics g)
|
|||
|
{
|
|||
|
Pen pen = new(Color.Black);
|
|||
|
Brush additionalBrush = new
|
|||
|
SolidBrush(EntityMash.BodyColor);
|
|||
|
|
|||
|
g.FillRectangle(additionalBrush, _startPosX + 30, _startPosY + 31, 140, 35);
|
|||
|
g.FillRectangle(additionalBrush, _startPosX + 60, _startPosY + 2, 15, 35);
|
|||
|
g.FillRectangle(additionalBrush, _startPosX + 125, _startPosY + 2, 40, 40);
|
|||
|
|
|||
|
Brush additionalBrush1 = new
|
|||
|
SolidBrush(EntityMash.BodyColor);
|
|||
|
|
|||
|
Brush gr = new SolidBrush(Color.Gray);
|
|||
|
|
|||
|
g.FillEllipse(additionalBrush1, _startPosX + 20, _startPosY + 72, 25, 25);
|
|||
|
g.FillEllipse(additionalBrush1, _startPosX + 145, _startPosY + 72, 25, 25);
|
|||
|
|
|||
|
g.FillEllipse(gr, _startPosX + 55, _startPosY + 81, 17, 17);
|
|||
|
g.FillEllipse(gr, _startPosX + 85, _startPosY + 81, 17, 17);
|
|||
|
g.FillEllipse(gr, _startPosX + 110, _startPosY + 81, 17, 17);
|
|||
|
|
|||
|
g.FillEllipse(gr, _startPosX + 68, _startPosY + 72, 8, 8);
|
|||
|
g.FillEllipse(gr, _startPosX + 95, _startPosY + 72, 8, 8);
|
|||
|
|
|||
|
Pen blackPen = new Pen(Color.Black, 3);
|
|||
|
Rectangle rect1 = new Rectangle(_startPosX + 15, _startPosY + 69, 30, 30);
|
|||
|
g.DrawArc(blackPen, rect1, 90, 180);
|
|||
|
Rectangle rect2 = new Rectangle(_startPosX + 145, _startPosY + 69, 30, 30);
|
|||
|
g.DrawArc(blackPen, rect2, -90, 180);
|
|||
|
g.DrawLine(blackPen, _startPosX + 27, _startPosY + 69, _startPosX + 165, _startPosY + 69);
|
|||
|
g.DrawLine(blackPen, _startPosX + 27, _startPosY + 99, _startPosX + 165, _startPosY + 99);
|
|||
|
}
|
|||
|
public bool CanMove(DirectionType direction)
|
|||
|
{
|
|||
|
if (EntityMash == null)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
return direction switch
|
|||
|
{
|
|||
|
DirectionType.Left => _startPosX - EntityMash.Step > 0,
|
|||
|
DirectionType.Up => _startPosY - EntityMash.Step > 0,
|
|||
|
DirectionType.Right => _startPosX + _mashWidth + EntityMash.Step < _pictureWidth,
|
|||
|
DirectionType.Down => _startPosY + _mashHeight + EntityMash.Step < _pictureHeight,
|
|||
|
_ => false,
|
|||
|
};
|
|||
|
}
|
|||
|
}
|
|||
|
}
|