Ejemplo n.º 1
0
    public static AsteroidFactory SpawnAsteroid()
    {
        // Calc
        Vector2 expandOffset = Vector2.up * Boundaries.Rect.height * Refs.Instance.Settings.AsteroidSpawnAreaExpand * .5f;
        Vector2 position     =
            Vector2.Lerp(
                Boundaries.x1y0 - expandOffset,
                Boundaries.Max + expandOffset,
                Random.value
                ) +
            Vector2.right * Refs.Instance.Settings.AsteroidSpawnRightShift
        ;
        Vector2 baseVelocity  = Vector2.left * Refs.Instance.Settings.AsteroidBaseSpeed;
        Vector2 addonVelocity = Random.insideUnitCircle * Refs.Instance.Settings.AsteroidAddonSpeed;
        Vector2 velocity      = baseVelocity + addonVelocity;


        // Create
        AsteroidFactory factory = new AsteroidFactory(position);

        // Launch
        factory.Model.Launch(velocity);

        // Bookkeeping
        Bookkeeper.Register(factory.Controller);

        return(factory);
    }
Ejemplo n.º 2
0
        internal Initializer(Controllers controller, GameData gameData)
        {
            var inputInitialized = new InputController(new PCInput());

            controller.AddController(inputInitialized);

            ServiceLocator.SetService(new ShipProviderPool(gameData.Ship.Provider));

            var shipWeaponFactory = new ShipWeaponFactory(
                gameData.ShipWeapon,
                new ShipWeaponBulletsPool(gameData.ShipWeapon.Bullet));

            var shipFactory = new ShipInitializer(
                gameData.Ship,
                ServiceLocator.Resolve <ShipProviderPool>(),
                shipWeaponFactory.GetShipWeapon);

            controller.AddController(shipFactory.CreateShipFromData(gameData.Ship));

            var playerInitialized = new PlayerInitializer(shipFactory.GetShip, gameData.Player, inputInitialized.Input);

            controller.AddController(playerInitialized.PlayerController);

            var cameraInitialized = new CameraInitializer(gameData.Camera, shipFactory.GetShip);

            controller.AddController(cameraInitialized.CameraController);

            IEnemyFactory factory = new AsteroidFactory();

            factory.Create(new Health(100.0f, 100.0f));
        }
Ejemplo n.º 3
0
        public MenuModule Create(Bank bank, Dictionary <string, Shape> shipList,
                                 Dictionary <string, Level> levelList, IReceiveMenuData receiver, ExitGame exit)
        {
            //spawn asteroids
            Level           menuScene     = levelList["MenuScene"];
            EntityHandler   entityHandler = new EntityHandler(null, menuScene.PlayArea);
            AsteroidFactory asteroidFac   = new AsteroidFactory(entityHandler);
            string          asteroidPath  = SwinGame.AppPath() + "\\resources\\data\\asteroids\\asteroid.json";

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

            MenuModule result = new MenuModule(new MenuSendData(receiver), bank, shipList, levelList, menuScene, entityHandler, exit);

            MenuFactory menuFac = new MenuFactory(dirPath, result);

            result.AddMenu(menuFac.CreateNormalMenu("\\help.json"));
            result.AddMenu(menuFac.CreateHighscoreMenu("\\highscores.json"));
            result.AddMenu(menuFac.CreateNormalMenu("\\main.json"));
            result.AddMenu(menuFac.CreateNormalMenu("\\options.json"));
            result.AddMenu(menuFac.CreateNormalMenu("\\scorescreen.json"));
            result.AddMenu(menuFac.CreateSelectMenu("\\select.json", shipList, levelList));

            result.ChangeMenu("Main");

            return(result);
        }
Ejemplo n.º 4
0
        public static Entity CreateAsteroid(AsteroidFactory asteroid, Vector2 position)
        {
            //Nave1 = new Nave("Ship.png", 150, 400, (float)Math.Cos(0));
            //Nave2 = new Nave("ship.png", 250, 500, (float)Math.Sin(0)*200*250);
            //Nave3 = new Nave("ship.png", 50, 300, (float)Math.Cos(0)*50*250);
            switch (asteroid)
            {
            //Agrego opcion para agregar posicion random
            case AsteroidFactory.asteroid1:
                return(new Asteroid(position, new Vector2(0.5f, 0.5f), new Vector2(70, 61), 0, "Textures/Entities/Asteroids/Asteroid1.png", 5, 10, 50, new Vector2(60, 60)));

            case AsteroidFactory.asteroid2:
                return(new Asteroid(position, new Vector2(0.5f, 0.5f), new Vector2(76, 63), 0, "Textures/Entities/Asteroids/Asteroid2.png", 5, 10, 10, new Vector2(10, 10)));

            case AsteroidFactory.asteroid3:
                return(new Asteroid(position, new Vector2(0.5f, 0.5f), new Vector2(150, 112), 0, "Textures/Entities/Asteroids/Asteroid3.png", 5, 30, 10, new Vector2(30, 30)));

            case AsteroidFactory.asteroid4:
                return(new Asteroid(position, new Vector2(0.5f, 0.5f), new Vector2(199, 165), 0, "Textures/Entities/Asteroids/Asteroid4.png", 5, 30, 10, new Vector2(50, 50)));

            case AsteroidFactory.asteroid5:
                return(new Asteroid(position, new Vector2(0.5f, 0.5f), new Vector2(106, 96), 0, "Textures/Entities/Asteroids/Asteroid5.png", 5, 30, 10, new Vector2(10, 10)));

            default:
                return(new Asteroid(position, new Vector2(0.5f, 0.5f), new Vector2(70, 61), 0, "Textures/Entities/Asteroids/Asteroid1.png", 5, 10, 50, new Vector2(30, 30)));
            }
        }
