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 GameState(Game game) { Game = game; ActiveScripts = new List<GameEntityScript>(); BlockingHandlers = new List<object>(); Camera = new Camera2D(); Player = new Player(); Level = new Level(); Inventory = new InventoryService(); ReactionProgress = new ReactionProgressComponent(); }
protected override void OnStart(GameState state) { state.Player.IsMoving = true; _level = state.Level; base.OnStart(state); }
public static Level FromMetadata(LevelMetadata metadata, ContentManager contentManager) { var backgroundMetadata = contentManager.Load<BackgroundMetadata>(metadata.Background); var level = new Level { Distance = metadata.Distance, Background = BackgroundController.FromMetadata(backgroundMetadata, contentManager), Name = metadata.Name }; level.Melody = contentManager.Load<SoundEffect>(metadata.Melody).CreateInstance(); if (level.Melody != null) { level.Melody.IsLooped = true; level.Melody.Play(); } foreach (var enemy in metadata.Enemies) { var character = EnemyMapper.GetEnemy(enemy.EnemyType, contentManager); character.WorldPosition = enemy.Position; level.AddEnemy(character); } foreach (var obstacle in metadata.Obstacles) { var enemy = EnemyMapper.GetEnemy(obstacle.EnemyType, contentManager); enemy.WorldPosition = obstacle.Position; level.AddEnemy(enemy); } foreach (var bossMetadata in metadata.Bosses) { var boss = EnemyMapper.GetBoss(bossMetadata.EnemyType, contentManager); if (boss != null) { boss.WorldPosition = bossMetadata.Position; level.AddBoss(boss); } } foreach (var message in metadata.Messages) { level.Texts.Add(new LevelText(message.Text, message.Position)); } return level; }
public static void EmitParticle(Particle x, Level level) { x.Died += (s, e) => level.RemoveLevelObject(s as Particle); level.AddLevelObject(x); }
public static ActionReaction MoveReaction(Level level, GameState state) { return null; }