public static void UpdateFurnishings(Levels.Level currentLevel) { foreach (KeyValuePair <int, Furnishing> furnishing in furnishings) { furnishing.Value.Update(currentLevel); } }
public override void Update(GameTime gameTime, Levels.Level level) { Entity.ChangeWeapon(_boomerang, level); var passedTime = gameTime.TotalGameTime - _lastAttackTime; if (_followBehavior.CurrentTarget.Distance <= _followBehavior.Distance) { Entity.Look(CurrentTarget.Position, true); bool attack = _lastAttackTime + TimeBetweenAttacks < gameTime.TotalGameTime; _boomerang.Attack(gameTime, level, attack, CurrentTarget.Position); OverrideRelativeTo = _boomerang; if (attack) { _lastAttackTime = gameTime.TotalGameTime; } } else { _lastAttackTime = gameTime.TotalGameTime; _boomerang.Attack(gameTime, level, false, Vector2.Zero); level.RemoveEntity(_boomerang); _followBehavior.Update(gameTime, level); } }
public override bool IsActive(Microsoft.Xna.Framework.GameTime gameTime, Levels.Level level) { if (_dead || (Entity.Health != null && Entity.Health <= 0)) { if (!_dead) { if (!Entity.SpriteSheet.Animations.ContainsKey("dying")) { _deathTime = gameTime.TotalGameTime; } else { _playingAnimation = true; Entity.CurrentAnimation = "dying"; EventHandler animationEnded = null; animationEnded = delegate { Entity.AnimationEnded -= animationEnded; _deathTime = gameTime.TotalGameTime; _playingAnimation = false; }; Entity.AnimationEnded += animationEnded; } } _dead = true; return(true); } return(false); }
protected override bool MakeMoveAttempt(Levels.Level currentLevel, int deltaX, int deltaY) { if (HasTrait(Trait.Immobilised)) { MainGraphicDisplay.TextConsole.AddOutputText("You can't move right now"); return(false); } int newX = deltaX + _xLoc; int newY = deltaY + _yLoc; if (!currentLevel.IsValidMapCoord(newX, newY)) { MainGraphicDisplay.TextConsole.AddOutputText("Stay within the map"); return(false); } if (!currentLevel.IsPassible(this, newX, newY)) { MainGraphicDisplay.TextConsole.AddOutputText("You can't move there"); return(false); } return(base.MakeMoveAttempt(currentLevel, deltaX, deltaY)); }
public void DrawMap(Levels.Level level, int xCentre, int yCentre) { Clear(); var xLimits = getDrawingLimits(level.MapWidth, _console.Width, xCentre); var yLimits = getDrawingLimits(level.MapHeight, _console.Height, yCentre); for (int y = yLimits.Min; y < yLimits.Max; y++) { for (int x = xLimits.Min; x < xLimits.Max; x++) { if (level.IsRevealed(x, y)) { _console.Set(x + xLimits.Offset, y + yLimits.Offset, null, Palette.GetColor(level.GetFogColor(x, y)), ' '); } } } // Now set the tiles that can be seen foreach (var position in level.VisibleTiles) { _console.Set(position.X + xLimits.Offset, position.Y + yLimits.Offset, null, Palette.GetColor(level.GetBGColor(position.X, position.Y)), ' '); if (level.HasDrawingEntity(position.X, position.Y)) { var entity = level.GetDrawingEntity(position.X, position.Y); _console.Set(position.X + xLimits.Offset, position.Y + yLimits.Offset, Palette.GetColor(entity.FGColorName), null, entity.Symbol); } } CopyToBackConsole(); }
public override void Update(GameTime gameTime, Levels.Level level) { Entity.ChangeWeapon(_bow, level); var passedTime = gameTime.TotalGameTime - _lastAttackTime; if (_followBehavior.CurrentTarget.Distance <= _followBehavior.Distance) { Entity.Look(CurrentTarget.Position, true); bool fireArrow = _lastAttackTime + TimeBetweenAttacks < gameTime.TotalGameTime; _bow.Attack(gameTime, level, fireArrow, CurrentTarget.Position * (OptionsManager.CurrentOptions.InvertAim ? -1 : 1)); if (fireArrow) { _lastAttackTime = gameTime.TotalGameTime; } } else { _lastAttackTime = gameTime.TotalGameTime; _bow.Attack(gameTime, level, false, Vector2.Zero); level.RemoveEntity(_bow); _followBehavior.Update(gameTime, level); } }
protected override Game.Characters.Item Copy() { Level <TBoard> level = new Levels.Level <TBoard>(); CopyTo(level); return(level); }
public override void Deactivated(Microsoft.Xna.Framework.GameTime gameTime, Levels.Level level) { if (_bow != null) { _bow.Attack(gameTime, level, false, Vector2.Zero); } }
public override void Hit(Entity attacker, GameTime gameTime, Levels.Level level, Vector2 direction) { var previewEnemy = PreviewEnemyLocation(gameTime, level, attacker.Parent, attacker.Speed); //TODO: Projectile base class. var arrow = attacker as Arrow; if (arrow != null) { attacker.CurrentDirection = previewEnemy.Position.Normalized(); attacker.Parent = this; arrow.HitEntity = null; return; } var fireBall = attacker as FireBall; if (fireBall != null) { attacker.CurrentDirection = previewEnemy.Position.Normalized(); attacker.Parent = this; fireBall.HitEntity = null; return; } if (attacker is Boomerang) { base.Hit(attacker, gameTime, level, direction); } }
public override void Hit(Entity attacker, GameTime gameTime, Levels.Level level, Vector2 direction) { if (attacker is Arrow) { Health.Quantity -= 2; } base.Hit(attacker, gameTime, level, direction); }
public override void Hit(Entity attacker, GameTime gameTime, Levels.Level level, Vector2 direction) { if (_canDestroy(attacker)) { Health.ValueChanged -= Health_ValueChanged; Health.Quantity = 0; base.Hit(attacker, gameTime, level, direction); } }
public override bool IsActive(GameTime gameTime, Levels.Level level) { if (base.IsActive(gameTime, level) && Entity.Weapons != null) { _wand = Entity.Weapons.OfType <FireWand>().FirstOrDefault(); return(_wand != null && Entity.Magic > 0); } return(false); }
public override void Update(Levels.Level currentLevel) { base.Update(currentLevel); if (!_destroyed) { GetNextMove(currentLevel); } }
public override void Update(GameTime gameTime, Levels.Level level) { if (Health == null) { Health = level.GetEntities <Poltergeist>().Select(p => p.Health).FirstOrDefault() ?? new Container(7); } base.Update(gameTime, level); }
public override void Update(GameTime gameTime, Levels.Level level) { _timeFromCreation += gameTime.ElapsedGameTime; if (level.Map.Collides(CollisionRect, false, true)) { level.RemoveEntity(this); return; } if (HitEntity != null) { SoundManager.PlaySound("onfire"); if (gameTime.TotalGameTime > _entHitTime + _maxHitTime) { level.RemoveEntity(this); } return; } var timeFactor = gameTime.ElapsedGameTime.TotalMilliseconds / 1000; Position += CurrentDirection * (float)timeFactor * Speed; foreach (var ent in level.CollidesWith(CollisionRect).Distinct()) { if (ent != this && ent != Parent && ent.Health != null) { _entHitTime = gameTime.TotalGameTime; HitEntity = ent; var direction = VectorHelper.AngleToV2(Angle, 5); direction = new Vector2(-direction.Y, direction.X); ent.Hit(this, gameTime, level, direction); if (HitEntity != null) { OverlapEntities = false; Position = ent.CenterPosition; Angle = 0; return; } else { _timeFromCreation = TimeSpan.Zero; } } } if (_timeFromCreation > MaxFlyTime) { level.RemoveEntity(this); } }
public override void Update(GameTime gameTime, Levels.Level level) { if (oldHealth != null && oldHealth > Entity.Health) { _startBlink = gameTime.TotalGameTime; } Blink(gameTime); oldHealth = Entity.Health; }
int xpos, ypos; //the location in tiles (xpos = column, ypos= row) #endregion Fields #region Constructors //float movingTime = (0); public PlayerCharacter(ContentManager myContent, SpriteBatch spriteBatch, int x, int y, Levels.Level currentLevel) { isMoving = false; environment = currentLevel; xpos = x; ypos = y; location = setlocation(); sprite = new Sprite("playercharacter", true, location, myContent, spriteBatch); moveSpeed = ((float)environment.tileSize) / 24f; }
public override void Hit(Entity attacker, GameTime gameTime, Levels.Level level, Vector2 direction) { var oldHealth = Health.Quantity; base.Hit(attacker, gameTime, level, direction); if (level.GetEntities <Poltergeist>().Any()) { Health.Quantity = oldHealth; } }
public override void Update(GameTime gameTime, Levels.Level level) { foreach (Entity en in level.CollidesWith(this.CollisionRect)) { //TODO: Remove en is Player if (Teleportable.Split(';').Contains(en.Category)) { level.GoToDungeon(en, Dungeon); } } //base.Update(gameTime, level); }
public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Levels.Level level) { base.Update(gameTime, level); if (_itemsDropped) { return; } _itemsDropped = true; bool itemsDropped = false; var weapons = Entity.Weapons ?? Enumerable.Empty <Entity>(); var items = Entity.Holding ?? Enumerable.Empty <Entity>(); var additional = _additionalItems.Select(f => f(gameTime, level)).Where(i => i != null); foreach (var ent in weapons.Union(items).Union(additional)) { var dropEntity = ent; if (ent is Weapon) { var weaponName = ent.GetType().Name; var allowedWeapons = GameStateManager.CurrentState.AllowWeapon; var currentWeapons = GameStateManager.CurrentState.Player.Weapons; if (AutomaticAllowWeapons && !allowedWeapons.Contains(weaponName)) { allowedWeapons.Add(weaponName); } if (currentWeapons.Contains(weaponName)) { if (CreateAmmo.ContainsKey(weaponName) && Random.NextDouble() > 0.1) { dropEntity = CreateAmmo[weaponName](); } continue; } } Drop(level, dropEntity); itemsDropped = true; } Entity.Weapons = null; Entity.Holding = null; if (!itemsDropped && Random.NextDouble() < 0.1 && !GameStateManager.CurrentState.Player.Health.IsFull) { Drop(level, new Health()); } }
void SpotHidden(Levels.Level currentLevel, List <Entity> concealedEntities) { foreach (Entity entity in concealedEntities) { if (currentLevel.InSight(XLoc, YLoc, entity.XLoc, entity.YLoc, ViewDistance) && Resources.Geometry.DistanceFunctions.Distance(this, entity) <= 5 - entity.SpotDC) { entity.PlayerSpotted = true; // TODO: Add some text here - actually make it an event and a statistic. } } }
protected override void GetNextMove(Levels.Level currentLevel) { // Check FOV and concealed objects var inSight = currentLevel.GetFOV(XLoc, YLoc, ViewDistance); currentLevel.VisibleTiles = inSight; foreach (Resources.Geometry.XYCoordinateStruct tile in inSight) { currentLevel.RevealTile(tile.X, tile.Y); } SpotHidden(currentLevel, currentLevel.GetConcealedEntity(inSight)); MainGraphicDisplay.UpdateGameScreen(); bool hasMoved = false; while (!hasMoved) { var key = UserInterface.UserInputHandler.GetNextKey(); if (UserInterface.UserInputHandler.DirectionKeys.ContainsKey(key)) { var direction = UserInterface.UserInputHandler.DirectionKeys[key]; hasMoved = MakeMoveAttempt(currentLevel, direction.X, direction.Y); } if (key == "U") { var direction = UserInterface.UserInputHandler.GetDirection("Which direction", true); if (direction == null) { continue; } if (currentLevel.HasFurnishing(XLoc + direction.X, YLoc + direction.Y)) { var furnishing = currentLevel.GetFurnishing(XLoc + direction.X, YLoc + direction.Y); furnishing.InteractWith(this); } else { MainGraphicDisplay.TextConsole.AddOutputText("There is nothing there to make use of"); } hasMoved = true; } if (key == "ESCAPE") { hasMoved = true; MainProgram.Quit(); } } }
void SpotHidden(Levels.Level currentLevel, List <Entity> concealedEntities) { foreach (Entity entity in concealedEntities) { var concealmentLevel = int.Parse(entity.GetOtherAttributeValue("ConcealmentLevel")); if (currentLevel.InSight(XLoc, YLoc, entity.XLoc, entity.YLoc, ViewDistance) && Resources.Geometry.DistanceFunctions.Distance(this, entity) <= 5 - concealmentLevel) { entity.PlayerSpotted = true; // TODO: Add some text here - actually make it an event and a statistic. } } }
// TODO: Decide whether this needs to be public for the AI module. protected virtual bool MakeMoveAttempt(Levels.Level currentLevel, int deltaX, int deltaY) { // TODO: Apply movement functions here. // TODO: Add movement mode when appropriate // TODO: Also make sure this can always be done in advance, i.e. nothing that follows can change this. GameEvents.MoveActorEvent.GenerateMoveActorEvent(this, deltaX, deltaY); currentLevel.RemoveActor(this); Move(deltaX, deltaY); currentLevel.AddActor(this); return(true); }
public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Levels.Level level) { if (_attackedBy == null || !level.ContainsEntity(_attackedBy) || _attackedBy.IsDead || _attackTime + _hitAttackerTime < gameTime.TotalGameTime) { foreach (var beh in Entity.Behaviors.SelectMany(l => l.Value.OfType <AttackBehavior>())) { if (beh.OverrideTarget == _attackedBy) { beh.OverrideTarget = null; } } _attackedBy = null; } }
public override void Update(GameTime gameTime, Levels.Level level) { var col = CollisionRect; var ent = level.CollidesWith(new Rectangle( x: (int)(col.X + CurrentDirection.X * 8), y: (int)(col.Y + CurrentDirection.Y * 8), width: col.Width, height: col.Height)).FirstOrDefault(e => e != this); if (ent != null) { ent.Hit(this, gameTime, level, CurrentDirection); } base.Update(gameTime, level); }
public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Levels.Level level) { foreach (var ent in level.CollidesWith(CollisionRect).Where(e => !e.IsDead).Distinct()) { if (Parent == null) { if (ent.Health != null && ent.Health.Quantity < ent.Health.Maximum) { ent.Health.Quantity += PickupCount; level.RemoveEntity(this); } return; } } base.Update(gameTime, level); }
public override bool IsActive(Microsoft.Xna.Framework.GameTime gameTime, Levels.Level level) { if (Entity.IsDead) { return(false); } _currentTarget = level.EntityCloserTo(Entity, TargetCategory); if (_currentTarget != null && (MaxDistance == null || _currentTarget.Distance < MaxDistance)) { return(true); } Walk(gameTime, level, Vector2.Zero); return(false); }
private void Drop(Levels.Level level, Base.Entity dropEntity) { var enemyPosition = Entity.CenterPosition; var dropDistance = VectorHelper.AngleToV2((float)(Random.NextDouble() * Math.PI - Math.PI / 2), 32); var dropPosition = enemyPosition + dropDistance; dropEntity.Parent = null; dropEntity.OverlapEntities = true; dropEntity.Position = dropPosition; if (level.Map.Collides(dropEntity.CollisionRect)) { dropEntity.Position = enemyPosition; } level.AddEntity(dropEntity); }
public override void Update(Microsoft.Xna.Framework.GameTime gameTime, Levels.Level level) { if (_playingAnimation) { return; } if (_deathTime + BlinkTime < gameTime.TotalGameTime) { level.RemoveEntity(Entity); } else { Entity.IsInvisible = !Entity.IsInvisible; } }
public override bool IsActive(Microsoft.Xna.Framework.GameTime gameTime, Levels.Level level) { if (Entity.IsDead) { return(false); } if (Following != null) { if (MaxDistance != null) { var distance = new Vector2(Following.CenterPosition.X - Entity.CenterPosition.X, Following.CenterPosition.Y - Entity.CenterPosition.Y).Length(); if (distance > MaxDistance) { Following.GetBehavior <ChainBehavior <T> >().FollowedBy = null; Following = null; } } if (Following != null && (Following.IsDead || !level.ContainsEntity(Following))) { Following.GetBehavior <ChainBehavior <T> >().FollowedBy = null; Following = null; } } if (Following == null) { Following = (from ent in level.GetEntities <T>() where ent != Entity && !ent.IsDead && level.ContainsEntity(ent) let beh = ent.GetBehavior <ChainBehavior <T> >() where beh != null && beh.FollowedBy == null && !beh.IsFollowingEntity(Entity) let pos = new Vector2(Entity.CenterPosition.X - ent.CenterPosition.X, Entity.CenterPosition.Y - ent.CenterPosition.Y) let distance = pos.Length() where MaxDistance == null || distance < MaxDistance orderby distance select ent).FirstOrDefault(); if (Following != null) { Following.GetBehavior <ChainBehavior <T> >().FollowedBy = Entity; } } return(Following != null); }
public GameScreen(SpriteBatch spriteBatch, ContentManager myContent) { currentLevel = new Levels.Level(spriteBatch, myContent, gameBorder); existingMobs = new List<Mobs.BaseMob>(); thePlayer = new Mobs.PlayerCharacter(myContent, spriteBatch, 0,0, currentLevel); }