Esempio n. 1
0
 public EvadeBossAttackScript(GameState state, int bossAttackMode, float movingTime, float transitionTime)
 {
     _state = state;
     _transitionTime = transitionTime;
     _movingTime = movingTime;
     _bossAttackMode = bossAttackMode;
 }
Esempio n. 2
0
        public override void Initialize()
        {
            _gameState = _game.Services.GetService<GameState>();
            // Game Over
            _gameOver = new GameOver(Game);
            _gameOver.Initialize();

            // Level finished
            _levelFinished = new LevelFinished(Game);
            _levelFinished.Initialize();

            _inventoryComponent = new InventoryComponent(Game);
            _inventoryComponent.Initialize();

            _spriteBatch = Game.Services.GetService<SpriteBatch>();

            // Player health
            _playerHealthBar = new ProgressBar(Game, @"Textures\UI\Health", @"Textures\UI\HealthVessel")
            {
                DestinationRectangle = new Rectangle(20, 10, 250, 20),
                Max = _gameState.Player.MaxHealth
            };
            _playerHealthBar.Initialize();

            base.Initialize();
        }
Esempio n. 3
0
        public virtual void Update(GameState gameState, GameTime gameTime)
        {
            _isUpdatingScripts = true;

            if (_scripts != null)
            {
                for (int index = 0; index < _scripts.Count; index++)
                {
                    var script = _scripts[index];
                    if (!script.IsStarted)
                    {
                        script.Start(gameState);
                    }

                    script.Update(gameState, gameTime);
                }
            }

            for (int i = _scripts.Count - 1; i >= 0; i-- )
            {
                if (_scripts[i].IsFinished)
                {
                    _scripts.RemoveAt(i);
                }
            }

            for (int index = 0; index < _scriptsAddedOnThisUpdate.Count; index++)
            {
                var script = _scriptsAddedOnThisUpdate[index];
                _scripts.Add(script);
            }

            _scriptsAddedOnThisUpdate.Clear();
            _isUpdatingScripts = false;
        }
        public override void Update(GameState state, GameTime time)
        {
            if (Combatant.WorldPosition.X - Target.WorldPosition.X > Combatant.AttackRange)
            {
                return;
            }

            var bot = state.Player.Nanobot;
            if (bot.Intersects(Combatant.WorldCollisionRectangle) != Rectangle.Empty)
            {
                bot.Damage(new DamageTakenEventArgs(Combatant.AttackDamage, Combatant.WorldPosition));
                Combatant.Health = 0;
            }

            if (Combatant.Health == 0)
            {
                Stop(state);
            }

            var velocityDiff = Combatant.Acceleration * time.ElapsedGameTime.Milliseconds;
            var vector = new Vector2(Target.WorldCollisionRectangle.Center.X - Combatant.WorldCollisionRectangle.Center.X,
                    Target.WorldCollisionRectangle.Center.Y - Combatant.WorldCollisionRectangle.Center.Y);
            vector.Normalize();

            Combatant.Velocity += velocityDiff;
            if (Combatant.Velocity > Combatant.MaxVelocity)
            {
                Combatant.Velocity = Combatant.MaxVelocity;
            }

            Combatant.WorldPosition += vector * Combatant.Velocity;

            base.Update(state, time);
        }
Esempio n. 5
0
 protected override void OnStart(GameState state)
 {
     _currentTime = 0;
     _inventoryMappingService = _game.Services.GetService<InventoryMappingService>();
     PickTarget.IsBeingPicked = true;
     base.OnStart(state);
 }
