Ejemplo n.º 1
0
        public override void Update(GameTime gameTime, Spaceman player, BlackHole blackHole, Weapon weapon1, Weapon weapon2, InventoryManager inventory, Unicorn[] unicorns)
        {
            //resting stage
            if (_restTimer >= TimeSpan.Zero)        //not started yet
            {
                _restTimer -= gameTime.ElapsedGameTime;
                if (_restTimer < TimeSpan.Zero)
                {
                    setPosition(blackHole.Position, true);        //set portal position
                }
                return;         //not ready to start
            }

            //Waiting for previous or already complete
            if (!Active) { return; }

            //active stage
            //spawning
            //spawn particles if still spawning enemies
            if (_enemySpawnIndex < _numEnemies && SpawnEnable)
            {
                _portalEffect.Spawn(_spawnLocation, 90.0f + _portalAngle, gameTime.ElapsedGameTime, Vector2.Zero);
                _portalEffect.Spawn(_spawnLocation, -90.0f + _portalAngle, gameTime.ElapsedGameTime, Vector2.Zero);
                trySpawnEnemy(gameTime.ElapsedGameTime, blackHole.Position);
            }
            _portalAngle += (float)gameTime.ElapsedGameTime.TotalSeconds * c_portalRotationRate;
            _portalEffect.Update(gameTime);

            //update units
            base.Update(gameTime, player, blackHole, weapon1, weapon2, inventory, unicorns);
        }
Ejemplo n.º 2
0
        Wave[] _waves; //collection of all trickle waves and active burst wave

        #endregion Fields

        #region Constructors

        public Level(ContentManager content, int levelNumber, InventoryManager im)
            : base(content, false, "Level")
        {
            LevelData data = DataManager.GetData<LevelData>(String.Format(c_levelNameFormat, levelNumber));
            _levelBounds = new Rectangle(0, 0, data.Width, data.Height);
            _player = new Spaceman(new Vector2(data.PlayerX, data.PlayerY));
            _blackHole = new BlackHole(data.BlackHole);
            //store active burst wave as last tricklewave
            _waves = new Wave[data.TrickleWaves.Length + data.BurstWaves.Length];
            _camera = new Camera2D(_player.Position, _levelBounds.Width, _levelBounds.Height);
            //construct waves
            for (int i = 0; i < data.TrickleWaves.Length; i++)
            {
                _waves[i] = new TrickleWave(data.TrickleWaves[i], _levelBounds);
            }
            for (int i = 0; i < data.BurstWaves.Length; i++)
            {
                BurstWave prevWave = (i == 0) ? null : (BurstWave)_waves[i + data.TrickleWaves.Length - 1];
                _waves[i + data.TrickleWaves.Length] = new BurstWave(data.BurstWaves[i], _levelBounds, prevWave);
            }
            //Test code to set weapons 1-6 to created weapons
            im.setPrimaryGadget(new Gadget("Teleporter", this));
            im.setSecondaryGadget(new Gadget("Stopwatch", this));
            im.setSlot(1, new ThrowableWeapon("Cryonade", _player));

            if (data.Unicorns == null)
            {
                _unicorns = new Unicorn[0];
            }
            else
            {
                _unicorns = new Unicorn[data.Unicorns.Length];
                for (int j = 0; j < data.Unicorns.Length; j++)
                {
                    _unicorns[j] = new Unicorn(data.Unicorns[j]);
                }
            }

            _primaryGadget = im.getPrimaryGadget();
            _secondaryGadget = im.getSecondaryGadget();
            _inventoryManager = im;

            userInterface = new Hud(_player, _blackHole, _waves);

            _cursorTextureCenter = new Vector2(s_CursorTexture.Width / 2 , s_CursorTexture.Height / 2);
            selectRandomWeapons();
        }
