示例#1
0
        private void CreateTexturedToast(bool[,] texture, string name, string text, Vector2 position)
        {
            bool[,] scaledTexture = BoolToTextureConverter.ScaleTexture(texture, 80, 80);

            TextBlock textBlock = new TextBlock(name + "Text")
            {
                Foreground = Color.Black,
                Text       = text,
                Margin     = new Thickness(position.X - 50, position.Y - 75, 0, 0),
            };

            EntityManager.Add(textBlock);

            Entity previewToast = new Entity(name + "Toast")
                                  .AddComponent(new Sprite("Assets/Textures/toast_2D.wpk"))
                                  .AddComponent(new SpriteRenderer(DefaultLayers.Alpha))
                                  .AddComponent(new Transform2D()
            {
                Opacity   = 1,
                X         = position.X,
                Y         = position.Y,
                DrawOrder = 0.1f,
                XScale    = 0.2f,
                YScale    = 0.2f,
                Origin    = Vector2.Center,
            });

            EntityManager.Add(previewToast);

            Entity previewModel = new Entity(name + "Texture")
                                  .AddComponent(new Sprite(BoolToTextureConverter.TxdFromBoolArray(scaledTexture, this.RenderManager)))
                                  .AddComponent(new SpriteRenderer(DefaultLayers.Alpha))
                                  .AddComponent(new Transform2D()
            {
                Opacity   = 1,
                X         = position.X,
                Y         = position.Y,
                DrawOrder = 0.05f,
                Origin    = Vector2.Center,
            });

            EntityManager.Add(previewModel);
        }
        protected override void ResolveDependencies()
        {
            _givenToastEntity   = Scene.EntityManager.Find("givenToast");
            _givenTextureEntity = Scene.EntityManager.Find("givenTexture");

            _drawnToastEntity   = Scene.EntityManager.Find("drawnToast");
            _drawnTextureEntity = Scene.EntityManager.Find("drawnTexture");

            _centeredToast = new Entity("centeredToast")
                             .AddComponent(new Sprite("Assets/Textures/toast_2D.wpk"))
                             .AddComponent(new SpriteRenderer(DefaultLayers.Alpha))
                             .AddComponent(new Transform2D()
            {
                Opacity   = 1,
                X         = WaveServices.Platform.ScreenWidth / 2,
                Y         = 200,
                DrawOrder = 0.1f,
                XScale    = 0.2f,
                YScale    = 0.2f,
                Origin    = Vector2.Center,
            });
            _centeredToast.IsVisible = false;

            bool[,] scaledGivenTexture = BoolToTextureConverter.ScaleTexture(_givenTexture, 80, 80);
            bool[,] scaledDrawnTexture = BoolToTextureConverter.ScaleTexture(_drawnTexture, 80, 80);
            _centeredTexture           = new Entity("centeredTexture")
                                         .AddComponent(new Sprite(BoolToTextureConverter.TxdFromBoolArray(scaledGivenTexture, scaledDrawnTexture, Scene.RenderManager)))
                                         .AddComponent(new SpriteRenderer(DefaultLayers.Alpha))
                                         .AddComponent(new Transform2D()
            {
                Opacity   = 1,
                X         = WaveServices.Platform.ScreenWidth / 2,
                Y         = 200,
                DrawOrder = 0.05f,
                Origin    = Vector2.Center,
            });
            _centeredTexture.IsVisible = false;

            Scene.EntityManager.Add(_centeredToast);
            Scene.EntityManager.Add(_centeredTexture);
        }
