Exemplo n.º 1
0
 public EntityFactory(B2DWorld Box2dWorld, World world, ContentManager contentManager, GraphicsDevice graphicsDevice)
 {
     _Box2dWorld     = Box2dWorld;
     _world          = world;
     _graphicsDevice = graphicsDevice;
     _BodyFactory    = BodyFactory.GetFactory();
     _contentManager = contentManager;
 }
Exemplo n.º 2
0
        public override void LoadContent()
        {
            var wallTexture = _sceneHandler._content.Load <Texture2D>("background2");

            wallSprite = new Sprite(wallTexture);
            transform  = new Transform2(new Vector2(512, 400));

            b2DWorld = new B2DWorld(new System.Numerics.Vector2(0.0f, 1.500000000000000e+01f));
            client   = new Client <Frame>(0);
            client.Connect(new IPEndPoint(IPAddress.Parse(_ip), 1337));
            inputClient = new Client <byte>(0);
            inputClient.Connect(inputEndPoint);

            var xx     = ProtoHelper.LoadEntities();
            var camera = new OrthographicCamera(_sceneHandler._graphicsDevice);

            ProtoHelper.OnChatRecieve += OnChatRecive;
            spriteBatch = new SpriteBatch(_sceneHandler._graphicsDevice);
            world       = new WorldBuilder()
                          .AddSystem(new RenderSystem(spriteBatch, camera))
                          .AddSystem(new PhysicsSystem())
                          .AddSystem(new MouseSystem())
                          .AddSystem(new MovementSystem())
                          .Build();

            _sceneHandler._gameComponents.Add(world);

            entityFactory = new EntityFactory(
                b2DWorld,
                world,
                _sceneHandler._content,
                _sceneHandler._graphicsDevice);

            foreach (var x in xx)
            {
                if (x.Kind == 2)
                {
                    entityFactory.CreateDynamicCircle(new Vector2(x.PositionX, x.PositionY), x.SizeX).Get <IRigidBody>().id = x.Id;
                }
                if (x.Kind == 3)
                {
                    var pars   = x.Params.Split(",");
                    var skin   = (skin)int.Parse(pars[1]);
                    var player = entityFactory.CreatePlayer(x.Params, new Vector2(x.PositionX, x.PositionY), skin.ToString());
                    player.Get <IRigidBody>().id = x.Id;
                }
                if (x.Params == "foot")
                {
                    entityFactory.CreateFoot(new Vector2(x.PositionX, x.PositionY), new Vector2(x.SizeX, x.SizeY)).Get <IRigidBody>().id = x.Id;
                }
                if (x.Params == "rfoot")
                {
                    entityFactory.CreateReverseFoot(new Vector2(x.PositionX, x.PositionY), new Vector2(x.SizeX, x.SizeY)).Get <IRigidBody>().id = x.Id;
                }
            }

            points      = entityFactory.CreateText(new Vector2(50, 50), "0", 0);
            enemyPoints = entityFactory.CreateText(new Vector2(720, 50), "0", 0);

            new TaskFactory().StartNew(() =>
            {
                while (true)
                {
                    try
                    {
                        var msg       = client.Listen();
                        var RigitBody = BodyFactory.RigidBodies.FirstOrDefault(x => x.id == msg.id);
                        if (RigitBody != null)
                        {
                            RigitBody.Position = new System.Numerics.Vector2(msg.X, msg.Y);
                            RigitBody.Angle    = msg.R;
                        }
                    }
                    catch { }
                }
            }
                                       );

            IsLoaded = true;
        }