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); } } }