Ejemplo n.º 5
0
 public AsteroidSpawner(Game gameView)
 {
     asteroidFactory = new AsteroidFactory(gameView);
     asteroidFactory.AddModel(new AsteroidModel());
     asteroidFactory.AddModel(new AsteroidModel("Asteroid2"));
     asteroidCount = 0;
     frameCount    = 0;
 }
Ejemplo n.º 6
0
        public void CreateAsteroidTest()
        {
            var asteroidFactory = new AsteroidFactory();
            var asteroid        = asteroidFactory.CreateAsteroid(100, 100);

            string expectedName = "first";

            Assert.AreEqual(expectedName, asteroid.Name);
        }
Ejemplo n.º 7
0
 public AsteroidController(EnemyData enemyData, PlayerModel playerModel,
                           PointModel pointModel, AsteroidFactory asteroidFactory,
                           EnemyPool pool)
 {
     _pool            = pool;
     _spawnTime       = enemyData.EnemyTimer;
     _pointPerEnemy   = enemyData.PointsPerEnemy;
     _playerTransform = playerModel.Transform;
     _pointModel      = pointModel;
 }
Ejemplo n.º 8
0
        protected override List <MovingObject> GetAsteroids()
        {
            List <MovingObject> retour = new List <MovingObject>();

            for (int i = 0; i < 10; i++)
            {
                retour.Add(AsteroidFactory.GenerateAsteroid());
            }
            return(retour);
        }
Ejemplo n.º 9
0
    /* not used anymore TO DO remove
     * public int getFreeId()
     * {
     *
     *  for (int i = 0; i < maxAsteroid; i++ )
     *  {
     *      if (asteroidList[i] == null)
     *          return i;
     *  }
     *
     *  foreach (Asteroid ast in asteroidList)
     *  {
     *      if (!ast.isUsed)
     *      {
     *          Debug.Log(ast.id);
     *          return ast.id;
     *      }
     *  }
     *  return -1;
     * }
     */
    void Awake()
    {
        if (_factory != null)
        {
            Debug.Log(" AsteroidFactory should be unique");
        }
        else
        {
            _factory = this;

            _factory.asteroidNotInUse = new Stack <Asteroid>();
        }
    }
Ejemplo n.º 10
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            // TODO: use this.Content to load your game content here

            RectanglePrimative.LoadTexture(Content);
            ProjectileFactory.Initiate(Content);
            AsteroidFactory.Initiate(Content);

            SoundEffectEngine.Initiate(Content);
            MusicEngine.Initiate(Content);

            gameField = GameField.Initiate(Content);
        }
Ejemplo n.º 11
0
 private void _processProjectileHit()
 {
     hitCount++;
     if (hitCount >= _maxHits)
     {
         _expired = true;
         if (_addSmallOnExpire)
         {
             AsteroidFactory.GetInstance().AddSmallAsteroids(3, _color, _location);
         }
     }
     else
     {
         _textureRectangle.X += _textureRectangle.Width;
     }
 }
Ejemplo n.º 12
0
        public void Reset()
        {
            FieldObjects = new List <IGameObject>();

            var projectileFactory = ProjectileFactory.GetInstance();
            var asteroidFactory   = AsteroidFactory.GetInstance();

            asteroidFactory.StopIntervaledProduction();

            var player = new Ship(_playerTexture, new Rectangle(0, 0, 130, 210), new Rectangle(140, 0, 20, 67), new Rectangle(168, 2, 20, 10), 0.5f);

            AddPlayer(player);

            asteroidFactory.AddAsteroids(3);
            asteroidFactory.BeginIntervaledProduction(5000);
        }
Ejemplo n.º 13
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));
        }