Esempio n. 6
0
        public override void Update(GameState gameState, GameTime gameTime)
        {
            var elapsedTime = (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            const float speedMultiplier = 0.001f;

            var offset =
                new Vector2(
                    (float)(Speed * Math.Cos(DirectionAngle) * elapsedTime * speedMultiplier),
                    (float)(Speed * Math.Sin(DirectionAngle) * elapsedTime * speedMultiplier));
            WorldPosition += offset;
            var size = Size ?? AutoSize;

            var bot = gameState.Player.Nanobot;
            var hitRectangle = bot.Intersects(new Rectangle((int) WorldPosition.X, (int) WorldPosition.Y,
                (int) size.X, (int) size.Y));
            if (!hitRectangle.IsEmpty)
            {
                bot.Damage(new DamageTakenEventArgs(HitDamage,
                    new Vector2(
                        hitRectangle.X + hitRectangle.Width / 2,
                        hitRectangle.Y + hitRectangle.Height / 2)));
                gameState.Level.RemoveLevelObject(this);
                SoundManager.BotHit.Play();
            }
            var screenPosition = gameState.Camera.GetScreenPosition(WorldPosition, gameState.Camera.MinScale);
            if (screenPosition.X < 0 || screenPosition.Y < 0)
            {
                gameState.Level.RemoveLevelObject(this);
            }

            base.Update(gameState, gameTime);
        }
Esempio n. 7
0
        public override void Update(GameState gameState, GameTime gameTime)
        {
            base.Update(gameState, gameTime);

            if (_boss.WorldPosition.X - gameState.Player.WorldPosition.X <= _boss.AttackRange)
            {
                _timeAfterLastAttack += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

                if (_intervalForNextAttack - _timeAfterLastAttack < _boss.AttackInterval && !_boss.IsPreparingForAttack)
                {
                    _boss.StartAttack();
                }

                if (_timeAfterLastAttack >= _intervalForNextAttack &&
                    _boss.Health > 0)
                {
                    ShootNewBullet(gameState);
                    _timeAfterLastAttack = 0;
                    _intervalForNextAttack = RandomHelper.GetRandomFloatFromInterval(_boss.AttackRateMin, _boss.AttackRateMax) + _boss.AttackInterval;
                    _boss.StopAttack();
                }

            }

            if (_boss.Health == 0 && _activeBullets.Count == 0)
            {
                Stop(gameState);
            }
        }
Esempio n. 8
0
        protected override void OnStart(GameState gameState)
        {
            GenerateNanobotsEvasions();
            base.OnStart(gameState);

            Stop(gameState);
        }
Esempio n. 9
0
 public static ActionReaction ShootReaction(Level level, GameState state)
 {
     Func<Level, IEnumerable<IPlayerAttackTarget>> findEnemies = l => l.CustomLevelObjects
                                                                          .OfType<IPlayerAttackTarget>()
                                                                          .Where(
                                                                              enemy => enemy.Health > 0 &&
                                                                                       enemy.WorldPosition.X <=
                                                                                       state.Player.WorldPosition
                                                                                           .X +
                                                                                       state.Player.AttackRange).
                                                                          OrderBy(
                                                                              target =>
                                                                              target.PlayerAttackPriority);
     const int duration = 1500;
     return new ActionReaction
                {
                    Duration = duration,
                    CanBeIvoked = gameState => findEnemies(gameState.Level).Any(),
                    Invoke = gameState =>
                                 {
                                     var enemiesInRange = findEnemies(gameState.Level);
                                     gameState.Player.AddScript(new PlayerShootScript(enemiesInRange)
                                                                    {
                                                                        ShootingTime =
                                                                            duration +
                                                                            gameState.ReactionProgress.
                                                                                ReactionInertia
                                                                    });
                                 }
                };
 }
Esempio n. 10
0
        public static GameState CreateDefaultGameState(Game game)
        {
            var gameState = new GameState(game);

            gameState.Camera = new Camera2D
                                   {
                                       Scale = 1f,
                                       FocusedAt = gameState.Player
                                   };

            gameState.Camera.FocusedAtOffset = new Vector2(370, 70) / gameState.Camera.Scale;
            gameState.IsHealthBarEnabled = true;
            gameState.IsInventoryEnabled = true;
            gameState.IsHeartbeatEnabled = true;
            gameState.IsGodModeEnabled = false;
            gameState.AreControlsEnabled = true;
            gameState.Inventory.Add(Items.BloodElement, 0);

            //gameState.Inventory.ToActive(0, 0);
            //gameState.Inventory.ToActive(1, 1);

            gameState.ServiceProvider = game.Services;

            gameState.GameStory = BuildGameStory(game);

            return gameState;
        }
Esempio n. 11
0
        private void UseMedkit(GameState state)
        {
            IsEnabled = false;

            var script = new HealPlayerScript(HealingValue);

            state.AddScript(script);
        }
Esempio n. 12
0
        public override void Initialize()
        {
            _gameState = Game.Services.GetService<GameState>();
            _spriteBatch = Game.Services.GetService<SpriteBatch>();
            _spriteFont = Fonts.Tutorial;

            _screenCenter = new Vector2(Game.GraphicsDevice.Viewport.Width / 2f, Game.GraphicsDevice.Viewport.Height / 2f);
            base.Initialize();
        }
Esempio n. 13
0
 private void MovePlayerIfPossible(GameTime gameTime, GameState state)
 {
     var stopPosition = _level.GetNextStopPosition(state.Player.WorldPosition);
     if (!stopPosition.HasValue || stopPosition.Value.X - state.Player.WorldPosition.X> GameState.ScreenLength - 300)
     {
         state.Player.WorldPosition = new Vector2(state.Player.WorldPosition.X + MovingSpeed,
                                                  state.Player.WorldPosition.Y);
     }
 }
Esempio n. 14
0
 protected MatchStrategy(GameState state)
 {
     State = state;
     var rhythm = State.Game.Services.GetService<RhythmEngine>();
     BeatController = new BeatMatchingController(rhythm.PatternGenerator)
     {
         IsMatchingTriggered = () => InputManager.IsKeyTriggered(Keys.A) || InputManager.IsKeyTriggered(Keys.S)
     };
 }
Esempio n. 15
0
 public override void Update(GameState gameState, GameTime gameTime)
 {
     _target.GroupPosition = _target.GroupPosition + _delta * (float)gameTime.ElapsedGameTime.TotalMilliseconds;
     _currentMovingTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
     if (_currentMovingTime >= _time)
     {
         Stop(gameState);
     }
     base.Update(gameState, gameTime);
 }
Esempio n. 16
0
        public bool Use(GameState state)
        {
            if (ItemsCount > 0 && UseAction != null)
            {
                UseAction(state);
                ItemsCount--;
                return true;
            }

            return false;
        }
Esempio n. 17
0
 public bool TryInvokeReaction(PlayerAction action, GameState state)
 {
     var reaction = _reactions[action];
     if (reaction.CanBeIvoked(state))
     {
         ReactionInvoked.Fire(this, () => new ReactionInvokedEventArgs{ReactionInvoked = reaction});
         reaction.Invoke(state);
         return true;
     }
     return false;
 }
Esempio n. 18
0
 public override void Update(GameState gameState, GameTime gameTime)
 {
     base.Update(gameState, gameTime);
     var deltaSize = StartSize - EndSize;
     _curentSize = StartSize -  deltaSize*_changingTime/TimeAlive;
     _changingTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
     WorldPosition = new Vector2(WorldPosition.X + MovePlayerScript.PlayerSpeed, WorldPosition.Y);
     if(_changingTime > TimeAlive)
     {
         OnEnded();
     }
 }
Esempio n. 19
0
 public void OnUse(GameState state)
 {
     if(IsReuseble)
     {
         IsEnabled = false;
         ColdownTime = ReuseTime;
     }
     if (Use != null)
     {
         Use(state);
     }
 }
Esempio n. 20
0
        public override void Update(GameState state, GameTime gameTime)
        {
            MovePlayerIfPossible(gameTime, state);

            if (state.Level.GetDistanceForClosestEnemy(state.Player.WorldPosition) < state.Camera.ViewportWidth - 100 && state.Player.Handled)
            {
                state.Player.IsShooting = true;
            }
            else
            {
                state.Player.IsShooting = false;
            }
        }
Esempio n. 21
0
 public override void Update(GameState gameState, GameTime gameTime)
 {
     if (_movingToScript.IsFinished)
     {
         _currentTransitionTime += (float) gameTime.ElapsedGameTime.TotalMilliseconds;
         if (_currentTransitionTime >= _transitionTime)
         {
             _target.AddScript(new MoveNanobotScript(_target, -_offset, _time));
             Stop(gameState);
         }
     }
     base.Update(gameState, gameTime);
 }
Esempio n. 22
0
        public override void Update( GameState state, GameTime gameTime)
        {
            bool atLeastOneEnemyDied = false;

            for (int index = 0; index < _actualTargets.Count; index++)
            {
                var enemy = _actualTargets[index];
                if (enemy != null)
                {
                    enemy.Damage(
                        new DamageTakenEventArgs((float) (_damagePerTime*gameTime.ElapsedGameTime.TotalMilliseconds),
                                                 (enemy as DrawableGameObject).WorldPosition));

                    if (!enemy.IsAlive)
                    {
                        atLeastOneEnemyDied = true;
                    }
                }
            }

            bool allDead = true;
            for (int i = 0; i < Targets.Count; i++ )
            {
                if (Targets[i].IsAlive)
                {
                    allDead = false;
                    break;
                }
            }

            if (allDead)
            {
                Stop(state);
                return;
            }

            if (atLeastOneEnemyDied)
            {
                UpdateActualTargets();
            }

            CurrentShootingTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            if (CurrentShootingTime > ShootingTime)
            {
                Stop(state);
            }
        }
Esempio n. 23
0
        protected override void OnStart(GameState state)
        {
            //base.OnStart(state);

            //state.Inventory.Slots[1].ItemsCount = 10;

            //state.Camera.Position = state.Player.WorldPosition;
            //state.Camera.FocusedAt = state.Player;
            //state.Camera.FocusedAtOffset = new Vector2(370, 70) / state.Camera.Scale;
            //state.IsHealthBarEnabled = true;
            //state.IsInventoryEnabled = true;
            //state.IsHeartbeatEnabled = true;
            //state.IsGodModeEnabled = false;
            //state.AreControlsEnabled = true;
            //Stop(state);
        }
Esempio n. 24
0
        public override void Update(GameState gameState, GameTime gameTime)
        {
            if (_isFinished)
            {
                return;
            }

            if (_currentTime >= _holdTime)
            {
                InvokeFinished(EventArgs.Empty);
                _isFinished = true;
            }

            _currentTime += (float) gameTime.ElapsedGameTime.TotalMilliseconds;

            base.Update(gameState, gameTime);
        }
Esempio n. 25
0
        public static ActionReaction EvadeReaction(GameState state)
        {
            Func<GameState, Boss> findBoss =
                gameState => gameState.Level.CustomLevelObjects.OfType<Boss>().FirstOrDefault(
                    boss =>
                    boss.WorldPosition.X - gameState.Player.WorldPosition.X <=
                    gameState.Player.AttackRange && boss.IsPreparingForAttack);

            const int duration = 1700;
            return new ActionReaction
                       {
                           CanBeIvoked = gameState => findBoss(gameState) != null,
                           Duration = duration,
                           Invoke =
                               gameState => gameState.Player.CanEvadeAttack = true
                       };
        }
Esempio n. 26
0
        public override void Update(GameState gameState, GameTime gameTime)
        {
            if (_livedFor >= Lifetime)
            {
                IsAlive = false;
                InvokeDied();
            }

            var elapsedTime = (float) gameTime.ElapsedGameTime.TotalMilliseconds;

            _livedFor += elapsedTime;

            if (Behavior != null)
            {
                WorldPosition = Behavior.GetNewPosition(WorldPosition, elapsedTime);
            }

            base.Update(gameState, gameTime);
        }
Esempio n. 27
0
 public override void Update(GameState gameState, GameTime gameTime)
 {
     base.Update(gameState, gameTime);
     WorldPosition = Vector2.Add(WorldPosition, new Vector2(Speed, 0));
     //var size = Size ?? AutoSize;
     //var enemyies = level.IntersectedObstacle(new Rectangle((int)WorldPosition.X, (int)WorldPosition.Y, (int)size.X, (int)size.Y)).ToList();
     //if (enemyies.Count > 0)
     //{
     //    var enemy = enemyies[0];
     //    if (enemy != null)
     //    {
     //        enemy.Damage(
     //            new DamageTakenEventArgs(HitDamage,
     //                                     enemy.WorldPosition));
     //        gameState.Player.Nanobot.Gun.RemoveBullet(this);
     //        Unload(Game);
     //    }
     //}
 }
Esempio n. 28
0
        public override void Update(GameState gameState, GameTime gameTime)
        {
            base.Update(gameState, gameTime);

            WorldPosition = Vector2.Add(WorldPosition, new Vector2(Speed, (float)(Math.Cos((WorldPosition.X - StartPoint.X) / _multyplierX + StartAngel) * _multyplierY)));
            var level = gameState.Level;
            var size = Size ?? AutoSize;
            var enemyies = level.IntersectedObstacle(new Rectangle((int)WorldPosition.X, (int)WorldPosition.Y, (int)size.X, (int)size.Y)).ToList();
            if (enemyies.Count > 0)
            {
                var enemy = enemyies[0];
                if (enemy != null)
                {
                    gameState.Player.Nanobot.FrontWeapon.RemoveBullet(this);
                    enemy.Damage(
                        new DamageTakenEventArgs(HitDamage,
                                                 enemy.WorldPosition));
                }
            }
        }
Esempio n. 29
0
        public override void Update(GameState state, GameTime time)
        {
            var elapsedTime = (float) time.ElapsedGameTime.TotalMilliseconds;

            var remainingDistance = new Vector2(PickBy.WorldCollisionRectangle.Center.X - PickTarget.WorldCollisionRectangle.Center.X,
                    PickBy.WorldCollisionRectangle.Center.Y - PickTarget.WorldCollisionRectangle.Center.Y);
            var remainingTime = PickingTime - _currentTime;
            var requiredSpeed = remainingDistance / remainingTime;
            var offset = requiredSpeed * elapsedTime;
            PickTarget.WorldPosition += offset;

            if (PickTarget.Intersects(PickBy.WorldCollisionRectangle) != Rectangle.Empty || _currentTime >= PickingTime)
            {
                AddToInventory(state);
            }

            _currentTime += elapsedTime;

            base.Update(state, time);
        }
Esempio n. 30
0
        public override void Update(GameState gameState, GameTime gameTime)
        {
            if (_delay >= 0)
            {
                _delay -= (float) gameTime.ElapsedGameTime.TotalMilliseconds;
                return;
            }

            var elapsedTime = (float)gameTime.ElapsedGameTime.TotalMilliseconds;

            _angle += elapsedTime / _speed;
            if (_angle > MathHelper.TwoPi)
            {
                _angle -= MathHelper.TwoPi;
            }

            var dx = (float)(_radius * Math.Cos(_angle));
            var dy = (float)(_radius * Math.Sin(_angle));

            Target.WorldPosition = new Vector2(InitialPosition.X + dx, InitialPosition.Y + dy);
        }