예제 #1
0
        public void dropItem(Vector2 dropPosition, Being killedBeing)
        {
            DropItem item = new DropItem();

            item.body                 = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, item.radius, item.radius, item.weight);
            item.body.Position        = new Vector2(dropPosition.X, dropPosition.Y + 25);
            item.body.Rotation        = 100f * (float)(rand.NextDouble() - .5f);
            item.body.AngularVelocity = (float)(rand.NextDouble() - .5f);
            item.body.LinearVelocity  = 50f * new Vector2((float)rand.NextDouble() - .5f, 1);
            #region geometry setup
            item.geom = new Geom();
            item.geom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, item.body, item.radius, item.radius);
            item.geom.FrictionCoefficient = .6f;
            item.geom.CollisionCategories = item.geom.CollidesWith = killedBeing.geom.CollisionCategories;
            #endregion
            item.setItem(DropManager.generateItem(killedBeing));
            item.startdepth = (uint)PhysicsHelper.collisionCategoryToDepth(item.geom.CollisionCategories);
            activeItems.Add(item.guid, item);
            network.sendFullObjectsUpdate();
        }
예제 #2
0
        public void addGameItem(GameItem item)
        {
            item.geom = new Geom();
            switch (item.polygonType)
            {
            case PhysicsPolygonType.Circle:
                item.body = BodyFactory.Instance.CreateCircleBody(physicsSimulator, item.radius, item.weight);
                item.geom = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, item.body, item.radius, 12);
                break;

            case PhysicsPolygonType.Rectangle:
                item.body = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, item.sideLengths.X, item.sideLengths.Y, item.weight);
                item.geom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, item.body, item.sideLengths.X, item.sideLengths.Y);
                break;

            case PhysicsPolygonType.Polygon:
                item.geom = PhysicsHelper.textureToGeom(physicsSimulator, texMan.getTex(item.name), item.weight);
                item.body = item.geom.Body;
                break;
            }
            if (item.immovable)
            {
                item.body.IsStatic = item.immovable;
            }
            item.geom.FrictionCoefficient = .6f;
            #region Collision Categories
            item.geom.CollisionCategories = CollisionCategory.None;
            for (int depth = (int)item.startdepth; depth < item.width + item.startdepth; depth++)
            {
                item.geom.CollisionCategories |= (CollisionCategory)PhysicsHelper.depthToCollisionCategory(depth);
            }
            item.geom.CollidesWith = item.geom.CollisionCategories;
            #endregion
            item.body.Position = item.loc;
            item.body.Rotation = item.rotation;
            activeItems.Add(item.guid, item);
            if (network.isServer())
            {
                network.sendFullObjectsUpdate();
            }
        }