Ejemplo n.º 14
0
        private GameField(ContentManager content)
        {
            _ready             = false;
            _texture           = content.Load <Texture2D>("Sprites/StarField");
            _playerTexture     = content.Load <Texture2D>("Sprites/SpaceShip");
            _collisionDetector = new CollisionDetector();

            var projectileFactory = ProjectileFactory.GetInstance();
            var asteroidFactory   = AsteroidFactory.GetInstance();

            _gameObjectFactories = new List <IGameObjectFactory>()
            {
                asteroidFactory,
                projectileFactory
            };

            Reset();

            MusicEngine.GetInstance().PlayMeditation();
        }
Ejemplo n.º 15
0
    private void CreateAsteroidSpawner()
    {
        var asteroidSpawnerGameObject = Game.Create <GameObject>();

        var asteroidSpawnerTransform = asteroidSpawnerGameObject.AddComponent <Transform>();

        asteroidSpawnerTransform.Position  = new Vector2(0, 0);
        asteroidSpawnerTransform.Scale     = new Vector2(10, 10);
        asteroidSpawnerTransform.Direction = new Vector2(0, 1);

        var asteroidSpawner = asteroidSpawnerGameObject.AddComponent <CooldownSpawner <Asteroid> >();

        asteroidSpawner.Cooldown = 150;

        var asteroidFactory = new AsteroidFactory();

        asteroidFactory.Duplicator = new ChildAsteroidFactory();
        asteroidFactory.Duplicator.Spawned.AddListener((x) => unityAsteroidFactory.OnSpawn(game, x));
        asteroidFactory.Spawned.AddListener((x) => unityAsteroidFactory.OnSpawn(game, x));
        asteroidSpawner.Factory = asteroidFactory;
    }
Ejemplo n.º 16
0
        private void Start()
        {
            _controllerList = new ControllerList();

            var asteroidFactory = new AsteroidFactory();
            var playerFactory   = new PlayerFactory(_data.PlayerData);

            var playerModel = new PlayerModel(playerFactory);
            var inputModel  = new InputModel();
            var pointModel  = new PointModel();
            var pauseModel  = new PauseModel();

            var enemyPool = new EnemyPool(
                _data.EnemyData.AsteroidPoolSize, _data.EnemyData,
                asteroidFactory);

            _controllerList.Add(new InputController(
                                    inputModel.GetInputKeyboard(), inputModel.GetInputMouse(),
                                    inputModel.Pause(), inputModel.Ability()));

            _controllerList.Add(new PlayerController(
                                    _data, inputModel,
                                    playerModel, pauseModel));

            _controllerList.Add(new AsteroidController(
                                    _data.EnemyData, playerModel,
                                    pointModel, asteroidFactory,
                                    enemyPool));

            _controllerList.Add(new UIController(
                                    inputModel, pointModel,
                                    enemyPool, pauseModel));

            _controllerList.Add(new PauseController(
                                    pauseModel));

            _controllerList.Initialize();
        }
Ejemplo n.º 17
0
        private static IEnemy CreateEnemy(string typeEnemies)
        {
            IEnemy enemy = null;

            switch (typeEnemies)
            {
            case "AsteroidView":
                enemy = new AsteroidFactory(_data, _listenerHitShowDamage).Create(new Health(_data.Enemies.Hp));
                break;

            case "CometView":
                enemy = new CometFactory(_data, _listenerHitShowDamage).Create(new Health(_data.Enemies.Hp));
                break;

            case "EnemyShipView":
                enemy = new EnemyShipFactory(_data, _listenerHitShowDamage).Create(new Health(_data.Enemies.Hp));
                break;

            default:
                throw new NullReferenceException("The specified enemy type was not found.");
            }
            return(enemy);
        }
Ejemplo n.º 18
0
        public static Entity CreateAsteroid(AsteroidFactory asteroid, Vector2 position)
        {
            switch (asteroid)
            {
            //Agrego parámetro para agregar posicion random
            case AsteroidFactory.asteroid1:
                return(new Asteroid(position, new Vector2(0.5f, 0.5f), new Vector2(70, 61), 0, "Textures/Entities/Asteroids/Asteroid1.png", 5, 30, 5, new Vector2(60, 60)));

            case AsteroidFactory.asteroid2:
                return(new Asteroid(position, new Vector2(0.5f, 0.5f), new Vector2(76, 63), 0, "Textures/Entities/Asteroids/Asteroid2.png", 15, 30, 3, new Vector2(80, 80)));

            case AsteroidFactory.asteroid3:
                return(new Asteroid(position, new Vector2(0.5f, 0.5f), new Vector2(150, 112), 0, "Textures/Entities/Asteroids/Asteroid3.png", 3, 35, 10, new Vector2(30, 30)));

            case AsteroidFactory.asteroid4:
                return(new Asteroid(position, new Vector2(0.5f, 0.5f), new Vector2(199, 165), 0, "Textures/Entities/Asteroids/Asteroid4.png", 5, 40, 15, new Vector2(50, 50)));

            case AsteroidFactory.asteroid5:
                return(new Asteroid(position, new Vector2(0.5f, 0.5f), new Vector2(106, 96), 0, "Textures/Entities/Asteroids/Asteroid5.png", 10, 45, 10, new Vector2(10, 10)));

            default:
                return(new Asteroid(position, new Vector2(0.5f, 0.5f), new Vector2(70, 61), 0, "Textures/Entities/Asteroids/Asteroid1.png", 5, 30, 5, new Vector2(30, 30)));
            }
        }
