public Scene(Map mp) { this.map = mp; t.Tick += new EventHandler((o, e) => { game.Draw(g => { game.ClearAll(); if (map != null) { map.DrawMap(g); } layers.ForEach(layer => { if (layer.Visible) layer.draw(g); }); }); game.Refresh(); }); }
public void ChangeMap(Map map) { this.map = map; }
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; }
public void ChangeMap(string mapName) { DeactivatePlayerControl(); m = maps[mapName]; currentscene.ChangeMap(m); ActivatePlayerControl(); }
public Story(GameWindow g, string scriptpath) { this.game = g; this.tb = g.Tiles; this.scriptpath = scriptpath; // Grab images string[] imagefiles = Directory.GetFiles(Path.Combine(scriptpath, "images"), "*.*g"); imagefiles.ToList().ForEach(x => { string imagename = Path.GetFileName(x); images.Add(imagename, Image.FromFile(x)); }); // Grab tiles string[] files = Directory.GetFiles(Path.Combine(scriptpath, "tiles"), "*.png"); files.ToList().ForEach(x => { string tilename = Path.GetFileNameWithoutExtension(x); tb.LoadTile(tilename, x); }); ObjectsAssembly fa = new ObjectsAssembly(tb); // Grab floor types string[] floors = Directory.GetFiles(Path.Combine(scriptpath, "floors"), "*.floor"); floors.ToList().ForEach(x => { string floorname = Path.GetFileNameWithoutExtension(x); fa.AddFloor(floorname, x); }); // Grab object types string[] objects = Directory.GetFiles(Path.Combine(scriptpath, "objects"), "*.desc"); objects.ToList().ForEach(x => { string objname = Path.GetFileNameWithoutExtension(x); fa.AddObject(objname, x); }); // Compile the types and prepare them fa.Compile(); floortypes = fa.GetFloorTypes(); objecttypes = fa.GetObjectTypes(); // Grab maps string[] maps = Directory.GetDirectories(Path.Combine(scriptpath, "maps")); maps.ToList().ForEach(x => { Map m = LoadMap(g.canvas,x); string mapname = Path.GetFileNameWithoutExtension(x); this.maps[mapname] = m; }); currentscene = new PlayScene(null, null); g.Scene = currentscene; player = null; this.m = null; narrationdialog = new NarrationDialog(30, 400, 740, 200); menudialog = new MenuDialog(30, 400, 740, 200); staticImage = new StaticImage(images); staticOverlay = new StaticImage(images); currentscene.AddLayer(staticImage); currentscene.AddLayer(staticOverlay); currentscene.AddLayer(narrationdialog); currentscene.AddLayer(menudialog); //menudialog.SetQuestion("どうする?"); //menudialog.AddMenuItem("a", "Run"); //menudialog.AddMenuItem("b", "Pokemon"); //menudialog.AddMenuItem("c", "LOL What?!"); //menudialog.Visible = true; }
public PlayScene(Map map, ICharacter chr) : base(map) { this.chr = chr; this.map = map; }