Ejemplo n.º 1
0
        protected override void AssignResources()
        {
            world = new World(Vector2.Zero);
            GameObject.World = world;

            bug = GameObject.CreateCircular(new AnimatedSprite(ResMan.Get<Texture2D>("bug2"),4,1,"walk"), new Vector2(500, 500), BodyType.Dynamic);
            Player = Character.CreatePlayer(new Vector2(500, 500));

            floatingText = new FloatText(ResMan.GetResource<SpriteFont>("default"));

            //załozenie że są zasoby
            level.AssignResources();
            Obstacles = level.Obstacles;
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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;
 }
Ejemplo n.º 5
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;
 }
Ejemplo n.º 6
0
 protected void LookAt(GameObject target)
 {
     if (target != null)
         camera = (target.Position + 0 * target.Origin) - Settings.DesiredResolution / 2;
     else
         camera = Vector2.Zero;
 }
Ejemplo n.º 7
0
 protected void DrawGameObject(SpriteBatch batch, GameObject obj)
 {
     //if(GameObject
     batch.Draw(obj.Sprite.Sprite, obj.Position - camera , obj.Sprite.Area, Color.White, obj.Rotation, obj.Origin, 1.0f, SpriteEffects.None, 0.0f);
 }