Beispiel #1
0
        public void UpdateEnemies(CVGameTime gameTime)
        {
            // Update the Enemies
            for (int i = ActiveEnemies.Count - 1; i >= 0; i--)
            {
                ActiveEnemies[i].Update(gameTime);

                if (ActiveEnemies[i].Active == false)
                {
                    // If not active and health <= 0
                    //if (ActiveEnemies[i].Health <= 0 && !ActiveEnemies[i].IsDead)
                    //{
                    //    // Add an explosion
                    //    AddExplosion(ActiveEnemies[i].WorldPosition, ActiveEnemies[i].ExplosionAnimation, ActiveEnemies[i].ExplosionSound);
                    //    ActiveEnemies[i].Die(gameTime);

                    //    // Play the explosion sound


                    //    //Add to the player's score
                    //    //score += enemies[i].Value;
                    //}
                    ActiveEnemies.RemoveAt(i);
                }
            }
        }
 public override void Die(CVGameTime gameTime)
 {
     CurrentStage.AddExplosion(this.BoundingBox().Center.ToVector() - new Vector2(ExplosionAnimation.FrameWidth / 2, ExplosionAnimation.FrameHeight / 2), ExplosionAnimation, ExplosionSound);
     IsDead = true;
     VulnerableToBullets  = false;
     CollisionIsHazardous = false;
 }
        public override void Die(CVGameTime gameTime)
        {
            //soundDestroyed.Play();
            ExplosionSound.Play();

            base.Die(gameTime);
        }
Beispiel #4
0
        public override void Die(CVGameTime gameTime)
        {
            IsDead = true;
            Active = false;
            Vector2 firstExplosionPosition = this.WorldPosition;

            CurrentStage.AddExplosion(firstExplosionPosition + new Vector2(0, 0), ExplosionAnimation.CreateCopy(), ExplosionSound, 0);
            CurrentStage.AddExplosion(firstExplosionPosition + new Vector2(-15, -10), ExplosionAnimation.CreateCopy(), ExplosionSound, 100);
            CurrentStage.AddExplosion(firstExplosionPosition + new Vector2(-15, 10), ExplosionAnimation.CreateCopy(), null, 200);
            CurrentStage.AddExplosion(firstExplosionPosition + new Vector2(5, -10), ExplosionAnimation.CreateCopy(), ExplosionSound, 300);
            CurrentStage.AddExplosion(firstExplosionPosition + new Vector2(5, 10), ExplosionAnimation.CreateCopy(), null, 400);
            CurrentStage.AddExplosion(firstExplosionPosition + new Vector2(25, -10), ExplosionAnimation.CreateCopy(), ExplosionSound, 500);
            CurrentStage.AddExplosion(firstExplosionPosition + new Vector2(25, 10), ExplosionAnimation.CreateCopy(), null, 600);
            CurrentStage.AddExplosion(firstExplosionPosition + new Vector2(45, -10), ExplosionAnimation.CreateCopy(), ExplosionSound, 700);
            CurrentStage.AddExplosion(firstExplosionPosition + new Vector2(45, 10), ExplosionAnimation.CreateCopy(), null, 800);
            CurrentStage.AddExplosion(firstExplosionPosition + new Vector2(65, -10), ExplosionAnimation.CreateCopy(), ExplosionSound, 900);
            CurrentStage.AddExplosion(firstExplosionPosition + new Vector2(65, 10), ExplosionAnimation.CreateCopy(), null, 1000);

            foreach (var tile in CurrentStage.StageTiles.Where(t => t.DestructionLayer1GID > 0))
            {
                tile.Status = StageTile.TileStatus.Destroyed;
            }

            CurrentStage.StartComplete(gameTime, this);
        }
