Beispiel #1
0
 public BossModeService(WindowsInputHandler inputHandler, List<TouchSequenceEntry> combinationToKillBoss, GameState gameState)
 {
     _inputHandler = inputHandler;
     _gameState = gameState;
     _combinationToKillBoss = combinationToKillBoss;
     _rhytmEngine = _gameState.Game.Services.GetService<RhythmEngine>();
 }
Beispiel #2
0
 public EvadeBossAttackScript(GameState state, int bossAttackMode, float movingTime, float transitionTime)
 {
     _state = state;
     _transitionTime = transitionTime;
     _movingTime = movingTime;
     _bossAttackMode = bossAttackMode;
 }
Beispiel #3
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);
            }
        }
Beispiel #4
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
                                                                    });
                                 }
                };
 }
Beispiel #5
0
        protected override void OnStart(GameState gameState)
        {
            GenerateNanobotsEvasions();
            base.OnStart(gameState);

            Stop(gameState);
        }
Beispiel #6
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;
        }
Beispiel #7
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, 800);

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

            gameState.ServiceProvider = game.Services;

            gameState.GameStory = BuildGameStory(game);

            return gameState;
        }
Beispiel #8
0
        public override void Initialize()
        {
            _gameState = _game.Services.GetService<GameState>();
            _inputDisplay = new InputSequenceDisplay(Game);
            _inputDisplay.Initialize();

            // Game Over
            _gameOver = new GameOver(Game);
            _gameOver.Initialize();

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

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

            _heartbeatComponent = new HeartbeatComponent(Game);
            _heartbeatComponent.Initialize();

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

            base.Initialize();
        }
Beispiel #9
0
 protected override void OnStart(GameState state)
 {
     _currentTime = 0;
     _inventoryMappingService = _game.Services.GetService<InventoryMappingService>();
     PickTarget.IsBeingPicked = true;
     base.OnStart(state);
 }
Beispiel #10
0
        protected override void OnStart(GameState state)
        {
            state.Player.Confused += (o, e) => Stop(state);

            state.Player.IsMoving = true;
            state.RegisterBlockingHandler(this);
            base.OnStart(state);
        }
Beispiel #11
0
        public override void Update(GameTime gameTime, GameState gameState)
        {
            Thrombus.Update(gameState, gameTime);

            IsFinished = Thrombus.Health <= 0;

            base.Update(gameTime, gameState);
        }
Beispiel #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();
        }
Beispiel #13
0
        protected override void OnStop(GameState state)
        {
            _currentDistance = 0;
            IsFinished = true;
            state.Player.IsMoving = false;
            state.ReleaseBlockingHandler(this);

            base.OnStop(state);
        }
Beispiel #14
0
 public static void Save(string filename, GameState gameState)
 {
     var game = MapToSavedGame(gameState);
     var formatter = new BinaryFormatter();
     using (var stream = new FileStream(filename, FileMode.Create))
     {
         formatter.Serialize(stream, game);
     }
 }
Beispiel #15
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)
     };
 }
Beispiel #16
0
 private void Shoot(GameState state)
 {
     if (_shootScript == null || _shootScript.IsFinished)
     {
         _shootScript = new PlayerShootScript();
         _shootScript.AddTarget(Thrombus);
         //state.AddScript(_shootScript);
     }
 }
Beispiel #17
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);
 }
        public override void Update(GameState gameState, GameTime gameTime)
        {
            if (_bossService.Boss.WorldPosition.X - gameState.Player.WorldPosition.X <= _bossModeActivationDistance)
            {
                _bossService.SwitchBossModeOn();
                Stop(gameState);
            }

            base.Update(gameState, gameTime);
        }
Beispiel #19
0
        public bool Use(GameState state)
        {
            if (ItemsCount > 0 && UseAction != null)
            {
                UseAction(state);
                ItemsCount--;
                return true;
            }

            return false;
        }
Beispiel #20
0
 public override void Update(GameState state, GameTime gameTime)
 {
     if (!state.Level.NextStop.HasValue || state.Player.WorldPosition.X < state.Level.NextStop.Value)
     {
         MovePlayerIfPossible(gameTime, state);
     }
     else
     {
         state.Player.Confuse();
         Stop(state);
     }
 }
Beispiel #21
0
 private static SavedGame MapToSavedGame(GameState gameState)
 {
     var savedGame = new SavedGame
                         {
                             Body = gameState.Inventory.Body,
                             Gun = gameState.Inventory.Gun,
                             Shield = gameState.Inventory.Shield,
                             Money = gameState.Inventory.Money,
                             NextLevelIndex = gameState.GameStory.NextLevelIndex
                         };
     return savedGame;
 }
Beispiel #22
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;
     }
     state.Player.Confuse();
     return false;
 }
Beispiel #23
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);
 }
Beispiel #24
0
        public override void Update(GameTime gameTime, GameState gameState)
        {
            var time = (float) gameTime.ElapsedGameTime.TotalMilliseconds;

            if (_currentScaleTime < _targetScaleTime)
            {
                var diffTime = _targetScaleTime - _currentScaleTime;
                var diff = _targetScale - GameState.Camera.Scale;
                GameState.Camera.Scale += diff / diffTime * time;
                _currentScaleTime += time;
            }

            base.Update(gameTime, gameState);
        }
Beispiel #25
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);
        }
Beispiel #26
0
 private void MovePlayerIfPossible(GameTime gameTime, GameState state)
 {
     if (_currentDistance < Distance)
     {
         var remainingDistance = Distance - _currentDistance;
         var remainingTime = MoveTime - _currentMoveTime;
         var delta = (float) gameTime.ElapsedGameTime.TotalMilliseconds;
         var shift = remainingDistance / remainingTime * delta;
         _currentDistance += shift;
         _currentMoveTime += delta;
         state.Player.WorldPosition = new Vector2(state.Player.WorldPosition.X + shift, state.Player.WorldPosition.Y);
     }
     else
     {
         Stop(state);
     }
 }
Beispiel #27
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
                       };
        }
Beispiel #28
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);
        }
Beispiel #29
0
 public static ActionReaction MoveReaction(Level level, GameState state)
 {
     const int duration = 2000;
     return new ActionReaction
                {
                    Duration = duration,
                    CanBeIvoked = gameState => !gameState.Player.IsMoving && (gameState.Level.NextStop == null ||
                                                                              gameState.Level.NextStop >
                                                                              gameState.Player.WorldPosition.X),
                    Invoke =
                        gameState =>
                            gameState.Player.AddScript(new MovePlayerScript
                                                           {
                                                               Distance = 1000,
                                                               MoveTime =
                                                                   duration + gameState.ReactionProgress.ReactionInertia
                                                           })
                };
 }
Beispiel #30
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);
        }