private void DisableRespawn(EntityPlacement placement, GameEntity entity)
        {
            if (placement.respawn != RespawnBehavior.Offscreen)
                _respawnableEntities[placement] = false;

            entity.Removed -= () => DisableRespawn(placement, entity);
        }
        public bool IsRespawnable(EntityPlacement placement)
        {
            if (_respawnableEntities.ContainsKey(placement))
                return _respawnableEntities[placement];

            return true;
        }
        public EntityPlacement Load(XElement node)
        {
            EntityPlacement info = new EntityPlacement();

            info.Id = node.TryAttribute("id", Guid.NewGuid().ToString());

            info.entity = node.TryAttribute("name", node.GetAttribute<string>("entity"));

            info.state = node.TryAttribute("state", "Start");

            info.screenX = node.GetAttribute<int>("x");
            info.screenY = node.GetAttribute<int>("y");

            var dirAttr = node.Attribute("direction");
            if (dirAttr != null)
            {
                Direction dir = Direction.Left;
                Enum.TryParse<Direction>(dirAttr.Value, true, out dir);
                info.direction = dir;
            }

            var respawnAttr = node.Attribute("respawn");
            if (respawnAttr != null)
            {
                RespawnBehavior respawn = RespawnBehavior.Offscreen;
                Enum.TryParse<RespawnBehavior>(respawnAttr.Value, true, out respawn);
                info.respawn = respawn;
            }

            return info;
        }
 public void Write(EntityPlacement info, XmlWriter writer)
 {
     writer.WriteStartElement("Entity");
     if (info.Id != null)
     {
         writer.WriteAttributeString("id", info.Id);
     }
     writer.WriteAttributeString("entity", info.entity);
     if (info.state != "Start") writer.WriteAttributeString("state", info.state);
     writer.WriteAttributeString("x", info.screenX.ToString());
     writer.WriteAttributeString("y", info.screenY.ToString());
     writer.WriteAttributeString("direction", info.direction.ToString());
     writer.WriteAttributeString("respawn", info.respawn.ToString());
     writer.WriteEndElement();
 }
        public void Click(ScreenDrawingSurface surface, System.Drawing.Point location)
        {
            // select nearest entity
            var index = surface.Screen.FindEntityAt(location);
            surface.Screen.SelectEntity(index);
            surface.ReDrawEntities();

            heldEntity = surface.Screen.GetEntity(index);
            if (heldEntity != null)
            {
                entityAnchor = new Point(location.X - (int)heldEntity.screenX, location.Y - (int)heldEntity.screenY);
            }
            else
            {
                entityAnchor = Point.Empty;
            }
        }
        public EntityPlacementControlViewModel(EntityPlacement placement, EntityInfo entityInfo, ScreenDocument screen)
        {
            if (placement == null)
                throw new ArgumentNullException("placement");

            if (entityInfo == null)
                throw new ArgumentNullException("entityInfo");

            if (screen == null)
                throw new ArgumentNullException("screen");

            this.Placement = placement;
            this._entityInfo = entityInfo;
            this._screen = screen;

            DeleteCommand = new RelayCommand(Delete);
            FlipCommand = new RelayCommand(Flip);
            RespawnCommand = new RelayCommand(SetRespawnMode);
            StartStateCommand = new RelayCommand(SetStartState);

            ViewModelMediator.Current.GetEvent<ZoomChangedEventArgs>().Subscribe(ZoomChanged);
        }
Beispiel #7
0
        public static EntityPlacement LoadEntityPlacement(XElement entity)
        {
            EntityPlacement info = new EntityPlacement();

            info.Id = entity.TryAttribute<string>("id", Guid.NewGuid().ToString());

            var nameAttr = entity.Attribute("name");
            if (nameAttr == null)
                nameAttr = entity.RequireAttribute("entity");

            info.entity = nameAttr.Value;

            string state = "Start";
            XAttribute stateAttr = entity.Attribute("state");
            if (stateAttr != null) state = stateAttr.Value;
            info.state = state;

            info.screenX = entity.GetAttribute<int>("x");
            info.screenY = entity.GetAttribute<int>("y");

            var dirAttr = entity.Attribute("direction");
            if (dirAttr != null)
            {
                Direction dir = Direction.Left;
                Enum.TryParse<Direction>(dirAttr.Value, true, out dir);
                info.direction = dir;
            }

            var respawnAttr = entity.Attribute("respawn");
            if (respawnAttr != null)
            {
                RespawnBehavior respawn = RespawnBehavior.Offscreen;
                Enum.TryParse<RespawnBehavior>(respawnAttr.Value, true, out respawn);
                info.respawn = respawn;
            }

            return info;
        }
 public AddEntityAction(EntityPlacement entity, ScreenDrawingSurface surface)
 {
     this.entity = entity;
     this.surface = surface;
 }