Beispiel #5
0
        public override void Move(CVGameTime gameTime)
        {
            if (_reloadTimeRemaining > 0)
            {
                _reloadTimeRemaining -= gameTime.ElapsedGameTime.TotalMilliseconds;

                if (_reloadTimeRemaining <= 0)
                {
                    _shotsRemaining = 3;
                }
            }
            if (_reloadTimeRemaining <= 0)
            {
                if (_shotsRemaining > 0)
                {
                    var elapsedTime = gameTime.ElapsedGameTime.TotalMilliseconds;

                    if (_recoilTimeRemaining > 0)
                    {
                        _recoilTimeRemaining -= elapsedTime;
                        if (_recoilTimeRemaining < 0)
                        {
                            _recoilTimeRemaining    = 0;
                            _recoveryTimeRemaining += _recoilTimeRemaining;
                            elapsedTime             = _recoilTimeRemaining * -1; // keep the difference to carry into recovery time to be decreased
                        }
                        else
                        {
                            elapsedTime = 0f;
                        }
                    }
                    if (_recoveryTimeRemaining > 0)
                    {
                        _recoveryTimeRemaining -= elapsedTime;
                    }

                    if (_recoilTimeRemaining <= 0 && _recoveryTimeRemaining <= 0)
                    {
                        // target
                        Player nearestPlayer = (Player)TargetingLogic.FindNearest(this.BoundingBox().Center.ToVector(), CurrentStage.Players);

                        // aim
                        this.direction    = nearestPlayer.WorldPosition.X < this.WorldPosition.X ? Player.PlayerDirection.Left : Player.PlayerDirection.Right;
                        _targetClockAngle = TargetingLogic.FindClockPosition(this.BoundingBox().Center.ToVector(), nearestPlayer.WorldPosition);

                        // fire
                        _gun.AddProjectile(this.CurrentStage, GunBarrelLocation(), _targetClockAngle * 30, 1.2f);
                        _shotsRemaining--;

                        _recoilTimeRemaining   = _recoilTime;
                        _recoveryTimeRemaining = _recoveryTime;
                    }
                }
                else
                {
                    // out of shots, time to reload
                    _reloadTimeRemaining = _reloadTime;
                }
            }
        }
        public override void Update(CVGameTime gameTime)
        {
            Random r;

            if (_spawnedEnemy != null && _spawnedEnemy.Active == false)
            {
                _spawnedEnemy   = null;
                r               = new Random();
                _enemySpawnTime = r.Next(200, 2000);
            }
            if (!this.CurrentStage.Game.LaunchParameters.ContainsKey("DoNotSpawnEnemies"))
            {
                if (_spawnedEnemy == null && CurrentStage.ScreenCoordinates().Intersects(VirtualBox()) && VirtualBox().Right > CurrentStage.ScreenCoordinates().Right)
                {
                    _enemySpawnTime -= gameTime.ElapsedGameTime.TotalMilliseconds;

                    if (_enemySpawnTime < 0)
                    {
                        Vector2 spawnLocation =
                            new Vector2(this.VirtualBox().Left + (this.CurrentStage.ScreenCoordinates().Right - this.VirtualBox().Left),
                                        VirtualBox().Bottom);

                        CurrentStage.AddEnemy(_enemyType, spawnLocation);

                        r = new Random();
                        // TODO: rework this so that enemies spawn more similarly to classic Contra
                        _enemySpawnTime = Math.Sqrt(r.Next(50000, 4000000));
                    }

                    base.Update(gameTime);
                }
            }
        }
Beispiel #7
0
 public void SustainDamage(CVGameTime gameTime, int damage)
 {
     _health -= damage;
     if (_health <= 0)
     {
         Die(gameTime);
     }
 }
Beispiel #8
0
        public override void Die(CVGameTime gameTime)
        {
            ExplosionSound.Play();
            var item = new PlayerItem(_contentManager, WorldPosition, CurrentStage, _itemType);

            CurrentStage.ActiveEnemies.Add(item);

            base.Die(gameTime);
        }
        public override void ApplyPhysics(CVGameTime gameTime)
        {
            base.ApplyPhysics(gameTime);

            if (!this.IsJumping && this.IsOnGround)
            {
                this.Velocity.X = 0;
            }
        }
