void CalcAbroad() { for (int i = 0; i < engineModelsList.Count; i++) { EngineModel engMd = engineModelsList[i]; if (engMd.GetX() < 0 || engMd.GetY() < 0 || engMd.GetX() + engMd.GetFixture().GetLength(0) > width || engMd.GetY() + engMd.GetFixture().GetLength(0) > height) { engMd.OnAbroad(); } } }
public void NextTick() { List <EngineModel> buf = new List <EngineModel>(); for (int i = 0; i < engineModelsList.Count; i++) { EngineModel engMd = engineModelsList[i]; if (!(engMd == null || engMd.IsDisposed())) { buf.Add(engMd); } } engineModelsList = buf; CalcAbroad(); CalcColisions(); MoveByAcceleration(); CallLoopEvents(); }
void CalcColisions() { int[,] colisionMap = GetColisionMap(); for (int i = 0; i < engineModelsList.Count; i++) { EngineModel engMd = engineModelsList[i]; bool haveColision = CheckColision( colisionMap, engMd.GetFixture(), (int)engMd.GetX(), (int)engMd.GetY() ); if (haveColision) { engMd.OnColision(); } } }
public char[,] GetRendered() { char[,] renderMap = new char[width, height]; for (int i = 0; i < renderMap.GetLength(0); i++) { for (int j = 0; j < renderMap.GetLength(1); j++) { renderMap[i, j] = ' '; } } for (int i = 0; i < engineModelsList.Count; i++) { EngineModel engMd = engineModelsList[i]; ImposeTexture( renderMap, engMd.GetTexture(), (int)engMd.GetX(), (int)engMd.GetY() ); } return(renderMap); }
public int[,] GetColisionMap() { int[,] colisionMap = new int[width, height]; for (int i = 0; i < colisionMap.GetLength(0); i++) { for (int j = 0; j < colisionMap.GetLength(1); j++) { colisionMap[i, j] = 0; } } for (int i = 0; i < engineModelsList.Count; i++) { EngineModel engMd = engineModelsList[i]; ImposeFixture( colisionMap, engMd.GetFixture(), (int)engMd.GetX(), (int)engMd.GetY() ); } return(colisionMap); }
void MoveByAcceleration() { for (int i = 0; i < engineModelsList.Count; i++) { EngineModel engMd = engineModelsList[i]; Acceleration ac = engMd?.GetAcceleration(); if (ac == null) { continue; } double xModification = 0, yModification = 0; double distance = speedModificator * ac.Speed; switch (ac.MoveDirection) { case MoveDirection.up: yModification -= distance; break; case MoveDirection.down: yModification += distance; break; case MoveDirection.left: xModification -= distance; break; case MoveDirection.right: xModification += distance; break; } engMd.SetPosition( engMd.GetX() + xModification, engMd.GetY() + yModification ); } }
public void AddEngineModel(EngineModel engineModel) { engineModelsList.Add(engineModel); }