public EvadeBossAttackScript(GameState state, int bossAttackMode, float movingTime, float transitionTime) { _state = state; _transitionTime = transitionTime; _movingTime = movingTime; _bossAttackMode = bossAttackMode; }
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(); }
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); }
protected override void OnStart(GameState state) { _currentTime = 0; _inventoryMappingService = _game.Services.GetService<InventoryMappingService>(); PickTarget.IsBeingPicked = true; base.OnStart(state); }
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); }
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); } }
protected override void OnStart(GameState gameState) { GenerateNanobotsEvasions(); base.OnStart(gameState); Stop(gameState); }
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 }); } }; }
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; }
private void UseMedkit(GameState state) { IsEnabled = false; var script = new HealPlayerScript(HealingValue); state.AddScript(script); }
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(); }
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); } }
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) }; }
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 bool Use(GameState state) { if (ItemsCount > 0 && UseAction != null) { UseAction(state); ItemsCount--; return true; } return false; }
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; }
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(); } }
public void OnUse(GameState state) { if(IsReuseble) { IsEnabled = false; ColdownTime = ReuseTime; } if (Use != null) { Use(state); } }
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; } }
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); }
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); } }
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); }
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); }
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 }; }
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); }
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); // } //} }
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)); } } }
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); }
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); }