Beispiel #10
0
        public void SpawnEnemies(CVGameTime gameTime)
        {
            //if (!Game.LaunchParameters.ContainsKey("DoNotSpawnRandomEnemies"))
            //{
            //    // randomly spawwn foot soldiers

            //    if (gameTime.TotalGameTime - _previousSpawnTime > _enemySpawnTime && ActiveEnemies.Count <= 3)
            //    {
            //        _previousSpawnTime = gameTime.TotalGameTime;

            //        float fVerticalSpawnLocation = 0;
            //        float fHorizontalSpawnLocation = CameraPosition.X + Game.iScreenModelWidth;
            //        if (CameraPosition.X + Game.iScreenModelWidth < this.MapWidth * this.TileWidth)
            //        {
            //            int iYTile = 0;
            //            for (iYTile = 0; iYTile < MapHeight; iYTile++)
            //            {

            //                if (this.getStageTileByGridPosition((int)fHorizontalSpawnLocation / TileWidth, iYTile).IsPlatform())
            //                {
            //                    fVerticalSpawnLocation = iYTile * TileHeight;
            //                    break;
            //                }
            //            }
            //        }

            //        Vector2 enemySpawnPosition = new Vector2(CameraPosition.X + Game.iScreenModelWidth, fVerticalSpawnLocation);

            //        if (this.Game.CurrentGame == Game.GameType.Contra)
            //        {
            //            AddEnemy("EnemyFootSoldier", enemySpawnPosition);
            //        }
            //        else
            //        {
            //            AddEnemy("Zombie", enemySpawnPosition);
            //        }


            //        Random r = new Random();
            //        _enemySpawnTime = TimeSpan.FromMilliseconds(r.Next(200, 1500));
            //    }
            //}

            for (int i = waitingEnemies.Count - 1; i >= 0; i--)
            {
                Enemy e = waitingEnemies[i];
                if (e.SpawnConditionsMet())
                {
                    ActiveEnemies.Add(e);
                    waitingEnemies.Remove(e);
                }
            }
        }
Beispiel #11
0
        private void UpdateProjectiles(CVGameTime gameTime, List <Projectile> lstProjectiles)
        {
            // Update the Projectiles
            for (int i = lstProjectiles.Count - 1; i >= 0; i--)
            {
                lstProjectiles[i].Update(gameTime, _currentStage.CameraPosition);

                if (lstProjectiles[i].Active == false)
                {
                    lstProjectiles.RemoveAt(i);
                }
            }
        }
Beispiel #12
0
 private void UpdateStageObjects(CVGameTime gameTime, List <StageObject> lStageObjects)
 {
     for (int i = lStageObjects.Count - 1; i >= 0; i--)
     {
         if (lStageObjects[i].Active)
         {
             lStageObjects[i].Update(gameTime);
         }
         else
         {
             lStageObjects.RemoveAt(i);
         }
     }
 }
Beispiel #13
0
        protected virtual float DoJump(float velocityY, CVGameTime gameTime)
        {
            float launchVelocity = 0f;

            if (IsDying)
            {
                launchVelocity = JumpLaunchVelocityDying;
            }
            else
            {
                launchVelocity = JumpLaunchVelocity;
            }


            // If the player wants to jump
            if (this.IsJumping || this.JumpInProgress)
            {
                // Begin or continue a jump
                if ((!this.WasJumping && this.IsOnGround) || this.JumpTime > 0.0f)
                {
                    this.JumpTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
                    //sprite.PlayAnimation(jumpAnimation);
                }

                // If we are in the ascent of the jump
                if (0.0f < this.JumpTime && this.JumpTime <= MaxJumpTime)
                {
                    // Fully override the vertical velocity with a power curve that gives players more control over the top of the jump
                    velocityY = launchVelocity * (1.0f - (float)Math.Pow(this.JumpTime / MaxJumpTime, Player.JumpControlPower));
                }
                else
                {
                    // Reached the apex of the jump
                    this.JumpTime = 0.0f;
                }
            }
            else
            {
                // Continues not jumping or cancels a jump in progress
                this.JumpTime = 0.0f;
            }
            this.WasJumping = this.IsJumping;

            return(velocityY);
        }
Beispiel #14
0
        public void StartComplete(CVGameTime gameTime, Enemy boss)
        {
            // destroy all enemies on screen
            for (int i = 0; i < this.ActiveEnemies.Count; i++)
            {
                if (boss != this.ActiveEnemies[i])
                {
                    this.ActiveEnemies[i].Die(gameTime);
                }
            }

            MediaPlayer.Stop();

            ProgresstoNextLevel = true;

            // from here, the Update method will wait until explosions are done, pause for a moment of silence of the awesomeness that just occurred, and then play the fanfare song.
            // then, the update method will wait for that song to be finished, and game will end.
        }
