예제 #1
0
 /// <summary>
 /// Creates a new Level 9.
 /// </summary>
 /// <param name="boxesMax">Max boxes allowed.</param>
 /// <param name="boxNeed">Boxes needed.</param>
 /// <param name="spawnPoint">Spawn point.</param>
 /// <param name="billboardsThisLevel">List of billboards.</param>
 /// <param name="levelTheme">Theme of the level.</param>
 /// <param name="levelModel">Base terrain of the level.</param>
 /// <param name="glassModels">Array of glass models.</param>
 /// <param name="normalCatcher">Goal.</param>
 /// <param name="machines">List of machines.</param>
 /// <param name="tubes">List of tubes.</param>
 /// <param name="data">LevelCompletionData.</param>
 /// <param name="name">Name of the level.</param>
 public Level9(int boxesMax, int boxNeed, Vector3 spawnPoint, List<Vector3> billboardsThisLevel,
     BaseModel levelModel, BaseModel[] glassModels, Goal normalCatcher, Goal coloredCatcher,
     Dictionary<OperationalMachine, bool> machines, List<Tube> tubes, LevelCompletionData data, string name)
     : base(9, boxesMax, boxNeed, spawnPoint, billboardsThisLevel, Theme.Beach, levelModel, glassModels, normalCatcher, coloredCatcher,
     machines, tubes, data, name)
 {
 }
예제 #2
0
        public Level10(int boxesMax, int boxNeed, Vector3 spawnPoint, List<Vector3> billboardList,
            Theme levelTheme, BaseModel levelModel, BaseModel levelModelTwo, BaseModel[] glassModels, Goal catcher,
            Dictionary<OperationalMachine, bool> machines, List<Tube> tubes, LevelCompletionData data, string name)
            : base(10, boxesMax, boxNeed, spawnPoint, billboardList, levelTheme, levelModel, glassModels,
            catcher, null, machines, tubes, data, name)
        {
            currentCameraPoint = RenderingDevice.Camera.Position;

            boxesMaxOne = boxesMax;
            boxesNeedOne = boxNeed;
            boxesMaxTwo = 20;
            boxesNeedTwo = 10;

            spawnTheFirst = spawnPoint;
            spawnTheSecond = new Vector3(197.153f, -4.134f, 1.5f);

            catcherTheFirst = normalCatcher;
            catcherTheSecond = new Goal(new Vector3(313.454f, -3.801f, 5.5f), true);

            baseTheSecond = levelModelTwo;

            Vector3 pos = new Vector3(198.273f, -4.468f, 6.037f);
            ADVertexFormat[] verts = new ADVertexFormat[4];
            verts[0] = new ADVertexFormat(new Vector3(0, 13.686f / 2, -11.359f / 2) + pos, new Vector2(0, 0), Vector3.UnitX);
            verts[1] = new ADVertexFormat(new Vector3(0, -13.686f / 2, -11.359f / 2) + pos, new Vector2(0, 1), Vector3.UnitX);
            verts[2] = new ADVertexFormat(new Vector3(0, 13.686f / 2, 11.359f / 2) + pos, new Vector2(1, 1), Vector3.UnitX);
            verts[3] = new ADVertexFormat(new Vector3(0, -13.686f / 2, 11.359f / 2) + pos, new Vector2(1, 0), Vector3.UnitX);

            buff = new VertexBuffer(RenderingDevice.GraphicsDevice, ADVertexFormat.VertexDeclaration, 4, BufferUsage.WriteOnly);
            buff.SetData(verts);

            blackTex = new Texture2D(RenderingDevice.GraphicsDevice, 1, 1);
            blackTex.SetData(new Color[] { new Color(0, 0, 0, 255) });
        }