Ejemplo n.º 3
0
        public Level(int levelNumber, InventoryManager im)
            : base(false)
        {
            LevelData data = DataLoader.LoadLevel(levelNumber);
            _levelBounds = new Rectangle(0, 0, data.Width, data.Height);
            _player = new Spaceman(data.PlayerStartLocation);
            _blackHole = data.BlackHole;
            _waves = new Wave[data.TrickleWaveData.Length + data.BurstWaveData.Length];
            _camera = new Camera2D(_player.Position, _levelBounds.Width, _levelBounds.Height);
            //construct waves
            for (int i = 0; i < data.TrickleWaveData.Length; i++)
            {
                _waves[i] = new Wave(data.TrickleWaveData[i], true, _levelBounds);
            }
            for (int i = 0; i < data.BurstWaveData.Length; i++)
            {
                _waves[i + data.TrickleWaveData.Length] = new Wave(data.BurstWaveData[i], false, _levelBounds);
            }
            //Test code to set weapons 1-6 to created weapons
            im.setPrimaryWeapon(new ProjectileWeapon("Rocket", _player));
            im.setSecondaryWeapon(new ThrowableWeapon("Cryonade", _player));
            im.setPrimaryGadget(new Gadget("Teleporter", this));
            im.setSlot(1, new ThrowableWeapon("Cryonade", _player));

            //Set Weapon holders in level
            _primaryWeapon = im.getPrimaryWeapon();
            _secondaryWeapon = im.getSecondaryWeapon();

            _unicorns = new Unicorn[data.Unicorns.Length];
            for (int j = 0; j < data.Unicorns.Length; j++)
            {
                _unicorns[j] = new Unicorn(data.Unicorns[j]);
            }

            _foodCarts = data.FoodCarts;

            _primaryGadget = im.getPrimaryGadget();
            _inventoryManager = im;

            userInterface = new GUI(_player, _blackHole);
        }
Ejemplo n.º 4
0
        public override void Update(GameTime gameTime, InputManager input, InventoryManager im)
        {
            _mousePos = input.MouseLocation;
            input.SetCameraOffset(_camera.Position);
            handleInput(input);
            _camera.Update(gameTime, _player.Position);
            //if player is outside static area rectangle, call update on camera to update position of camera until
            //the player is in the static area rectangle or the camera reaches the _levelbounds, in which case,
            //the camera does not move in that direction (locks)

            /*
            if ((_player.HitRect.Bottom > _cameraLock.Bottom && _player.HitRect.Top < _cameraLock.Top &&
            _player.HitRect.Right < _cameraLock.Right && _player.HitRect.Left > _cameraLock.Left) && (player is in level bounds)
            {
             * _camera.Update(gameTime);
             * _cameraLock.X = (int)(_camera.position.X + (_camera.getViewportWidth() * 0.2));
             * _cameraLock.Y = (int)(_camera.position.Y + (_camera.getViewportHeight() * 0.2));
             *
            }*/

            if (_timeSlowed)
                gameTime = new GameTime(gameTime.TotalGameTime,
                    TimeSpan.FromSeconds((float)gameTime.ElapsedGameTime.TotalSeconds / 2));

            if (_blackHole.State == BlackHole.BlackHoleState.Pulling)
            {
                _blackHole.ApplyToUnit(_player, gameTime);
            }
            _player.Update(gameTime, _levelBounds);
            _primaryGadget.Update(gameTime);
            _blackHole.Update(gameTime);

            if (_blackHole.State == BlackHole.BlackHoleState.Overdrive)
            {
                foreach (Wave w in _waves)
                {
                    w.SpawnEnable = false;
                }
                foreach (Unicorn u in _unicorns)
                {
                    u.SpawnEnable = false;
                }
            }

            for (int i = 0; i < _waves.Length; i++)
            {
                _waves[i].Update(gameTime, _player, _blackHole, _primaryWeapon, _secondaryWeapon, _inventoryManager, _unicorns);
                //check cross-wave collisions
                if (_waves[i].Active)
                {
                    for (int j = i + 1; j < _waves.Length; j++)
                    {
                        _waves[i].CheckAndApplyCollisions(_waves[j]);
                    }
                }
            }

            for (int i = 0; i < _unicorns.Length; i++)
            {
                _unicorns[i].Update(gameTime, _levelBounds, _blackHole.Position, _player.Position, _player.HitRect);
                _unicorns[i].CheckAndApplyCollision(_player, gameTime);
                _blackHole.TryEatUnicorn(_unicorns[i], gameTime);
                for (int j = 0; j < _foodCarts.Length; j++)
                {
                    _unicorns[i].CheckAndApplyCollision(_foodCarts[j], gameTime);
                }
            }

            for (int i = 0; i < _foodCarts.Length; i++)
            {
                _foodCarts[i].Update(gameTime, _levelBounds, _blackHole.Position);
                _primaryWeapon.CheckAndApplyCollision(_foodCarts[i], gameTime.ElapsedGameTime);
                _secondaryWeapon.CheckAndApplyCollision(_foodCarts[i], gameTime.ElapsedGameTime);
                _inventoryManager.CheckCollisions(gameTime, _foodCarts[i]);
                _blackHole.ApplyToUnit(_foodCarts[i], gameTime);
            }

            //Update Weapons
            _primaryWeapon.Update(gameTime);
            _secondaryWeapon.Update(gameTime);
            //update all items
            _inventoryManager.Update(gameTime, input);
        }
Ejemplo n.º 5
0
 public override void Update(GameTime gameTime, InputManager input, InventoryManager im)
 {
 }