Beispiel #15
0
        public void Update(CVGameTime gameTime)
        {
            UpdateAnimations(gameTime);

            Move(gameTime);

            ApplyPhysics(gameTime);

            // if enemy goes off-screen or health runs out, deactivate
            if (this.BoundingBox().Right < CurrentStage.CameraPosition.X || this.BoundingBox().Left > CurrentStage.CameraPosition.X + Game.iScreenModelWidth + (this.BoundingBox().X - this.WorldPosition.X))
            {
                Active = false;
            }
            else if (_health <= 0 && !IsDead)
            {
                Die(gameTime);
            }
        }
Beispiel #16
0
        public override void Move(CVGameTime gameTime)
        {
            _elapsedOpenCloseTime += gameTime.ElapsedGameTime.Milliseconds;

            if (_elapsedOpenCloseTime > FrameOpenCloseTime && (_currentOpenCloseFrame == 0 || _currentOpenCloseFrame == 2))
            {
                _elapsedOpenCloseTime -= FrameOpenCloseTime;
                _currentOpenCloseFrame = 1;
                _opening = !_opening;
            }
            else if (_elapsedOpenCloseTime > FrameOpenCloseAnimationTime && _currentOpenCloseFrame == 1)
            {
                _elapsedOpenCloseTime  -= FrameOpenCloseAnimationTime;
                _currentOpenCloseFrame += (_opening ? 1 : -1);
            }

            BulletProof = _currentOpenCloseFrame > 0 ? false : true;
        }
Beispiel #17
0
        private void UpdateExplosions(CVGameTime gameTime)
        {
            for (int i = _explosions.Count - 1; i >= 0; i--)
            {
                _explosions[i].Update(gameTime);
                if (_explosions[i].Active == false)
                {
                    _explosions.RemoveAt(i);
                }
            }

            for (int i = _explosionsounds.Count - 1; i >= 0; i--)
            {
                if (_explosionsounds[i].State == SoundState.Stopped)
                {
                    _explosionsounds.RemoveAt(i);
                }
            }
        }
Beispiel #18
0
        public virtual void ApplyPhysics(CVGameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            Vector2 previousWorldPosition = this.WorldPosition;

            previousPosition = this.WorldPosition;

            // Get Thumbstick Controls
            //this.Velocity.X = this.currentGamePadState.ThumbSticks.Left.X * this.MaxGroundVelocity;
            //Velocity.X = movement * elapsed;

            this.Velocity.Y = MathHelper.Clamp(this.Velocity.Y + GravityAcceleration * elapsed, -MaxFallVelocity, MaxFallVelocity);
            this.Velocity.Y = DoJump(this.Velocity.Y, gameTime);

            this.WorldPosition.X += this.Velocity.X;

            if (this.Velocity.Y > 0 && this.Velocity.Y * elapsed < 1)
            {
                this.WorldPosition.Y += 1;
            }
            else
            {
                this.WorldPosition.Y += this.Velocity.Y * elapsed;
            }

            this.WorldPosition.Y = (float)Math.Round(this.WorldPosition.Y);

            HandleCollisions(gameTime);

            this.IsJumping = false;

            if (WorldPosition.X == previousPosition.X)
            {
                Velocity.X = 0.0f;
            }

            if (WorldPosition.Y == previousPosition.Y)
            {
                Velocity.Y = 0.0f;
            }
        }
Beispiel #19
0
        public override void Update(CVGameTime gameTime)
        {
            // Update the elapsed time
            elapsedTime         += (int)gameTime.ElapsedGameTime.TotalMilliseconds;
            _elapsedFlickerTime += (int)gameTime.ElapsedGameTime.TotalMilliseconds;

            if (elapsedTime > frameTime)
            {
                if (currentFrame < frameCount - 1)
                {
                    currentFrame++;
                }
                // Reset the elapsed time to zero
                elapsedTime = 0;
            }
            if (_elapsedFlickerTime > _flickerTime)
            {
                _flickerDisplay     = !_flickerDisplay;
                _elapsedFlickerTime = 0;
            }

            destinationRect = new Rectangle((int)ScreenPosition().X, (int)ScreenPosition().Y, _frames[currentFrame].Width, _frames[currentFrame].Height);
        }
