Exemplo n.º 1
0
        public override JabActor CreateBox(Vector2 dim, Vector2 pos, JabActor.BodyType bodytype)
        {
            try
            {
                dim /= 100;
                FarActor actor = new FarActor();
                actor.body = new Body(world);// world.CreateBody();
                actor.body.UserData = actor;
                Vector2 center = new Vector2(-dim.X, -dim.Y) / 2.0f;
                Vertices box = PolygonTools.CreateRectangle(dim.X / 2.0f, dim.Y / 2.0f, center, 0);
                for (int i = 0; i < box.Count(); i++)
                {
                    Vector2 vert = box[i];
                    vert.X += dim.X / 2.0f;
                    vert.Y += dim.Y / 2.0f;
                    box[i] = vert;
                    vert = box[i];
                }
                PolygonShape shape = new PolygonShape(box, 1.0f);
                actor.BodyState = bodytype;
                actor.body.CreateFixture(shape, 1.0f);
                actor.Position = pos;
                actor.Width = dim.X * 100;
                actor.Height = dim.Y * 100;

                actors.Add(actor);
                return actor;
            }
            catch (Exception e)
            {
                return null;
            }
        }
Exemplo n.º 2
0
 public CharacterController(JabWorld world, Vector2 pos, Vector2 dim)
 {
     this.world = world;
     this.dim = dim;
     body = world.CreateBox(dim, pos, JabActor.BodyType.STATIC);
     float xpos = body.PosX;
 }
Exemplo n.º 3
0
        public override bool DestroyActor(JabActor actor)
        {
            FarActor act = (FarActor)(actor);

            world.RemoveBody(act.body);
            act.body = null;
            actors.Remove(act);
            return(true);
        }
Exemplo n.º 4
0
 static float Nearest(Fixture fixture, Vector2 point, Vector2 normal, float fraction)
 {
     if (Vector2.Distance(point, rayOrigin) < rayCurBest && !((JabActor)fixture.Body.UserData).IgnoreRayCast)
     {
         hitPosition = point;
         hitNormal   = normal;
         rayCurBest  = Vector2.Distance(point, rayOrigin);
         rayActorHit = (JabActor)fixture.Body.UserData;
     }
     return(1);
 }
Exemplo n.º 5
0
 public JabActor HasActor(JabActor actor)
 {
     if (actor == actor1)
     {
         return actor2;
     }
     else if (actor == actor2)
     {
         return actor1;
     }
     else
         return null;
 }
