예제 #1
0
 //------------------------------------------------------------------------------------------------------------------------
 //														Add()
 //------------------------------------------------------------------------------------------------------------------------
 internal void Add(GameObject gameObject)
 {
     if (!_gameObjectsContained.Contains(gameObject))
     {
         _updateManager.Add(gameObject);
         _collisionManager.Add(gameObject);
         _gameObjectsContained.Add(gameObject);
     }
 }
예제 #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            _scene            = new GraphicScene();
            _collisionManager = new CollisionManager();
            _weaponManager    = new WeaponManager();
            _enemyFactory     = new EnemyFactory();

            _player = new Player();
            _scene.Add(_player);
            _collisionManager.Add(_player);
            _weapon = new Weapon(this, _player);

            _bgLayer1       = new ParallaxingBackground();
            _bgLayer2       = new ParallaxingBackground();
            _rectBackground = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

            TouchPanel.EnabledGestures = GestureType.FreeDrag;

            // init our laser
            laserBeams = new EntityList <Laser>(_scene, _collisionManager);

            // Initialize the enemies list
            enemies = new EntityList <Enemy>(_scene, _collisionManager);

            //used to determine how fast the enemies will respawn.
            enemySpawnTime = TimeSpan.FromSeconds(1.0f);

            // init our random number generator
            random = new Random();

            explosions = new EntityList <Explosion>(_scene, _collisionManager);

            base.Initialize();

            ConfigurationManager.logConfiguration();

            var task2 = readJson("enemies");

            task2.ContinueWith(task =>
            {
                var content = task.Result;

                try
                {
                    JsonArray config = (JsonArray)JsonArray.Parse(content);
                    _enemyFactory.Initialize(config);
                }
                catch (Exception e)
                {
                }
            });
        }
예제 #3
0
        protected void UpdatePowerup(GameTime gameTime)
        {
            if (powerup != null)
            {
                powerup.Update(gameTime);

                if (!powerup.Active)
                {
                    _collisionManager.Remove(powerup);
                    _scene.Remove(powerup);
                    powerup = null;
                    previousPowerupSpawnTime = gameTime.TotalGameTime;


                    powerupSpawnTime = TimeSpan.FromSeconds(powerupMinSpawnTime + (powerupMaxSpawnTime - powerupMinSpawnTime) * random.NextDouble());
                }
            }
            else
            {
                if (gameTime.TotalGameTime - previousPowerupSpawnTime > powerupSpawnTime)
                {
                    previousPowerupSpawnTime = gameTime.TotalGameTime;

                    // randomly generate the postion of the enemy
                    Vector2 position = new Vector2(
                        random.Next(100, GraphicsDevice.Viewport.Width - 100),
                        random.Next(100, GraphicsDevice.Viewport.Height - 100)
                        );


                    var weapon = _weaponManager.GetRandomWeapon(this, _player);

                    powerup = new Powerup(weapon.GetPowerupAnimation(), position, weapon);
                    _collisionManager.Add(powerup);
                    _scene.Add(powerup);
                }
            }
        }
예제 #4
0
        /// <summary>
        /// Creates the GameScene scene
        /// </summary>
        /// <param name="game">Current game reference</param>
        /// <param name="spriteBatch">spriteBatch to draw scene</param>
        public GameScene(Game game, SpriteBatch spriteBatch) : base(game)
        {
            this.spriteBatch = spriteBatch;

            inputNameString = new KbInputString(Game, spriteBatch,
                                                resources.MonoFont,
                                                new Vector2(GraphicsDevice.Viewport.Width / 2f,
                                                            GraphicsDevice.Viewport.Height / 2f + resources.MonoFont.LineSpacing * 2),
                                                Color.Wheat,
                                                SimpleString.TextAlignH.Middle);

            // Add the infinite terrain (which also does gas cans)
            var tempTerrain = new Terrain(Game, spriteBatch,
                                          GraphicsDevice.Viewport.Bounds.Width / 3f, 50,
                                          80, 1, 0, 4,
                                          ColourSchemes.brown, new Vector2(0, GraphicsDevice.Viewport.Bounds.Height * 0.75f));

            Components.Add(terrain = new InfiniteTerrain(Game, spriteBatch, tempTerrain, 3, 3));
            // Add our UFO
            this.Components.Add(ufo = new UFO(Game, spriteBatch,
                                              new Vector2(50, terrain.ExtremeHeightAt(25, 50, false))));

            // Add distance string
            Components.Add(
                distance = new SimpleString(game, spriteBatch,
                                            resources.BoldFont,
                                            new Vector2(20, 20),
                                            "Distance: 0",
                                            ColourSchemes.pink));

            // Create Speed meter & string
            Components.Add(
                meterSpeed = new MeterBar(
                    new SimpleString(game, spriteBatch,
                                     resources.RegularFont,
                                     new Vector2(215, 70),
                                     "", Color.Black,
                                     SimpleString.TextAlignH.Right),
                    new Rectangle(20, 70, 200, resources.RegularFont.LineSpacing),
                    0, ufo.MaxVelocity));
            Components.Add(new SimpleString(game, spriteBatch,
                                            resources.RegularFont,
                                            new Vector2(25, 70),
                                            "Speed", Color.Black));

            // Create Gas meter & string
            Components.Add(
                meterGas = new MeterBar(
                    new SimpleString(game, spriteBatch,
                                     resources.RegularFont,
                                     new Vector2(215, 120),
                                     "", Color.Black,
                                     SimpleString.TextAlignH.Right),
                    new Rectangle(20, 120, 200, resources.RegularFont.LineSpacing),
                    0, ufo.Gas));
            Components.Add(new SimpleString(game, spriteBatch,
                                            resources.RegularFont,
                                            new Vector2(25, 120),
                                            "Gas: ", Color.Black));


            // Create collision manager
            Components.Add(collisionManager = new CollisionManager(Game));
            collisionManager.Add(ufo);

            // Create explosion
            explosion = new Explosion(game, spriteBatch, resources.Explosion, Vector2.Zero, 3);
            this.Components.Add(explosion);

            // Death sound
            deathSouthIns        = resources.deathSound.CreateInstance();
            deathSouthIns.Volume = .2f;
        }