Beispiel #20
0
        protected override void UpdateAnimations(CVGameTime gameTime)
        {
            _elapsedTime += (int)gameTime.ElapsedGameTime.TotalMilliseconds;

            if (_elapsedTime > FrameTime)
            {
                // Move to the next frame
                if (_animatingforward)
                {
                    _currentFrame++;
                    if (_currentFrame == spritecollectionlist.Count)
                    {
                        _currentFrame     = spritecollectionlist.Count - 1;
                        _animatingforward = false;
                    }
                }
                else
                {
                    _currentFrame--;
                    if (_currentFrame == 0)
                    {
                        _animatingforward = true;

                        _currentFrame = 0;
                    }
                }

                // Reset the elapsed time to zero
                _elapsedTime = 0;
            }

            foreach (PlayerSpriteCollection psc in spritecollectionlist)
            {
                psc.ScreenPosition = ScreenPosition;
            }
        }
Beispiel #21
0
        public override void Move(CVGameTime gameTime)
        {
            if (_emergeStatus == 0 && SpawnConditionsMet())
            {
                _emergeStatus        = 1;
                _emergeTimeRemaining = _emergeTime;
            }
            else if (_emergeStatus == 1 || _emergeStatus == 2)
            {
                if (_emergeTimeRemaining > 0)
                {
                    _emergeTimeRemaining -= gameTime.ElapsedGameTime.Milliseconds;
                    if (_emergeTimeRemaining <= 0)
                    {
                        _emergeStatus++;
                        _emergeTimeRemaining = _emergeTime + Math.Abs(_emergeTimeRemaining);
                    }
                }
            }
            else if (_emergeStatus == 3)
            {
                if (_reloadTimeRemaining > 0)
                {
                    _reloadTimeRemaining -= gameTime.ElapsedGameTime.TotalMilliseconds;

                    if (_reloadTimeRemaining <= 0)
                    {
                        _shotsRemaining = 3;
                    }
                }
                if (_reloadTimeRemaining <= 0)
                {
                    if (_shotsRemaining > 0)
                    {
                        var elapsedTime = gameTime.ElapsedGameTime.TotalMilliseconds;

                        //if (_recoilTimeRemaining > 0)
                        //{
                        //    _recoilTimeRemaining -= elapsedTime;
                        //    if (_recoilTimeRemaining < 0)
                        //    {
                        //        _recoilTimeRemaining = 0;
                        //        _recoveryTimeRemaining += _recoilTimeRemaining;
                        //        elapsedTime = _recoilTimeRemaining * -1; // keep the difference to carry into recovery time to be decreased
                        //    }
                        //    else
                        //    {
                        //        elapsedTime = 0f;
                        //    }
                        //}
                        if (_recoveryTimeRemaining > 0)
                        {
                            _recoveryTimeRemaining -= elapsedTime;
                        }

                        if (//_recoilTimeRemaining <= 0 &&
                            _recoveryTimeRemaining <= 0)
                        {
                            // target
                            Player nearestPlayer = (Player)TargetingLogic.FindNearest(this.BoundingBox().Center.ToVector(), CurrentStage.Players);

                            // aim
                            _targetClockAngle = TargetingLogic.FindClockPosition(this.BoundingBox().Center.ToVector(), nearestPlayer.BoundingBox().Center.ToVector());

                            if (_targetClockAngle >= 9 && _targetClockAngle <= 11)
                            {
                                // fire
                                _gun.AddProjectile(this.CurrentStage, GunBarrelLocation(), _targetClockAngle * 30, 1.2f);
                                _shotsRemaining--;
                            }

                            _recoveryTimeRemaining = _recoveryTime;
                        }
                    }
                    else
                    {
                        // out of shots, time to reload
                        _reloadTimeRemaining = _reloadTime;
                    }
                }
            }
        }
Beispiel #22
0
 public abstract void Move(CVGameTime gameTime);
Beispiel #23
0
 public abstract void Die(CVGameTime gameTime);
 public virtual void Update(CVGameTime gameTime)
 {
     // do nothing by default.  inherited objects might do something
 }
