Пример #1
0
        protected override void Initialize()
        {
            base.Initialize();

            player1 = new Entity("Player1");
            DrawComponent     player1DC = new DrawComponent(player1, Content, "Sprites/paddle", Color.White);
            PositionComponent player1PC = new PositionComponent(player1);

            player1PC.position.X = player1PC.origin.X = engine.Width - (player1DC.GetTextureWidth() + 20f);
            player1PC.position.Y = player1PC.origin.Y = (engine.Height / 2f) - (player1DC.GetTextureHeight() / 2f);
            player1.AddComponent(player1DC);
            player1.AddComponent(player1PC);
            player1.AddCollider(player1PC.origin.X, player1PC.origin.Y, player1DC.GetTextureWidth(), player1DC.GetTextureHeight());
            engine.AddEntity(player1);

            player2 = new Entity("Player2");
            DrawComponent     player2DC = new DrawComponent(player2, Content, "Sprites/paddle", Color.White);
            PositionComponent player2PC = new PositionComponent(player2);

            player2PC.position.X = player2PC.origin.X = 20f;
            player2PC.position.Y = player2PC.origin.Y = (engine.Height / 2f) - (player2DC.GetTextureHeight() / 2f);
            player2.AddComponent(player2DC);
            player2.AddComponent(player2PC);
            player2.AddCollider(player2PC.origin.X, player2PC.origin.Y, player2DC.GetTextureWidth(), player2DC.GetTextureHeight());
            engine.AddEntity(player2);

            ball = new Entity("Ball");
            DrawComponent     ballDC = new DrawComponent(ball, Content, "Sprites/ball", Color.White);
            PositionComponent ballPC = new PositionComponent(ball);

            ballPC.position.X = ballPC.origin.X = (engine.Width / 2f) - (ballDC.GetTextureWidth() / 2f);
            ballPC.position.Y = ballPC.origin.Y = (engine.Height / 2f) - (ballDC.GetTextureHeight() / 2f);
            ball.AddComponent(ballPC);
            ball.AddComponent(ballDC);
            ball.AddCollider(ballPC.origin.X, ballPC.origin.Y, ballDC.GetTextureWidth(), ballDC.GetTextureHeight());
            engine.AddEntity(ball);

            Entity            centerLine   = new Entity("centerLine");
            DrawComponent     centerLineDC = new DrawComponent(centerLine, Content, "Sprites/center", Color.White);
            PositionComponent centerLinePC = new PositionComponent(centerLine);

            centerLinePC.position.X = (engine.Width / 2f) - (centerLineDC.GetTextureWidth() / 2f);
            centerLinePC.position.Y = 7f;
            centerLine.AddComponent(centerLineDC);
            centerLine.AddComponent(centerLinePC);
            engine.AddEntity(centerLine);

            Reset();
        }