コード例 #1
0
        public TileSelection(GameWindow win)
        {
            InitializeComponent();
            this.win = win;

            // Grab tiles
            string[] files = Directory.GetFiles("res/res/tiles", "*.png");
            files.ToList().ForEach(x => {
                RadioButton cb = new RadioButton();
                cb.Appearance = Appearance.Button;
                cb.Image = Bitmap.FromFile(x);
                cb.Size = new Size(32, 32);
                flow_tiles.Controls.Add(cb);

                string tilename = Path.GetFileNameWithoutExtension(x);
                cb.Tag = win.LoadTile(tilename, x);

                cb.CheckedChanged += new EventHandler((ob, ev) => {
                    selectedtile = (int)cb.Tag;
                });
            });

            MapList ml = new MapList();
            ml.Show();

            (flow_tiles.Controls[0] as RadioButton).Checked = true;

            // Make the selection box
            Bitmap box = new Bitmap(32, 32);
            using (Graphics gfx = Graphics.FromImage(box))
            {
                gfx.FillRectangle(new SolidBrush(Color.FromArgb(0, Color.Black)), new Rectangle(0, 0, 32, 32));
                gfx.DrawRectangle(new Pen(Color.Cyan), new Rectangle(0, 0, 31, 31));
            }

            selectionbox = new AnObject(win.LoadTile("selection", box));

            m = new Map(win, 30, 30);

            m.CheckPassable = false;
            m.SetCeiling(selectionbox, 0, 0);
            m.FillFloor(new FloorTile(0));

             s = new Scene(m);
            win.Scene = s;

            // Set up the keys
            s.KeyDown += new EventHandler<KeyEventArgs>((o, e) =>
            {
                m.SetCeiling(null, m.CameraX, m.CameraY);
                switch (e.KeyCode)
                {
                    case Keys.Up:
                        m.CameraY--;
                        break;
                    case Keys.Down:
                        m.CameraY++;
                        break;
                    case Keys.Left:
                        m.CameraX--;
                        break;
                    case Keys.Right:
                        m.CameraX++;
                        break;
                    case Keys.Space:
                        m.SetFloor(new FloorTile(selectedtile), m.CameraX, m.CameraY);
                        break;
                    //case Keys.Escape:
                    //    mnu.Visible = !mnu.Visible;
                    //    break;
                }

                m.SetCeiling(selectionbox, m.CameraX, m.CameraY);
            });
        }
コード例 #2
0
        Map LoadMap(MapEditor editor, GameControl gc, string map)
        {
            if (maps[map].map != null)
            {
                maps[map].map.GameControl = gc;
                return maps[map].map;
            }

            string mapdir = maps[map].fulldir;

            Map m;
            BinaryFormatter bf = new BinaryFormatter();

            // Load the floor
            using (StreamReader floortiles = new StreamReader(Path.Combine(mapdir, "floor.tiles")))
            {
                using (FileStream floormap = new FileStream(Path.Combine(mapdir, "floor.map"), FileMode.Open))
                {
                    int[,] floor = (int[,])bf.Deserialize(floormap);
                    int w = floor.GetUpperBound(0) + 1;
                    int h = floor.GetUpperBound(1) + 1;
                    m = new Map(gc, w, h);

                    Dictionary<int, string> tilenumToName = new Dictionary<int, string>();
                    while (!floortiles.EndOfStream)
                    {
                        string line = floortiles.ReadLine();
                        string[] tokens = line.Split(':');
                        tilenumToName[int.Parse(tokens[0])] = tokens[1];
                    }
                    for (int xx = 0; xx < w; xx++)
                    {
                        for (int yy = 0; yy < h; yy++)
                        {
                            m.SetFloor((MapFloor)Activator.CreateInstance(floortypes[tilenumToName[floor[xx, yy]]]), xx, yy);
                        }
                    }
                }
            }

            Regex objectnamelabel = new Regex(@"^\[(?<objectname>[a-z][a-z|0-9]*)\]", RegexOptions.Compiled);
            // Load the objects that are on this map
            using (StreamReader objectlist = new StreamReader(Path.Combine(mapdir, "objects.list")))
            {
                string line = objectlist.ReadLine();
                Match match = objectnamelabel.Match(line);

                while (!objectlist.EndOfStream)
                {
                    string instancename = match.Groups["objectname"].ToString();
                    ICharacter mo = null;
                    // For each instance block
                    while (!objectlist.EndOfStream)
                    {
                        line = objectlist.ReadLine();

                        if (line.StartsWith("type:"))
                        {
                            string type = line.Substring(5);
                            mo = (ICharacter)Activator.CreateInstance(objecttypes[type]);
                        }
                        else if (line.StartsWith("location:"))
                        {
                            string[] tokens = line.Substring(9).Split(',');
                            m.SetCharacter(mo, int.Parse(tokens[0]), int.Parse(tokens[1]));
                        }
                        else if (line.StartsWith("use:"))
                        {
                        }

                        match = objectnamelabel.Match(line);
                        if (match.Success) break;
                    }
                }

            }

            return m;
        }