Beispiel #25
0
        public virtual void HandleCollisions(CVGameTime gameTime)
        {
            if (this.WorldPosition.Y > Game.iScreenModelWidth && IsDying == false)
            {
                Die(gameTime);
            }

            Rectangle actorbounds = this.BoundingBox();

            bool wasonground = this.IsOnGround;

            // get nearest tile below player.
            this.IsOnGround = false;

            int leftTile   = (int)Math.Floor((float)actorbounds.Left / CurrentStage.TileWidth);
            int rightTile  = (int)Math.Ceiling(((float)actorbounds.Right / CurrentStage.TileWidth)) - 1;
            int topTile    = (int)Math.Floor((float)actorbounds.Top / CurrentStage.TileHeight);
            int bottomTile = (int)Math.Ceiling(((float)actorbounds.Bottom / CurrentStage.TileHeight)) - 1;

            // For each potentially colliding platform tile,
            for (int y = topTile; y <= bottomTile; ++y)
            {
                for (int x = leftTile; x <= rightTile; ++x)
                {
                    StageTile stageTile = CurrentStage.getStageTileByGridPosition(x, y);
                    if (stageTile != null)
                    {
                        if (stageTile.IsImpassable())
                        {
                            Rectangle tilebounds = CurrentStage.getTileBoundsByGridPosition(x, y);
                            Vector2   depth      = RectangleExtensions.GetIntersectionDepth(actorbounds, tilebounds);

                            if (actorbounds.Intersects(tilebounds))
                            {
                                WorldPosition = new Vector2(WorldPosition.X + depth.X, WorldPosition.Y);
                                actorbounds   = this.BoundingBox();
                            }
                        }

                        else if (stageTile.IsPlatform() && y == bottomTile)
                        {
                            List <Platform> tileboundsList = CurrentStage.getTilePlatformBoundsByGridPosition(x, bottomTile);
                            foreach (Platform platformbounds in tileboundsList)
                            {
                                Rectangle tilebounds = platformbounds.PlatformBounds;
                                Vector2   depth      = RectangleExtensions.GetIntersectionDepth(actorbounds, tilebounds);


                                if (this.PreviousBottom <= tilebounds.Top && Velocity.Y >= 0 && actorbounds.Intersects(tilebounds))
                                //if (Velocity.Y >= 0 && (depth.Y < 0)) // || this.IgnoreNextPlatform))
                                {
                                    this.IsOnGround     = true;
                                    this.JumpInProgress = false;
                                    //this.Velocity.X = 0f;

                                    this.WorldPosition.Y += depth.Y;
                                    // perform further collisions with the new bounds
                                    actorbounds = this.BoundingBox();
                                }
                            }
                        }
                    }
                }
            }

            if (wasonground && !IsOnGround)
            {
                Velocity.Y = 0;
            }

            this.PreviousBottom = actorbounds.Bottom;
        }
Beispiel #26
0
        public void Update(CVGameTime gameTime, List <Player> players)
        {
            _elapsedTime += (int)gameTime.ElapsedGameTime.TotalMilliseconds;

            if (_elapsedTime > _frameTime)
            {
                _tileSourceCurrentFrame++;
                _elapsedTime = 0;
                if (_tileSourceCurrentFrame == _backgroundTileSource.Count)
                {
                    _tileSourceCurrentFrame = 0;
                }
            }


            if (ProgresstoNextLevel)
            {
                UpdateExplosions(gameTime);

                UpdateEnemies(gameTime);

                if (_explosions.Count == 0 && ActiveEnemies.Where(e => !e.IsDead).Count() == 0 && _explosionsounds.Count == 0)
                {
                    if (momentOfSilence > 0.0f)
                    {
                        // do nothing- wait for enemies to die (they should), explosions to finish.
                        momentOfSilence = MathHelper.Clamp(momentOfSilence - (float)gameTime.ElapsedGameTime.TotalSeconds, 0.0f, 5.0f);
                    }
                    else if (!fanfarePlaying)
                    {
                        fanfarePlaying = true;
                        MediaPlayer.Play(_fanfare);
                        MediaPlayer.IsRepeating = false;
                    }
                    else if (MediaPlayer.State == MediaState.Stopped)
                    {
                        StageIsComplete = true;
                    }
                }
            }
            else
            {
                if (AutoScroll)
                {
                    if (CameraPosition.X + Game.iScreenModelWidth < TileWidth * (MapWidth - 1))
                    {
                        CameraPosition.X += 1.2f;
                    }
                }

                if (!Game.LaunchParameters.ContainsKey("DoNotSpawnEnemies"))
                {
                    SpawnEnemies(gameTime);
                }

                UpdateEnemies(gameTime);

                UpdateExplosions(gameTime);
            }

            UpdateStageObjects(gameTime, uniqueBackgroundObjects);
            UpdateStageObjects(gameTime, uniqueForegroundObjects);


            HandleCollisions(gameTime, players);
        }