예제 #3
0
 /// <summary>
 /// Creates a new Ice level.
 /// </summary>
 /// <param name="boxesMax">Max boxes allowed.</param>
 /// <param name="boxNeed">Boxes needed.</param>
 /// <param name="spawnPoint">Spawn point.</param>
 /// <param name="billboardsThisLevel">List of billboards.</param>
 /// <param name="levelTheme">Theme of the level.</param>
 /// <param name="levelModel">Base terrain of the level.</param>
 /// <param name="glassModels">Array of glass models.</param>
 /// <param name="normalCatcher">Goal.</param>
 /// <param name="machines">List of machines.</param>
 /// <param name="tubes">List of tubes.</param>
 /// <param name="data">LevelCompletionData.</param>
 /// <param name="name">Name of the level.</param>
 public IceLevel(int level, int boxesMax, int boxNeed, Vector3 spawnPoint, List<Vector3> billboardsThisLevel,
     BaseModel levelModel, BaseModel extras, BaseModel[] glassModels, Goal normalCatcher,
     Dictionary<OperationalMachine, bool> machines, List<Tube> tubes, LevelCompletionData data, string name)
     : base(level, boxesMax, boxNeed, spawnPoint, billboardsThisLevel, Theme.Ice, levelModel, glassModels, normalCatcher,
     null, machines, tubes, data, name)
 {
     this.extras = extras;
 }
예제 #4
0
 /// <summary>
 /// Creates a new Level 6.
 /// </summary>
 /// <param name="boxesMax">Max boxes allowed.</param>
 /// <param name="boxNeed">Boxes needed.</param>
 /// <param name="spawnPoint">Spawn point.</param>
 /// <param name="billboardsThisLevel">List of billboards.</param>
 /// <param name="levelTheme">Theme of the level.</param>
 /// <param name="levelModel">Base terrain of the level.</param>
 /// <param name="glassModels">Array of glass models.</param>
 /// <param name="normalCatcher">Goal.</param>
 /// <param name="machines">List of machines.</param>
 /// <param name="tubes">List of tubes.</param>
 /// <param name="data">LevelCompletionData.</param>
 /// <param name="name">Name of the level.</param>
 /// <param name="plane">Tacos.</param>
 public Level6(int boxesMax, int boxNeed, Vector3 spawnPoint, List<Vector3> billboardsThisLevel,
     BaseModel levelModel, BaseModel extras, BaseModel[] glassModels, Goal normalCatcher,
     Dictionary<OperationalMachine, bool> machines, List<Tube> tubes, LevelCompletionData data, string name, BaseModel plane)
     : base(6, boxesMax, boxNeed, spawnPoint, billboardsThisLevel, levelModel, extras, glassModels, normalCatcher,
     machines, tubes, data, name)
 {
     invisiblePlane = plane;
     //spawnBlackBox = true;
 }
예제 #5
0
        public Button(Vector3 translationAxis, BaseModel button)
        {
            Model = button;
            this.translationAxis = translationAxis;

            joint = new PrismaticJoint(null, button.Ent, button.Ent.Position, translationAxis, button.Ent.Position);
            joint.Motor.IsActive = true;
            joint.Motor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
            joint.Motor.Settings.Servo.BaseCorrectiveSpeed = joint.Motor.Settings.Servo.MaxCorrectiveVelocity = 1.5f;
            joint.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            joint.Motor.Settings.Servo.SpringSettings.DampingConstant /= 12;
            joint.Limit.Minimum = -0.7f;
            joint.Limit.Maximum = 0;
        }
예제 #6
0
        //, FluidVolume fluid)
        protected Theme(Effect shader, Model planeModel, Color textColor, Color titleColor, Texture2D shaderTex, BaseModel outer, BaseModel skybox)
        {
            RemovalHeight = -9f;
            this.planeModel = planeModel;
            //internalFluid = fluid;
            shaderTexture = shaderTex;
            internalTextColor = textColor;
            LevelTitleColor = titleColor;
            internalShader = shader;
            OuterModel = outer;
            SkyBox = skybox;

            setUpModel();
        }