コード例 #3
0
 public void ApplyFloor(Map map, int x, int y)
 {
     map.SetFloor((MapFloor)Activator.CreateInstance(selectedFloor), x, y);
 }
コード例 #4
0
ファイル: Story.cs プロジェクト: davidsiaw/emeralddream
        Map LoadMap(GameControl g, string mapdir)
        {
            Map m;
            BinaryFormatter bf = new BinaryFormatter();

            // Load the floor
            using (StreamReader floortiles = new StreamReader(Path.Combine(mapdir, "floor.tiles")))
            {
                using (FileStream floormap = new FileStream(Path.Combine(mapdir, "floor.map"), FileMode.Open))
                {
                    int[,] floor = (int[,])bf.Deserialize(floormap);
                    int w = floor.GetUpperBound(0) + 1;
                    int h = floor.GetUpperBound(1) + 1;
                    m = new Map(g, w, h);

                    Dictionary<int, string> tilenumToName = new Dictionary<int, string>();
                    while (!floortiles.EndOfStream)
                    {
                        string line = floortiles.ReadLine();
                        string[] tokens = line.Split(':');
                        tilenumToName[int.Parse(tokens[0])] = tokens[1];
                    }
                    for (int xx = 0; xx < w; xx++)
                    {
                        for (int yy = 0; yy < h; yy++)
                        {
                            m.SetFloor((MapFloor)Activator.CreateInstance(floortypes[tilenumToName[floor[xx, yy]]]), xx, yy);
                        }
                    }
                }
            }

            Regex objectnamelabel = new Regex(@"^\[(?<objectname>[a-z][a-z|0-9]*)\]", RegexOptions.Compiled);
            // Load the objects that are on this map
            using (StreamReader objectlist = new StreamReader(Path.Combine(mapdir, "objects.list")))
            {
                string line = objectlist.ReadLine();
                Match match = objectnamelabel.Match(line);

                while (!objectlist.EndOfStream)
                {
                    string instancename = match.Groups["objectname"].ToString();
                    ICharacter mo = null;
                    // For each instance block
                    while (!objectlist.EndOfStream)
                    {
                        line = objectlist.ReadLine();

                        if (line.StartsWith("type:"))
                        {
                            string type = line.Substring(5);
                            mo = (ICharacter)Activator.CreateInstance(objecttypes[type]);
                        }
                        else if (line.StartsWith("location:"))
                        {
                            string[] tokens = line.Substring(9).Split(',');
                            m.SetCharacter(mo, int.Parse(tokens[0]), int.Parse(tokens[1]));
                        }
                        else if (line.StartsWith("use:"))
                        {
                            Script s = new Script("inst_" + instancename, objectlist, true);

                            mo.Use = (st) => { s.Execute(st); };
                        }

                        match = objectnamelabel.Match(line);
                        if (match.Success) break;
                    }
                }

                //var ob = (ICharacter)Activator.CreateInstance(objecttypes["box"]);
                //m.SetCharacter(ob, 10, 5);

                //Thread t = new Thread(x =>
                //{
                //    int xx = 10;
                //    int yy = 5;
                //    bool right = true;
                //    while (true)
                //    {
                //        Thread.Sleep(1000);

                //        if (right)
                //        {
                //            if (m.MoveCharacter(xx, yy, Direction.Right))
                //            {
                //                xx++;
                //            }
                //            else
                //            {
                //                right = false;
                //            }
                //        }
                //        else
                //        {
                //            if (m.MoveCharacter(xx, yy, Direction.Left))
                //            {
                //                xx--;
                //            }
                //            else
                //            {
                //                right = true;
                //            }
                //        }
                //    }
                //});
                //t.IsBackground = true;
                //t.Start();

            }

            return m;
        }