Example #1
0
        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--;
        }
Example #2
0
        public static void Fly(object obj, ElapsedEventArgs e)
        {
            Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate
            {
                FirePlace main = (FirePlace)Application.Current.MainWindow;

                if (animationStop)
                {
                    return;
                }

                foreach (var line in allLines)
                {
                    main.firePlace.Children.Remove(line);
                }

                allLines.Clear();
                Shilka.DrawGuns(main);

                fireMutex++;

                foreach (var shell in shells)
                {
                    shell.x = (shell.x + Constants.SHELL_SPEED * shell.cos);
                    shell.y = (shell.y - Constants.SHELL_SPEED * shell.sin);

                    shell.shellImage.Margin = new Thickness(shell.x, shell.y, 0, 0);

                    foreach (Aircraft aircraft in Aircraft.aircrafts)
                    {
                        if (
                            shell.fly &&
                            (shell.y < (aircraft.aircraftImage.Margin.Top + aircraft.aircraftImage.Height)) &&
                            (shell.y > (aircraft.aircraftImage.Margin.Top)) &&
                            (shell.x > (aircraft.aircraftImage.Margin.Left)) &&
                            (shell.x < (aircraft.aircraftImage.Margin.Left + aircraft.aircraftImage.Width))
                            )
                        {
                            if (aircraft.cloud)
                            {
                                continue;
                            }

                            bool itsOnlyTargetPlane = false;

                            if (Shilka.training && (aircraft.aircraftType == "il28bm_77bm2"))
                            {
                                if (aircraft.TargetTubHit(shell, ref itsOnlyTargetPlane))
                                {
                                    continue;
                                }
                            }

                            if (itsOnlyTargetPlane && aircraft.fly && (aircraft.tragetTugHitPoint <= 0))
                            {
                                aircraft.TargetTugDisengaged();
                            }

                            Line shellTrace = new Line
                            {
                                X1 = shell.x + shell.cos,
                                Y1 = shell.y - shell.sin,
                                X2 = shell.x + Constants.FLASH_SIZE,
                                Y2 = shell.y - Constants.FLASH_SIZE
                            };
                            shell.flash                = true;
                            shellTrace.Stroke          = Brushes.Red;
                            shellTrace.StrokeThickness = Constants.FLASH_SIZE;

                            Wrecks.WreckBreackOffFromAircraft(
                                startX: shell.x,
                                startY: shell.y,
                                direction: aircraft.flightDirection,
                                maxSpeed: (aircraft.zeroSpeed ? 0 : (int)aircraft.speed),
                                maxSize: aircraft.wrecksMaxSize,
                                number: aircraft.wrecksNumber,
                                randomDistance: (aircraft.zeroSpeed ? aircraft.size[0] : 0)
                                );

                            if (aircraft.weight == Aircraft.WeightType.Light)
                            {
                                aircraft.y -= Constants.THROWS_UP_BY_HITS;
                            }
                            else if (aircraft.weight == Aircraft.WeightType.Middle)
                            {
                                aircraft.y -= Constants.THROWS_UP_BY_HITS_FOR_MIDDLE_AIRCRAFT;
                            }

                            main.firePlace.Children.Add(shellTrace);
                            Canvas.SetZIndex(shellTrace, 20);
                            allLines.Add(shellTrace);

                            Statistic.ShellFiredAdd(inTarget: true);

                            if (itsOnlyTargetPlane)
                            {
                                shell.fly = false;
                                continue;
                            }

                            aircraft.hitpoint -= 1;

                            if (aircraft.hitpoint <= 0 && !aircraft.dead)
                            {
                                aircraft.Shutdown(main);
                            }

                            double planeMiddle     = aircraft.aircraftImage.Margin.Left + aircraft.aircraftImage.Width / 2;
                            aircraft.placeOfDamage = (shell.x < planeMiddle ? 1 : -1);
                        }
                        else if (shell.flash)
                        {
                            shell.fly = false;
                        }
                    }

                    if ((shell.delay >= Constants.SHELL_DELAY) && (shell.shellImage.Visibility == Visibility.Hidden))
                    {
                        shell.shellImage.Visibility = Visibility.Visible;
                    }

                    if ((shell.y < 0) || (shell.x > currentWidth))
                    {
                        shell.fly = false;
                    }
                    else if (shell.delay < Constants.SHELL_DELAY)
                    {
                        shell.delay++;
                    }
                }

                for (int x = 0; x < shells.Count; x++)
                {
                    if ((shells[x].fly == false) && (fireMutex == 1))
                    {
                        main.firePlace.Children.Remove(shells[x].shellImage);
                        shells.RemoveAt(x);
                    }
                }

                fireMutex--;
            }));
        }