예제 #7
0
        /// <summary>
        /// Creates a new Machine. Machines contain any number of supporting immobile pieces and any number of machines that
        /// would be considered associated with one "machine."
        /// </summary>
        /// <param name="models">All of these are expected to be kinetic. This is enforced.</param>
        /// <param name="machines">All of these are expected to have the same MachineNumber. This is enforced.</param>
        public Machine(BaseModel[] models, params OperationalMachine[] machines)
        {
            this.models = models;
            this.machines = machines;

            foreach(BaseModel m in models)
                if(m.Ent.IsDynamic)
                    throw new ArgumentException("Can't have dynamic BaseModels in a Machine.");

            if(machines.Length == 0)
                throw new ArgumentException("Can't have no machines, use a BeltPiece for that.");

            int machineNumber = -1;
            foreach(OperationalMachine o in machines)
                if(machineNumber == -1)
                    machineNumber = o.MachineNumber;
                else if(machineNumber != o.MachineNumber)
                    throw new ArgumentException("Can't have OperationalMachines with different numbers in a Machine.");
        }
        private static void drawSingleModel(BaseModel model, List<Texture2D> textures, string tech, Plane? clipPlane, Matrix view, float? customAlpha)
        {
            if(model.IsInvisible)
                return;
            Matrix[] transforms = new Matrix[model.Model.Bones.Count];
            Matrix entityWorld = Matrix.Identity;
            if(!model.IsTerrain)
                entityWorld = model.Ent.CollisionInformation.WorldTransform.Matrix;
            model.Model.CopyAbsoluteBoneTransformsTo(transforms);
            int i = 0;
            foreach(ModelMesh mesh in model.Model.Meshes)
            {
                foreach(Effect currentEffect in mesh.Effects)
                {
                    currentEffect.CurrentTechnique = currentEffect.Techniques[tech];

                    if(textures != null)
                        currentEffect.Parameters["Texture"].SetValue(textures[i++]);

                    currentEffect.Parameters["xCamerasViewProjection"].SetValue(view * Camera.Projection);
                    currentEffect.Parameters["xLightsViewProjection"].SetValue(lights.ViewProjection);
                    currentEffect.Parameters["xWorld"].SetValue(transforms[mesh.ParentBone.Index] * model.Transform * entityWorld * Camera.World);
                    currentEffect.Parameters["xLightPos"].SetValue(lights.LightPosition);
                    currentEffect.Parameters["xLightPower"].SetValue(lights.LightPower);
                    currentEffect.Parameters["xAmbient"].SetValue(lights.AmbientPower);
                    currentEffect.Parameters["xLightDir"].SetValue(lights.LightDirection);

                    if(clipPlane.HasValue)
                    {
                        currentEffect.Parameters["xEnableClipping"].SetValue(true);
                        currentEffect.Parameters["xClipPlane"].SetValue(new Vector4(clipPlane.Value.Normal, clipPlane.Value.D));
                    }
                    else
                        currentEffect.Parameters["xEnableClipping"].SetValue(false);

                    if(customAlpha.HasValue)
                    {
                        currentEffect.Parameters["xEnableCustomAlpha"].SetValue(true);
                        currentEffect.Parameters["xCustomAlpha"].SetValue(customAlpha.Value);
                    }
                    else
                        currentEffect.Parameters["xEnableCustomAlpha"].SetValue(false);
                }
                mesh.Draw();
            }
        }
        protected void CalculateVelocity(BaseModel m)
        {
            Vector3 distance;

            if(atOrigin)
                distance = targetPosition;
            else
                distance = -targetPosition;

            m.Ent.LinearVelocity = distance / timeStep;
        }
 public ModelData(BaseModel m, List<Texture2D> textures)
 {
     if(textures.Count == 0)
         throw new ArgumentException("Can't create a ModelData without any textures.");
     isActive = true;
     this.textures = new List<Texture2D>(textures);
     Model = m;
 }
        public static void Add(BaseModel m)
        {
            try
            {
                if(m == null || m.Model == null)
                {
                    Cutter.WriteToLog(d, "Warning: Add(m) was called with a null parameter. Ensure this is correct behavior.");
                    return;
                }
                if(m.IsInvisible)
                    return;

                //if(m.UsesLaserSound)
                //{
                //    m.AddToRenderer();
                //    return;
                //}

                if(!m.RenderAsGlass)
                {
                    foreach(ModelData d in texturedModels)
                        if(d == m)
                        {
                            d.MakeActive();
                            return;
                        }
                    //if(untexturedModels.ContainsKey(m))
                    //{
                    //    untexturedModels[m] = true;
                    //    return;
                    //}
                }
                else
                    foreach(ModelData d in glassModels)
                        if(d == m)
                        {
                            d.MakeActive();
                            return;
                        }

                List<Texture2D> list;
                BasicEffect currentEffect;

                list = new List<Texture2D>();
                foreach(ModelMesh mesh in m.Model.Meshes)
                {
                    bool alreadyConverted = false;
                    for(int i = 0; i < mesh.Effects.Count; i++)
                    {
                        currentEffect = mesh.Effects[i] as BasicEffect;
                        EffectParameter e;
                        if(currentEffect != null)
                            list.Add(currentEffect.Texture);
                        else if((e = mesh.Effects[i].Parameters.FirstOrDefault(v => { return v.Name == "Texture"; })) != null)
                        {
                            list.Add(e.GetValueTexture2D());
                            alreadyConverted = true;
                        }
                        else
                        {
                            if(masterDict.ContainsKey(m.Model))
                                list.AddRange(masterDict[m.Model]);
                            alreadyConverted = true;
                            break;
                        }
                    }

                    if(!masterDict.ContainsKey(m.Model))
                        masterDict.Add(m.Model, list);
                    if(!alreadyConverted)
                    {
                        foreach(ModelMeshPart meshPart in mesh.MeshParts)
                            meshPart.Effect = lights.Shader.Clone();
                    }
                }

                if((list.Count == 0) || (list.Count > 0 && list[0] == null))
                    throw new ArgumentException("Models that are textureless can't be added to the renderer. Offending model name: " + m.Model.Meshes[0].Name);
                else if(m.RenderAsGlass)
                    glassModels.Add(new ModelData(m, list));
                else
                    texturedModels.Add(new ModelData(m, list));
            }
            catch(OutOfMemoryException)
            {
                //foreach(BaseModel b in untexturedModels.Keys)
                //    if(!untexturedModels[b])
                //        untexturedModels.Remove(b);
                for(int i = 0; i < texturedModels.Count; i++)
                    if(!texturedModels[i].IsActive)
                        texturedModels.RemoveAt(i);
                for(int i = 0; i < primitives.Count; i++)
                    if(!primitives[i].IsActive)
                        primitives.RemoveAt(i);
                for(int i = 0; i < glassModels.Count; i++)
                    if(!glassModels[i].IsActive)
                        glassModels.RemoveAt(i);
                for(int i = 0; i < shaderModels.Count; i++)
                    if(!shaderModels[i].IsActive)
                        shaderModels.RemoveAt(i);
                GC.Collect(); // force a collection of released objects
            }
        }
        public TruckMachine(int machineNo, int soundIndex, float translationTime, float rotationTime, float angle,
            Vector3 translationAxis, Vector3 glassRotationAxis, Vector3 wheelRotationAxis,
            Vector3 glassZeroAxis, Vector3 glassCenter1, Vector3 glassCenter2, Vector3 wheelsCenter1,
            Vector3 wheelsCenter2, BaseModel wheels1, BaseModel wheels2, BaseModel glass1,
            BaseModel glass2, params BaseModel[] models)
            : base(machineNo, soundIndex, models.Concat(new BaseModel[] { wheels1, wheels2, glass1, glass2 }).ToArray<BaseModel>())
        {
            translation = translationAxis;
            this.translationTime = translationTime;
            this.rotationTime = rotationTime;

            originalGlassAxis = glassRotationAxis;
            originalWheelAxis = wheelRotationAxis;
            unitsToTranslate = translationAxis;

            baseJoint = new PrismaticJoint(null, models[0].Ent, models[0].Ent.Position, translationAxis, models[0].Ent.Position);
            baseJoint.Motor.IsActive = true;
            baseJoint.Motor.Settings.Mode = MotorMode.Servomechanism;
            baseJoint.Motor.Settings.Servo.Goal = 0;
            baseJoint.Limit.Maximum = translationAxis.Length();
            baseJoint.Limit.Minimum = 0;
            baseJoint.Limit.IsActive = true;
            baseJoint.Motor.Settings.Servo.BaseCorrectiveSpeed = translationAxis.Length() / translationTime;
            baseJoint.Motor.Settings.Servo.MaxCorrectiveVelocity = translationAxis.Length() / translationTime;
            baseJoint.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            baseJoint.Motor.Settings.Servo.SpringSettings.DampingConstant /= 11;

            glassJoint1 = new RevoluteJoint(models[0].Ent, glass1.Ent, glassCenter1, glassRotationAxis);
            glassJoint1.Motor.IsActive = true;
            glassJoint1.Motor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
            glassJoint1.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            glassJoint1.Motor.Settings.Servo.SpringSettings.DampingConstant /= 12;
            glassJoint1.Motor.Settings.Servo.Goal = 0;
            glassJoint1.Motor.Settings.Servo.MaxCorrectiveVelocity = angle / rotationTime;
            glassJoint1.Motor.Settings.Servo.BaseCorrectiveSpeed = angle / rotationTime;
            glassJoint1.Motor.Basis.SetWorldAxes(glassRotationAxis, glassZeroAxis);
            glassJoint1.Motor.TestAxis = glassZeroAxis;
            glassJoint1.Limit.IsActive = true;
            glassJoint1.Limit.MinimumAngle = 0;
            glassJoint1.Limit.MaximumAngle = angle;
            glassJoint1.Limit.Basis.SetWorldAxes(glassRotationAxis, glassZeroAxis);
            glassJoint1.Limit.TestAxis = glassZeroAxis;

            glassJoint2 = new RevoluteJoint(models[0].Ent, glass2.Ent, glassCenter2, -glassRotationAxis);
            glassJoint2.Motor.IsActive = true;
            glassJoint2.Motor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
            glassJoint2.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            glassJoint2.Motor.Settings.Servo.SpringSettings.DampingConstant /= 12;
            glassJoint2.Motor.Settings.Servo.Goal = 0;
            glassJoint2.Motor.Settings.Servo.MaxCorrectiveVelocity = angle / rotationTime;
            glassJoint2.Motor.Settings.Servo.BaseCorrectiveSpeed = angle / rotationTime;
            glassJoint2.Motor.Basis.SetWorldAxes(-glassRotationAxis, glassZeroAxis);
            glassJoint2.Motor.TestAxis = glassZeroAxis;
            glassJoint2.Limit.IsActive = true;
            glassJoint2.Limit.MinimumAngle = 0;
            glassJoint2.Limit.MaximumAngle = angle;
            glassJoint2.Limit.Basis.SetWorldAxes(-glassRotationAxis, glassZeroAxis);
            glassJoint2.Limit.TestAxis = glassZeroAxis;

            wheelsJoint1 = new RevoluteJoint(models[0].Ent, wheels1.Ent, wheelsCenter1, wheelRotationAxis);
            wheelsJoint1.Motor.Settings.Mode = MotorMode.VelocityMotor;
            wheelsJoint1.Motor.Settings.VelocityMotor.GoalVelocity = 0f;
            wheelsJoint1.Motor.Settings.VelocityMotor.Softness = 1 / glassJoint1.Motor.Settings.Servo.SpringSettings.DampingConstant;
            wheelsJoint2 = new RevoluteJoint(models[0].Ent, wheels2.Ent, wheelsCenter2, wheelRotationAxis);
            wheelsJoint2.Motor.Settings.Mode = MotorMode.VelocityMotor;
            wheelsJoint2.Motor.Settings.VelocityMotor.GoalVelocity = 0f;
            wheelsJoint2.Motor.Settings.VelocityMotor.Softness = 1 / glassJoint2.Motor.Settings.Servo.SpringSettings.DampingConstant;

            if(models.Length > 1)
                foreach(BaseModel m in models)
                {
                    if(m == models[0])
                        continue;
                    WeldJoint j = new WeldJoint(models[0].Ent, m.Ent);
                    j.IsActive = true;
                    joints.Add(j);
                }
        }
        public static void Add(BaseModel m, List<Texture2D> textures)
        {
            try
            {
                if(m == null || textures == null || m.Model == null)// || textures.Count == 0)
                {
                    Cutter.WriteToLog(d, "Warning: Add(m, textures) was called with a null parameter. Ensure this is correct behavior.");
                    return;
                }
                if(m.IsInvisible)
                    return;

                foreach(ModelData d in texturedModels)
                    if(d == m)
                    {
                        d.MakeActive();
                        return;
                    }
                texturedModels.Add(new ModelData(m, textures));
            }
            catch(OutOfMemoryException)
            {
                //foreach(BaseModel b in untexturedModels.Keys)
                //    if(!untexturedModels[b])
                //        untexturedModels.Remove(b);
                for(int i = 0; i < texturedModels.Count; i++)
                    if(!texturedModels[i].IsActive)
                        texturedModels.RemoveAt(i);
                for(int i = 0; i < primitives.Count; i++)
                    if(!primitives[i].IsActive)
                        primitives.RemoveAt(i);
                for(int i = 0; i < glassModels.Count; i++)
                    if(!glassModels[i].IsActive)
                        glassModels.RemoveAt(i);
                for(int i = 0; i < shaderModels.Count; i++)
                    if(!shaderModels[i].IsActive)
                        shaderModels.RemoveAt(i);
                GC.Collect();
            }
        }
