Ejemplo n.º 1
0
        public JoinHandler(Join join, int tileSize, int height, int width, string name)
        {
            JoinInfo = join;

            this.height = height;
            this.width = width;
            this.tileSize = tileSize;

            size = join.Size * tileSize;
            ticks = ((JoinInfo.type == JoinType.Vertical) ? Game.CurrentGame.PixelsAcross : Game.CurrentGame.PixelsDown) / Const.ScrollSpeed;

            if (join.screenOne == name)
            {
                NextScreenName = join.screenTwo;
                if (join.type == JoinType.Horizontal)   // bottom edge
                {
                    direction = Direction.Down;
                    threshXmin = join.offsetOne * tileSize;
                    threshYmin = height - Const.PlayerScrollTrigger;
                    threshXmax = threshXmin + size;
                    threshYmax = height + 100;
                    NextScreenX = (join.offsetTwo - join.offsetOne) * tileSize;
                }
                else // right edge
                {
                    direction = Direction.Right;
                    threshXmin = width - Const.PlayerScrollTrigger;
                    threshYmin = join.offsetOne * tileSize;
                    threshXmax = width + 100;
                    threshYmax = threshYmin + size;
                    NextScreenY = (join.offsetTwo - join.offsetOne) * tileSize;
                }
            }
            else
            {
                NextScreenName = join.screenOne;
                if (join.type == JoinType.Horizontal)   // top edge
                {
                    direction = Direction.Up;
                    threshXmin = join.offsetTwo * tileSize;
                    threshYmin = -100;
                    threshXmax = threshXmin + size;
                    threshYmax = Const.PlayerScrollTrigger;
                    NextScreenX = (join.offsetOne - join.offsetTwo) * tileSize;
                }
                else // left edge
                {
                    direction = Direction.Left;
                    threshXmin = -100;
                    threshYmin = join.offsetTwo * tileSize;
                    threshXmax = Const.PlayerScrollTrigger;
                    threshYmax = threshYmin + size;
                    NextScreenY = (join.offsetOne - join.offsetTwo) * tileSize;
                }
            }
        }
Ejemplo n.º 2
0
 private static JoinHandler CreateJoin(Join join, ScreenHandler currentScreen)
 {
     if (join.bossDoor)
     {
         GameEntity door = GameEntity.Get(join.bossEntityName);
         if (door != null)
         {
             return new BossDoorHandler(door, join, currentScreen);
         }
     }
     return new JoinHandler(join, currentScreen);
 }
Ejemplo n.º 3
0
        public JoinForm(Join join, IEnumerable<ScreenDocument> screens)
        {
            InitializeComponent();
            this.join = join;
            joinType.SelectedIndex = 0;

            foreach (ScreenDocument s in screens)
            {
                screenOne.Items.Add(s.Name);
                screenTwo.Items.Add(s.Name);
            }

            Direction = join.direction;
            JoinWidth = join.Size;
            ScreenOne = join.screenOne;
            ScreenTwo = join.screenTwo;
            OffsetOne = join.offsetOne;
            OffsetTwo = join.offsetTwo;
            Type = join.type;
        }
Ejemplo n.º 4
0
        public BossDoorHandler(Join join, IGameplayContainer container, IEntityPool entityPool, int tileSize, int height, int width, string name)
            : base(join, tileSize, height, width, name)
        {
            this.container = container;
            _entityPool = entityPool;

            if (direction == Direction.Down)
            {
                doorOneX = join.offsetOne * tileSize;
                doorOneY = height - tileSize;

                doorTwoX = join.offsetOne * tileSize;
                doorTwoY = height;
            }
            else if (direction == Direction.Left)
            {
                doorOneX = 0;
                doorOneY = join.offsetTwo * tileSize;

                doorTwoX = -tileSize;
                doorTwoY = join.offsetTwo * tileSize;
            }
            else if (direction == Direction.Right)
            {
                doorOneX = width - tileSize;
                doorOneY = join.offsetOne * tileSize;

                doorTwoX = width;
                doorTwoY = join.offsetOne * tileSize;
            }
            else if (direction == Direction.Up)
            {
                doorOneX = join.offsetTwo * tileSize;
                doorOneY = 0;

                doorTwoX = join.offsetTwo * tileSize;
                doorTwoY = -tileSize;
            }
        }
Ejemplo n.º 5
0
        private void DrawJoinEnd(Join join, bool one)
        {
            if (joinLayer == null) return;
            using (Graphics g = Graphics.FromImage(joinLayer))
            {
                int offset = one ? join.offsetOne : join.offsetTwo;
                int start = offset * Screen.Tileset.TileSize;
                int end = start + (join.Size * Screen.Tileset.TileSize);
                int edge;
                Pen pen;

                if (one ? join.direction == JoinDirection.BackwardOnly : join.direction == JoinDirection.ForwardOnly) pen = blockPen;
                else pen = passPen;

                if (join.type == JoinType.Horizontal)
                {
                    edge = one ? Screen.PixelHeight - 2 : 2;
                    int curl = one ? edge - 6 : edge + 6;
                    g.DrawLine(pen, start, edge, end, edge);
                    g.DrawLine(pen, start + 1, edge, start + 1, curl);
                    g.DrawLine(pen, end - 1, edge, end - 1, curl);
                }
                else
                {
                    edge = one ? Screen.PixelWidth - 2 : 2;
                    int curl = one ? edge - 6 : edge + 6;
                    g.DrawLine(pen, edge, start, edge, end);
                    g.DrawLine(pen, edge, start, curl, start);
                    g.DrawLine(pen, edge, end, curl, end);
                }
            }
        }