Beispiel #27
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Microsoft.Xna.Framework.Input.Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            var cvGameTime = new CVGameTime(gameTime);

            switch (CurrentGameState)
            {
            case GameState.TitleScreen:
            {
                if (_titleScreen.Update(gameTime, this) == GameState.Playing)
                {
                    CurrentGameState = GameState.Initializing;
                }

                break;
            }

            case GameState.Initializing:
            {
                // if playing ContraVania, load world content from ContraVania folder.
                // otherwise, assume we are playing Contra, which loads from Content folder, same as Core Game Content.
                //if (CurrentGame == GameType.ContraVania)
                //{
                //    _worldContent = new ContentManager(this.Services);
                //    _worldContent.RootDirectory = "ContraVania";
                //}
                //else
                //{
                _worldContent = Content;
                //}

                //var directInput = new DirectInput();

                //IList<DeviceInstance> devices = null;

                //if (App.Default.InputType == "USB Gamepad")
                //{
                //    // TODO: only acquire devices if setting is specified in the application.
                //    devices = directInput.GetDevices(DeviceType.Joystick,
                //        DeviceEnumerationFlags.AllDevices);
                //}

                _currentStage = new Stage(_worldContent);

                for (int iPlayerID = 1; iPlayerID <= _titleScreen.NumPlayers; iPlayerID++)
                {
                    var newPlayer = new Player(iPlayerID, this);
                    _players.Add(newPlayer);

                    //if (devices.Count >= iPlayerID)
                    //{
                    //    newPlayer.InitializeJoystick(devices[iPlayerID-1].InstanceGuid, directInput);
                    //}
                }
                //players.Add(new Player(2, this));

                int playerStartingPosition = 0;
                if (this.LaunchParameters.ContainsKey("PlayerStartingPosition"))
                {
                    playerStartingPosition = int.Parse(this.LaunchParameters["PlayerStartingPosition"]);
                }

                string initialStage;
                if (this.LaunchParameters.ContainsKey("StartupStage"))
                {
                    initialStage = this.LaunchParameters["StartupStage"];
                }
                else
                {
                    if (CurrentGame == GameType.Contra)
                    {
                        initialStage = "Contra1-1Jungle";
                    }
                    else
                    {
                        initialStage = "Castlevania1-1-1";
                    }
                }

                foreach (Player player in _players)
                {
                    player.Initialize(Content,
                                      new Vector2(
                                          GraphicsDevice.Viewport.TitleSafeArea.X + ((player.ID - 1) * _currentStage.TileWidth) + playerStartingPosition,
                                          GraphicsDevice.Viewport.TitleSafeArea.Y),
                                      _currentStage, _startingLifeCount);
                }


                if (CurrentGame == GameType.Contra)
                {
                    _currentStage.Initialize(this, _worldContent, initialStage, 32, 32);
                }
                else
                {
                    _currentStage.Initialize(this, _worldContent, initialStage, 16, 16);
                }
                _currentStage.Players = _players;

                this.ResetElapsedTime();
                CurrentGameState = GameState.Playing;
                break;
            }


            case GameState.Playing:
            {
                if (_currentStage.StageIsComplete)
                {
                    this.Exit();
                }

                // as part of Player update, get total life count between the two players.
                int iLifeCount = 0;
                foreach (Player player in _players)
                {
                    player.Update(cvGameTime);
                    iLifeCount += player.LifeCount;
                }

                // if all players are out of lives, Game Over.
                if (iLifeCount <= 0)
                {
                    this.Exit();
                }

                if (!gamePaused)
                {
                    UpdateProjectiles(cvGameTime, _currentStage.Projectiles);
                    UpdateProjectiles(cvGameTime, _currentStage.EnemyProjectiles);

                    _currentStage.Update(cvGameTime, _players);
                }

                // TODO: update code so that currentStage doesn't advance until all players advance.
                // (already-advanced players will be inactive until game stage advances. //
                if (_players[0].CurrentStage.StageID != _currentStage.StageID)
                {
                    _currentStage = _players[0].CurrentStage;
                }

                break;
            }
            }

            base.Update(gameTime);
        }
