Esempio n. 1
0
        public void AddComponent_WhenScriptComponent_AttachesScriptToEntity()
        {
            var entity = new Mock <IEntity>();
            var script = new Mock <IScriptComponent>(MockBehavior.Strict);

            script.Setup(_ => _.Attach());
            _mockEntityContainer.Setup(_ => _.AddComponent(entity.Object, script.Object));

            _target.AddComponent(entity.Object, script.Object);

            script.Verify(_ => _.Attach(), Times.Once);
            _mockEntityContainer.Verify(_ => _.AddComponent(entity.Object, script.Object), Times.Once);
        }
Esempio n. 2
0
        public void Attach()
        {
            _scene.Init();
            _physicsContainer.Gravity = new Vector3(0, -800, 0);

            var entity = _scene.CreateEntity();

            _scene.AddComponent(entity, new CameraComponent {
                Camera = _camera, Active = true
            });

            var texture = _factory.Create <ITexture2D>();

            texture.SetData("Assets/landscape.jpeg");

            var soundBuffer = _soundManager.CreateSoundBuffer();

            soundBuffer.SetData("Assets/jump.wav");

            var source = _soundManager.CreateSource();

            source.Gain = 1f;

            entity = _scene.CreateEntity();
            _scene.AddComponent(entity, new PositionComponent {
                Position = new Vector3(-400, -100, 0)
            });
            _scene.AddComponent(entity, new SizeComponent {
                Width = 100, Height = 100
            });
            _scene.AddComponent(entity, new TextureComponent {
                Texture = texture
            });
            var physicsComponent = new PhysicsComponent();

            _scene.AddComponent(entity, physicsComponent);
            var sourceComponent = new SourceComponent {
                Source = source, SoundBuffer = soundBuffer
            };

            _scene.AddComponent(entity, sourceComponent);
            _scene.AddComponent(entity, new ControlScript(physicsComponent, sourceComponent));

            entity = _scene.CreateEntity();
            _scene.AddComponent(entity, new PositionComponent {
                Position = new Vector3(0, -360, 0)
            });
            _scene.AddComponent(entity, new SizeComponent {
                Width = 1280, Height = 10
            });
            _scene.AddComponent(entity, new PhysicsComponent {
                Fixed = true
            });

            entity = _scene.CreateEntity();
            _scene.AddComponent(entity, new PositionComponent {
                Position = new Vector3(0, -200, 0)
            });
            _scene.AddComponent(entity, new SizeComponent {
                Width = 600, Height = 10
            });
            _scene.AddComponent(entity, new PhysicsComponent {
                Fixed = true
            });

            entity = _scene.CreateEntity();
            _scene.AddComponent(entity, new PositionComponent {
                Position = new Vector3(420, -95, 0), Rotation = new Vector3(0, 0, 45)
            });
            _scene.AddComponent(entity, new SizeComponent {
                Width = 300, Height = 10
            });
            _scene.AddComponent(entity, new PhysicsComponent {
                Fixed = true
            });

            entity = _scene.CreateEntity();
            _scene.AddComponent(entity, new PositionComponent {
                Position = new Vector3(0, -100, 0)
            });
            _scene.AddComponent(entity, new SizeComponent {
                Width = 10, Height = 300
            });
            _scene.AddComponent(entity, new PhysicsComponent {
                Fixed = true
            });

            _physicsContainer.Start(144, _scene.EntityContainer);
            _soundManager.Start(60, _scene.EntityContainer);
        }