Ejemplo n.º 6
0
 public void RemoveJoin(Join join)
 {
     map.Joins.Remove(join);
     Dirty = true;
     if (JoinChanged != null) JoinChanged(join);
 }
Ejemplo n.º 7
0
 public void AddJoin(Join join)
 {
     map.Joins.Add(join);
     Dirty = true;
     if (JoinChanged != null) JoinChanged(join);
 }
Ejemplo n.º 8
0
        private void LayoutNextScreen(ScreenDrawingSurface surface, Point location, Join join, bool one)
        {
            int offsetX = location.X;
            int offsetY = location.Y;
            int mag = one ? 1 : -1;

            if (join.type == JoinType.Horizontal)
            {
                offsetX += (join.offsetOne - join.offsetTwo) * stage.Tileset.TileSize * mag;
                offsetY += surfaces[join.screenOne].Screen.PixelHeight * mag;
            }
            else
            {
                offsetX += surfaces[join.screenOne].Screen.PixelWidth * mag;
                offsetY += (join.offsetOne - join.offsetTwo) * stage.Tileset.TileSize * mag;
            }

            LayoutFromScreen(surface, new Point(offsetX, offsetY));
        }
Ejemplo n.º 9
0
        public StageInfo LoadStageXml(FilePath path)
        {
            _info = new StageInfo();

            _info.StagePath = path;

            var mapXml = XElement.Load(Path.Combine(_info.StagePath.Absolute, "map.xml"));
            _info.Name = Path.GetFileNameWithoutExtension(_info.StagePath.Absolute);

            string tilePathRel = mapXml.Attribute("tiles").Value;
            var tilePath = FilePath.FromRelative(tilePathRel, _info.StagePath.BasePath);

            var tileset = new TilesetXmlReader().Load(tilePath);
            _info.ChangeTileset(tileset);

            _info.PlayerStartX = 3;
            _info.PlayerStartY = 3;

            LoadMusicXml(mapXml);
            LoadScreens(mapXml);

            XElement start = mapXml.Element("Start");
            if (start != null)
            {
                _info.StartScreen = start.RequireAttribute("screen").Value;
                _info.PlayerStartX = start.GetAttribute<int>("x");
                _info.PlayerStartY = start.GetAttribute<int>("y");
            }

            foreach (XElement contPoint in mapXml.Elements("Continue"))
            {
                string screen = contPoint.GetAttribute<string>("screen");
                int x = contPoint.GetAttribute<int>("x");
                int y = contPoint.GetAttribute<int>("y");
                _info.AddContinuePoint(screen, new Point(x, y));
            }

            foreach (XElement join in mapXml.Elements("Join"))
            {
                string t = join.Attribute("type").Value;
                JoinType type;
                if (t.ToLower() == "horizontal") type = JoinType.Horizontal;
                else if (t.ToLower() == "vertical") type = JoinType.Vertical;
                else throw new GameXmlException(join, "map.xml file contains invalid join type.");

                string s1 = join.RequireAttribute("s1").Value;
                string s2 = join.RequireAttribute("s2").Value;
                int offset1 = join.GetAttribute<int>("offset1");
                int offset2 = join.GetAttribute<int>("offset2");
                int size = join.GetAttribute<int>("size");

                JoinDirection direction;
                XAttribute dirAttr = join.Attribute("direction");
                if (dirAttr == null || dirAttr.Value.ToUpper() == "BOTH") direction = JoinDirection.Both;
                else if (dirAttr.Value.ToUpper() == "FORWARD") direction = JoinDirection.ForwardOnly;
                else if (dirAttr.Value.ToUpper() == "BACKWARD") direction = JoinDirection.BackwardOnly;
                else throw new GameXmlException(dirAttr, "map.xml file contains invalid join direction.");

                string bosstile = null;
                XAttribute bossAttr = join.Attribute("bossdoor");
                bool bossdoor = (bossAttr != null);
                if (bossdoor) bosstile = bossAttr.Value;

                Join j = new Join();
                j.direction = direction;
                j.screenOne = s1;
                j.screenTwo = s2;
                j.offsetOne = offset1;
                j.offsetTwo = offset2;
                j.type = type;
                j.Size = size;
                j.bossDoor = bossdoor;
                j.bossEntityName = bosstile;

                _info.Joins.Add(j);
            }

            return _info;
        }
