Esempio n. 1
0
        public GameStartup()
        {
            const float dt = 1 / 60f;

            ClientSize       = new Size(900, 720);
            DoubleBuffered   = true;
            keys             = new KeyState();
            world            = new EcsWorld();
            worldEvents      = new EcsWorld();
            worldConstraints = new EcsWorld();
            gameplayData     = new GameplayData(new Vector2(0, -9.80665f));
            physicsData      = new PhysicsData(dt, 10, 4, 2);
            renderData       = new RenderData(ClientSize.Width, ClientSize.Height, 60f);
            var sharedData = new SharedData(new PhysicsObjectsFactory(world, worldConstraints), gameplayData, physicsData, renderData, keys);

            gameplaySystems = new EcsSystems(world, sharedData);
            gameplaySystems
            .AddWorld(worldEvents, PhysicsWorldNames.Events)
            .AddWorld(worldConstraints, PhysicsWorldNames.Constraints)
            .Add(new InitEnvironment())
            // .Add(new CreateSegments())
            .Add(new Grabber())
            .Inject()
            .Init();

            physicsSystems = new EcsSystems(world, physicsData);
            physicsSystems
            .AddWorld(worldEvents, PhysicsWorldNames.Events)
            .AddWorld(worldConstraints, PhysicsWorldNames.Constraints)
            // force generators
            .Add(new ApplyStaticGravity())     // custom one
            .Add(new UpdateSprings())
            // apply forces
            .Add(new IntegratePoses())
            // update bounding volumes
            .Add(new UpdateCirclesBV())
            .Add(new UpdateMeshesBV())
            // broad phase
            .Add(new BroadPhase())
            // narrow phase
            .Add(new ContactTesterCircleCircle())
            .Add(new ContactTesterCircleMesh())
            .Add(new ContactTesterCircleSegment())
            .Add(new ContactTesterMeshSegment())
            .Add(new ContactTesterCircleAABox())
            // solver phase
            .Add(new DynamicDefaultContactSolver <Dynamic, Dynamic>())
            .Add(new StaticDefaultContactSolver <Dynamic, Static>())
            // physics systems internally use PhysicsData,
            // but you can inject your own data for custom force generators
            .Inject(gameplayData)
            .Init();

            renderSystems = new EcsSystems(world, sharedData);
            renderSystems
            .AddWorld(worldEvents, PhysicsWorldNames.Events)
            .AddWorld(worldConstraints, PhysicsWorldNames.Constraints)
            .Add(new DrawVelocities())
            .Add(new DrawSegments())
            .Add(new DrawMeshes())
            .Add(new DrawAABoxes())
            .Add(new DrawSprings())
            // .Add(new DrawBoundingBoxes())
            .Add(new RenderMeshesMassCenter())
            .Inject(renderData)
            .Init();

            var timer = new Timer();

            timer.Interval = 16;
            timer.Tick    += GameLoop;
            timer.Start();
        }
Esempio n. 2
0
 public SharedData(PhysicsObjectsFactory objectsFactory, GameplayData gameplayData, PhysicsData physicsData, RenderData renderData, KeyState keys)
 {
     ObjectsFactory = objectsFactory;
     GameplayData   = gameplayData;
     PhysicsData    = physicsData;
     RenderData     = renderData;
     Keys           = keys;
 }
Esempio n. 3
0
 public void Update(KeyState keyState, Variables variables, ContentManager content, Map map, GraphicsDevice graphicsDevice)
 {
     if (keyState.IsKeyReleased(Keys.Enter))
     {
         variables.blocks.Add(new Block {
             spriteRectangle = new Rectangle(variables.editorCursorRectangle.X - variables.moveScreenX, variables.editorCursorRectangle.Y - variables.moveScreenY, variables.blockWidth, variables.blockHeight), hitboxRectangle = new Rectangle(0, 0, 64, 64), texture = content.Load <Texture2D>("Textures/3"), collision = true
         });
     }
     if (keyState.IsKeyReleased(Keys.L))
     {
         variables.blocks.Clear();
         map.LoadMap(variables.blocks, "mapa", content, variables);
     }
     if (keyState.IsKeyReleased(Keys.S))
     {
         map.SaveMap(variables.blocks, "mapa");
     }
     if (keyState.IsKeyReleased(Keys.C))
     {
         variables.blocks.Clear();
     }
     if (keyState.IsKeyReleased(Keys.Z))
     {
         if (variables.blocks.Count >= 1)
         {
             variables.blocks.RemoveAt(variables.blocks.Count - 1);
         }
     }
     if (keyState.IsKeyReleased(Keys.E))
     {
         variables.isCollisionEnabled = !variables.isCollisionEnabled;
     }
     if (keyState.IsKeyPressed(Keys.Left, 800))
     {
         if (variables.editorCursorRectangle.X <= (graphicsDevice.Viewport.Width / 100) * 2)
         {
             variables.moveScreenX += variables.blockWidth;
         }
         else
         {
             variables.editorCursorRectangle.X -= variables.blockWidth;
         }
     }
     if (keyState.IsKeyPressed(Keys.Right, 800))
     {
         if (variables.editorCursorRectangle.X >= (graphicsDevice.Viewport.Width / 100) * 98)
         {
             variables.moveScreenX -= variables.blockWidth;
         }
         else
         {
             variables.editorCursorRectangle.X += variables.blockWidth;
         }
     }
     if (keyState.IsKeyPressed(Keys.Up, 800))
     {
         if (variables.editorCursorRectangle.Y <= (graphicsDevice.Viewport.Height / 100) * 2)
         {
             variables.moveScreenY += variables.blockHeight;
         }
         else
         {
             variables.editorCursorRectangle.Y -= variables.blockHeight;
         }
     }
     if (keyState.IsKeyPressed(Keys.Down, 800))
     {
         if (variables.editorCursorRectangle.Y >= (graphicsDevice.Viewport.Height / 100) * 99)
         {
             variables.moveScreenY -= variables.blockHeight;
         }
         else
         {
             variables.editorCursorRectangle.Y += variables.blockHeight;
         }
     }
 }