void MineExplosion(ref State state, Mine mine, Player enemyPlayer) { Effect pr = new Effect(); //todo denis // надо при взрыве бомбы рисовать следующую строку. Там будет меняться последний параметр альфа. Он сначала увеличивается от 0 до 1 (до половины времени), затем уменьшается до 0 //Animator.Rectangle(ref frame, ESprite.explosionPoint, mine.obj.objs[0].Pos.x - Const.TileWidth * 2.5, mine.obj.objs[0].Pos.y - Const.TileHeight * 2.5, Const.TileWidth * 5, Const.TileHeight * 5, alpha); pr.AddNextStep(new DynamicObject(new Sprite(ESprite.explosionNuclear, 5 * Const.TileWidth * 1.7791, 5 * Const.TileHeight, new Vector2(mine.obj.objs[0].Pos.x, mine.obj.objs[0].Pos.y)))); pr.AddAnimationToLastStep(0, 0, 0, 2.0); state.effects.AddEffect(pr); int radius = mine.ExplosionRadius; for (int i = 0; i < Const.NumberOfLines; i++) { Unit enemyUnit = enemyPlayer.Units[i]; if (enemyUnit == null || enemyUnit.AtBase() || enemyUnit.State == UnitState.Dead) { continue; } if (Math.Abs(enemyUnit.PosTileX - mine.PosTileX) <= mine.ExplosionRadius / 2 && Math.Abs(enemyUnit.Line - mine.Line) <= mine.ExplosionRadius / 2) { enemyUnit.Hp -= mine.Damage; if (enemyUnit.Hp <= 0) { enemyUnit.State = UnitState.Dead; } } } }
void MineExplosion(ref State state, Mine mine, Player enemyPlayer) { Effect pr = new Effect(); pr.AddNextStep(new DynamicObject(new Sprite(ESprite.explosionGreen, 5 * Const.TileWidth, 5 * Const.TileHeight, new Vector2(mine.obj.objs[0].Pos.x, mine.obj.objs[0].Pos.y)))); pr.AddAnimationToLastStep(0, 0, 0, 2.0); state.effects.AddEffect(pr); int radius = mine.ExplosionRadius; for (int i = 0; i < Const.NumberOfLines; i++) { Unit enemyUnit = enemyPlayer.Units[i]; if (enemyUnit == null || enemyUnit.AtBase()) { continue; } if (Math.Pow(radius, 2) >= Math.Pow(Math.Abs(i - mine.Line), 2) + Math.Pow(Math.Abs(mine.PosTileX - enemyUnit.PosTileX), 2)) { enemyUnit.Hp -= mine.Damage; if (enemyUnit.Hp <= 0) { enemyUnit.State = UnitState.Dead; } } } }
void AddProjectile(ref State state, Point2 from, Point2 to, double duration, bool destroyed, double latency) { Effect pr = new Effect(); pr.AddNextStep(new DynamicObject(new Sprite(ESprite.shell1, 2, 2, new Vector2(from.x, from.y)))); pr.AddAnimationToLastStep(to.x - from.x, to.y - from.y, 0, duration, latency); if (destroyed) { pr.AddNextStep(new DynamicObject(new Sprite(ESprite.explosion, Const.TileWidth, Const.TileHeight, new Vector2(0, 0)))); pr.AddAnimationToLastStep(0, 0, 0, 1.0); } else { pr.AddNextStep(new DynamicObject(new Sprite(ESprite.explosion, 5, 5, new Vector2(0, 0)))); pr.AddAnimationToLastStep(0, 0, 0, 0.2); } state.effects.AddEffect(pr); }
void ProcessFire(ref State state) { ProcessShots(ref state, state.players[0], state.players[1]); ProcessShots(ref state, state.players[1], state.players[0]); List <Unit> UnitsForCollision = new List <Unit>(); for (int i = 0; i < Const.NumberOfLines; i++) { Unit unit1 = state.players[0].Units[i]; Unit unit2 = state.players[1].Units[i]; if (unit1 != null && unit1.State != UnitState.Dead) { UnitsForCollision.Add(unit1); } if (unit2 != null && unit2.State != UnitState.Dead) { UnitsForCollision.Add(unit2); } } StartCollisionsProcessing: List <Collision> collisions = Geometry.GetAllCollisionsDuringTheTurn(UnitsForCollision, state.shells); for (int i = 0; i < collisions.Count; i++) { Collision collision = collisions[i]; Point2 finish = (Point2)collision.shell.GetCoordinate(collision.stage); state.shells.Remove(collision.shell); if (collision.unit != null) { //debug code double _rightSide = collision.unit.GetNextCoordinateXWithStage(collision.stage) + collision.unit.HitBox.Width / 2; double _leftSide = collision.unit.GetNextCoordinateXWithStage(collision.stage) - collision.unit.HitBox.Width / 2; //finish.x = _rightSide; //end if (collision.unit.Owner != collision.shell.Owner) { collision.unit.Hp -= collision.shell.Damage; collision.unit.HpDuringTurn[collision.stage] = collision.unit.Hp; } if (collision.unit.Hp <= 0) { double lastX = collision.unit.GetNextCoordinateXWithStage(0); double deathX = collision.unit.GetNextCoordinateXWithStage(collision.stage); collision.unit.CancelMove(); collision.unit.AddMove(deathX - lastX, 0, collision.stage); collision.unit.State = UnitState.Dead; collision.unit.DeathStage = collision.stage; AddProjectile(ref state, collision.shell.StartPosition, finish, collision.stage - collision.shell.LaunchStage, false, collision.shell.LaunchStage); Effect eff = new Effect(); eff.AddNextStep(new DynamicObject(new Sprite(ESprite.explosion, Const.TileWidth * 1.2, Const.TileHeight * 1.2, new Vector2(deathX, collision.unit.GetCoordinate(0).y)))); eff.AddAnimationToLastStep(0, 0, 0, 1.0, collision.stage); state.effects.AddEffect(eff); for (int j = 0; j < collisions.Count; j++) { if (collisions[j].shell.OwnerUnit == collision.unit && Utility.doubleGreaterOrEqual(collisions[j].shell.LaunchStage, collision.stage)) { collisions.Remove(collisions[j]); } } for (int j = 0; j < state.shells.Count; j++) { if (state.shells[j].OwnerUnit == collision.unit && state.shells[j].LaunchStage > collision.stage + 0.0001) { state.shells.Remove(state.shells[j]); } } UnitsForCollision.Remove(collision.unit); goto StartCollisionsProcessing; } else { AddProjectile(ref state, collision.shell.StartPosition, finish, collision.stage - collision.shell.LaunchStage, false, collision.shell.LaunchStage); } } else { AddProjectile(ref state, collision.shell.StartPosition, finish, collision.stage - collision.shell.LaunchStage, false, collision.shell.LaunchStage); } } foreach (Shell shell in state.shells) { Point2 start = shell.StartPosition; Point2 finish = (Point2)shell.GetCoordinate(1.0); Effect pr = new Effect(); pr.AddNextStep(new DynamicObject(new Sprite(ESprite.shell1, 2, 2, new Vector2(start.x, start.y)))); pr.AddAnimationToLastStep(finish.x - start.x, finish.y - start.y, 0, 1.0 - shell.LaunchStage, shell.LaunchStage); state.effects.AddEffect(pr); shell.StartPosition = finish; shell.LaunchStage = 0.0; } }