Ejemplo n.º 10
0
 private static void EditJoin(ScreenDrawingSurface surface, Join join)
 {
     JoinForm form = new JoinForm(join, surface.Screen.Stage.Screens);
     form.OK += () => surface.Screen.Stage.RaiseJoinChange(join);
     form.Show();
 }
Ejemplo n.º 11
0
 private static void DeleteJoin(ScreenDrawingSurface surface, Join join)
 {
     surface.Screen.Stage.RemoveJoin(join);
 }
Ejemplo n.º 12
0
 private static void NewJoin(ScreenDrawingSurface surface, string s1, string s2, JoinType type, int offset)
 {
     Join newjoin = new Join {screenTwo = s2, screenOne = s1, type = type, Size = 1};
     newjoin.offsetOne = newjoin.offsetTwo = offset;
     JoinForm form = new JoinForm(newjoin, surface.Screen.Stage.Screens);
     form.OK += () => surface.Screen.Stage.AddJoin(newjoin);
     form.Show();
 }
Ejemplo n.º 13
0
 // this should probably be replaced by a join wrapper that has events
 public void RaiseJoinChange(Join join)
 {
     if (JoinChanged != null) JoinChanged(join);
 }
Ejemplo n.º 14
0
        private JoinHandler CreateJoin(Join join, StageHandler stage, ScreenInfo screen)
        {
            if (join.bossDoor)
            {
                return new BossDoorHandler(join, stage, _entityPool, screen.Tileset.TileSize, screen.PixelHeight, screen.PixelWidth, screen.Name);
            }

            return new JoinHandler(join, screen.Tileset.TileSize, screen.PixelHeight, screen.PixelWidth, screen.Name);
        }
Ejemplo n.º 15
0
        public void LoadMapXml(FilePath path)
        {
            StagePath = path;

            var mapXml = XElement.Load(Path.Combine(StagePath.Absolute, "map.xml"));
            Name = Path.GetFileNameWithoutExtension(StagePath.Absolute);

            string tilePathRel = mapXml.Attribute("tiles").Value;
            tilePath = FilePath.FromRelative(tilePathRel, StagePath.Absolute);

            Tileset = new Tileset(tilePath.Absolute);

            PlayerStartX = 3;
            PlayerStartY = 3;

            LoadMusicXml(mapXml);
            LoadScreenXml(mapXml);

            XElement start = mapXml.Element("Start");
            if (start != null)
            {
                int px, py;
                var screenAttr = start.Attribute("screen");
                if (screenAttr == null) throw new Exception("Start tag must have a screen attribute!");
                StartScreen = screenAttr.Value;
                if (!start.Attribute("x").Value.TryParse(out px)) throw new Exception("Start tag x is not a valid integer!");
                PlayerStartX = px;
                if (!start.Attribute("y").Value.TryParse(out py)) throw new Exception("Start tag y is not a valid integer!");
                PlayerStartY = py;
            }

            foreach (XElement contPoint in mapXml.Elements("Continue"))
            {
                string screen = contPoint.Attribute("screen").Value;
                int x;
                contPoint.Attribute("x").Value.TryParse(out x);
                int y;
                contPoint.Attribute("y").Value.TryParse(out y);
                continuePoints.Add(screen, new Point(x, y));
            }

            foreach (XElement join in mapXml.Elements("Join"))
            {
                string t = join.Attribute("type").Value;
                JoinType type;
                if (t.ToLower() == "horizontal") type = JoinType.Horizontal;
                else if (t.ToLower() == "vertical") type = JoinType.Vertical;
                else throw new Exception("map.xml file contains invalid join type.");

                string s1 = join.Attribute("s1").Value;
                string s2 = join.Attribute("s2").Value;
                int offset1;
                join.Attribute("offset1").Value.TryParse(out offset1);
                int offset2;
                join.Attribute("offset2").Value.TryParse(out offset2);
                int size;
                join.Attribute("size").Value.TryParse(out size);

                JoinDirection direction;
                XAttribute dirAttr = join.Attribute("direction");
                if (dirAttr == null || dirAttr.Value.ToUpper() == "BOTH") direction = JoinDirection.Both;
                else if (dirAttr.Value.ToUpper() == "FORWARD") direction = JoinDirection.ForwardOnly;
                else if (dirAttr.Value.ToUpper() == "BACKWARD") direction = JoinDirection.BackwardOnly;
                else throw new Exception("map.xml file contains invalid join direction.");

                string bosstile = null;
                XAttribute bossAttr = join.Attribute("bossdoor");
                bool bossdoor = (bossAttr != null);
                if (bossdoor) bosstile = bossAttr.Value;

                Join j = new Join();
                j.direction = direction;
                j.screenOne = s1;
                j.screenTwo = s2;
                j.offsetOne = offset1;
                j.offsetTwo = offset2;
                j.type = type;
                j.Size = size;
                j.bossDoor = bossdoor;
                j.bossEntityName = bosstile;

                Joins.Add(j);
            }
        }
Ejemplo n.º 16
0
 private void StageJoinChanged(Join obj)
 {
     LayoutScreens();
 }