public Camera(UrbanRace game) { // Reference to the car we follow this.game = game; // Movement properties this.height = Settings.getOpt("height"); this.distance = Settings.getOpt("distance"); this.aheadDistance = Settings.getOpt("aheadDistance"); this.angle = 0.0f; this.rotation = 0.0f; this.maxRotation = Settings.getOpt("maxRotation"); this.maxAngularAcceleration = Settings.getOpt("maxAngularAcceleration"); // Initial position view = Matrix.CreateLookAt(new Vector3(1.0f, 1.0f, 1.0f), new Vector3(0.0f, 0.0f, 0.0f), Vector3.UnitY); projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)game.Window.ClientBounds.Width / (float)game.Window.ClientBounds.Height, 1, 1000); }
public MenuState(UrbanRace game) : base(game) { this.type = Type.MENU; // Create objects spriteBatch = new SpriteBatch(game.GraphicsDevice); // Positions should be relative to windows size backgroundPos = new Vector2(0.0f, 0.0f); trackPos = new Vector2(Settings.getOpt("menuTrackPanelX"), Settings.getOpt("menuTrackPanelY")); leftArrowPos = new Vector2(Settings.getOpt("menuLeftArrowX"), Settings.getOpt("menuLeftArrowY")); selectTrackPos = new Vector2(Settings.getOpt("menuSelectTrackX"), Settings.getOpt("menuSelectTrackY")); trackNamePos = new Vector2(Settings.getOpt("menuTrackNameX"), Settings.getOpt("menuTrackNameY")); recordPos = new Vector2(Settings.getOpt("menuRecordX"), Settings.getOpt("menuRecordY")); rightArrowPos = new Vector2(Settings.getOpt("menuRightArrowX"), Settings.getOpt("menuRightArrowY")); // Arrows pressed leftPressed = false; rightPressed = false; // Audio optionOver = null; optionSelected = null; song = null; // Initialize selectedTrack = 0; }
/// <summary> /// The main entry point for the application. /// </summary> static void Main(string[] args) { using (UrbanRace game = new UrbanRace()) { game.Run(); } }
public static void saveTracks(UrbanRace game) { // Create new document XDocument doc = new XDocument(); // Create tracks node XElement tracksNode = new XElement("tracks"); foreach (Track track in tracks) { // Create new track xml element XElement trackNode = new XElement("track"); // Add attributes trackNode.SetAttributeValue("name", track.name); trackNode.SetAttributeValue("file", track.filename); trackNode.SetAttributeValue("song", track.song); trackNode.SetAttributeValue("laps", track.laps); trackNode.SetAttributeValue("time", track.time); trackNode.SetAttributeValue("record", track.record); trackNode.SetAttributeValue("image", track.imageFile); // Attach track node to tracks node tracksNode.Add(trackNode); } // Attack tracks node to doc doc.Add(tracksNode); Log.log(Log.Type.INFO, "Saving xml file with record"); // Save xml file doc.Save(game.Content.RootDirectory + "\\XML\\tracks.xml"); }
public VictoryState(UrbanRace game) : base(game) { this.type = Type.VICTORY; this.background = null; this.record = null; this.button = null; this.pressedButton = null; this.selectedButton = null; this.ledFont = null; this.retroFont = null; // Audio optionOver = null; optionSelected = null; song = null; retryButtonPos = new Vector2(Settings.getOpt("victoryRetryButtonX"), Settings.getOpt("victoryRetryButtonY")); retryTextPos = new Vector2(Settings.getOpt("victoryRetryTextX"), Settings.getOpt("victoryRetryTextY")); menuButtonPos = new Vector2(Settings.getOpt("victoryMenuButtonX"), Settings.getOpt("victoryMenuButtonY")); menuTextPos = new Vector2(Settings.getOpt("victoryMenuTextX"), Settings.getOpt("victoryMenuTextY")); recordPanelPos = new Vector2(Settings.getOpt("victoryRecordPanelX"), Settings.getOpt("victoryRecordPanelY")); recordTextPos = new Vector2(Settings.getOpt("victoryRecordTextX"), Settings.getOpt("victoryRecordTextY")); recordNumberPos = new Vector2(Settings.getOpt("victoryRecordNumberX"), Settings.getOpt("victoryRecordNumberY")); this.spriteBatch = new SpriteBatch(game.GraphicsDevice); }
public Car(UrbanRace game, Vector3 position, Quaternion orientation) : base(game, "Lamborghini", position, orientation, 1.0f) { this.type = Type.CAR; this.state = State.NORMAL; this.oldPos = this.position; this.oldAngle = 0.0f; // Physics properties this.velocity = Vector3.Zero; this.maxSpeed = Settings.getOpt("carMaxSpeed"); this.maxAcceleration = Settings.getOpt("carMaxAcceleration"); this.brake = Settings.getOpt("carBrake"); this.rotation = 0.0f; this.angular = 0.0f; this.maxAngularAcceleration = Settings.getOpt("carMaxAngularAcceleration"); this.friction = Settings.getOpt("carFriction"); this.visible = false; this.angle = QuaternionToEuler2(orientation).Z; // Sound this.engine = game.soundBank.GetCue("engine"); this.engine.Play(); game.audioEngine.SetGlobalVariable("engineVolume", 0.0f); game.audioEngine.SetGlobalVariable("idleVolume", 1.0f); }
public CheckPoint(UrbanRace game, Vector3 position, Quaternion orientation, int number, int laps) : base(game, "checkpoint", position, orientation, 1.0f) { this.type = Type.CHECKPOINT; this.state = State.NORMAL; this.number = number; this.lapCounter = laps; }
public TimeBonus(UrbanRace game, Vector3 position, Quaternion orientation, float scale, int seconds) : base(game, "timebonus", position, orientation, scale) { this.type = Type.TIMEBONUS; this.state = State.NORMAL; this.velocity = new Vector3(0.0f, 0.0f, 3.0f); this.maxZ = 2.5f; this.minZ = 1.0f; this.rotation = 1.0f; this.seconds = seconds; }
public GameObject(UrbanRace game, String modelName, Vector3 position, Quaternion orientation, float scale) { this.game = game; this.model = game.Content.Load<Model>("Models\\" + modelName); this.position = position; this.orientation = orientation; this.scale = scale; this.type = Type.BASIC; this.state = State.NORMAL; this.shape = CollisionManager.getShape(modelName); }
public GameObject(UrbanRace game, String modelName, Vector3 position, Quaternion orientation, float scale) { this.game = game; this.model = game.Content.Load <Model>("Models\\" + modelName); this.position = position; this.orientation = orientation; this.scale = scale; this.type = Type.BASIC; this.state = State.NORMAL; this.shape = CollisionManager.getShape(modelName); }
public GameState(UrbanRace game) : base(game) { // Initialise attributes and properties this.type = Type.GAME; this.laps = 1; this.levelName = "level.xml"; this.level = null; this.car = null; this.checkPoints = new List<CheckPoint>(); this.timeBonuses = new List<TimeBonus>(); this.sceneObjects = new List<GameObject>(); this.geometry = new List<GameObject>(); this.skyBox = null; this.terrain = null; this.collisionManager = new CollisionManager(); this.font = null; this.speedPanel = null; this.nextCheckPoint = 0; // Audio this.song = null; this.carCrash = null; this.pickTime = null; // GUI speedPanelPos = new Vector2(Settings.getOpt("gameSpeedPanelX"), Settings.getOpt("gameSpeedPanelY")); speedTextPos = new Vector2(Settings.getOpt("gameSpeedTextX"), Settings.getOpt("gameSpeedTextY")); lapsPanelPos = new Vector2(Settings.getOpt("gameLapsPanelX"), Settings.getOpt("gameLapsPanelY")); lapsText1Pos = new Vector2(Settings.getOpt("gameLapsText1X"), Settings.getOpt("gameLapsText1Y")); lapsText2Pos = new Vector2(Settings.getOpt("gameLapsText2X"), Settings.getOpt("gameLapsText2Y")); timePanelPos = new Vector2(Settings.getOpt("gameTimePanelX"), Settings.getOpt("gameTimePanelY")); timeTextPos = new Vector2(Settings.getOpt("gameTimeTextX"), Settings.getOpt("gameTimeTextY")); // Time (in ms) this.remainingTime = 0.0; this.totalTime = 0.0; this.playTime = 0.0; // Configure callbacks collisionManager.addCallback(GameObject.Type.CAR, GameObject.Type.SCENEOBJECT, collisionCarScene, CollisionManager.CallbackType.DURING); collisionManager.addCallback(GameObject.Type.CAR, GameObject.Type.TIMEBONUS, collisionCarBonus, CollisionManager.CallbackType.BEGIN); collisionManager.addCallback(GameObject.Type.CAR, GameObject.Type.CHECKPOINT, collisionCarCheckPoint, CollisionManager.CallbackType.BEGIN); // Load shapes CollisionManager.initShapeCatalog(game.Content.RootDirectory); this.spriteBatch = new SpriteBatch(game.GraphicsDevice); }
public GameState(UrbanRace game) : base(game) { // Initialise attributes and properties this.type = Type.GAME; this.laps = 1; this.levelName = "level.xml"; this.level = null; this.car = null; this.checkPoints = new List <CheckPoint>(); this.timeBonuses = new List <TimeBonus>(); this.sceneObjects = new List <GameObject>(); this.geometry = new List <GameObject>(); this.skyBox = null; this.terrain = null; this.collisionManager = new CollisionManager(); this.font = null; this.speedPanel = null; this.nextCheckPoint = 0; // Audio this.song = null; this.carCrash = null; this.pickTime = null; // GUI speedPanelPos = new Vector2(Settings.getOpt("gameSpeedPanelX"), Settings.getOpt("gameSpeedPanelY")); speedTextPos = new Vector2(Settings.getOpt("gameSpeedTextX"), Settings.getOpt("gameSpeedTextY")); lapsPanelPos = new Vector2(Settings.getOpt("gameLapsPanelX"), Settings.getOpt("gameLapsPanelY")); lapsText1Pos = new Vector2(Settings.getOpt("gameLapsText1X"), Settings.getOpt("gameLapsText1Y")); lapsText2Pos = new Vector2(Settings.getOpt("gameLapsText2X"), Settings.getOpt("gameLapsText2Y")); timePanelPos = new Vector2(Settings.getOpt("gameTimePanelX"), Settings.getOpt("gameTimePanelY")); timeTextPos = new Vector2(Settings.getOpt("gameTimeTextX"), Settings.getOpt("gameTimeTextY")); // Time (in ms) this.remainingTime = 0.0; this.totalTime = 0.0; this.playTime = 0.0; // Configure callbacks collisionManager.addCallback(GameObject.Type.CAR, GameObject.Type.SCENEOBJECT, collisionCarScene, CollisionManager.CallbackType.DURING); collisionManager.addCallback(GameObject.Type.CAR, GameObject.Type.TIMEBONUS, collisionCarBonus, CollisionManager.CallbackType.BEGIN); collisionManager.addCallback(GameObject.Type.CAR, GameObject.Type.CHECKPOINT, collisionCarCheckPoint, CollisionManager.CallbackType.BEGIN); // Load shapes CollisionManager.initShapeCatalog(game.Content.RootDirectory); this.spriteBatch = new SpriteBatch(game.GraphicsDevice); }
public Terrain(UrbanRace game, string file, Vector3 position, Quaternion orientation, float scale) { this.game = game; this.file = file; this.position = new Vector3(position.X, position.Z, position.Y); this.orientation = orientation; this.scale = scale; this.vertices = null; this.indices = null; this.min = new Vector2(float.PositiveInfinity, float.PositiveInfinity); this.max = new Vector2(float.NegativeInfinity, float.NegativeInfinity); parseFile(); calculateNormals(); setupTexture(); copyToBuffers(); }
public DefeatState(UrbanRace game) : base(game) { this.type = Type.DEFEAT; this.spriteBatch = new SpriteBatch(game.GraphicsDevice); this.background = null; this.button = null; this.pressedButton = null; this.selectedButton = null; this.retroFont = null; retryButtonPos = new Vector2(Settings.getOpt("defeatRetryButtonX"), Settings.getOpt("defeatRetryButtonY")); retryTextPos = new Vector2(Settings.getOpt("defeatRetryTextX"), Settings.getOpt("defeatRetryTextY")); menuButtonPos = new Vector2(Settings.getOpt("defeatMenuButtonX"), Settings.getOpt("defeatMenuButtonY")); menuTextPos = new Vector2(Settings.getOpt("defeatMenuTextX"), Settings.getOpt("defeatMenuTextY")); // Audio optionOver = null; optionSelected = null; song = null; }
public static void loadTracks(UrbanRace game) { // Create track list tracks = new List <Track>(); // Load xml file with tracks XDocument doc = XDocument.Load(game.Content.RootDirectory + "\\XML\\tracks.xml"); foreach (XElement node in doc.Element("tracks").Descendants("track")) { string name = node.Attribute("name").Value; string filename = node.Attribute("file").Value; string song = node.Attribute("song").Value; int laps = XmlConvert.ToInt32(node.Attribute("laps").Value); double time = XmlConvert.ToDouble(node.Attribute("time").Value); double record = XmlConvert.ToDouble(node.Attribute("record").Value); string imageFile = node.Attribute("image").Value; Texture2D image = game.Content.Load <Texture2D>("Images\\" + imageFile); tracks.Add(new Track(name, filename, imageFile, image, record, laps, time, song)); } }
public static void loadTracks(UrbanRace game) { // Create track list tracks = new List<Track>(); // Load xml file with tracks XDocument doc = XDocument.Load(game.Content.RootDirectory + "\\XML\\tracks.xml"); foreach (XElement node in doc.Element("tracks").Descendants("track")) { string name = node.Attribute("name").Value; string filename = node.Attribute("file").Value; string song = node.Attribute("song").Value; int laps = XmlConvert.ToInt32(node.Attribute("laps").Value); double time = XmlConvert.ToDouble(node.Attribute("time").Value); double record = XmlConvert.ToDouble(node.Attribute("record").Value); string imageFile = node.Attribute("image").Value; Texture2D image = game.Content.Load<Texture2D>("Images\\" + imageFile); tracks.Add(new Track(name, filename, imageFile, image, record, laps, time, song)); } }
public SkyBox(UrbanRace game, Vector3 position, Quaternion orientation, float scale) { this.game = game; this.position = new Vector3(position.X, position.Y, position.Z); this.orientation = orientation; this.scale = scale; // Initialize vertices verts = new VertexPositionTexture[6][]; for (int i = 0; i < 6; ++i) verts[i] = new VertexPositionTexture[4]; verts[0][0] = new VertexPositionTexture(new Vector3(-1, 1, -1), new Vector2(0, 0)); verts[0][1] = new VertexPositionTexture(new Vector3(1, 1, -1), new Vector2(1, 0)); verts[0][2] = new VertexPositionTexture(new Vector3(-1, -1, -1), new Vector2(0, 1)); verts[0][3] = new VertexPositionTexture(new Vector3(1, -1, -1), new Vector2(1, 1)); verts[1][0] = new VertexPositionTexture(new Vector3(1, 1, 1), new Vector2(0, 0)); verts[1][1] = new VertexPositionTexture(new Vector3(-1, 1, 1), new Vector2(1, 0)); verts[1][2] = new VertexPositionTexture(new Vector3(1, -1, 1), new Vector2(0, 1)); verts[1][3] = new VertexPositionTexture(new Vector3(-1, -1, 1), new Vector2(1, 1)); verts[2][0] = new VertexPositionTexture(new Vector3(1, 1, -1), new Vector2(0, 0)); verts[2][1] = new VertexPositionTexture(new Vector3(1, 1, 1), new Vector2(1, 0)); verts[2][2] = new VertexPositionTexture(new Vector3(1, -1, -1), new Vector2(0, 1)); verts[2][3] = new VertexPositionTexture(new Vector3(1, -1, 1), new Vector2(1, 1)); verts[3][0] = new VertexPositionTexture(new Vector3(-1, 1, 1), new Vector2(0, 0)); verts[3][1] = new VertexPositionTexture(new Vector3(-1, 1, -1), new Vector2(1, 0)); verts[3][2] = new VertexPositionTexture(new Vector3(-1, -1, 1), new Vector2(0, 1)); verts[3][3] = new VertexPositionTexture(new Vector3(-1, -1, -1), new Vector2(1, 1)); verts[4][0] = new VertexPositionTexture(new Vector3(-1, -1, -1), new Vector2(0, 0)); verts[4][1] = new VertexPositionTexture(new Vector3(1, -1, -1), new Vector2(1, 0)); verts[4][2] = new VertexPositionTexture(new Vector3(-1, -1, 1), new Vector2(0, 1)); verts[4][3] = new VertexPositionTexture(new Vector3(1, -1, 1), new Vector2(1, 1)); verts[5][0] = new VertexPositionTexture(new Vector3(1, 1, -1), new Vector2(0, 0)); verts[5][1] = new VertexPositionTexture(new Vector3(-1, 1, -1), new Vector2(1, 0)); verts[5][2] = new VertexPositionTexture(new Vector3(1, 1, 1), new Vector2(0, 1)); verts[5][3] = new VertexPositionTexture(new Vector3(-1, 1, 1), new Vector2(1, 1)); // Textures textures = new Texture2D[6]; textures[0] = game.Content.Load<Texture2D>("Images\\back"); textures[1] = game.Content.Load<Texture2D>("Images\\front"); textures[2] = game.Content.Load<Texture2D>("Images\\right"); textures[3] = game.Content.Load<Texture2D>("Images\\left"); textures[4] = game.Content.Load<Texture2D>("Images\\bottom"); textures[5] = game.Content.Load<Texture2D>("Images\\top"); // Set vertex data in VertexBuffer vertexBuffers = new VertexBuffer[6]; vertexBuffers[0] = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionTexture), verts[0].Length, BufferUsage.None); vertexBuffers[0].SetData(verts[0]); vertexBuffers[1] = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionTexture), verts[1].Length, BufferUsage.None); vertexBuffers[1].SetData(verts[1]); vertexBuffers[2] = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionTexture), verts[2].Length, BufferUsage.None); vertexBuffers[2].SetData(verts[2]); vertexBuffers[3] = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionTexture), verts[3].Length, BufferUsage.None); vertexBuffers[3].SetData(verts[3]); vertexBuffers[4] = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionTexture), verts[4].Length, BufferUsage.None); vertexBuffers[4].SetData(verts[4]); vertexBuffers[5] = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionTexture), verts[5].Length, BufferUsage.None); vertexBuffers[5].SetData(verts[5]); // Initialize the BasicEffect effect = new BasicEffect(game.GraphicsDevice); }
public SkyBox(UrbanRace game, Vector3 position, Quaternion orientation, float scale) { this.game = game; this.position = new Vector3(position.X, position.Y, position.Z); this.orientation = orientation; this.scale = scale; // Initialize vertices verts = new VertexPositionTexture[6][]; for (int i = 0; i < 6; ++i) { verts[i] = new VertexPositionTexture[4]; } verts[0][0] = new VertexPositionTexture(new Vector3(-1, 1, -1), new Vector2(0, 0)); verts[0][1] = new VertexPositionTexture(new Vector3(1, 1, -1), new Vector2(1, 0)); verts[0][2] = new VertexPositionTexture(new Vector3(-1, -1, -1), new Vector2(0, 1)); verts[0][3] = new VertexPositionTexture(new Vector3(1, -1, -1), new Vector2(1, 1)); verts[1][0] = new VertexPositionTexture(new Vector3(1, 1, 1), new Vector2(0, 0)); verts[1][1] = new VertexPositionTexture(new Vector3(-1, 1, 1), new Vector2(1, 0)); verts[1][2] = new VertexPositionTexture(new Vector3(1, -1, 1), new Vector2(0, 1)); verts[1][3] = new VertexPositionTexture(new Vector3(-1, -1, 1), new Vector2(1, 1)); verts[2][0] = new VertexPositionTexture(new Vector3(1, 1, -1), new Vector2(0, 0)); verts[2][1] = new VertexPositionTexture(new Vector3(1, 1, 1), new Vector2(1, 0)); verts[2][2] = new VertexPositionTexture(new Vector3(1, -1, -1), new Vector2(0, 1)); verts[2][3] = new VertexPositionTexture(new Vector3(1, -1, 1), new Vector2(1, 1)); verts[3][0] = new VertexPositionTexture(new Vector3(-1, 1, 1), new Vector2(0, 0)); verts[3][1] = new VertexPositionTexture(new Vector3(-1, 1, -1), new Vector2(1, 0)); verts[3][2] = new VertexPositionTexture(new Vector3(-1, -1, 1), new Vector2(0, 1)); verts[3][3] = new VertexPositionTexture(new Vector3(-1, -1, -1), new Vector2(1, 1)); verts[4][0] = new VertexPositionTexture(new Vector3(-1, -1, -1), new Vector2(0, 0)); verts[4][1] = new VertexPositionTexture(new Vector3(1, -1, -1), new Vector2(1, 0)); verts[4][2] = new VertexPositionTexture(new Vector3(-1, -1, 1), new Vector2(0, 1)); verts[4][3] = new VertexPositionTexture(new Vector3(1, -1, 1), new Vector2(1, 1)); verts[5][0] = new VertexPositionTexture(new Vector3(1, 1, -1), new Vector2(0, 0)); verts[5][1] = new VertexPositionTexture(new Vector3(-1, 1, -1), new Vector2(1, 0)); verts[5][2] = new VertexPositionTexture(new Vector3(1, 1, 1), new Vector2(0, 1)); verts[5][3] = new VertexPositionTexture(new Vector3(-1, 1, 1), new Vector2(1, 1)); // Textures textures = new Texture2D[6]; textures[0] = game.Content.Load <Texture2D>("Images\\back"); textures[1] = game.Content.Load <Texture2D>("Images\\front"); textures[2] = game.Content.Load <Texture2D>("Images\\right"); textures[3] = game.Content.Load <Texture2D>("Images\\left"); textures[4] = game.Content.Load <Texture2D>("Images\\bottom"); textures[5] = game.Content.Load <Texture2D>("Images\\top"); // Set vertex data in VertexBuffer vertexBuffers = new VertexBuffer[6]; vertexBuffers[0] = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionTexture), verts[0].Length, BufferUsage.None); vertexBuffers[0].SetData(verts[0]); vertexBuffers[1] = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionTexture), verts[1].Length, BufferUsage.None); vertexBuffers[1].SetData(verts[1]); vertexBuffers[2] = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionTexture), verts[2].Length, BufferUsage.None); vertexBuffers[2].SetData(verts[2]); vertexBuffers[3] = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionTexture), verts[3].Length, BufferUsage.None); vertexBuffers[3].SetData(verts[3]); vertexBuffers[4] = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionTexture), verts[4].Length, BufferUsage.None); vertexBuffers[4].SetData(verts[4]); vertexBuffers[5] = new VertexBuffer(game.GraphicsDevice, typeof(VertexPositionTexture), verts[5].Length, BufferUsage.None); vertexBuffers[5].SetData(verts[5]); // Initialize the BasicEffect effect = new BasicEffect(game.GraphicsDevice); }
public State(UrbanRace game) { this.game = game; this.loaded = false; }