Beispiel #28
0
 public override void ApplyPhysics(CVGameTime gameTime)
 {
     // do nothing - Panel is anchored to the stage
 }
Beispiel #29
0
 protected override void UpdateAnimations(CVGameTime gameTime)
 {
     // do nothing.
     snipersprites.ScreenPosition = ScreenPosition;
 }
Beispiel #30
0
        private void HandleCollisions(CVGameTime gameTime, List <Player> players)
        {
            Rectangle rectangle1;
            Rectangle rectangle2;
            Rectangle playerBoundingBox;

            // Player Projectile vs Enemy Collision
            for (int i = 0; i < Projectiles.Count; i++)
            {
                rectangle1 = new Rectangle((int)Projectiles[i].WorldPosition.X -
                                           Projectiles[i].Width() / 2, (int)Projectiles[i].WorldPosition.Y -
                                           Projectiles[i].Height() / 2, Projectiles[i].Width(), Projectiles[i].Height());
                //foreach (var enemy in ActiveEnemies.ToList()) // .Where(e => e.VulnerableToBullets))
                for (int j = ActiveEnemies.Count - 1; j >= 0; j--)
                {
                    Enemy enemy = ActiveEnemies[j];
                    if (enemy.VulnerableToBullets)
                    {
                        // Create the rectangles we need to determine if we collided with each other
                        rectangle2 = enemy.BoundingBox();

                        // Determine if the two objects collided with each other
                        if (rectangle1.Intersects(rectangle2))
                        {
                            if (!enemy.BulletProof)
                            {
                                enemy.SustainDamage(gameTime, Projectiles[i].Damage);
                                if (enemy.Health > 0)
                                {
                                    Projectiles[i].PlayHitSound();
                                }
                            }
                            Projectiles[i].Active = false;
                        }
                    }
                }
            }

            // player Collision: enemies, portals
            foreach (Player player in players)
            {
                playerBoundingBox = player.HurtBox();
                //playerBoundingBox = player.BoundingBox();
                if (player.IsVulnerable())
                {
                    for (int i = 0; i < EnemyProjectiles.Count; i++)
                    {
                        rectangle1 = new Rectangle((int)EnemyProjectiles[i].WorldPosition.X -
                                                   EnemyProjectiles[i].Width() / 2, (int)EnemyProjectiles[i].WorldPosition.Y -
                                                   EnemyProjectiles[i].Height() / 2, EnemyProjectiles[i].Width(), EnemyProjectiles[i].Height());
                        if (rectangle1.Intersects(playerBoundingBox))
                        {
                            player.Die(gameTime);
                            EnemyProjectiles[i].Active = false;
                        }
                    }
                }

                for (int i = 0; i < ActiveEnemies.Count; i++)
                {
                    if ((ActiveEnemies[i].CollisionIsHazardous && player.IsVulnerable()) || ActiveEnemies[i].GetType() == typeof(PlayerItem))
                    {
                        rectangle1 = ActiveEnemies[i].BoundingBox();

                        if (rectangle1.Intersects(playerBoundingBox) && ActiveEnemies[i].CollisionIsHazardous)
                        {
                            player.Die(gameTime);
                        }
                        if (rectangle1.Intersects(playerBoundingBox) && ActiveEnemies[i].GetType() == typeof(PlayerItem))
                        {
                            // if item acquired is a Gun, equip it to the player.
                            if (((PlayerItem)ActiveEnemies[i]).Gun != null)
                            {
                                if (((PlayerItem)ActiveEnemies[i]).Gun.GunType == GunType.Rapid)
                                {
                                    player.Gun.Rapid = true;
                                }
                                else
                                {
                                    player.Gun = ((PlayerItem)ActiveEnemies[i]).Gun;
                                }
                            }
                            ActiveEnemies[i].Die(gameTime);
                        }
                    }
                }

                for (int i = 0; i < StageTiles.Count; i++)
                {
                    if (StageTiles[i].PortalID != null)
                    {
                        rectangle1 = getTileBoundsByGridPosition(StageTiles[i].X, StageTiles[i].Y);
                        if (playerBoundingBox.Intersects(rectangle1))
                        {
                            player.CurrentStage    = (Stage)this._portals[StageTiles[i].PortalID];
                            player.WorldPosition.X = 0;
                            player.Update(gameTime);
                        }
                    }
                }
            }
        }