示例#3
0
        protected override void Update(TimeSpan gameTime)
        {
            var touches = WaveServices.Input.TouchPanelState;

            if (touches.Count > 0)
            {
                var firstTouch = touches[0];
                if (_toastRectangle.Contains(firstTouch.Position))
                {
                    _drawMatrix[(int)((firstTouch.Position.Y - _toastRectangle.Y) * (_drawMatrix.GetLength(1) / _toastRectangle.Height)),
                                (int)((firstTouch.Position.X - _toastRectangle.X) * (_drawMatrix.GetLength(0) / _toastRectangle.Width))] = true;

                    EntityManager.Remove("drawnTexture");

                    bool[,] scaledTexture = BoolToTextureConverter.ScaleTexture(_drawMatrix, Convert.ToInt32(Transform2D.Rectangle.Width * Transform2D.XScale * 0.8), Convert.ToInt32(Transform2D.Rectangle.Height * Transform2D.YScale * 0.8));

                    Entity drawnTexture = new Entity("drawnTexture")
                                          .AddComponent(new Sprite(BoolToTextureConverter.TxdFromBoolArray(scaledTexture, this.RenderManager)))
                                          .AddComponent(new SpriteRenderer(DefaultLayers.Alpha))
                                          .AddComponent(new Transform2D()
                    {
                        Opacity   = 1,
                        X         = WaveServices.Platform.ScreenWidth / 2,
                        Y         = WaveServices.Platform.ScreenHeight / 2,
                        DrawOrder = 0.05f,
                        Origin    = Vector2.Center,
                    });
                    EntityManager.Add(drawnTexture);

                    //Owner.RemoveComponent<Sprite>();
                    //Owner.AddComponent(new Sprite(BoolToTextureConverter.TxdFromBoolArray(_drawMatrix, this.RenderManager)));

                    //Sprite = new Sprite(BoolToTextureConverter.TxdFromBoolArray(_drawMatrix, this.RenderManager));

                    WaveServices.GetService <TextureMapService>().DrawnTexture = _drawMatrix;
                }
            }
        }
        protected override void CreateScene()
        {
            WaveServices.GetService <StatisticsService>().TotalGamesPlayed++;
            WaveServices.GetService <AchievementService>().Steps(GameStep.GameStarted);

            EntityManager.Add(CreateEntity.Background());

            TextBlock levelText = new TextBlock("levelText")
            {
                Foreground          = Color.Black,
                Text                = "Level " + WaveServices.GetService <LevelInformationService>().Level,
                Margin              = new Thickness(20f),
                HorizontalAlignment = HorizontalAlignment.Left,
            };

            EntityManager.Add(levelText);

            TextBlock infoText = new TextBlock("infoText")
            {
                Foreground          = Color.Black,
                Text                = String.Format("{0}, please draw this pattern:", Configuration.Instance.PlayerName),
                Margin              = new Thickness(20f),
                HorizontalAlignment = HorizontalAlignment.Center,
            };

            EntityManager.Add(infoText);

            //Add Picture here
            //bool[,] texture = new bool[,]
            //    {
            //        {true, false, false, false, true},
            //        {false, false, true, false, false},
            //        {false, true, false, true, false},
            //        {false, false, true, false, false},
            //        {true, false, false, false, true},
            //    };

            ulong textureSize = WaveServices.GetService <LevelInformationService>().TextureSize;

            bool[,] texture = new bool[textureSize, textureSize];
            for (ulong i = 0; i < textureSize; i++)
            {
                for (ulong j = 0; j < textureSize; j++)
                {
                    texture[i, j] = WaveServices.Random.NextBool();
                }
            }

            WaveServices.GetService <TextureMapService>().GivenTexture = texture;

            Entity previewToast = new Entity("previewToast")
                                  .AddComponent(new Sprite("Assets/Textures/toast_2D.wpk"))
                                  .AddComponent(new SpriteRenderer(DefaultLayers.Alpha))
                                  .AddComponent(new Transform2D()
            {
                Opacity   = 1,
                X         = WaveServices.Platform.ScreenWidth / 2,
                Y         = WaveServices.Platform.ScreenHeight / 2,
                DrawOrder = 0.1f,
                XScale    = 0.5f,
                YScale    = 0.5f,
                Origin    = Vector2.Center,
            });

            EntityManager.Add(previewToast);

            bool[,] scaledTexture = BoolToTextureConverter.ScaleTexture(texture, 200, 200);

            Entity previewTexture = new Entity("previewTexture")
                                    .AddComponent(new Sprite(BoolToTextureConverter.TxdFromBoolArray(scaledTexture, this.RenderManager)))
                                    .AddComponent(new SpriteRenderer(DefaultLayers.Alpha))
                                    .AddComponent(new Transform2D()
            {
                Opacity   = 1,
                X         = WaveServices.Platform.ScreenWidth / 2,
                Y         = WaveServices.Platform.ScreenHeight / 2,
                DrawOrder = 0.05f,
                Origin    = Vector2.Center,
            });

            EntityManager.Add(previewTexture);


            TextBlock timerText = new TextBlock("Timer")
            {
                Foreground          = Color.Black,
                Margin              = new Thickness(20f),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment   = VerticalAlignment.Bottom,
            };

            EntityManager.Add(timerText);

            this.AddSceneBehavior(new PreGameSceneBehavior(), SceneBehavior.Order.PostUpdate);

            WaveServices.GetService <AnalyticsService>().TagEvent("Page opened", "Page", "Pre-game");
        }