Example #1
0
        public override void unload()
        {
            // Remove objects from collision manager
            collisionManager.removeAllObjects();

            // Set every game element to null so we can save memory
            car = null;
            level = null;
            checkPoints.Clear();
            timeBonuses.Clear();
            sceneObjects.Clear();
            geometry.Clear();
            skyBox = null;
            terrain = null;

            font = null;
            retroFont = null;
            speedPanel = null;
            timePanel = null;

            MediaPlayer.Stop();
            song = null;
            carCrash = null;
            pickTime = null;

            // Clear input callbacks
            Input.clearCallbacks();

            loaded = false;
        }
Example #2
0
        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);
        }
Example #3
0
        public override void load()
        {
            Log.log(Log.Type.INFO, "Loading state game type " + type);

            // Parse level and create game objects
            level = new Level(this, levelName);
            level.load();

            // Sort check point list
            checkPoints.Sort();

            // Create car with level data
            car = new Car(game, level.carPosition, level.carOrientation);

            // Add gameobjects to collision manager
            collisionManager.addObject(car);

            foreach (TimeBonus timeBonus in timeBonuses)
            {
                collisionManager.addObject(timeBonus);
            }

            foreach (CheckPoint checkPoint in checkPoints)
            {
                collisionManager.addObject(checkPoint);
            }

            foreach (GameObject sceneObject in sceneObjects)
            {
                collisionManager.addObject(sceneObject);
            }

            font = game.Content.Load<SpriteFont>("Fonts\\LED");
            retroFont = game.Content.Load<SpriteFont>("Fonts\\MenuBig");
            speedPanel = game.Content.Load<Texture2D>("Images\\speedPanel");
            timePanel = game.Content.Load<Texture2D>("Images\\speedPanel");

            // Time (in ms)
            this.remainingTime = totalTime * 1000.0;
            this.playTime = 0.0f;

            // Song
            song = game.Content.Load<Song>("Audio\\game");
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(song);

            // Set input callbacks
            Input.setKeyPressedCallback(keyPressed);
            Input.setKeyReleasedCallback(keyReleased);

            game.camera.setInitialPosition(car);

            // Next checkpoint
            nextCheckPoint = 0;

            lapsDone = 1;

            loaded = true;
        }