Example #1
0
        protected override void OnAnimationTimerTick(object stateInfo)
        {
            time++;
            base.OnAnimationTimerTick(stateInfo);

            BlockReference rocketLaunched = (BlockReference)Entities[9];

            Parabolating parabolating = (Parabolating)rocketLaunched;

            if (parabolating != null && (parabolating.timeHitsGround - 2) == time)
            {
                StopAnimation();
                time = 0;

                rocketLaunched.Visible = true;

                Target[] targetsArray = targets.ToArray();

                // checks if the rocket hits one of the targets
                for (int i = 0; i < 3; i++)
                {
                    if (xPos > (targetsArray[i].xTarget - 7) && xPos <(targetsArray[i].xTarget + 5) && yPos> (targetsArray[i].yTarget - 7) && yPos < (targetsArray[i].yTarget + 5))
                    {
                        Entities[i + 4].Visible = true;
                        Dispatcher.Invoke(() => { Invalidate(); });
                        break;
                    }
                }
            }
        }
Example #2
0
        // this function fires the rocket
        private void FireButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (model1 == null)
            {
                return;
            }

            BlockReference rocketBlockReference = (BlockReference)model1.Entities[0];

            rocketBlockReference.Visible = false;

            Parabolating trajectory = new Parabolating("Rocket", model1, Utility.DegToRad(launchAngleSlider.Value), Utility.DegToRad(directionAngleSlider.Value), firePowerSlider.Value);

            trajectory.vp.targets.Add(_target1);
            trajectory.vp.targets.Add(_target2);
            trajectory.vp.targets.Add(_target3);

            model1.Entities.Add(trajectory);

            if (model1.Entities.Count > _numEntityInScene)
            {
                model1.Entities.RemoveAt(_numEntityInScene - 1);
            }

            model1.StartAnimation(50);

            model1.Entities.Regen();
            model1.Invalidate();

            ChangeStateLaunchButtons(false);
        }