Esempio n. 3
0
        public void Attach()
        {
            _scene.Init();

            var cameraEntity = _scene.CreateEntity();

            _scene.AddComponent(cameraEntity, new CameraComponent {
                Camera = _camera, Active = true
            });

            var fullscreenButton = _scene.CreateEntity();

            _scene.AddComponent(fullscreenButton, new PositionComponent {
                Position = new Vector3(530, 150, 0)
            });
            _scene.AddComponent(fullscreenButton, new SizeComponent {
                Width = 200, Height = 40
            });
            _scene.AddComponent(fullscreenButton, new ColorComponent());
            _scene.AddComponent(fullscreenButton, new SettingsScript(_settingsManager,
                                                                     _ =>
            {
                if (_.Settings.WindowMode.HasFlag(WindowMode.Fullscreen))
                {
                    _.Settings.WindowMode &= ~WindowMode.Fullscreen;
                }
                else
                {
                    _.Settings.WindowMode |= WindowMode.Fullscreen;
                }
            }, _ => _.Settings.WindowMode.HasFlag(WindowMode.Fullscreen), fullscreenButton));
            _scene.AddComponent(fullscreenButton, CreateButtonText("Fullscreen"));

            var borderlessButton = _scene.CreateEntity();

            _scene.AddComponent(borderlessButton, new PositionComponent {
                Position = new Vector3(530, 100, 0)
            });
            _scene.AddComponent(borderlessButton, new SizeComponent {
                Width = 200, Height = 40
            });
            _scene.AddComponent(borderlessButton, new ColorComponent());
            _scene.AddComponent(borderlessButton, new SettingsScript(_settingsManager,
                                                                     _ =>
            {
                if (_.Settings.WindowMode.HasFlag(WindowMode.Borderless))
                {
                    _.Settings.WindowMode &= ~WindowMode.Borderless;
                }
                else
                {
                    _.Settings.WindowMode |= WindowMode.Borderless;
                }
            }, _ => _.Settings.WindowMode.HasFlag(WindowMode.Borderless), borderlessButton));
            _scene.AddComponent(borderlessButton, CreateButtonText("Borderless"));

            var vsyncButton = _scene.CreateEntity();

            _scene.AddComponent(vsyncButton, new PositionComponent {
                Position = new Vector3(530, 50, 0)
            });
            _scene.AddComponent(vsyncButton, new SizeComponent {
                Width = 200, Height = 40
            });
            _scene.AddComponent(vsyncButton, new ColorComponent());
            _scene.AddComponent(vsyncButton, new SettingsScript(_settingsManager,
                                                                _ => _.Settings.Vsync = !_.Settings.Vsync, _ => _.Settings.Vsync, vsyncButton));
            _scene.AddComponent(vsyncButton, CreateButtonText("Vsync"));

            var zeroFpsButton = _scene.CreateEntity();

            _scene.AddComponent(zeroFpsButton, new PositionComponent {
                Position = new Vector3(460, 0, 0)
            });
            _scene.AddComponent(zeroFpsButton, new SizeComponent {
                Width = 60, Height = 40
            });
            _scene.AddComponent(zeroFpsButton, new ColorComponent());
            _scene.AddComponent(zeroFpsButton, new SettingsScript(_settingsManager,
                                                                  _ => _.Settings.MaxFps = 0, _ => _.Settings.MaxFps == 0, zeroFpsButton));
            _scene.AddComponent(zeroFpsButton, CreateButtonText("0"));

            var sixtyFpsButton = _scene.CreateEntity();

            _scene.AddComponent(sixtyFpsButton, new PositionComponent {
                Position = new Vector3(530, 0, 0)
            });
            _scene.AddComponent(sixtyFpsButton, new SizeComponent {
                Width = 60, Height = 40
            });
            _scene.AddComponent(sixtyFpsButton, new ColorComponent());
            _scene.AddComponent(sixtyFpsButton, new SettingsScript(_settingsManager,
                                                                   _ => _.Settings.MaxFps = 60, _ => _.Settings.MaxFps == 60, sixtyFpsButton));
            _scene.AddComponent(sixtyFpsButton, CreateButtonText("60"));

            var highFpsButton = _scene.CreateEntity();

            _scene.AddComponent(highFpsButton, new PositionComponent {
                Position = new Vector3(600, 0, 0)
            });
            _scene.AddComponent(highFpsButton, new SizeComponent {
                Width = 60, Height = 40
            });
            _scene.AddComponent(highFpsButton, new ColorComponent());
            _scene.AddComponent(highFpsButton, new SettingsScript(_settingsManager,
                                                                  _ => _.Settings.MaxFps = 144, _ => _.Settings.MaxFps == 144, highFpsButton));
            _scene.AddComponent(highFpsButton, CreateButtonText("144"));

            var resolution1Button = _scene.CreateEntity();

            _scene.AddComponent(resolution1Button, new PositionComponent {
                Position = new Vector3(479, -50, 0)
            });
            _scene.AddComponent(resolution1Button, new SizeComponent {
                Width = 98, Height = 40
            });
            _scene.AddComponent(resolution1Button, new ColorComponent());
            _scene.AddComponent(resolution1Button, new SettingsScript(_settingsManager,
                                                                      _ =>
            {
                _.Settings.ResolutionX = 1280;
                _.Settings.ResolutionY = 720;
            }, _ => _.Settings.ResolutionX == 1280 && _.Settings.ResolutionY == 720, resolution1Button));
            _scene.AddComponent(resolution1Button, CreateButtonText("1280x720", 20));

            var resolution2Button = _scene.CreateEntity();

            _scene.AddComponent(resolution2Button, new PositionComponent {
                Position = new Vector3(581, -50, 0)
            });
            _scene.AddComponent(resolution2Button, new SizeComponent {
                Width = 98, Height = 40
            });
            _scene.AddComponent(resolution2Button, new ColorComponent());
            _scene.AddComponent(resolution2Button, new SettingsScript(_settingsManager,
                                                                      _ =>
            {
                _.Settings.ResolutionX = 1920;
                _.Settings.ResolutionY = 1080;
            }, _ => _.Settings.ResolutionX == 1920 && _.Settings.ResolutionY == 1080, resolution2Button));
            _scene.AddComponent(resolution2Button, CreateButtonText("1920x1080", 20));

            var applyButton = _scene.CreateEntity();

            _scene.AddComponent(applyButton, new PositionComponent {
                Position = new Vector3(530, -100, 0)
            });
            _scene.AddComponent(applyButton, new SizeComponent {
                Width = 200, Height = 40
            });
            _scene.AddComponent(applyButton, new ColorComponent());
            _scene.AddComponent(applyButton, new SettingsScript(_settingsManager, _ => _.Apply(), _ => false, applyButton));
            _scene.AddComponent(applyButton, CreateButtonText("Apply"));

            var resetButton = _scene.CreateEntity();

            _scene.AddComponent(resetButton, new PositionComponent {
                Position = new Vector3(530, -150, 0)
            });
            _scene.AddComponent(resetButton, new SizeComponent {
                Width = 200, Height = 40
            });
            _scene.AddComponent(resetButton, new ColorComponent());
            _scene.AddComponent(resetButton, new SettingsScript(_settingsManager, _ => _.Reset(), _ => false, resetButton));
            _scene.AddComponent(resetButton, CreateButtonText("Reset"));
        }