Exemplo n.º 6
0
 // If the passed in actor is either actor1 or 2 this class returns the other actor,
 // if it's neither this function returns null
 public JabActor ActorPresent(JabActor actor)
 {
     if (actor == _Actor1)
     {
         return(_Actor2);
     }
     else if (actor == _Actor2)
     {
         return(_Actor1);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 7
0
 public JabActor HasActor(JabActor actor)
 {
     if (actor == actor1)
     {
         return(actor2);
     }
     else if (actor == actor2)
     {
         return(actor1);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 8
0
 // If the passed in actor is either actor1 or 2 this class returns the other actor,
 // if it's neither this function returns null
 public JabActor ActorPresent(JabActor actor)
 {
     if (actor == _Actor1)
     {
         return _Actor2;
     }
     else if (actor == _Actor2)
     {
         return _Actor1;
     }
     else
     {
         return null;
     }
 }
Exemplo n.º 9
0
 public PhysicSprite(Vector2 dim, Vector2 pos, bool dynamic, JabWorld world, string imagedir)
     : base()
 {
     TextureDir = imagedir;
     Width = dim.X;
     Height = dim.Y;
     JabActor.BodyType type = JabActor.BodyType.DYNAMIC;
     if (!dynamic)
     {
         type = JabActor.BodyType.STATIC;
     }
     body = world.CreateBox(dim, pos, type);
     body.UserData = this;
     this.world = world;
     DoDimensions = true;
     DoHandle = true;
 }
Exemplo n.º 10
0
        FarseerPhysics.Dynamics.BodyType GetBodyType(JabActor.BodyType type)
        {
            switch (type)
            {
                case BodyType.DYNAMIC:
                    return FarseerPhysics.Dynamics.BodyType.Dynamic;
                case BodyType.STATIC:
                    return FarseerPhysics.Dynamics.BodyType.Kinematic;
            }
            //System.Windows.MessageBox.Show("ERROR: Body type provided invalid for FarWorld");

            return FarseerPhysics.Dynamics.BodyType.Static;
        }
Exemplo n.º 11
0
 static float Nearest(Fixture fixture, Vector2 point, Vector2 normal, float fraction)
 {
     if (Vector2.Distance(point, rayOrigin) < rayCurBest && !((JabActor)fixture.Body.UserData).IgnoreRayCast)
     {
         hitPosition = point;
         hitNormal = normal;
         rayCurBest = Vector2.Distance(point, rayOrigin);
         rayActorHit = (JabActor)fixture.Body.UserData;
     }
     return 1;
 }
Exemplo n.º 12
0
        public override RayCastHit RayCast(Vector2 origin, Vector2 destination)
        {
            if (destination == origin)
            {
                return null;
            }
            origin /= 100.0f;
            destination /= 100.0f;

            rayOrigin = origin;
            rayCurBest = float.MaxValue;
            rayActorHit = null;

            try
            {
                world.RayCast(Nearest, origin, destination);
            }
            catch (Exception e)
            {
                return new RayCastHit();
            }
            RayCastHit hit = new RayCastHit();
            hit.actor = rayActorHit;
            hit.worldImpact = hitPosition * 100.0f;
            hit.worldNormal = hitNormal;

            hit.Distance = (hit.worldImpact - (origin*100)).Length();

            return hit;
        }
Exemplo n.º 13
0
        public override bool DestroyActor(JabActor actor)
        {
            FarActor act = (FarActor)(actor);

            world.RemoveBody(act.body);
            act.body = null;
            actors.Remove(act);
            return true;
        }
Exemplo n.º 14
0
        public override JabActor CreateSphere(float radius, Vector2 pos, JabActor.BodyType bodytype)
        {
            try
            {
                radius /= 100;
                FarActor actor = new FarActor();
                actor.body = new Body(world);// world.CreateBody();
                actor.body.UserData = actor;

                Vector2 center = new Vector2(-radius, -radius) / 2.0f;
              //  FarseerPhysics.Settings.MaxPolygonVertices = 33;
                Vertices sphere = PolygonTools.CreateCircle(radius, 32);

                PolygonShape shape = new PolygonShape(sphere, 1.0f);
                actor.BodyState = bodytype;
                actor.body.CreateFixture(shape, 1.0f);
                actor.Position = pos;
                actor.Width = radius;
                actor.Height = radius;

                actors.Add(actor);
                return actor;
            }
            catch (Exception e)
            {
                return null;
            }
        }
Exemplo n.º 15
0
 public PhysicShape(JabWorld world, JabActor.BodyType bodytype)
     : base()
 {
     this.bodyType = bodytype;
     this.world = world;
 }
Exemplo n.º 16
0
 public abstract bool DestroyActor(JabActor actor);
Exemplo n.º 17
0
 public abstract JabActor CreateSphere(float radius, Vector2 pos, JabActor.BodyType bodytype);
Exemplo n.º 18
0
 public abstract JabActor CreateFromTriangles(List<Vector2> triangles, Vector2 pos, JabActor.BodyType bodytype);
Exemplo n.º 19
0
 public abstract JabActor CreateBox(Vector2 dim, Vector2 pos, JabActor.BodyType bodytype);
Exemplo n.º 20
0
 public override void UnloadContent()
 {
     body.RaiseFlag(Flags.DELETE);
     body = null;
     base.UnloadContent();
 }
Exemplo n.º 21
0
        public override JabActor CreateFromTriangles(List<Vector2> triangles, Vector2 pos, JabActor.BodyType bodytype)
        {
            try
            {
                FarActor actor = new FarActor();
                actor.body = new Body(world);// world.CreateBody();
                actor.body.UserData = actor;

                //FarseerPhysics.Settings.MaxPolygonVertices = 33;

                for (int i = 0; i < triangles.Count; i++)
                {
                    Vector2[] tri = new Vector2[3];
                    tri[0] = triangles[i] / 100.0f;
                    ++i;
                    tri[1] = triangles[i] / 100.0f;
                    ++i;
                    tri[2] = triangles[i] / 100.0f;

                    Vertices vertices = new Vertices(tri);
                    PolygonShape shape = new PolygonShape(vertices, 1.0f);
                    actor.body.CreateFixture(shape, 1.0f);
                }

                actor.BodyState = bodytype;
                actor.Position = pos;

                actors.Add(actor);
                return actor;

            }
            catch (Exception e)
            {
                //System.Windows.MessageBox.Show(e.ToString());
            }

            return null;
        }
Exemplo n.º 22
0
        public PhysicSprite(float radius, Vector2 pos, bool dynamic, JabWorld world, string imagedir)
            : base()
        {
            TextureDir = imagedir;
            Width = radius;
            Height = radius;
            JabActor.BodyType type = JabActor.BodyType.DYNAMIC;
            if (!dynamic)
            {
                type = JabActor.BodyType.STATIC;
            }
            body = world.CreateSphere(radius/2.0f, pos, type);
            body.UserData = this;
            this.world = world;

               // Initialize();
        }
Exemplo n.º 23
0
 public abstract bool DestroyActor(JabActor actor);
Exemplo n.º 24
0
        public override void Initialize(ContentManager Content)
        {
            base.Initialize(Content);

            CreateFramesFromXML("misc_frames");
            Animation = "FanSpin";
            ResetDimensions();
            Width *= 2.0f;
            Height *= 2.0f;
            placeholder = new Sprite("ui/ui");
            placeholder.Initialize(Content);
            placeholder.CreateFramesFromXML("ui/ui_frames");
            placeholder.CurrentFrame = "whitecore";
            placeholder.Width = Width;
            placeholder.Height = 500;
            placeholder.Handle = SpriteHandle.BOTTOMCENTER;

            box = world.CreateBox(placeholder.Dimension + new Vector2(0, 100), placeholder.GetAbsoluteCenter(), JabActor.BodyType.STATIC);
            box.CollisionGroup = FanEntitySpaceGroup;
            box.IgnoreRayCast = true;
            box.UserData = this;

            m_Animations[Animation].curFrame = Jabber.BaseGame.Random.Next(0, m_Animations[Animation].animFrames.Count);
        }