예제 #14
0
        /// <summary>
        /// Create a new level.
        /// </summary>
        /// <param name="levelNo">The level number.</param>
        /// <param name="boxesMax">The number of boxes the level will give you.</param>
        /// <param name="boxNeed">The amount of boxes you need to win.</param>
        /// <param name="spawnPoint">The Vector3 to spawn boxes at.</param>
        /// <param name="levelTheme">The theme to use.</param>
        /// <param name="glassModels">The array of glass models to use.</param>
        /// <param name="billboardsThisLevel">A list of Vector3's that determine the location
        /// of this level's machine's billboards.</param>
        /// <param name="levelModel">A model of the level's static parts (machine bases and such).</param>
        /// <param name="machines">A list of machines in this level.</param>
        /// <param name="coloredCatcher">If the level has a colored catcher, this is it.</param>
        /// <param name="normalCatcher">The level's Catcher.</param>
        /// <param name="tubes">All the tubes. Lots... and lots... of tubes.</param>
        /// <param name="data">Data detailing the elite requirements of complete completion.</param>
        /// <param name="name">Level's name.</param>
        public Level(int levelNo, int boxesMax, int boxNeed, Vector3 spawnPoint, List<Vector3> billboardsThisLevel,
            Theme levelTheme, BaseModel levelModel, BaseModel[] glassModels, Goal normalCatcher, Goal coloredCatcher,
            Dictionary<OperationalMachine, bool> machines, List<Tube> tubes, LevelCompletionData data, string name)
        {
            levelNumber = levelNo;
            this.levelTheme = levelTheme;
            scoreboard = new Scoreboard(levelTheme.TextColor, boxNeed, boxesMax, 16333);
            this.boxesMax = boxesMax;
            boxesSaved = 0;
            BoxesDestroyed = 0;
            BoxesRemaining = boxesMax;
            boxesNeeded = boxNeed;
            BoxSpawnPoint = spawnPoint;
            levelName = name;
            boxesOnscreen = new List<Box>();
            tubeList = new List<Tube>(tubes);
            MachineList = new Dictionary<OperationalMachine, bool>(machines);
            Board = new Billboard(effectDelegate);

            this.levelModel = levelModel;
            //LevelModel.Lighting = levelTheme.Lighting;
            this.glassModels = new List<BaseModel>();
            textureList = new Texture2D[billboardsThisLevel.Count];
            activeList = new Texture2D[billboardsThisLevel.Count];

            this.normalCatcher = normalCatcher;
            this.coloredCatcher = coloredCatcher;

            CompletionData = data;

            foreach(BaseModel m in glassModels)
                this.glassModels.Add(m);
            foreach(OperationalMachine mach in machines.Keys)
                foreach(BaseModel m in mach.GetGlassModels())
                    this.glassModels.Add(m);

            //foreach(Machine m in machines.Keys)
            //    m.ApplyLighting(levelTheme.Lighting);

            if(billboardsThisLevel.Count != 0)
                Board.CreateBillboardVerticesFromList(billboardsThisLevel);

            for(int i = 0; i < textureList.Length; i++)
            {
                textureList[i] = billboardList[i];
                activeList[i] = activeBillboardList[i];
            }

            dispenser = new BaseModel(Dispenser, false, null, BoxSpawnPoint);
            dispenser.Ent.BecomeKinematic();

            //if(levelNumber != 0)
            //    Program.Game.Manager.CurrentSave.LevelData.SetCompletionData(levelNumber, data);

            gdmReset += onGDMReset;
        }
        public static void RemovePermanent(BaseModel m)
        {
            if(m == null || m.Model == null)
                return;

            //if(untexturedModels.ContainsKey(m))
            //{
            //    untexturedModels.Remove(m);
            //    return;
            //}
            foreach(ModelData d in texturedModels)
                if(d == m)
                {
                    texturedModels.Remove(d);
                    return;
                }
            foreach(ModelData d in glassModels)
                if(d == m)
                {
                    glassModels.Remove(d);
                    return;
                }
        }
        public static void Remove(BaseModel m)
        {
            if(m == null || m.Model == null)
                return;

            //if(m.UsesLaserSound)
            //{
            //    m.RemoveFromRenderer();
            //    return;
            //}

            //if(untexturedModels.ContainsKey(m))
            //{
            //    untexturedModels[m] = false;
            //    return;
            //}
            foreach(ModelData d in texturedModels)
                if(d == m)
                {
                    d.MakeInactive();
                    return;
                }
            foreach(ModelData d in glassModels)
                if(d == m)
                {
                    d.MakeInactive();
                    return;
                }
        }
        public static bool Contains(BaseModel m)
        {
            if(m == null || m.Model == null)
                return false;

            foreach(ModelData model in texturedModels)
                if(model.Model == m)
                    return true;
            //foreach(KeyValuePair<BaseModel, bool> k in untexturedModels)
            //    if(k.Key == m)
            //        return true;
            return false;
        }
