Esempio n. 1
0
 public Character(AnimatedSprite sprite, Vector2 pos, float angle = 0.0f)
     : base(sprite, pos, angle)
 {
     ai = new PatrolMovementStyle();
     Health = 0;
     MOVEMENT_SPEED = 120;
     PhysicsBody.UserData = this;
 }
Esempio n. 2
0
 public GameObject(AnimatedSprite animated_sprite, Vector2 pos, float rot, Vector2 ori, Vector2 vel)
 {
     PhysicsBody = BodyFactory.CreateBody(World);
     Sprite = animated_sprite;
     Position = pos;
     Rotation = rot;
     PhysicsBody.Rotation = Rotation;
     Origin = ori;
     Alive = true;
 }
Esempio n. 3
0
        public static Bullet CreateBullet(Vector2 pos, float angle)
        {
            var sprite = new AnimatedSprite(ResMan.Get<Texture2D>("bullet"));
            Bullet obj = new Bullet(sprite, pos, angle);
            obj.Velocity = new Vector2((float)(100 * Math.Sin(obj.Rotation)), (float)(-100 * Math.Cos(obj.Rotation))) / Settings.FramesPerSecond;
            obj.Damage = 10;

            obj.PhysicsBody.CreateFixture(new CircleShape(ConvertUnits.ToSimUnits(obj.Size.X / 2), 0));
            obj.PhysicsBody.BodyType = BodyType.Dynamic;
            obj.PhysicsBody.Mass = 10000;

            obj.PhysicsBody.CollisionCategories = (Category) 0x02;
            obj.PhysicsBody.CollidesWith = (Category) (0x1 + 0x4);

            obj.PhysicsBody.UserData = obj;
            obj.PhysicsBody.OnCollision += new OnCollisionEventHandler(PhysicsBody_OnCollision);

            return obj;
        }
Esempio n. 4
0
 public Bullet(AnimatedSprite sprite, Vector2 pos, float angle = 0.0f)
     : base(sprite, pos, angle)
 {
     PhysicsBody.OnCollision += new OnCollisionEventHandler(PhysicsBody_OnCollision);
 }
Esempio n. 5
0
        private GameObject CreatePhysicsObject(AnimatedSprite animated_sprite, Vector2 pos, float rot = 0.0f)
        {
            GameObject obj = new GameObject(animated_sprite, pos, rot);
            obj.PhysicsBody = BodyFactory.CreateBody(world);
            //obj.PhysicsFixture = obj.PhysicsBody.CreateFixture(new CircleShape(ConvertUnits.ToSimUnits(animated_sprite.Area.Width / 2), 0f));
            /*obj.PhysicsFixture = obj.PhysicsBody.CreateFixture(
                new FarseerPhysics.Collision.Shapes.LoopShape(
                new Vertices(
                    new Vector2[] { new Vector2(0,0),
                        new Vector2(0, animated_sprite.Area.Width),
                        new Vector2(animated_sprite.Area.Height),
                        new Vector2(animated_sprite.Area.Width),
                        new Vector2(animated_sprite.Area.Width, 0)})));*/

            var q = new PolygonShape(1);/*
            q.SetAsBox(ConvertUnits.ToSimUnits(animated_sprite.Area.Width / 2),
                ConvertUnits.ToSimUnits( animated_sprite.Area.Height / 2),
                ConvertUnits.ToSimUnits(new Vector2(animated_sprite.Area.Height / 2,
                    animated_sprite.Area.Height / 2)), 0);*/

            q.SetAsBox(ConvertUnits.ToSimUnits(animated_sprite.Area.Width / 2),
                ConvertUnits.ToSimUnits(animated_sprite.Area.Height / 2));
            obj.PhysicsFixture = obj.PhysicsBody.CreateFixture(q);

            obj.PhysicsBody.BodyType = BodyType.Dynamic;
            obj.PhysicsBody.Position = ConvertUnits.ToSimUnits(pos);
            obj.PhysicsBody.Rotation = MathHelper.ToRadians(rot);
            obj.PhysicsBody.Friction = 50;
            return obj;
        }