Ejemplo n.º 6
0
 public Shop(ContentManager content, InventoryManager im)
     : base(content, false)
 {
     _inventoryManager = im;
     _background = Content.Load<Texture2D>("gui/Shop_GUI");
 }
Ejemplo n.º 7
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()
        {
            Window.SetPosition(new Point(0, 0));
            _inputManager = new InputManager();
            _weaponManager = new InventoryManager();
            gamestate = GameStates.Menu;

            base.Initialize();
        }
Ejemplo n.º 8
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()
        {
            _inputManager = new InputManager();
            _weaponManager = new InventoryManager();
            gamestate = GameStates.Menu;

            base.Initialize();
        }
Ejemplo n.º 9
0
        private void handleInput(InputManager input, InventoryManager wm)
        {
            // Allows the game to exit
            if (input.Exit)
                this.PopState = true;

                if (input.SelectUp)
                {
                    this.Iterator--;
                }

                else if (input.SelectDown)
                {
                    this.Iterator++;
                }

                if (input.Confirm)
                {
                    if (this.Iterator == 0)
                    {
                        //load game
                        ReplaceState = new Level(1, wm);
                    }
                    else if (this.Iterator == 1)
                    {
                        //call method to load settings
                        this.PopState = true;

                    }

                    else if (this.Iterator == 2)
                    {
                        //quit game
                        this.PopState = true;
                    }

                    this.Iterator = 0;
                }
                    //Add more select menu logic here as menu items increase
        }