예제 #18
0
 /// <summary>
 /// Creates a new TrackPiece.
 /// </summary>
 /// <param name="model">The model that contains the specified tubes.</param>
 /// <param name="tubes">The tubes contained by the specified model.</param>
 public TrackPiece(BaseModel model, params Tube[] tubes)
 {
     Model = model;
     Tubes = tubes;
 }
        /// <summary>
        /// Makes a machine that automatically translates and user-rotates.
        /// </summary>
        /// <param name="machineNo">Machine number of the machine.</param>
        /// <param name="unitsToTranslate">The distance to translate from the origin.</param>
        /// <param name="pauseTime">The time in seconds to pause at each end.</param>
        /// <param name="centerOfRotation">The center of rotation based on the starting position.</param>
        /// <param name="rotateTime">Time to take to rotate.</param>
        /// <param name="degreesToRotate">The degrees on each axis to rotate.</param>
        /// <param name="models">The models that rotate.</param>
        /// <param name="angle">The angle to rotate.</param>
        /// <param name="rotationAxis">The axis to rotate on.</param>
        /// <param name="soundIndex">The sound to use for the machine.</param>
        /// <param name="stableModels">The models that don't rotate.</param>
        /// <param name="translationTime">The time to take to translate.</param>
        public RailMachine(int machineNo, int soundIndex, bool soundWhenMoves, Vector3 unitsToTranslate, float pauseTime, float translationTime,
            Vector3 centerOfRotation, float rotateTime, Vector3 rotationAxis, float angle, Vector3 zeroAxis, BaseModel[] stableModels,
            params BaseModel[] models)
            : base(machineNo, soundIndex, models)
        {
            if(stableModels.Length == 0)
                throw new ArgumentException("There must be at least one stable model.");
            if(models.Length == 0)
                throw new ArgumentException("There must be a least rotational model.");

            this.unitsToTranslate = unitsToTranslate;
            this.translationTime = translationTime;
            this.rotateTime = rotateTime;
            this.angle = angle;
            this.soundWhenMoves = soundWhenMoves;
            lengthToPause = pauseTime;
            originalAxis = rotationAxis;

            if(angle < 0)
            {
                negativeAngle = true;
                angle = -angle;
            }

            baseJoint = new PrismaticJoint(null, stableModels[0].Ent, stableModels[0].Ent.Position, Vector3.Normalize(unitsToTranslate), stableModels[0].Ent.Position);
            baseJoint.Motor.IsActive = true;
            baseJoint.Motor.Settings.Mode = MotorMode.Servomechanism;
            baseJoint.Motor.Settings.Servo.Goal = 0;
            baseJoint.Limit.Maximum = unitsToTranslate.Length();
            baseJoint.Limit.Minimum = 0;
            baseJoint.Limit.IsActive = true;
            baseJoint.Motor.Settings.Servo.BaseCorrectiveSpeed = unitsToTranslate.Length() / translationTime;
            baseJoint.Motor.Settings.Servo.MaxCorrectiveVelocity = unitsToTranslate.Length() / translationTime;
            baseJoint.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            baseJoint.Motor.Settings.Servo.SpringSettings.DampingConstant /= 2;

            rotateJoint = new RevoluteJoint(stableModels[0].Ent, models[0].Ent, centerOfRotation, rotationAxis);
            rotateJoint.Motor.IsActive = true;
            rotateJoint.Motor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
            rotateJoint.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            rotateJoint.Motor.Settings.Servo.SpringSettings.DampingConstant /= 4;
            rotateJoint.Motor.Settings.Servo.Goal = negativeAngle ? angle : 0;
            rotateJoint.Motor.Settings.Servo.MaxCorrectiveVelocity = angle / rotateTime;
            rotateJoint.Motor.Settings.Servo.BaseCorrectiveSpeed = angle / rotateTime;
            rotateJoint.Motor.Basis.SetWorldAxes(rotationAxis, zeroAxis);
            rotateJoint.Motor.TestAxis = zeroAxis;
            rotateJoint.Limit.IsActive = true;
            rotateJoint.Limit.MinimumAngle = 0;
            rotateJoint.Limit.MaximumAngle = angle;
            rotateJoint.Limit.Basis.SetWorldAxes(rotationAxis, zeroAxis);
            rotateJoint.Limit.TestAxis = zeroAxis;

            for(int i = 0; i < stableModels.Length - 1; i++)
            {
                WeldJoint j = new WeldJoint(stableModels[0].Ent, stableModels[i + 1].Ent);
                j.IsActive = true;
                welds.Add(j);
            }
            for(int i = 0; i < models.Length - 1; i++)
            {
                WeldJoint j = new WeldJoint(models[0].Ent, models[i + 1].Ent);
                j.IsActive = true;
                welds.Add(j);
            }
            foreach(Tube t in tubeList)
                t.SetParent(models[0].Ent);

            modelList.Clear();
            modelList.AddRange(stableModels);
            modelList.AddRange(models);

            //Vector3 radians = new Vector3(MathHelper.ToRadians(degreesToRotate.X),
            //    MathHelper.ToRadians(degreesToRotate.Y), MathHelper.ToRadians(degreesToRotate.Z));
            //radiansToRotate = Quaternion.CreateFromYawPitchRoll(radians.Y,
            //    radians.X, radians.Z);

            //for(int i = 1; i < modelList.Count; i++)
            //{
            //    BaseModel m = modelList[i];
            //    m.Ent.Orientation = Quaternion.Identity;
            //    m.Ent.CollisionInformation.LocalPosition = m.Ent.Position - centerOfRotation;
            //    m.Ent.Position = centerOfRotation;
            //    m.Ent.Orientation = m.OriginalOrientation; // Resets orientation
            //}
            //curve = new QuaternionSlerpCurve();
            //curve.ControlPoints.Add(0, Quaternion.Identity);
            //curve.ControlPoints.Add(rotateTime, radiansToRotate);
            //curve.PostLoop = CurveEndpointBehavior.Mirror;
            //curve.PreLoop = CurveEndpointBehavior.Mirror;
            timeStep = rotateTime * 1000;
        }