public static void WreckBreackOffFromAircraft(double startX, double startY, Aircraft.FlightDirectionType direction, int maxSpeed, int maxSize, int number, int randomDistance = 0) { if (rand.Next(Constants.WRECKS_RAND_RANGE) > number) { return; } wreckMutex++; if (wreckMutex > 1) { wreckMutex--; return; } Wrecks newWreck = new Wrecks { x = startX + (randomDistance > 0 ? rand.Next(randomDistance / Constants.WRECKS_SUSP_WRECKS_PART) : 0), y = startY, sin = 0, cos = (direction == Aircraft.FlightDirectionType.Left ? 1 : -1), flightDirection = direction, speed = RandomSpeed(maxSpeed), rotateSpeed = rand.Next(Constants.WRECKS_MIN_ROTATE_SPEED, Constants.WRECKS_MAX_ROTATE_SPEED), rotateDirection = (rand.Next(2) == 0 ? 1 : -1), fly = true }; int wr_rand_num = Constants.WRECKS_TYPE_NUM + 1; Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { FirePlace main = (FirePlace)Application.Current.MainWindow; Image newImage = new Image { Width = rand.Next(maxSize) + Constants.WRECKS_MIN_SIZE, Height = rand.Next(maxSize) + Constants.WRECKS_MIN_SIZE, Source = Functions.ImageFromResources("wrecks" + (Aircraft.rand.Next(1, wr_rand_num)), Aircraft.ImageType.Other), Margin = new Thickness(newWreck.x, newWreck.y, 0, 0) }; newWreck.wreckImage = newImage; main.firePlace.Children.Add(newImage); Wrecks.wrecks.Add(newWreck); })); wreckMutex--; }
public static void Change(object obj, ElapsedEventArgs e) { if (Shilka.training || Shilka.school) { return; } if ((thundar != 0) || (currentWeather == WeatherTypes.storm)) { Thunder(); } if (weatherCycle < Constants.WEATHER_CYCLE) { weatherCycle += 1; if (currentWeather == WeatherTypes.storm) { if (weatherCycle.ToString().Contains("00")) { stormDirection = (rand.Next(2) > 0 ? Aircraft.FlightDirectionType.Right : Aircraft.FlightDirectionType.Left); } } } else { Restart(); } if (currentWeather == WeatherTypes.good) { return; } int newWeatherElementsCount = (currentWeather == WeatherTypes.storm ? 4 : 1); for (int iterator = 0; iterator < newWeatherElementsCount; iterator++) { Weather newWeather = new Weather(); if (currentWeather == WeatherTypes.storm) { newWeather.x = rand.Next((int)SystemParameters.PrimaryScreenWidth * -1, (int)SystemParameters.PrimaryScreenWidth * 2); newWeather.y = 0; } else if (currentWeather == WeatherTypes.sand) { newWeather.x = 0; newWeather.y = rand.Next(0, (int)SystemParameters.PrimaryScreenHeight); } else { newWeather.x = rand.Next(0, (int)SystemParameters.PrimaryScreenWidth); newWeather.y = 0; } newWeather.speed = rand.Next(Constants.MIN_SPEED, Constants.MAX_SPEED); newWeather.fly = true; newWeather.type = currentWeather; Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate { Image newImage = new Image(); string imageName; if ((currentWeather == WeatherTypes.rain) || (currentWeather == WeatherTypes.storm)) { newImage.Width = rand.Next(Constants.RAIN_MIN_WIDTH, Constants.RAIN_MAX_WIDTH); newImage.Height = rand.Next(Constants.RAIN_MIN_HEIGHT, Constants.RAIN_MAX_HEIGHT); imageName = "rain" + rand.Next(1, Constants.MAX_RAIN_TYPE + 1).ToString(); } else if (currentWeather == WeatherTypes.sand) { newImage.Width = Constants.CASE_LENGTH; newImage.Height = Constants.CASE_LENGTH; imageName = "case"; } else { newImage.Width = rand.Next(Constants.SNOW_MIN_SIZE, Constants.SNOW_MAX_SIZE); newImage.Height = rand.Next(Constants.SNOW_MIN_SIZE, Constants.SNOW_MAX_SIZE); imageName = "snow" + rand.Next(1, Constants.MAX_SNOW_TYPE + 1).ToString(); } newImage.Source = Functions.ImageFromResources(imageName, Aircraft.ImageType.Other); newImage.Margin = new Thickness(newWeather.x, newWeather.y, 0, 0); newWeather.weatherImage = newImage; FirePlace main = (FirePlace)Application.Current.MainWindow; Canvas.SetZIndex(newImage, 120); main.firePlace.Children.Add(newImage); Weather.weather.Add(newWeather); })); } }