public bool CollidesWithWall(SimGame game) { return(CollidesWithWall(game, Position.X - HalfSize, Position.Y - HalfSize) || CollidesWithWall(game, Position.X + HalfSize, Position.Y - HalfSize) || CollidesWithWall(game, Position.X + HalfSize, Position.Y + HalfSize) || CollidesWithWall(game, Position.X - HalfSize, Position.Y + HalfSize)); }
public void Move(SimGame game, double dt) { if (IsDead) { return; } CollisionTime -= dt; Position.X += Dx * dt; Position.Y += Dy * dt; foreach (var unit in game.Units) { if (IsCollidingWith(unit)) { if (bullet.ExplosionParameters != null) { Explode(game); } unit.Health -= IsSimCreated ? bullet.Damage / 10 : bullet.Damage; IsDead = true; return; } } //TODO: Check mines if ((_collisionTime < 999999 && CollidesWithWall(game)) || CollisionTime <= 0) { IsDead = true; if (bullet.ExplosionParameters != null) { Explode(game); } } }
public void Explode(SimGame game) { var dmg = IsSimCreated ? bullet.ExplosionParameters.Value.Damage / 10 : bullet.ExplosionParameters.Value.Damage; foreach (var unit in game.Units) { if (Math.Abs(Position.X - unit.Position.X) > bullet.ExplosionParameters.Value.Radius + HalfSize * 2 + unit.HalfWidth || Math.Abs(Position.Y - unit.Position.Y) > bullet.ExplosionParameters.Value.Radius + HalfSize * 2 + unit.HalffHeight) { continue; } unit.Health -= dmg; } //TODO: Explode mines }
public void Fire(MyPosition target, SimGame game) { if (!HasWeapon || FireTimer > 0 || Rounds <= 0) { return; } var newAngle = Math.Atan2(target.Y - Position.Y, target.X - Position.X); var diff = Math.Abs(AimAngle - newAngle); if (diff > Math.PI) { var newDiff = Math.Abs(AimAngle - (newAngle - Math.PI * 2)); if (newDiff < diff) { diff = newDiff; } } AimAngle = newAngle; if (AimAngle < 0) { AimAngle += Math.PI * 2; } else if (AimAngle > Math.PI * 2) { AimAngle -= Math.PI * 2; } Spread = Math.Max(MinSpread, Math.Min(MaxSpread, Spread + diff)); if (debug) { LogService.DrawLine(Position, new MyPosition(Position.X + Math.Cos(AimAngle) * 10, Position.Y + Math.Sin(AimAngle) * 10), 0, 0, 1); } //var bullets = BulletFactory.GetBullets(WeaponType, Position, newAngle, Id, Spread); //game.Bullets.AddRange(bullets); Spread += Recoil; Rounds--; FireTimer = MaxFireTimer; if (Rounds <= 0) { FireTimer = ReloadTime; Rounds = Magazine; } Score += 0.5 * (MaxSpread - MinSpread) / Math.Max(0.01, Spread - MinSpread); }
public void Explode(SimGame game) { if (IsDead) { return; } IsDead = true; foreach (var unit in game.Units) { if (Math.Abs(Position.X - unit.Position.X) > Mine.ExplosionParameters.Radius + unit.HalfWidth || Math.Abs(Position.Y - unit.Position.Y) > Mine.ExplosionParameters.Radius + unit.HalffHeight) { continue; } unit.Health -= Mine.ExplosionParameters.Damage; } }
public void CalcCollisionTime(SimGame game) { var t = 0.0; var dt = 1.0 / Const.Properties.TicksPerSecond / 10; while (true) { t += dt; Position.X += Dx * dt; Position.Y += Dy * dt; if (CollidesWithWall(game)) { CollisionTime = _collisionTime = t; EndPosition = new MyPosition(Position.X, Position.Y); break; } } Position.UpdateFrom(_position); }
public bool CollidesWithWall(SimGame game, double x, double y) { var tile = game.GetTileD(x, y); return(tile == Tile.Wall); }
public void ApplyAction(MyAction action, SimGame game, double dt, bool canChange) { Spread = Math.Max(MinSpread, Math.Min(MaxSpread, Spread - (SpreadChange * dt))); FireTimer -= dt; if (canChange) { m_jumpUp = action.JumpUp; } var dy = -JumpSpeed; if (game.GetTileD(Position.X + HalfWidth, Position.Y - HalffHeight) == Tile.JumpPad || game.GetTileD(Position.X - HalfWidth, Position.Y - HalffHeight) == Tile.JumpPad || game.GetTileD(Position.X + HalfWidth, Position.Y + HalffHeight) == Tile.JumpPad || game.GetTileD(Position.X - HalfWidth, Position.Y + HalffHeight) == Tile.JumpPad) { JumpTime = Const.Properties.JumpPadJumpTime; Speed = Const.Properties.JumpPadJumpSpeed; CanCancel = false; } if (JumpTime > 0 && (m_jumpUp || !CanCancel)) { JumpTime -= dt; var speed = JumpSpeed; if (Speed > JumpSpeed) { speed = Speed; } dy = speed; } else { JumpTime = 0; CanCancel = true; } var y = Position.Y + dy * dt; var tile = game.GetTileD(Position.X - HalfWidth, y - HalffHeight); var otherTile = game.GetTileD(Position.X + HalfWidth, y - HalffHeight); var block = 0; if (tile == Tile.Wall || otherTile == Tile.Wall) { block = 2; } else if (tile == Tile.Platform || otherTile == Tile.Platform) { block = 1; } var onLadder = game.GetTileD(Position.X, y) == Tile.Ladder || game.GetTileD(Position.X, y - HalffHeight) == Tile.Ladder; if (block == 2) { y = Position.Y; JumpTime = MaxJumpTime; } else if (onLadder) { JumpTime = MaxJumpTime; if (m_jumpUp) { y = Position.Y + JumpSpeed * dt; } else if (action.JumpDown) { y = Position.Y - JumpSpeed * dt; } else { y = Position.Y; } } else if (block == 1 && !action.JumpDown && (int)(Position.Y - HalffHeight) > (int)(y - HalffHeight)) { y = Position.Y; JumpTime = MaxJumpTime; } if (y > Position.Y) { var above = game.GetTileD(Position.X - HalfWidth, Position.Y + HalffHeight); var above1 = game.GetTileD(Position.X + HalfWidth, Position.Y + HalffHeight); if (above == Tile.Wall || above1 == Tile.Wall) { y = Position.Y; JumpTime = 0; Speed = JumpSpeed; CanCancel = true; } } foreach (var u in game.Units) { if (u == this) { continue; } if (u.IsInside(Position.X, y)) { y = Position.Y; break; } } var x = Position.X + action.Dx * MyAction.GetSpeed * dt; if (game.GetTileD(x + HalfWidth * action.Dx, Position.Y + HalffHeight) == Tile.Wall || game.GetTileD(x + HalfWidth * action.Dx, Position.Y - HalffHeight) == Tile.Wall) { x = Position.X; } foreach (var u in game.Units) { if (u == this) { continue; } if (u.IsInside(x, y)) { x = Position.X; break; } } Position.X = x; Position.Y = y; if (canChange && ShootService.CanShootAt(Position, TargetEnemy.Position)) { //if (WeaponType != WeaponType.RocketLauncher || !IsMine) { Fire(TargetEnemy.Position, game); } } }