Beispiel #9
0
        private bool EntityBounded(EntityPlacement entityInfo, Point location)
        {
            Entity entity = Stage.Project.EntityByName(entityInfo.entity);
            MegaMan.Common.Geometry.RectangleF bounds;

            if (entity.MainSprite == null)
            {
                bounds = new MegaMan.Common.Geometry.RectangleF(-8, -8, 16, 16);
            }
            else
            {
                bounds = entity.MainSprite.BoundBox;
                bounds.Offset(-entity.MainSprite.HotSpot.X, -entity.MainSprite.HotSpot.Y);
            }

            bounds.Offset(entityInfo.screenX, entityInfo.screenY);
            return bounds.Contains(location);
        }
Beispiel #10
0
        private bool EntityBounded(EntityPlacement entityInfo, Point location)
        {
            var entity = Stage.Project.EntityByName(entityInfo.entity);
            RectangleF bounds;

            if (entity.DefaultSprite == null)
            {
                bounds = new RectangleF(-8, -8, 16, 16);
            }
            else
            {
                var sprite = entity.DefaultSprite;
                bounds = sprite.BoundBox;
                bounds.Offset(-sprite.HotSpot.X, -sprite.HotSpot.Y);
            }

            bounds.Offset(entityInfo.screenX, entityInfo.screenY);
            return bounds.Contains(location);
        }
Beispiel #11
0
 public void RemoveEntity(EntityPlacement info)
 {
     screen.Layers[0].Entities.Remove(info);
     Dirty = true;
     if (EntitiesChanged != null) EntitiesChanged();
 }
 public void AddEntity(EntityPlacement info)
 {
     screen.Layers[0].Entities.Add(info);
     Dirty = true;
     if (EntityAdded != null) EntityAdded(info);
 }
        private void EntityAdded(EntityPlacement placement)
        {
            var ctrl = new EntityPlacementControl();
            var info = this.Screen.Stage.Project.EntityByName(placement.entity);
            var vm = new EntityPlacementControlViewModel(placement, info, Screen);
            ctrl.DataContext = vm;
            ctrl.Visibility = Visibility.Visible;

            PositionControl(ctrl, vm);
            Canvas.SetZIndex(ctrl, 10000);

            vm.PlacementModified += (s, e) => PositionControl(ctrl, vm);

            this.Children.Add(ctrl);
            Update();
        }
        private void EntityRemoved(EntityPlacement placement)
        {
            var ctrl = this.Children.OfType<EntityPlacementControl>().SingleOrDefault(c => ((EntityPlacementControlViewModel)c.DataContext).Placement == placement);

            if (ctrl != null)
                this.Children.Remove(ctrl);

            Update();
        }
Beispiel #15
0
 public void AddEntity(EntityPlacement info)
 {
     screen.Layers[0].Entities.Add(info);
     Dirty = true;
 }
Beispiel #16
0
 public void RemoveEntity(EntityPlacement info)
 {
     screen.Layers[0].Entities.Remove(info);
 }
Beispiel #17
0
 public void AddEntity(EntityPlacement entity)
 {
     this.Entities.Add(entity);
 }
Beispiel #18
0
        public EntityPlacement AddEntity(Entity entity, Point location)
        {
            var info = new EntityPlacement
                {
                    entity = entity.Name,
                    screenX = location.X,
                    screenY = location.Y,
                };

            screen.Layers[0].Entities.Add(info);

            Dirty = true;

            return info;
        }
 public void AddEntity(EntityPlacement entity)
 {
     this.Entities.Add(entity);
 }
Beispiel #20
0
 public void AddEnemy(EntityPlacement enemy)
 {
     EnemyInfo.Add(enemy);
 }
 public void Track(EntityPlacement placement, GameEntity entity)
 {
     entity.Removed += () => DisableRespawn(placement, entity);
 }