Ejemplo n.º 19
0
 void Awake()
 {
     asteroidFactory = GetComponent <AsteroidFactory>();
 }
Ejemplo n.º 20
0
 void Start()
 {
     asteroidFactory = GetComponent <AsteroidFactory>();
 }
Ejemplo n.º 21
0
        internal State Play(GameDatabase db, State gameState, Boss boss, bool bossHasInstance,
                            StatsManager statsManager, GameTime gameTime, Random random)
        {
            State state = gameState;

            if (db.Players.GetAll().Any(s => s.Score >= 10000))
            {
                state = this.EnableBossMode(boss, bossHasInstance,
                                            db, gameState, gameTime);
            }
            else
            {
                for (int i = 0; i < db.Enemies.GetCount(); i++)
                {
                    BulletsFactory.EnemyShoot(db.Bullets, db.Enemies.GetAll()[i]);
                }

                //Creating entities
                EnemyFactory.CreateEnemies(db.Enemies, random);
                AsteroidFactory.CreateAsteroids(db.Asteroids, random);

                ItemFactory.CreateItems(db.Items, db.Enemies.GetAll().Cast <IGameObject>().ToList(), random);
                ItemFactory.CreateItems(db.Items, db.Asteroids.GetAll().Cast <IGameObject>().ToList(), random);

                // Handle collisions between players and enemy objects
                CollisionHandler.CheckForCollision(db.Asteroids.GetAll().Cast <IGameObject>().ToList(), db.Players.GetAll(), db.Explosions.GetAll());
                CollisionHandler.CheckForCollision(db.Enemies.GetAll().Cast <IGameObject>().ToList(), db.Players.GetAll(), db.Explosions.GetAll());

                // Handle collisions between players and enemy items
                CollisionHandler.CheckPlayerItemCollisions(db.Items.GetAll(), db.Players.GetAll());

                ExplosionFactory.CreateExplosion(db.Explosions, db.Enemies.GetAll().Cast <IGameObject>().ToList());
                ExplosionFactory.CreateExplosion(db.Explosions, db.Asteroids.GetAll().Cast <IGameObject>().ToList());

                //Updating entities
                db.Enemies.GetAll().ForEach(e => e.Update(gameTime));
                db.Asteroids.GetAll().ForEach(a => a.Update(gameTime));
                db.Items.GetAll().ForEach(i => i.Update(gameTime));

                // Cleaning with mr.Proper
                EntityCleanerHandler.ClearEnemies(db.Enemies);
                EntityCleanerHandler.ClearAsteroids(db.Asteroids);
                EntityCleanerHandler.ClearExplosion(db.Explosions);
                EntityCleanerHandler.ClearPlayers(db.Players);
            }

            //Update
            db.Bullets.GetAll().ForEach(b => b.Update(gameTime));
            db.Explosions.GetAll().ForEach(e => e.Update(gameTime));

            statsManager.UpdatePlayersStats(db.Players.GetAll());

            //Handle collisions between bullets and gameobjects
            CollisionHandler.CheckPlayerBulletsCollisions(db.Enemies.GetAll().Cast <IGameObject>().ToList(), db.Bullets.GetAll(), db.Players.GetAll(), db.Explosions.GetAll());
            CollisionHandler.CheckPlayerBulletsCollisions(db.Asteroids.GetAll().Cast <IGameObject>().ToList(), db.Bullets.GetAll(), db.Players.GetAll(), db.Explosions.GetAll());
            CollisionHandler.CheckEnemiesBulletsCollisions(db.Bullets.GetAll(), db.Players.GetAll());

            EntityCleanerHandler.ClearBullets(db.Bullets);

            return(state);
        }
Ejemplo n.º 22
0
 void Awake()
 {
     _asteroidFactory = GetComponentInChildren <AsteroidFactory>();
 }
Ejemplo n.º 23
0
 void Awake()
 {
     _asteroidFactory = GetComponentInChildren<AsteroidFactory>();
 }
Ejemplo n.º 24
0
 private void Awake()
 {
     _asteroidFactory = GetComponent <AsteroidFactory>();
     Physics2D.IgnoreLayerCollision(_asteroidLayer, _asteroidLayer);
 }