public SlideGauge(Vector2 itemPosition, float drawLayer, Texture2D gaugeTex, Texture2D handTex, MachineDependentParameter param, float extent, bool jitter = true, int jitterSpeed = 0, float reactionSpeed = 0.01f) { this.position = itemPosition; this.layer = drawLayer; this.tex = gaugeTex; this.handTex = handTex; this.rect.Width = tex.Width; this.rect.Height = tex.Height; this.handRect.Width = handTex.Width; this.handRect.Height = handTex.Height; this.extent = extent; this.handPosition = new Vector2(position.X + (rect.Width * (1.0f - extent)) / 2.0f + ((rect.Width * extent - handRect.Width) / (max - min)) * value, position.Y + (rect.Height - handRect.Height) / 2.0f); this.min = param.min; this.max = param.max; this.value = param.value; this.jitter = jitter; this.jitterSpeed = jitterSpeed; this.reaction = reactionSpeed; this.param = param; }
public Gauge(Vector2 itemPosition, float drawLayer, Texture2D gaugeTex, Texture2D handTex, MachineDependentParameter param, bool jitter = true, int jitterSpeed = 0, float reactionSpeed = 0.01f) { this.position = itemPosition; this.handPosition = position + new Vector2(100,100); this.layer = drawLayer; this.tex = gaugeTex; this.handTex = handTex; this.rect.Width = tex.Width; this.rect.Height = tex.Height; this.handRect.Width = handTex.Width; this.handRect.Height = handTex.Height; this.min = param.min; this.max = param.max; this.value = param.value; this.jitter = jitter; this.jitterSpeed = jitterSpeed; this.reaction = reactionSpeed; this.param = param; }
// === load things... ============== protected override void LoadContent() { //========== GRAPHICS ============================================== // set viewport to size of screen, dependant on fullscreen/windowed if (graphics.IsFullScreen == true) { GraphicsDevice.Viewport = new Viewport(0, 0, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height); } else { GraphicsDevice.Viewport = new Viewport(0, 0, Screen.PrimaryScreen.WorkingArea.Width - borderSpace, Screen.PrimaryScreen.WorkingArea.Height - SystemInformation.CaptionHeight - borderSpace); } // find maximum size of render field with 16:9 aspect ratio when full screen width = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width; height = (int)(width / aspectRatio); if (height > GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height) { height = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height; width = (int)(height * aspectRatio); } xScale = (float)((double)width / (double)targetWidth); yScale = (float)((double)height / (double)targetHeight); xOffset = (int)((GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width - width) / 2.0); yOffset = (int)((GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height - height) / 2.0); // find maximum size of render field with 16:9 aspect ratio when windowed wheight = Screen.PrimaryScreen.WorkingArea.Height - SystemInformation.CaptionHeight - borderSpace; wwidth = (int)(wheight * aspectRatio); if (wwidth > Screen.PrimaryScreen.WorkingArea.Width - borderSpace) { wwidth = Screen.PrimaryScreen.WorkingArea.Width - borderSpace; wheight = (int)(wwidth / aspectRatio); } wxScale = (float)((double)wwidth / (double)targetWidth); wyScale = (float)((double)wheight / (double)targetHeight); wxOffset = (int)((Screen.PrimaryScreen.WorkingArea.Width - borderSpace - wwidth) / 2.0); wyOffset = (int)((Screen.PrimaryScreen.WorkingArea.Height - SystemInformation.CaptionHeight - borderSpace - wheight) / 2.0); // set viewport to this maximum render size, dependent on fullscreen/windowed if (graphics.IsFullScreen == true) { GraphicsDevice.Viewport = new Viewport(xOffset, yOffset, width, height); } if (graphics.IsFullScreen == false) { GraphicsDevice.Viewport = new Viewport(wxOffset, wyOffset, wwidth, wheight); var form = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(this.Window.Handle); form.Location = new System.Drawing.Point(0, 0); } // spritebatch spriteBatch = new SpriteBatch(GraphicsDevice); // ========= GAME OBJECTS ================================================ // fonts cursorFont = Content.Load<SpriteFont>("font"); counterFont = Content.Load<SpriteFont>("font2"); // grid grid = new Grid(3600, 1750, 450, 20, 20, new Vector2(-850, 1070), true); reachable = new ReachableArea(grid, floorObjectList,graphics); // counters research = new NumericalCounter("Research", new Vector2(25, 15), 0, 500, 0, 0, counterFont, Color.Green, Color.Green, Content.Load<Texture2D>("counter_box")); madness = new NumericalCounter("Madness", new Vector2(25, 85), 0, 0, 0, 0, counterFont, Color.Red, Color.Green, Content.Load<Texture2D>("counter_box")); money = new NumericalCounter("Money", new Vector2(25, 155), 0, 1000, 0, 60, counterFont, Color.Orange, Color.Yellow, Content.Load<Texture2D>("counter_box"), true); papers = new NumericalCounter("Papers Published", new Vector2(10, 300), 0, 0, 0, 0, cursorFont, Color.Black, Color.Black); lifeForce = new NumericalCounter("Life Force", new Vector2(10, 320), 100, 0, 0, 0, cursorFont, Color.Black, Color.Black); longevity = new NumericalCounter("Longevity", new Vector2(10, 340), 100, 0, 0, 0, cursorFont, Color.Black, Color.Black); humanity = new NumericalCounter("Humanity", new Vector2(10, 360), 100, 0, 0, 0, cursorFont, Color.Black, Color.Black); counters = new List<NumericalCounter>{research,madness,money,papers,lifeForce,longevity,humanity}; build = new Build(new Vector2(5, 900), Content.Load<Texture2D>("build_icon_standard"), Content.Load<Texture2D>("build_icon_highlight"), Content.Load<Texture2D>("build_icon_pressed"), Content.Load<Texture2D>("invarrow"), Content.Load<Texture2D>("highinvarrow"), GraphicsDevice); //===================================================== testAction = new MenuAction("test", true, false, 2, 2, null, 2, null, 2, null, 2, null, 2, null, 2, null, true, false, false); // load menu actions from XML System.IO.Stream stream = TitleContainer.OpenStream("XMLActions.xml"); XDocument doc = XDocument.Load(stream); menuActions = (from action in doc.Descendants("menuAction") select new MenuAction(action.Element("name").Value, Convert.ToBoolean(action.Element("scientist").Value), Convert.ToBoolean(action.Element("assistant").Value), Convert.ToInt32(action.Element("time").Value), (float)Convert.ToDouble(action.Element("researchUp").Value), new List<Tuple<NumericalCounter, int>> { }, (float)Convert.ToDouble(action.Element("madnessUp").Value), new List<Tuple<NumericalCounter, int>> { }, (float)Convert.ToDouble(action.Element("moneyChange").Value), new List<Tuple<NumericalCounter, int>> { }, (float)Convert.ToDouble(action.Element("lifeForceUp").Value), new List<Tuple<NumericalCounter, int>> { }, (float)Convert.ToDouble(action.Element("longevityUp").Value), new List<Tuple<NumericalCounter, int>> { }, (float)Convert.ToDouble(action.Element("humanityUp").Value), new List<Tuple<NumericalCounter, int>> { }, Convert.ToBoolean(action.Element("remain").Value), Convert.ToBoolean(action.Element("turnOn").Value), Convert.ToBoolean(action.Element("turnOff").Value))).ToList(); ////new List<Tuple<NumericalCounter, int>> { // //new Tuple<NumericalCounter, int>(null, Convert.ToInt16(action.Element("researchPower").Value)), // //new Tuple<NumericalCounter, int>(null, Convert.ToInt16(action.Element("researchPower2").Value)) }, ////new List<Tuple<NumericalCounter, int>> { // // new Tuple<NumericalCounter, int>(null, Convert.ToInt16(action.Element("madnessPower").Value)), // //new Tuple<NumericalCounter, int>(null, Convert.ToInt16(action.Element("madnessPower2").Value)) }, ////new List<Tuple<NumericalCounter, int>> { //// new Tuple<NumericalCounter, int>(null, Convert.ToInt16(action.Element("moneyPower").Value)), //// new Tuple<NumericalCounter, int>(null, Convert.ToInt16(action.Element("moneyPower2").Value)) }, ////new List<Tuple<NumericalCounter, int>> { //// new Tuple<NumericalCounter, int>(null, Convert.ToInt16(action.Element("lifeForcePower").Value)), //// new Tuple<NumericalCounter, int>(null, Convert.ToInt16(action.Element("lifeForcePower2").Value)) }, ////new List<Tuple<NumericalCounter, int>> { //// new Tuple<NumericalCounter, int>(null, Convert.ToInt16(action.Element("longevityPower").Value)), //// new Tuple<NumericalCounter, int>(null, Convert.ToInt16(action.Element("longevityPower2").Value)) }, ////new List<Tuple<NumericalCounter, int>> { //// new Tuple<NumericalCounter, int>(null, Convert.ToInt16(action.Element("humanityPower").Value)), //// new Tuple<NumericalCounter, int>(null, Convert.ToInt16(action.Element("humanityPower2").Value)) }, // dependant actions studyLiveCorpse = menuActions[6]; writePaper = menuActions[9]; // independent actions studyCorpse = menuActions[2]; dissectCorpse = menuActions[3]; clearCorpse = menuActions[4]; talk = menuActions[7]; // load in multiplying counters List<Tuple<string,int,string,int>> researchMs = new List<Tuple<string,int,string,int>>{}; List<Tuple<string,int,string,int>> madnessMs = new List<Tuple<string,int,string,int>>{}; List<Tuple<string,int,string,int>> moneyMs = new List<Tuple<string,int,string,int>>{}; List<Tuple<string,int,string,int>> lifeForceMs = new List<Tuple<string,int,string,int>>{}; List<Tuple<string,int,string,int>> longevityMs = new List<Tuple<string,int,string,int>>{}; List<Tuple<string,int,string,int>> humanityMs = new List<Tuple<string,int,string,int>>{}; foreach (MenuAction menuaction in menuActions) { researchMs = (from action in doc.Descendants("menuAction") select new Tuple<string, int, string, int>( Convert.ToString(action.Element("researchMultiplier").Value), (int)Convert.ToDouble(action.Element("researchPower").Value), Convert.ToString(action.Element("researchMultiplier2").Value), (int)Convert.ToDouble(action.Element("researchPower2").Value))).ToList(); madnessMs = (from action in doc.Descendants("menuAction") select new Tuple<string, int, string, int>( Convert.ToString(action.Element("madnessMultiplier").Value), (int)Convert.ToDouble(action.Element("madnessPower").Value), Convert.ToString(action.Element("madnessMultiplier2").Value), (int)Convert.ToDouble(action.Element("madnessPower2").Value))).ToList(); moneyMs = (from action in doc.Descendants("menuAction") select new Tuple<string, int, string, int>( Convert.ToString(action.Element("moneyMultiplier").Value), (int)Convert.ToDouble(action.Element("moneyPower").Value), Convert.ToString(action.Element("moneyMultiplier2").Value), (int)Convert.ToDouble(action.Element("moneyPower2").Value))).ToList(); lifeForceMs = (from action in doc.Descendants("menuAction") select new Tuple<string, int, string, int>( Convert.ToString(action.Element("lifeForceMultiplier").Value), (int)Convert.ToDouble(action.Element("lifeForcePower").Value), Convert.ToString(action.Element("lifeForceMultiplier2").Value), (int)Convert.ToDouble(action.Element("lifeForcePower2").Value))).ToList(); longevityMs = (from action in doc.Descendants("menuAction") select new Tuple<string, int, string, int>( Convert.ToString(action.Element("longevityMultiplier").Value), (int)Convert.ToDouble(action.Element("longevityPower").Value), Convert.ToString(action.Element("longevityMultiplier2").Value), (int)Convert.ToDouble(action.Element("longevityPower2").Value))).ToList(); humanityMs = (from action in doc.Descendants("menuAction") select new Tuple<string, int, string, int>( Convert.ToString(action.Element("humanityMultiplier").Value), (int)Convert.ToDouble(action.Element("humanityPower").Value), Convert.ToString(action.Element("humanityMultiplier2").Value), (int)Convert.ToDouble(action.Element("humanityPower2").Value))).ToList(); } int index = 0; foreach (MenuAction action in menuActions) { // research List<Tuple<NumericalCounter, int>> researchM; if (researchMs[index].Item1 != "none") { researchM = new List<Tuple<NumericalCounter, int>> { }; foreach (NumericalCounter counter in counters) { if (counter.name == researchMs[index].Item1) { researchM.Add(new Tuple<NumericalCounter, int>(counter, researchMs[index].Item2)); } else if (counter.name == researchMs[index].Item3) { researchM.Add(new Tuple<NumericalCounter, int>(counter, researchMs[index].Item4)); } } } else { researchM = new List<Tuple<NumericalCounter, int>> {new Tuple<NumericalCounter,int>(null,0) }; } // madness List<Tuple<NumericalCounter, int>> madnessM; if (madnessMs[index].Item1 != "none") { madnessM = new List<Tuple<NumericalCounter, int>> { }; foreach (NumericalCounter counter in counters) { if (counter.name == madnessMs[index].Item1) { madnessM.Add(new Tuple<NumericalCounter, int>(counter, madnessMs[index].Item2)); } else if (counter.name == researchMs[index].Item3) { madnessM.Add(new Tuple<NumericalCounter, int>(counter, madnessMs[index].Item4)); } } } else { madnessM = new List<Tuple<NumericalCounter, int>> { new Tuple<NumericalCounter, int>(null, 0) }; } // money List<Tuple<NumericalCounter, int>> moneyM; if (moneyMs[index].Item1 != "none") { moneyM = new List<Tuple<NumericalCounter, int>> { }; foreach (NumericalCounter counter in counters) { if (counter.name == moneyMs[index].Item1) { moneyM.Add(new Tuple<NumericalCounter, int>(counter, moneyMs[index].Item2)); } else if (counter.name == moneyMs[index].Item3) { moneyM.Add(new Tuple<NumericalCounter, int>(counter, moneyMs[index].Item4)); } } } else { moneyM = new List<Tuple<NumericalCounter, int>> { new Tuple<NumericalCounter, int>(null, 0) }; } // lifeforce List<Tuple<NumericalCounter, int>> lifeForceM; if (lifeForceMs[index].Item1 != "none") { lifeForceM = new List<Tuple<NumericalCounter, int>> { }; foreach (NumericalCounter counter in counters) { if (counter.name == lifeForceMs[index].Item1) { lifeForceM.Add(new Tuple<NumericalCounter, int>(counter, lifeForceMs[index].Item2)); } else if (counter.name == lifeForceMs[index].Item3) { lifeForceM.Add(new Tuple<NumericalCounter, int>(counter, lifeForceMs[index].Item4)); } } } else { lifeForceM = new List<Tuple<NumericalCounter, int>> { new Tuple<NumericalCounter, int>(null, 0) }; } // longevity List<Tuple<NumericalCounter, int>> longevityM; if (longevityMs[index].Item1 != "none") { longevityM = new List<Tuple<NumericalCounter, int>> { }; foreach (NumericalCounter counter in counters) { if (counter.name == longevityMs[index].Item1) { longevityM.Add(new Tuple<NumericalCounter, int>(counter, longevityMs[index].Item2)); } else if (counter.name == longevityMs[index].Item3) { longevityM.Add(new Tuple<NumericalCounter, int>(counter, longevityMs[index].Item4)); } } } else { longevityM = new List<Tuple<NumericalCounter, int>> { new Tuple<NumericalCounter, int>(null, 0) }; } // humanity List<Tuple<NumericalCounter, int>> humanityM; if (humanityMs[index].Item1 != "none") { humanityM = new List<Tuple<NumericalCounter, int>> { }; foreach (NumericalCounter counter in counters) { if (counter.name == humanityMs[index].Item1) { humanityM.Add(new Tuple<NumericalCounter, int>(counter, humanityMs[index].Item2)); } else if (counter.name == humanityMs[index].Item3) { humanityM.Add(new Tuple<NumericalCounter, int>(counter, humanityMs[index].Item4)); } } } else { humanityM = new List<Tuple<NumericalCounter, int>> { new Tuple<NumericalCounter, int>(null, 0) }; } action.multipliers = new List<List<Tuple<NumericalCounter, int>>> { researchM, madnessM, moneyM, lifeForceM, longevityM, humanityM }; } // load floor objects from XML System.IO.Stream stream2 = TitleContainer.OpenStream("XMLFloorObjects.xml"); XDocument doc2 = XDocument.Load(stream2); build.buildList = (from floorObject in doc2.Descendants("FloorObject") select new FloorObject(Content.Load<Texture2D>( Convert.ToString(floorObject.Element("texture").Value)), Content.Load<Texture2D>(Convert.ToString(floorObject.Element("icon").Value)), Convert.ToInt32(floorObject.Element("frameNumber").Value), Convert.ToInt32(floorObject.Element("animNumber").Value), new Vector2(Convert.ToInt32(floorObject.Element("gridPositionX").Value),Convert.ToInt32(floorObject.Element("gridPositionY").Value)), new Vector2(Convert.ToInt32(floorObject.Element("offsetX").Value), Convert.ToInt32(floorObject.Element("offsetY").Value)), new Vector2(Convert.ToInt32(floorObject.Element("operationPositionX").Value), Convert.ToInt32(floorObject.Element("operationPositionY").Value)), grid, floorObject.Element("name").Value, Convert.ToInt32(floorObject.Element("cost").Value), new List<MenuAction>{}, GraphicsDevice, new Vector2(Convert.ToInt32(floorObject.Element("footprintX").Value),Convert.ToInt32(floorObject.Element("footprintY").Value)), Convert.ToBoolean(floorObject.Element("prebuilt").Value)) ).ToList(); // load in menu actions List<Tuple<string,string,string,string>> actions = new List<Tuple<string,string,string,string>>(); actions = (from floorObject in doc2.Descendants("FloorObject") select new Tuple<string,string,string,string>( floorObject.Element("name").Value, floorObject.Element("menuAction").Value, floorObject.Element("menuAction2").Value, floorObject.Element("menuAction3").Value) ).ToList(); foreach (FloorObject machine in build.buildList) { foreach (Tuple<string,string,string,string> tuple in actions) { if (tuple.Item1 == machine.name) { foreach (MenuAction action in menuActions) { foreach (string name in new List<string>{tuple.Item2,tuple.Item3,tuple.Item4}) { if (action.name == name) { machine.menuActions.Add(action); } } } } } } // build any prebuilt objects foreach (FloorObject machine in build.buildList) { if (machine.prebuilt == true) { build.BuildThis(floorObjectList, machine, reachable); } } build.removeUpdate(); // objects table = build.buildList[0]; lightningAbsorber = build.buildList[1]; resurrect = new Resurrect(new Vector2(1750, 900), Content.Load<Texture2D>("raise_icon_standard"), Content.Load<Texture2D>("raise_icon_highlight"), Content.Load<Texture2D>("raise_icon_pressed"), GraphicsDevice, table); //=================================================== // background stuff room = new NonInteractive(Vector2.Zero, 0.6f, Content.Load<Texture2D>("room")); door = new NonInteractive(new Vector2(245, 200), 0.59f, Content.Load<Texture2D>("door"),2); graveyard = new Graveyard(new Vector2(1140,200), 0.8f, new Vector2(10,760),Content.Load<Texture2D>("back"), Content.Load<Texture2D>("dig_icon_standard"), Content.Load<Texture2D>("dig_icon_highlight"), Content.Load<Texture2D>("dig_icon_pressed"), GraphicsDevice, 0.5f); digger = new NonInteractive(new Vector2(1200, 300), 0.79f, Content.Load<Texture2D>("digger"), 1, 10); Switch = new NonInteractive(new Vector2(860,400), 0.58f, Content.Load<Texture2D>("switch"), 2, 1); // cursor cursor = new Cursor(Content.Load<Texture2D>("cursor"),GraphicsDevice); // characters Simon = new Scientist(Content.Load<Texture2D>("tmpprof"), new Vector2(10,1),grid,reachable,table); Jeremy = new Assistant(Content.Load<Texture2D>("tmpass"), new Vector2(8, 1), grid,reachable,table); // the corpse! corpse = new Corpse(new Vector2(660, 600),Content.Load<Texture2D>("corpse"), new List<MenuAction> { studyCorpse, dissectCorpse }, new List<MenuAction> { talk,studyLiveCorpse }, new List<MenuAction> { clearCorpse },GraphicsDevice,cursorFont,random); // update reachable area to account for these reachable.Update(floorObjectList); // test items... // machine parameters... pressure = new MachineControlParameter("Pressure", 100, 0, 20, 1); volume = new MachineControlParameter("Volume", 50, 0, 10, 2); aggression = new MachineControlParameter("Aggression", 1000, 0, 10, 1); Func<double, double> tempFunction = delegate(double x) { return 3 * x + 1; }; temperature = new MachineDependentParameter("Temperature", 0, 100, 20, pressure,tempFunction, 1); meltPercentage = new MachineDependentParameter("Melt Percentage", 0, 50, 10, volume, Math.Exp, 2); dogNumbers = new MachineDependentParameter("Number of Dogs", 0, 10, 1, volume, Math.Exp, 2); viscosity = new MachineDependentParameter("Viscosity", 0, 30, 5, pressure, Math.Exp, 2); machineparams = new List<MachineControlParameter> { pressure, volume, aggression }; machineDisplays = new List<MachineDependentParameter> { temperature, meltPercentage,dogNumbers,viscosity }; // machine controls... machineControls = new MachineControls(Content.Load<Texture2D>("knob"), Content.Load<Texture2D>("gauge"), Content.Load<Texture2D>("hand"), Content.Load<Texture2D>("slider"), Content.Load<Texture2D>("sliderknob"), Content.Load<Texture2D>("slidegauge"), Content.Load<Texture2D>("slidegaugeknob")); // flies // test saving... }