Esempio n. 6
0
 public GameObject(AnimatedSprite animated_sprite, Vector2 pos, float rot = 0.0f)
     : this(animated_sprite, pos, rot, Vector2.Zero, Vector2.Zero)
 {
     Origin = new Vector2(Sprite.Area.Width / 2, Sprite.Area.Height / 2);
 }
Esempio n. 7
0
 public static GameObject CreateStone(Vector2 pos)
 {
     AnimatedSprite sprite = new AnimatedSprite(ResMan.Get<Texture2D>("stone"));
     GameObject obj = CreateCircular(sprite, pos);
     return obj;
 }
Esempio n. 8
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sprite"></param>
        /// <param name="pos"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static GameObject CreateRectangular(AnimatedSprite sprite, Vector2 pos, BodyType type = BodyType.Static)
        {
            GameObject obj = new GameObject(sprite, pos);
            var q = new PolygonShape(1);
            q.SetAsBox(ConvertUnits.ToSimUnits(obj.Size.X / 2),
                ConvertUnits.ToSimUnits(obj.Size.Y / 2));

            obj.PhysicsBody.CreateFixture(q);
            obj.PhysicsBody.BodyType = type;
            return obj;
        }
Esempio n. 9
0
 public static GameObject CreateNonPhysics(AnimatedSprite sprite, Vector2 pos, float angle = 0f)
 {
     GameObject obj = new GameObject(sprite, pos, angle);
     //obj.PhysicsBody.IsSensor = true;
     return obj;
 }
Esempio n. 10
0
 public static GameObject CreateFire(Vector2 obstacle)
 {
     AnimatedSprite sprite = new AnimatedSprite(ResMan.Get<Texture2D>("fire"), 8, 0.5f, "burning");
     return GameObject.CreateCircular(sprite, obstacle);
 }
Esempio n. 11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="tex">Sprite</param>
 /// <param name="pos">Postion</param>
 /// <param name="angle">Angle in radians</param>
 /// <returns></returns>
 public static GameObject CreateCircular(AnimatedSprite sprite, Vector2 pos, BodyType type = BodyType.Static, float angle = 0f)
 {
     GameObject obj = new GameObject(sprite, pos, angle);
     obj.PhysicsBody.CreateFixture(new CircleShape(ConvertUnits.ToSimUnits(obj.Size.X / 2), 0));
     obj.PhysicsBody.BodyType = type;
     obj.PhysicsBody.CollisionCategories = (Category)0x1;
     //obj.PhysicsBody.CollisionCategories
     return obj;
 }
Esempio n. 12
0
        public static Character CreatePlayer(Vector2 pos)
        {
            AnimatedSprite sprite = new AnimatedSprite(ResMan.Get<Texture2D>("bug2"), 4, 1, "walk");

            Character obj = new Character(sprite, pos);
            obj.PhysicsBody.CreateFixture(new CircleShape(ConvertUnits.ToSimUnits(obj.Size.X / 2), 0));
            obj.PhysicsBody.BodyType = BodyType.Dynamic;
            obj.Health = 1000;
            obj.ai = new ManualMovementStyle();
            obj.MOVEMENT_SPEED = 80;
            obj.PhysicsBody.Mass = 100;
            obj.PhysicsBody.UserData = obj;
            obj.Relations = GameObject.Relationship.Friendly;
            obj.PhysicsBody.CollisionCategories = (Category) 0x04;
            obj.PhysicsBody.CollidesWith = (Category.All);
            return obj;
        }
Esempio n. 13
0
        public static Character CreateBug(Vector2 pos)
        {
            AnimatedSprite sprite = new AnimatedSprite(ResMan.Get<Texture2D>("bug"), 1, 1, "none");

            Character obj = new Character(sprite, pos);
            obj.PhysicsBody.CreateFixture(new CircleShape(ConvertUnits.ToSimUnits(obj.Size.X / 2), 0));
            obj.PhysicsBody.BodyType = BodyType.Dynamic;
            obj.Health = 100;
            obj.PhysicsBody.Mass = 200;
            obj.PhysicsBody.UserData = obj;
            obj.Relations = Relationship.Enemy;
            obj.PhysicsBody.CollisionCategories = (Category) 0x04;
            obj.PhysicsBody.CollidesWith = (Category.All);
            return obj;
        }