Esempio n. 4
0
        public void Attach()
        {
            _texture = _factory.Create <ITexture2D>();
            _texture.SetData("Assets/picture.png");

            _texture2 = _factory.Create <ITexture2D>();
            _texture2.SetData("Assets/picture2.png");

            _scene.Init();
            _physicsContainer.Gravity = new Vector3(0, -800, 0);

            var entity = _scene.CreateEntity();

            _scene.AddComponent(entity, new CameraComponent {
                Camera = _camera, Active = true
            });
            _scene.AddComponent(entity, new CameraScript(_camera));

            entity = _scene.CreateEntity();
            _scene.AddComponent(entity, new PositionComponent {
                Position = new Vector3(-100, 400, 0)
            });
            _scene.AddComponent(entity, new SizeComponent {
                Width = 300, Height = 300
            });
            _scene.AddComponent(entity, new ColorComponent {
                Color = new Vector4(0.5f, 0.5f, 0.5f, 1f)
            });

            entity = _scene.CreateEntity();
            var positionComponent = new PositionComponent {
                Position = new Vector3(400, -100, 0)
            };

            _scene.AddComponent(entity, positionComponent);
            _scene.AddComponent(entity, new SizeComponent {
                Width = 400, Height = 300
            });
            _scene.AddComponent(entity, new ColorComponent {
                Color = new Vector4(1, 0, 1, 1)
            });
            _scene.AddComponent(entity, new TextureComponent {
                Texture = _texture
            });
            _scene.AddComponent(entity, new DiceScript(positionComponent));

            entity = _scene.CreateEntity();
            _scene.AddComponent(entity, new PositionComponent {
                Position = new Vector3(-400, -100, 0)
            });
            _scene.AddComponent(entity, new SizeComponent {
                Width = 300, Height = 300
            });
            _scene.AddComponent(entity, new TextureComponent {
                Texture = _texture2
            });
            _scene.AddComponent(entity, new PhysicsComponent {
                Velocity = new Vector3(300, 500, 0)
            });

            entity = _scene.CreateEntity();
            _scene.AddComponent(entity, new PositionComponent {
                Position = new Vector3(0, -360, 0)
            });
            _scene.AddComponent(entity, new SizeComponent {
                Width = 1280, Height = 10
            });
            _scene.AddComponent(entity, new PhysicsComponent {
                Fixed = true
            });
        }