Пример #1
0
        public Player(ScreenManager screenManager, string propName, Vector2 pos, World world, int columns, int rows, Level sourceLevel) : base(screenManager, propName, new Vector2(0.75f, 0.25f), new Vector2(0.75f, 0.75f), columns, rows, sourceLevel)
        {
            _x            = 0;
            _y            = 0;
            _baseVelocity = 0.05f;
            Health        = 100;

            ObjectBody          = world.CreateCapsule(_objectBodySize.X, 0.25f, 10, _objectBodySize.Y, 10, 1f, pos);
            ObjectBody.BodyType = BodyType.Dynamic;
            ObjectBody.SetRestitution(0f);
            ObjectBody.Mass          = 2f;
            ObjectBody.FixedRotation = true;
            ObjectBody.SetFriction(1.0f);
            ObjectBody.OnSeparation += Seperation;
            ObjectBody.Tag           = "Player";

            AnimationTimeSpans = new Dictionary <CreatureState, TimeSpan>();
            AnimationTimeSpans[CreatureState.Moving] = TimeSpan.FromMilliseconds(200);
            foreach (var fixture1 in ObjectBody.FixtureList)
            {
                fixture1.Tag = "Player";
            }

            ObjectBody.SetCollisionCategories((Category)(Category.All - Category.Cat1));

            //create bottom rectangle for floor detection
            Vertices vertices = PolygonTools.CreateRectangle(0.1f, 0.1f);

            vertices.Translate(new Vector2(0f, -0.4f));
            Shape   rectangle = new PolygonShape(vertices, 1f);
            Fixture fixture   = ObjectBody.CreateFixture(rectangle);

            fixture.Tag          = "AirDetectorBottom";
            fixture.IsSensor     = true;
            fixture.OnSeparation = fixtureSeperated;
            fixture.OnCollision += Colided;
            //set sound effect

//            PlayerBody.CreateRectangle(0.2f, 0.2f, 1f, new Vector2(0f, -0.8f)).IsSensor = true;
            _inAir             = true;
            _isMoving          = false;
            _playerMovingForce = new Vector2(0, 0);
        }
Пример #2
0
        public MagicMissile(ScreenManager screenManager, World world, Vector2 pos, Vector2 cursorPos, ICanSpawnMissiles parentObject, int columns, int rows, Level sourceLevel) : base(screenManager, "Textures/magicMissile",
                                                                                                                                                                                       new Vector2(0.05f), new Vector2(0.25f), columns, rows, sourceLevel)
        {
            _world          = world;
            _parentObject   = parentObject;
            directionVector = cursorPos - pos;
            _originalPos    = pos;
            directionVector.Normalize();
            CircleShape shape = new CircleShape(0.05f, 20f);

            ObjectBody          = world.CreateBody();
            ObjectBody.BodyType = BodyType.Dynamic;
            ObjectBody.IsBullet = true;
            ObjectBody.Position = pos + (directionVector / 2);
            ObjectBody.SetCollisionCategories(Category.Cat1);
            ObjectBody.IgnoreGravity = true;
            ObjectBody.Mass          = 0.01f;


            Fixture fixture = ObjectBody.CreateFixture(shape);

            fixture.Restitution = 0.05f;
            if (GameSettings._Volume)
            {
                SoundEffects.MissileOut.Play();
            }

            ObjectBody.LinearVelocity = directionVector * 10f;
            ObjectBody.OnCollision   += Collided;

            ObjectBody.Tag = "MagicMissile";
            foreach (var fixture1 in ObjectBody.FixtureList)
            {
                fixture1.Tag = "MagicMissile";
            }
        }