Example #1
0
        public GameModule Create(string shipId, Difficulty diff, Level level, ShipFactory shipFac, GameSendData gameSendData)
        {
            Scoresheet       scoreSheet  = new Scoresheet();
            EntityHandler    entHandler  = new EntityHandler(scoreSheet, level.PlayArea);
            CollisionHandler collHandler = new CollisionHandler(level.PlayArea, entHandler);

            //create player's ship
            Ship p = shipFac.Create(shipId, Util.RandomPointInRect(level.PlayArea), new WrapBoundaryBehaviour(level.PlayArea), ControllerType.Player1, diff, entHandler);

            entHandler.Track(p);

            //camera
            CameraHandler camHandler = new CameraHandler(p, level.PlayArea);
            //ai spawner
            AISpawner aiSpawner = new AISpawner(diff, level.PlayArea, shipFac, entHandler);

            //spawn predefined ships from the level
            foreach (string enemyId in level.ShipsToSpawn)
            {
                Ship toSpawn = shipFac.Create(enemyId, Util.RandomPointInRect(level.PlayArea), new WrapBoundaryBehaviour(level.PlayArea), ControllerType.Computer, diff, entHandler);
                entHandler.Track(toSpawn);
            }

            //spawn asteroids
            AsteroidFactory asteroidFac  = new AsteroidFactory(entHandler);
            string          asteroidPath = SwinGame.AppPath() + "\\resources\\data\\asteroids\\asteroid.json";

            for (int i = 0; i < level.AsteroidsToSpawn; i++)
            {
                Asteroid toSpawn = asteroidFac.Create(asteroidPath, level.PlayArea);
                entHandler.Track(toSpawn);
            }

            InputController inpController;

            if (p is IControllable)
            {
                InputControllerFactory inpContFac = new InputControllerFactory();
                inpController = inpContFac.Create(p as IControllable, ControllerType.Player1);
            }
            else
            {
                inpController = null;
            }

            return(new GameModule(p, level, aiSpawner, entHandler, collHandler, camHandler, gameSendData, scoreSheet, inpController));
        }
Example #2
0
        public GameModule(Ship p, Level level, AISpawner aiSpawner, EntityHandler entHandler, CollisionHandler collHandler,
                          CameraHandler camHandler, GameSendData gameSendData, Scoresheet scoresheet, InputController inpController
                          )
        {
            player            = p;
            Level             = level;
            entityHandler     = entHandler;
            collisionHandler  = collHandler;
            cameraHandler     = camHandler;
            inputController   = inpController;
            this.scoresheet   = scoresheet;
            this.aiSpawner    = aiSpawner;
            this.gameSendData = gameSendData;

            gameTimer = SwinGame.CreateTimer();
            gameTimer.Start();
        }