Example #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            DefaultFont = Content.Load <SpriteFont>("Default");

            spriteBatch = new SpriteBatch(GraphicsDevice);
            //PrefabFactory.RegisterPrefab("machine gun", () => GameObjectFactory.New()
            //    .WithTexture(TextureUtil.CreateTexture(16, 16, Color.Red))
            //    .With(new Weapon() { FireRate = 0.5f })
            //    .Create());

            //PrefabFactory.RegisterPrefab("player", () => GameObjectFactory.New()
            //    .AtPosition(new Vector2(0))
            //    .WithTexture(TextureUtil.CreateTexture(64, 128, Color.Black))
            //    .With(new VelocityController())
            //    .With(new ShipEngine())
            //    .With(new PlayerController())
            //    .With(new Drag())
            //    .With(new ScreenWrapper()).With(new ParticleEmitter())
            //    .WithChild("machine gun", new Vector2(0, -1))
            //    .Create());

            //PrefabFactory.RegisterPrefab("bullet", () => GameObjectFactory.New()
            //    .WithTexture(TextureUtil.CreateTexture(16, 16, Color.Yellow))
            //    .With(new VelocityController())
            //    .With(new BulletController())
            //    .With(new ScreenWrapper())
            //    .Create());

            PrefabFactory.RegisterPrefab("unitbox", () => GameObjectFactory.New()
                                         .WithTexture(TextureUtil.CreateTexture(64, 64, Color.Black))
                                         .With(new Collider()
            {
                Body = BodyFactory.CreateRectangle(PhysicsWorld.World, 1, 1, 1)
            })
                                         .Create());

            PrefabFactory.RegisterPrefab("cursor", () => GameObjectFactory.New()
                                         .WithTexture(TextureUtil.CreateTexture(64, 64, Color.Red))
                                         .With(new SimpleController()).With(new Collider()
            {
                Body     = BodyFactory.CreateRectangle(PhysicsWorld.World, 1, 1, 1),
                BodyType = BodyType.Dynamic
            })
                                         .Create());

            GameObjectManager.Start();
        }
Example #2
0
        protected override void LoadContent()
        {
            base.LoadContent();

            scene.Start();

            return;

            scene.Engine.AddSystem(new StayOnMouseSystem());
            scene.Engine.AddSystem(new TestCollisionListener());

            var cursor = new Entity();

            cursor.Add(new Transform());
            cursor.Add(new Sprite()
            {
                Texture = TextureUtil.CreateTexture(32, 32, Color.Black)
            });
            cursor.Add(ColliderBuilder.New().BoxShape(0.5f, 0.5f).Create());
            cursor.Add(new StayOnMouse());

            var test      = new Entity();
            var transform = new Transform()
            {
                Position = new Vector2(1)
            };

            test.Add(transform);
            var sprite = new Sprite()
            {
                Texture = TextureUtil.CreateTexture(64, 64, Color.Red)
            };

            test.Add(sprite);

            var collider = ColliderBuilder.New().IsDynamic()
                           .Create();

            test.Add(collider);

            var camera = new Entity();

            camera.Add(new Transform());
            camera.Add(new Camera());

            var animation = AnimationBuilder.New()
                            .InsertFrame(0, new KeyFrame(new Vector2(-5, 0)))
                            .InsertFrame(2, new KeyFrame(new Vector2(5, 0)))
                            .InsertFrame(3, new KeyFrame(new Vector2(5, 2.5f)))
                            .Reverses(true)
                            .Loops(true)
                            .AnimatePhysics()
                            .Create();

            var animationContainer = new AnimationContainer();

            animationContainer.Animation.Add("test", animation);

            var animated = new Entity();

            animated.Add(new Transform());
            animated.Add(animationContainer);
            animated.Add(ColliderBuilder.New().IsDynamic().Create());
            animated.Add(new Sprite()
            {
                Texture = TextureUtil.CreateTexture(64, 64, Color.Pink)
            });

            scene.Engine.AddEntity(cursor);
            scene.Engine.AddEntity(test);
            scene.Engine.AddEntity(camera);
            scene.Engine.AddEntity(animated);
            scene.Engine.Systems.Get <CameraSystem>().ActiveCamera = camera;

            scene.Engine.MessageHub.SendMessage(new StartAnimationMessage(animated, "test"));
        }