Пример #1
0
        public static void addUIElementBehaviour(this UIElement uie, UIElementBehaviour f)
        {
            //CompositionTarget.Rendering += uie.Update;
            f.uiElement = uie;

            updateMethodDic.Add(uie, f);
            //elapsedMethodTimeDic.Add(uie, f.deltaTimeWatch);
        }
Пример #2
0
        /// <summary>
        /// erzeugt aus dem GameElements-Dict im GameModel alle Game-XAML-Objekte in der View
        /// hängt zudem an alle veränderlichen Elemente das dazugehörige Behaviour-Script
        /// </summary>
        private void generateGameField()
        {
            Dictionary <int, GameElement> gameElementsDict = GameModel.Instance.GameElements;

            foreach (int id in gameElementsDict.Keys)
            {
                Image actImage = new Image {
                    Source = new BitmapImage(new Uri(picturePath + GamePictures.Instance.pictureDict[gameElementsDict[id].Type]))
                };
                GameFieldCanvas.Children.Add(actImage);
                actImage.SetValue(Canvas.TopProperty, (double)gameElementsDict[id].PosY);
                actImage.SetValue(Canvas.LeftProperty, (double)gameElementsDict[id].PosX);
                ElementType actType       = gameElementsDict[id].Type;
                string      aktTypeString = actType.ToString();

                UIElementBehaviour behaviourScript = null;

                // "statische" Elemente mit Kollisions-Behaviourscripts austatten
                if (actType == ElementType.WAND_STARK_0)
                {
                    behaviourScript = new ChangeImageBehaviour(picturePath + "Element_Slingshot_0_Bounce.png", WAND_STARK_ANIMATIONTIME);
                }
                else if (actType == ElementType.WAND_STARK_1)
                {
                    behaviourScript = new ChangeImageBehaviour(picturePath + "Element_Slingshot_1_Bounce.png", WAND_STARK_ANIMATIONTIME);
                }
                else if (actType == ElementType.WAND_STARK_2)
                {
                    behaviourScript = new ChangeImageBehaviour(picturePath + "Element_Slingshot_2_Bounce.png", WAND_STARK_ANIMATIONTIME);
                }
                else if (actType == ElementType.WAND_STARK_3)
                {
                    behaviourScript = new ChangeImageBehaviour(picturePath + "Element_Slingshot_3_Bounce.png", WAND_STARK_ANIMATIONTIME);
                }

                else if (actType == ElementType.STEIN_0)
                {
                    behaviourScript = new VibrationBehaviour(STEIN_VIBRATIONTIME, 1);
                }
                else if (actType == ElementType.STEIN_1)
                {
                    behaviourScript = new VibrationBehaviour(STEIN_VIBRATIONTIME, 2);
                }
                else if (actType == ElementType.STEIN_2)
                {
                    behaviourScript = new VibrationChangeImageBehaviour(STEIN_VIBRATIONTIME, 3, picturePath + "Elemente_Bumper_L_Bounce.png");
                }

                // "agile" GameElements mit behaviourScripts ausstatten, die Position und Rotation jedes Frame updaten
                // wenns ein Flipper ist, hänge FlipperScript an
                else if (aktTypeString.Contains("FLIPPER"))
                {
                    behaviourScript = new FlipperBehaviour(id, aktTypeString);
                }

                // wenns ein Plunger ist, hänge Plunger-Script an
                else if (actType == ElementType.PLUNGER)
                {
                    behaviourScript = new PlungerBehaviour(id);
                }

                //uiElementBehaviour für Libero anhängen
                else if (aktTypeString.Contains("LIBERO"))
                {
                    behaviourScript = new AgileModelBehaviour(id);
                }
                else if (actType == ElementType.BALL)
                {
                    behaviourScript       = new BallBehaviour(id, BALLINVISIBLEAFTERGOALTIME);
                    ballBehaviourScriptId = id;
                }


                if (behaviourScript != null)
                {
                    actImage.addUIElementBehaviour(behaviourScript);

                    behaviourDict[id] = behaviourScript;
                    uieELementsWithBehaviourScript.Add(actImage);
                    actImage.startUpdate();
                }
                setLayer(gameElementsDict[id].Type, actImage);
            }

            GameModel.Instance.GameProducer.SignalLoadingComplete();

            // nach dem die generateGamefield aufgerufen wurde, entferne die Methode vom Event für zukünftige Spiele
            GameModel.Instance.FillDictCompleteEvent -= generateGameField;
        }