#region File Description
//-----------------------------------------------------------------------------
// Settings.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion
#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using System.IO;
using System.Xml.Serialization;
#endregion
namespace Spacewar
{
///
/// The Setting class handles loading and saving of global application settings.
/// The normal .Net classes (System.Configuration) for doing this are not available on the CF (and therefore 360)
///
public class Settings
{
#region General App Settings
///
/// The path to look for all media in
///
public string MediaPath = @"";
///
/// The name of the window when running in windowed mode
///
public string WindowTitle = "Spacewar";
///
/// The length of each level in seconds;
///
public int LevelTime = 30;
///
/// How much maximum thrust to apply
///
public float ThrustPower = 100f;
///
/// How much friction to apply to slow down the ship
///
public float FrictionFactor = .1f;
///
/// Maximum speed a ship will accelerate to
///
public float MaxSpeed = 200f;
///
/// Time ships spend in recovery after destruction
///
public float ShipRecoveryTime = 1.6f;
#endregion
#region Sun settings
///
/// The position of the sun
///
public Vector2 SunPosition = new Vector2(0f, 0f);
///
/// How fast items are pulled towards the sun
///
public double GravityStrength = 500000.0;
///
/// Power defines the fall off of the suns gravity. 2.0 is 1/(n^2) as in normal gravity.
/// Bigger numbers fall off faster.
///
public int GravityPower = 2;
///
/// Affect the color of the sun shader
///
public float ColorDistribution = 3.0f;
///
/// Affects the fade of the sun shader
///
public float Fade = 4.0f;
///
/// Affects the flame speed of the sun shader
///
public float FlameSpeed = 0.22f;
///
/// Affects the spread of flames of the sun shder
///
public float Spread = 0.50f;
///
/// Affects the flames of the sun shader
///
public float Flamability = 1.74f;
///
/// Size of the sun
///
public float Size = 70f;
#endregion
#region AsteroidSettings
///
/// Realtive Scale of Asteroids
///
public float AsteroidScale = .02f;
#endregion
#region BulletSettings
///
/// RelativeScale of bullets
///
public float BulletScale = .02f;
#endregion
#region Ship settings
///
/// Relative scaling of the ships
///
public float ShipScale = 0.02f;
///
/// Stores settings for the player ships
///
public struct PlayerShipInfo
{
///
/// The start position of this ship
///
public Vector2 StartPosition;
///
/// The start angle of this ship
///
public double StartAngle;
///
/// Makes a new ShipInfo
///
/// Start position
/// Start Angle
public PlayerShipInfo(Vector2 startPosition, double startAngle)
{
StartPosition = startPosition;
StartAngle = startAngle;
}
}
///
/// Store default information about the ships
///
public PlayerShipInfo[] Ships = new PlayerShipInfo[2] {new PlayerShipInfo(new Vector2(-300, 0), 90),
new PlayerShipInfo(new Vector2(300, 0), 90)};
#endregion
#region WeaponParameters
///
/// Stores information about weapons
///
public struct WeaponInfo
{
///
/// Cost of the weapon
///
public int Cost;
///
/// Nubmer of seconds the projectile lasts for
///
public double Lifetime;
///
/// Maximum number of ths projectile that can be shot at a time
///
public int Max;
///
/// How many projectile fired per trigger pull
///
public int Burst;
///
/// Acceleration of the projectile
///
public float Acceleration;
///
/// How much damage this bullet does
///
public int Damage;
///
/// Creates a new weapon
///
/// Cost of the weapon
public WeaponInfo(int cost, double lifetime, int max, int burst, float acceleration, int damage)
{
Cost = cost;
Lifetime = lifetime;
Max = max;
Burst = burst;
Acceleration = acceleration;
Damage = damage;
}
}
///
/// Stores default information about the weapons
///
public WeaponInfo[] Weapons = new WeaponInfo[]
{
new WeaponInfo(0, 3.0, 5, 1, 0, 1), //Pea
new WeaponInfo(1000, 3.0, 4, 3, 0, 1), //mgun
new WeaponInfo(2000, 3.0, 3, 3, 0, 1), //double mgun
new WeaponInfo(3000, 2.0, 1, 1, 1.0f, 5), //Rocket
new WeaponInfo(4000, 2.0, 3, 1, 0f, 5), //BFG
};
#endregion
#region Backdrop
///
/// How fast the 2 backdrops fade between each other
///
public float CrossFadeSpeed = 0.2f;
///
/// How much the 2 backdrops move
///
public float OffsetSpeed = 0.1f;
#endregion
#region Lighting
///
/// Store informtion about lighting the scenes
///
public struct ShipLighting
{
///
/// Ambient component color
///
public Vector4 Ambient;
///
/// The direction of the directional light
///
public Vector4 DirectionalDirection;
///
/// The color of the directional light
///
public Vector4 DirectionalColor;
///
/// The position of the point light
///
public Vector4 PointPosition;
///
/// The color of the point light
///
public Vector4 PointColor;
///
/// The fall off of the point light
///
public float PointFactor;
///
/// Creates a new lighting scheme
///
/// Ambient color
/// Directional light direction
/// Directional light color
/// Point light position
/// Point light color
/// Point light fall off
public ShipLighting(Vector4 ambient, Vector4 directionalDirection, Vector4 directionalColor, Vector4 pointPosition, Vector4 pointColor, float pointFactor)
{
Ambient = ambient;
DirectionalDirection = directionalDirection;
DirectionalColor = directionalColor;
PointPosition = pointPosition;
PointColor = pointColor;
PointFactor = pointFactor;
}
}
///
/// Lighting parameters for in game and menu shaders
///
public ShipLighting[] ShipLights = new ShipLighting[]
{ //0 is in game
new ShipLighting(new Vector4(1f, 1f, 1f, 1.0f),
new Vector4(1f, 1f, 1f, 0f),
new Vector4(.4f, .4f, .8f, 1.0f),
new Vector4(0f, 0f, 0f, 0f),
new Vector4(.8f, .6f, 0f, 1.0f),
.01f),
//1 is menu screens
new ShipLighting(new Vector4(.2f, .2f, .2f, 1.0f),
new Vector4(1f, 1f, 1f, 0f),
new Vector4(.4f, .4f, .8f, 1.0f),
new Vector4(0f, 0f, 0f, 0f),
new Vector4(.8f, .6f, 0f, 1.0f),
.008f),
};
#endregion
#region Keyboard Settings
///
/// Keyboard settings for two players
/// Note: not allowing extensibility for more than 2 players
///
// player 1
public Keys Player1Start = Keys.LeftControl;
public Keys Player1Back = Keys.LeftShift;
public Keys Player1A = Keys.V;
public Keys Player1B = Keys.G;
public Keys Player1X = Keys.F;
public Keys Player1Y = Keys.T;
public Keys Player1ThumbstickLeftXmin = Keys.A;
public Keys Player1ThumbstickLeftXmax = Keys.D;
public Keys Player1ThumbstickLeftYmin = Keys.S;
public Keys Player1ThumbstickLeftYmax = Keys.W;
public Keys Player1Left = Keys.A;
public Keys Player1Right = Keys.D;
public Keys Player1Down = Keys.S;
public Keys Player1Up = Keys.W;
public Keys Player1LeftTrigger = Keys.Q;
public Keys Player1RightTrigger = Keys.E;
// player 2
public Keys Player2Start = Keys.RightControl;
public Keys Player2Back = Keys.RightShift;
public Keys Player2A = Keys.Home;
public Keys Player2B = Keys.End;
public Keys Player2X = Keys.PageUp;
public Keys Player2Y = Keys.PageDown;
public Keys Player2ThumbstickLeftXmin = Keys.Left;
public Keys Player2ThumbstickLeftXmax = Keys.Right;
public Keys Player2ThumbstickLeftYmin = Keys.Down;
public Keys Player2ThumbstickLeftYmax = Keys.Up;
public Keys Player2Left = Keys.Left;
public Keys Player2Right = Keys.Right;
public Keys Player2Down = Keys.Down;
public Keys Player2Up = Keys.Up;
public Keys Player2LeftTrigger = Keys.Insert;
public Keys Player2RightTrigger = Keys.Delete;
#endregion
#region Load/Save code
///
/// Saves the current settings
///
/// The filename to save to
public void Save(string filename)
{
Stream stream = File.Create(filename);
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
serializer.Serialize(stream, this);
stream.Close();
}
///
/// Loads settings from a file
///
/// The filename to load
public static Settings Load(string filename)
{
Stream stream = File.OpenRead(filename);
XmlSerializer serializer = new XmlSerializer(typeof(Settings));
return (Settings)serializer.Deserialize(stream);
}
#endregion
}
}