public MainWindow()
        {
            _proc = HookCallback;

            _hookId = SetHook(_proc);
            //Application.Run();

            _timer.Interval = 1;
            _timer.Tick += _timer_Tick;
            InitializeComponent();
            _timer.Start();
            _area = Screen.PrimaryScreen.WorkingArea;

            _world = new World(new Vector2(0, 9.8f));

            // Farseer expects objects to be scaled to MKS (meters, kilos, seconds)
            // 1 meters equals 64 pixels here
            ConvertUnits.SetDisplayUnitToSimUnitRatio(64f);

            /* Circle */
            // Convert screen center from pixels to meters
            Vector2 circlePosition = ConvertUnits.ToSimUnits(new Vector2((float)_area.Width/2, (float)_area.Height/2));

            Left = (float)_area.Width/2 - (Width/2);
            Top = (float) _area.Height/2 - (Height/2);

            // Create the circle fixture
            _circleBody = BodyFactory.CreateCircle(_world, ConvertUnits.ToSimUnits(100 / 2f), 10f, circlePosition);
            _circleBody.BodyType = BodyType.Dynamic;
            _circleBody.ApplyTorque(500f);

            // Create the ground fixture
            _groundBody = BodyFactory.CreateRectangle(_world, ConvertUnits.ToSimUnits(_area.Width*4),
                                                      ConvertUnits.ToSimUnits(1f), 1f,
                                                      ConvertUnits.ToSimUnits(new Vector2(_area.Width/2, _area.Height)));
            _groundBody.IsStatic = true;
            _groundBody.Restitution = 0.8f;
            _groundBody.Friction = 0.5f;

            // Create east wall
            _groundBody2 = BodyFactory.CreateRectangle(_world, ConvertUnits.ToSimUnits(1f),
                                                       ConvertUnits.ToSimUnits(_area.Height), 1f,
                                                       ConvertUnits.ToSimUnits(new Vector2(_area.Width * 2 - 50,
                                                                                           _area.Height)));
            _groundBody2.IsStatic = true;
            _groundBody2.Restitution = 0.8f;
            _groundBody2.Friction = 0.5f;
        }
Esempio n. 2
0
        public void Initialize(Texture2D sprite, ProjectileType type, Player plr, Body b, Texture2D shadow)
        {
            B = b;

            alreadyCollidedOnceOrMore = false;

            shade = shadow;

            foreach (var item in Game1.projectiles) {
                B.IgnoreCollisionWith(item.B);
            }

            B.OnCollision += new OnCollisionEventHandler(B_OnCollision);

            uint[] d = new uint[shade.Width * shade.Height];

            shade.GetData(d);

            Vertices v = PolygonTools.CreatePolygon(d, shade.Width, true);

            Vector2[] a = v.ToArray();

            h = ShadowHull.CreateConvex(ref a);

            if (plr.direction == 1)
                dir = 1;

            lock (Game1.projectileLock)
            Game1.lightingEngine.Hulls.Add(h);

            //  B.ApplyLinearImpulse(new Vector2(50, -10));
            if (plr.direction == 1) {
                B.Position = new Vector2(-plr.Position.X, plr.Position.Y + 1);
                B.ApplyTorque(-250f);
                B.LinearVelocity = new Vector2(-65, 7);
            } else {
                B.Position = new Vector2(-plr.Position.X, plr.Position.Y + 1);
                B.ApplyTorque(250f);
                B.LinearVelocity = new Vector2(65, 7);
            }

            Active = true;

            position = ConvertUnits.ToDisplayUnits(-plr.Position);
            texture = sprite;

            Type = type;

            Pelaaja = plr;

            hitBox.Width = 17;
            hitBox.Height = 17;
            hitBox.X = (int)position.X;
            hitBox.Y = (int)position.Y;
        }