/// <summary> /// Creates a new Hi score table with a given sort order /// </summary> /// <param name="sort">the sort order</param> /// <returns>A new hiscore table object</returns> public static HiScoreTable NewEmptyTable(string columns, string sort) { HiScoreTable hi = new HiScoreTable(columns, sort); return hi; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { //SFX Wind = Content.Load<SoundEffect>("windy2"); Heart = Content.Load<SoundEffect>("heart_beating_at_normal_speed"); Scream = Content.Load<SoundEffect>("bloodscream"); NearMonster = Content.Load<SoundEffect>("this_way_comes_2"); //Models testmodel = Content.Load<Model>("box"); monsterModel = Content.Load<Model>("SphereHighPoly"); //Music BackgroundMusic = Content.Load<Song>("MonsterMusicTest"); Music2 = Content.Load<Song>("breifing"); //Mini Map MiniMap_Closed = Content.Load<Texture2D>("minimap_closed"); MiniMap_Monster = Content.Load<Texture2D>("minimap_monster"); MiniMap_Open = Content.Load<Texture2D>("minimap_open"); MiniMap_Player = Content.Load<Texture2D>("minimap_player"); //compass CompassTexture = Content.Load<Texture2D>("gamecompass2"); CompassSkull = Content.Load<Texture2D>("skull"); CompassArrow = Content.Load<Texture2D>("tele"); CompassPointer = Content.Load<Texture2D>("compasspointer"); //Banner Banner = Content.Load<Texture2D>("banner"); //Point Spirtes pointSpritesEffect = Content.Load<Effect>("Effect\\pointsprites"); pointSpritesEffect.Parameters["SpriteTexture"].SetValue( Content.Load<Texture2D>("fire")); spriteArray = new VertexPositionColor[200]; vertexPosColDecl = new VertexDeclaration(graphics.GraphicsDevice, VertexPositionColor.VertexElements); device = graphics.GraphicsDevice; basicEffect = new BasicEffect(device, null); font = Content.Load<SpriteFont>("SpriteFont1"); smallfont = Content.Load<SpriteFont>("SpriteFont2"); if (graphics.GraphicsDevice.GraphicsDeviceCapabilities. PixelShaderVersion.Major >= 3) { baseEffect = Content.Load<Effect>("Effect\\MaterialShader30"); numLights = 3; baseEffect.Parameters["numLights"].SetValue(numLights); shaderVersionString = "Using Shader Model 3.0"; } else { baseEffect = Content.Load<Effect>("Effect\\MaterialShader20"); numLights = 3; baseEffect.Parameters["numLights"].SetValue(numLights); shaderVersionString = "Using Shader Model 2.0"; } // cache the effect parameters viewParameter = baseEffect.Parameters["view"]; projectionParameter = baseEffect.Parameters["projection"]; cameraPositionParameter = baseEffect.Parameters["cameraPosition"]; // create the materials BasicMaterial = new Material(Content, graphics.GraphicsDevice,baseEffect); WallMaterial = new Material(Content, graphics.GraphicsDevice, baseEffect); FloorMaterial = new Material(Content, graphics.GraphicsDevice, baseEffect); CeilingMaterial = new Material(Content, graphics.GraphicsDevice, baseEffect); BasicMaterial.SetBasicProperties(Color.Purple, 0.5f, 1.2f); WallMaterial.SetTexturedMaterial(Color.White, Stage.ConfigurationSettings.WallSpecularPower, Stage.ConfigurationSettings.WallSpecularIntensity*2, "wall_diffuse", "wall_specular", 1f, 1f); FloorMaterial.SetTexturedMaterial(Color.White, 0, 0, "ground06", "ground06", 1f, 1f); CeilingMaterial.SetTexturedMaterial(Color.White, 0, 0, "ground06", "ground06", 1f, 1f); //Set ambient light baseEffect.Parameters["ambientLightColor"].SetValue( new Vector4(Stage.ConfigurationSettings.Ambient*1.4f, Stage.ConfigurationSettings.Ambient*1.3f, Stage.ConfigurationSettings.Ambient, 1.0f)); // Recalculate the projection properties on every LoadGraphicsContent call. // That way, if the window gets resized, then the perspective matrix will // be updated accordingly float aspectRatio = (float)graphics.GraphicsDevice.Viewport.Width / (float)graphics.GraphicsDevice.Viewport.Height; float fieldOfView = aspectRatio * MathHelper.PiOver4 * 3f / 4f; projection = Matrix.CreatePerspectiveFieldOfView( fieldOfView, aspectRatio, .1f, 1000f); projectionParameter.SetValue(projection); // calculate the safe left and top edges of the screen safeBounds = new Vector2( (float)graphics.GraphicsDevice.Viewport.X + (float)graphics.GraphicsDevice.Viewport.Width * 0.1f, (float)graphics.GraphicsDevice.Viewport.Y + (float)graphics.GraphicsDevice.Viewport.Height * 0.1f ); // Init light PlayerLight = new PointLight(new Vector4(0, 0, 0, 1.0f) , baseEffect.Parameters["lights"].Elements[0]); MonsterLight = new PointLight(new Vector4(0, 0, 0, 1.0f) , baseEffect.Parameters["lights"].Elements[1]); TeleporterLight = new PointLight(new Vector4(0, 0, 0, 1.0f) , baseEffect.Parameters["lights"].Elements[2]); //color, range, and power of the lights PlayerLight.Range = Stage.ConfigurationSettings.TorchRange; PlayerLight.Falloff = Stage.ConfigurationSettings.TorchAttenuation; MonsterLight.Range = Stage.ConfigurationSettings.TorchRange/8; MonsterLight.Falloff = Stage.ConfigurationSettings.TorchAttenuation; TeleporterLight.Range = Stage.ConfigurationSettings.TorchRange/2; TeleporterLight.Falloff = Stage.ConfigurationSettings.TorchAttenuation; // always set light 0 to pure white as a reference point PlayerLight.Color = new Color(0.0f,0.0f,0.0f); MonsterLight.Color = new Color(0.0f, 1.0f, 0.0f); TeleporterLight.Color = new Color(0.0f, 0.0f, 1.0f); spriteBatch = new SpriteBatch(graphics.GraphicsDevice); //Set up the UI component UI = new UIComponent(this, graphics); UI.GameSpriteBatch = spriteBatch; this.Components.Add(UI); //Set up the UI component Texture2D mouseTexture = Content.Load<Texture2D>("mouse"); Point mouseHotspot = new Point(8, 7); Point mouseLocation = new Point(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2); Dictionary<MousePointerState, Rectangle> mouserects = new Dictionary<MousePointerState, Rectangle>(); mouserects.Add(MousePointerState.Default, new Rectangle(0, 0, 31, 31)); mouserects.Add(MousePointerState.ActiveArea, new Rectangle(32, 0, 63, 31)); Rectangle screenRectangle = new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight); UI.CurrentMousePointer = MousePointer.CreateFromTexture2D( mouseTexture, mouseHotspot, mouseLocation, mouserects, screenRectangle); //Load UI Form Forms.TestRootForm root = new GOOS.MonsterMaze.Forms.TestRootForm("TheRootForm"); root.Content = Content; root.RenderRectangle = new Rectangle(0, 0, graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height); root.AddControls(); UI.RootForm = root; //Add event handlers UI.RootForm.GetControl("Button_NewGame").Click += new GameControlEventHandler(ClickNew); UI.RootForm.GetControl("Button_Quit").Click += new GameControlEventHandler(ClickQuit); UI.RootForm.GetControl("Button_Ok").Click += new GameControlEventHandler(ClickOk); UI.RootForm.GetControl("Button_HiScore").Click += new GameControlEventHandler(ClickHiScore); UI.RootForm.GetControl("Button_Options").Click += new GameControlEventHandler(ClickOptions); UI.RootForm.GetControl("Button_Help").Click += new GameControlEventHandler(ClickHelp); //Load the hi-scores, or make some up. string columnNames = "name|level|time|score"; string sortOrder = "score|level|time;ASC|name;ASC"; HiScores = HiScoreTable.LoadFromFile("CreatureCave.hiscores", columnNames, sortOrder); if (HiScores.Scores.Count < 1) { //Scores are empty or score file isn't available. Make up some scores. HiScores.AddScore("Robert Prim", 1, 50, 200); HiScores.AddScore("Rex", 2, 170, 400); HiScores.AddScore("Vojtech Jarnik", 4, 290, 800); HiScores.AddScore("William Dyer", 6, 410, 1600); HiScores.AddScore("Joseph Kruskal", 8, 530, 3200); HiScores.AddScore("Ellen Ripley", 10, 650, 6400); HiScores.AddScore("Edsger Dijkstra", 14, 770, 12800); HiScores.AddScore("Danny Torrance", 18, 890, 25600); HiScores.AddScore("Alan Turing", 22, 1010, 51200); HiScores.AddScore("Theseus", 26, 1130, 102400); } //Set up display mode slider //((DisplayMode)Modes[0]).Width Slider DisplayModeSlider = ((GOOS.JFX.UI.Controls.Slider)UI.RootForm.GetControl("SliderDisplayMode")); DisplayModeSlider.MinValue = 0; DisplayModeSlider.MaxValue = ModeList.Count(); //Set the options contgrols to the loaded values from config. //floats ((GOOS.JFX.UI.Controls.Slider)UI.RootForm.GetControl("SliderSampling")).Value = OptionsTextureSampler; ((GOOS.JFX.UI.Controls.Slider)UI.RootForm.GetControl("SliderParticles")).Value = OptionsParticleDensity; ((GOOS.JFX.UI.Controls.Slider)UI.RootForm.GetControl("SliderSFX")).Value = OptionsSFXVolume; ((GOOS.JFX.UI.Controls.Slider)UI.RootForm.GetControl("SliderMusic")).Value = OptionsMusicVolume; ((GOOS.JFX.UI.Controls.Slider)UI.RootForm.GetControl("SliderViewDist")).Value = OptionsViewDistance; ((GOOS.JFX.UI.Controls.Slider)UI.RootForm.GetControl("SliderBloom")).Value = OptionsBloomLevel; //bools ((GOOS.JFX.UI.Controls.Checkbox)UI.RootForm.GetControl("OptionsCheckFullscreen")).Checked = Stage.ConfigurationSettings.Fullscreen; ((GOOS.JFX.UI.Controls.Checkbox)UI.RootForm.GetControl("OptionsCheckMusicMute")).Checked = OptionsMuteMusic; ((GOOS.JFX.UI.Controls.Checkbox)UI.RootForm.GetControl("OptionsCheckSFXMute")).Checked = OptionsMuteSFX; ((GOOS.JFX.UI.Controls.Checkbox)UI.RootForm.GetControl("OptionsCheckBloom")).Checked = OptionsBloomOn; //Add scores to table control ((HiScoreTableControl)root.GetControl("HiScoreTable")).Table = HiScores; //Set the initial Game State Stage.GameState.Console = false; Stage.GameState.DemoMode = true; Stage.GameState.Menu = true; Stage.GameState.Pause = false; //Generate the initial map GenerateNewMap(); //Keyboard input test UI.KeyboardActive = true; UI.ControlWithInputFocus = root.GetControl("KeyboardTestLabel"); }
/// <summary> /// Load the hiscore table from a file or an empty one if the file is not found. /// </summary> /// <param name="path">the full file path</param> /// <returns>a new hiscore table object</returns> public static HiScoreTable LoadFromFile(string path, string columns, string sort) { if (File.Exists(path)) { try { HiScoreTable t; Stream stream = File.Open(path, FileMode.Open); BinaryFormatter bFormatter = new BinaryFormatter(); t = (HiScoreTable)bFormatter.Deserialize(stream); stream.Close(); return t; } catch { HiScoreTable hi = new HiScoreTable(columns, sort); return hi; } } else { HiScoreTable hi = new HiScoreTable(columns, sort); return hi; } }