Ejemplo n.º 10
0
 public override void Update(GameTime gameTime, InputManager input, InventoryManager wm)
 {
     handleInput(input, wm);
     //update logic goes here
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Update wave, updating behavior of all enemies.
        /// Check collisions against player and self, but not other waves
        /// Check weapon collisions against player
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="player"></param>
        /// <param name="blackHole"></param>
        /// <param name="weapon1"></param>
        /// <param name="weapon2"></param>
        public void Update(GameTime gameTime, Spaceman player, 
            BlackHole blackHole, Weapon weapon1, Weapon weapon2, InventoryManager inventory, Unicorn[] unicorns)
        {
            if (_startTimer >= TimeSpan.Zero)        //not started yet
            {
                _startTimer -= gameTime.ElapsedGameTime;
                if (_startTimer < TimeSpan.Zero)
                {
                    Active = true;      //activate if start timer complete
                    setPosition(blackHole.Position, _levelBounds.Width, _levelBounds.Height);        //set first spawn position
                }
            }

            if (_portalEffect != null)
                _portalEffect.Update(gameTime);

            if (!Active)
                return;     //don't update if not active

            //play particle effect if existant
            if (_portalEffect != null)
            {
                //spawn particles if still spawning enemies
                if (_spawnedSoFar < _numEnemies && SpawnEnable)
                {
                    _portalEffect.Spawn(_spawnLocation, 90.0f + _portalAngle, gameTime.ElapsedGameTime, Vector2.Zero);
                    _portalEffect.Spawn(_spawnLocation, -90.0f + _portalAngle, gameTime.ElapsedGameTime, Vector2.Zero);
                }
                _portalAngle += (float)gameTime.ElapsedGameTime.TotalSeconds * PORTAL_ROTATION_RATE;
                if (_activationDelay >= TimeSpan.Zero)      //gradually increase particle intensity
                {
                    _portalEffect.IntensityFactor = 1.0f - (float)_activationDelay.TotalSeconds / ACTIVATION_DELAY_SECONDS;
                }
            }

            //only start spawning if activation delay is elapsed.
            //Otherwise, just start particleeffect and don't spawn enemies yet
            if (_activationDelay > TimeSpan.Zero)
            {
                _activationDelay -= gameTime.ElapsedGameTime;
                return;
            }

            //run spawning logic
            spawn(gameTime, _spawnLocation, blackHole.Position);

            //update all enemies in wave
            bool allDestroyed = true;   //check if all enemies destroyed
            for (int i = _enemies.Length - 1; i >= 0; i--)
            {
                if (!_enemies[i].Updates)
                    continue;   //don't update units that shouldn't be updated

                allDestroyed = false;       //found one that isn't destroyed

                for (int j = i - 1; j >= 0; j--)
                {
                    //check collision against other enemies in same wave
                    _enemies[i].CheckAndApplyUnitCollision(_enemies[j]);
                }

                for (int j = 0 ; j < unicorns.Length ; j++)
                {
                    //check collision against unicorns
                    unicorns[j].CheckAndApplyCollision(_enemies[i], gameTime);
                }
                _enemies[i].CheckAndApplyUnitCollision(player);
                _enemies[i].CheckAndApplyWeaponCollision(player, gameTime.ElapsedGameTime);

                _enemies[i].Update(gameTime, player.Position, Vector2.Zero, _levelBounds);
                blackHole.ApplyToUnit(_enemies[i], gameTime);
                weapon1.CheckAndApplyCollision(_enemies[i], gameTime.ElapsedGameTime);
                weapon2.CheckAndApplyCollision(_enemies[i], gameTime.ElapsedGameTime);
                inventory.CheckCollisions(gameTime, _enemies[i]);
            }
            //stay active unless it is not a trickle wave and all enemies are destroyed
            Active = Active && (_isTrickleWave || !allDestroyed);
        }
Ejemplo n.º 12
0
 public abstract void Update(GameTime gameTime, InputManager input, InventoryManager im);
Ejemplo n.º 13
0
        /// <summary>
        /// Update wave, updating behavior of all enemies.
        /// Check collisions against player and self, but not other waves
        /// Check weapon collisions against player
        /// </summary>
        /// <param name="gameTime"></param>
        /// <param name="player"></param>
        /// <param name="blackHole"></param>
        /// <param name="weapon1"></param>
        /// <param name="weapon2"></param>
        public virtual void Update(GameTime gameTime, Spaceman player,
            BlackHole blackHole, Weapon weapon1, Weapon weapon2, InventoryManager inventory, Unicorn[] unicorns)
        {
            if (!Active) { return; }

            //update all enemies in wave
            bool allDestroyed = true;   //check if all enemies destroyed
            for (int i = _bodies.Length - 1; i >= 0; i--)
            {
                if (_bodies[i].UnitLifeState != PhysicalBody.LifeState.Destroyed)
                {
                    allDestroyed = false;       //found one that isn't destroyed
                }

                if (!_bodies[i].Updates)
                    continue;   //don't update units that shouldn't be updated

                for (int j = i - 1; j >= 0; j--)
                {
                    //check collision against other enemies in same wave
                    _bodies[i].CheckAndApplyUnitCollision(_bodies[j]);
                    if (_bodies[i] is Obstacle)
                    {
                        (_bodies[i] as Obstacle).CheckAndApplyEffect(_bodies[j], gameTime.ElapsedGameTime);
                    }
                }

                for (int j = 0; j < unicorns.Length; j++)
                {
                    //check collision against unicorns
                    unicorns[j].CheckAndApplyCollision(_bodies[i], gameTime);
                }

                _bodies[i].CheckAndApplyUnitCollision(player);

                if (_bodies[i] is Enemy)
                {
                    (_bodies[i] as Enemy).CheckAndApplyWeaponCollision(player, gameTime.ElapsedGameTime);
                    (_bodies[i] as Enemy).Update(gameTime, player.Position, blackHole, _levelBounds);
                }
                else
                {
                    (_bodies[i] as Obstacle).Update(gameTime, _levelBounds);
                    (_bodies[i] as Obstacle).CheckAndApplyEffect(player, gameTime.ElapsedGameTime);
                }

                blackHole.ApplyToUnit(_bodies[i], gameTime);
                if (weapon1 != null)
                {
                    weapon1.CheckAndApplyCollision(_bodies[i], gameTime.ElapsedGameTime);
                }
                if (weapon2 != null)
                {
                    weapon2.CheckAndApplyCollision(_bodies[i], gameTime.ElapsedGameTime);
                }
                inventory.CheckCollisions(gameTime, _bodies[i]);
            }

            trySpawnObstacle(gameTime.ElapsedGameTime, blackHole.Position);

            _allDestroyed = allDestroyed;
        }
Ejemplo n.º 14
0
        public override void Update(GameTime gameTime, Spaceman player, BlackHole blackHole, Weapon weapon1, Weapon weapon2, InventoryManager inventory, Unicorn[] unicorns)
        {
            if (_startTimer > TimeSpan.Zero)
            {   //not started yet
                _startTimer -= gameTime.ElapsedGameTime;
                return;
            }
            if (_endTimer <= TimeSpan.Zero)
            {
                SpawnEnable = false;
            }
            else
            {
                _endTimer -= gameTime.ElapsedGameTime;
            }

            if (trySpawnEnemy(gameTime.ElapsedGameTime, blackHole.Position))
            {   //reposition if enemy spawned successfully
                setPosition(blackHole.Position, false);
            }

            //cycle through enemy slots
            _enemySpawnIndex = (_enemySpawnIndex + 1) % _numEnemies;

            //update enemies
            base.Update(gameTime, player, blackHole, weapon1, weapon2, inventory, unicorns);
        }