/
Vagabond132
/
TerrariaCourse
Обзор
Документация
Войти
/
Vagabond132
/
TerrariaCourse
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
Windows
ConsoleView/Game/ConsolePlayerView.cs
140 строк
4 KB
Vagabond132
Исправлено наследование
10 янв 2025, 13:34
10 янв 2025, 13:34
f1eb5b4
Код
Авторство
О чём код?
using Model.GameComponents.Entities; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using View.Core; using View.Game; using static ConsoleView.Game.ConsoleGameView; namespace ConsoleView.Game { public class ConsolePlayerView : PlayerView { /// <summary> /// Коэффициент для расчета координат по X /// </summary> private const double SCREEN_COEFFICIENT_X = 5 / 8.0; /// <summary> /// Коэффициент для расчета координат по Y /// </summary> private const double SCREEN_COEFFICIENT_Y = 0.25; /// <summary> /// Игрок, смотрящий влево /// </summary> private string[] FACING_LEFT_PLAYER = { " O ", "<| ", " / ", }; /// <summary> /// Игрок, смотрящий вправо /// </summary> private string[] FACING_RIGHT_PLAYER = { " O ", " |>", " /\\", }; /// <summary> /// Изображение игрока /// </summary> private string[] _playerImage; /// <summary> /// Символы консольного вывода /// </summary> private CharInfo[] _buffer; /// <summary> /// Ширина буфера /// </summary> private int _bufferWidth; private int _bufferHeight; private ConsoleMapView _mapView; /// <summary> /// Номер цвета игрока /// </summary> //private short _color; /// <summary> /// Конструктор /// </summary> /// <param name="parPlayer">Игрок</param> public ConsolePlayerView(PlayerModel parPlayer, ref CharInfo[] parBuffer, int parWidth, int parHeight, ref readonly ConsoleMapView parMapView) : base(parPlayer) { _buffer = parBuffer; _bufferWidth = parWidth; _bufferHeight = parHeight; //_color = parColor; _mapView = parMapView; Player.OnPlayerChange += Draw; } /// <summary> /// Отрисовка /// </summary> public override void Draw() { if (Player.Direction == Direction.LEFT) { _playerImage = FACING_LEFT_PLAYER; } else if (Player.Direction == Direction.RIGHT) { _playerImage = FACING_RIGHT_PLAYER; DrawOnBuffer(); } DrawOnBuffer(); } /// <summary> /// Перерисовка /// </summary> public override void Redraw() { //if (Player.IsVisible) //{ // DrawOnBuffer(); //} DrawOnBuffer(); } /// <summary> /// Отрисовка на буфере /// </summary> public void DrawOnBuffer() { //// Позиция игрока //int x = (int)Player.Pos.X; //int y = (int)Player.Pos.Y; int x = (int)Player.Pos.X - _mapView.CameraX; int y = (int)Player.Pos.Y - _mapView.CameraY; //// Центр камеры с учетом размеров буфера //x = Math.Max(0, x - (_bufferWidth / 2)); //y = Math.Max(0, y - (_bufferHeight / 2)); //int x = (int)Math.Round(Player.Pos.X * 1.0); //int y = (int)Math.Round(Player.Pos.Y * 1.0); // Рисуем игрока for (int row = 0; row < _playerImage.Length; row++) { for (int col = 0; col < _playerImage[0].Length; col++) { int index = (y + row) * _bufferWidth + (x + col); if (index >= 0 && index < _buffer.Length && x + col < _bufferWidth) { _buffer[index].Char.AsciiChar = (byte)_playerImage[row][col]; _buffer[index].Attributes = 1; // Цвет } } } } } }