public AnimationSource(MekaItem _item) { if (_item.Contains("Sprites")) { foreach (MekaItem frame in _item["Sprites"].Children) { this.Sprites.Add(GameBase.LoadImageSource(frame.Data)); this.Offsets.Add(frame.Contains("Offset") ? frame["Offset"].To <Vector>() : 0); } } else { ImageSource src = GameBase.LoadImageSource(_item["Spriteset"].Children[0].Data); this.Sprites.Add(src.Split(_item["Spriteset"]["Count"].To <int>())); for (int i = 0; i < this.Sprites.Count; i++) { this.Offsets.Add(0); } } if (_item.Contains("Offset")) { Vector offset = _item["Offset"].To <Vector>(); for (int i = 0; i < this.Sprites.Count; i++) { this.Offsets[i] = offset; } } this.Speed = _item["Speed"].To <int>(); this.Repeated = _item.Contains("Repeated"); }
public PixelFont(string _path) { MekaItem file = MekaItem.LoadFromFile(_path); MekaItem chars = file["Characters"].Children[0]; ImageSource src = new ImageSource(chars.Data); ImageSource[,] cs = src.Split(chars["Count"].To <Point>()); foreach (ImageSource c in cs) { for (int x = 0; x < c.Width; x++) { for (int y = 0; y < c.Height; y++) { if (c[x, y].A > 0 && c[x, y] != Color.White) { c[x, y] = Color.White; } } } } { int y = 0; foreach (MekaItem line in file["Characters"].Children.Where(item => item.Name == "Line")) { for (int x = 0; x < line.Content.Length; x++) { this.Chars[line.Content[x]] = cs[x, y]; } y++; } } if (file.Contains("Character Size")) { this.CharSize = file["Character Size"].To <Point>(); } else { this.CharSize = this.Chars.ToArray()[0].Value.Size; } if (file.Contains("Default")) { this._DefaultChar = file["Default"].Content[0]; } }
public LayerSource(MekaItem _item, Bunch <string> _areasets) { this.Main = _item.Contains("Main"); ImageSource img = GameBase.LoadImageSource(_item["Tiles"].Data); Color[,] px = img.Pixels; this.Tiles = new Tuple <string, int> [img.Width, img.Height]; for (int x = 0; x < img.Width; x++) { for (int y = 0; y < img.Height; y++) { this.Tiles[x, y] = new Tuple <string, int>(_areasets[(int)Beth.FromEndian(px[x, y].Bytes.Sub(0, 2))], (int)Beth.FromEndian(px[x, y].Bytes.Sub(2, 2))); } } foreach (MekaItem entity in _item["Entities"].Children) { this.Entities.Add(new EntityInstance(entity)); } }
public override void OnInitialization() { this.Children.Add(this.Editor = new AnimationEditorHidden()); this.Children.Remove(this.Editor); this.Children.Add(this.AlignmentButtons = new Alignment ( new Label("Animation:"), new Button("Add", () => { this.Parent.ReleaseKey(Key.MouseLeft); File f = this.Parent.OpenFile("png"); if (f != null) { this.Editor.SpritesheetSource = GameBase.LoadImageSource(f.Bytes); this.AnimationShown = true; } }), new Button("Open", () => { this.Parent.ReleaseKey(Key.MouseLeft); File f = this.Parent.OpenFile("meka"); if (f != null) { MekaItem file = MekaItem.FromBytesEncrypted(f.Bytes); this.Editor.SpritesheetSource = GameBase.LoadImageSource(file["Spriteset"].Children[0].Data); this.Editor.BoxSprites.Value = file["Spriteset"]["Count"].To <int>(); this.Editor.BoxSpeed.Value = file["Speed"].To <int>(); this.Editor.BoxRepeated.Checked = file.Contains("Repeated"); this.AnimationShown = true; } }) ) { Spacing = 3 }); }
private void _Receive() { this._Game._Americanize(); //int failed = 0; while (this._Game.IsRunning) { if (this.Server._CanReceive) { //bool f = false; //ByteReader r = new ByteReader(this.Server._Data); //while (r.CanRead && !f) this.Server._Receive(); while (this.Server._ByteReader.CanRead) { //MekaItem data = null; //try { data = r.ReadCustom<MekaItem>(); } //catch { f = true; failed++; this._Game.Title = failed.ToString(); } //if (data != null) //{ MekaItem data = this.Server._ByteReader.ReadCustom <MekaItem, Meka.Hidden.MekaItemParser>(); if (data.Name == "Start") { this.Server.Ids = data["Server IDs"].Content.Split(", ").Select(item => item.To <int>()).ToBunch(); this._Game.LocalPlayerIds = data["Player IDs"].Content.Split(", ").Select(item => item.To <int>()).ToBunch(); this._Game.OnlinePlayerIds = data["User IDs"].Content.Split(", ").Select(item => item.To <int>()).ToBunch(); this._Game._UserIds.Add(this._Game.OnlinePlayerIds); //this._Game.OnServerConnect(data["Info"].Children); this._Game._ServerConnect = data["Info"]; } else if (data.Name == "Sync") { //foreach (MekaItem key in data["Keys"].Children) // this._Game._PressKey(key["Name"].Content, key["ID"].To<int>(), key["Pressed"].To<bool>(), false, false); if (data.Contains("Custom")) { Dictionary <string, MekaItem> syncs = new Dictionary <string, MekaItem>(); foreach (MekaItem sync in data["Custom"].Children) { syncs[sync.Name] = sync; } if (syncs.Count > 0) { this._Game._Syncs.Add(new Tuple <User, Dictionary <string, MekaItem> >(this.Server, syncs)); } } //foreach (MekaItem message in data["Messages"].Children) // this._Game.OnMessageFromServer(message); foreach (MekaItem player in data["Players"].Children) { Entity p = this._Game.RealEntities.First(item => item.PlayerId == player.Name.To <int>()); p.Motion += player.Content.To <Vector>() - (p.Position + p.Motion); } if (data.Contains("Ping")) { this._LastPing = data["Ping"].Content; } if (data.Contains("Info")) { this.Server._Speed = data["Info"]["Speed"].Content.To <double>(); this.Server._Latencies.Add(data["Info"]["Latency"].Content.To <double>()); if (this.Server._Latencies.Count > 10) { this.Server._Latencies.RemoveAt(0); } } } //else if (data.Name == "Key") // this._Game._PressKey(data["Name"].Content, data["ID"].To<int>(), data["Pressed"].To<bool>(), false, false); //this._Game.Title = this.Server._ByteReader._Bytes.Count.ToString(); //} Thread.Sleep(1); } } Thread.Sleep(1); } }
private void _Receive() { this._Game._Americanize(); try { System.Net.WebClient c = new System.Net.WebClient(); this._Ip = c.DownloadString("http://icanhazip.com"); this._Ip = this._Ip.Substring(0, this._Ip.Length - 1); } catch { } //int failed = 0; Bunch <byte> bytes = new Bunch <byte>(); while (this._Game.IsRunning) { foreach (User p in this.Users.Where(item => item._CanReceive)) { p._Receive(); //byte[] bs = p._Data; //MekaItem data = null; //try { data = Todes.Data.Read(bs); bytes += bs; } //catch //{ // failed++; // this._Game.Title = failed.ToString(); // File.Write("Part 0", bytes.ToBunch()); // File.Write("Part 1", bs.ToBunch()); //} while (p._ByteReader.CanRead) { MekaItem data = p._ByteReader.ReadCustom <MekaItem, Meka.Hidden.MekaItemParser>(); if (data.Name == "Sync") { //foreach (MekaItem key in data["Keys"].Children) // this._Game._PressKey(key["Name"].Content, key["ID"].To<int>(), key["Pressed"].To<bool>(), false, false); if (data.Contains("Custom")) { Dictionary <string, MekaItem> syncs = new Dictionary <string, MekaItem>(); foreach (MekaItem sync in data["Custom"].Children) { syncs[sync.Name] = sync; } if (syncs.Count > 0) { this._Game._Syncs.Add(new Tuple <User, Dictionary <string, MekaItem> >(p, syncs)); } } foreach (MekaItem message in data["Messages"].Children) { this._Game.OnMessageFromClient(message); } if (data.Contains("Pong")) { TimeSpan dif = DateTime.Now - this._Pings.First(item => item.Item1 == data["Pong"].Content.To <int>()).Item2; Interlocked.Exchange <Bunch <double> >(ref p._Latencies, p._Latencies + dif.TotalMilliseconds); if (p._Latencies.Count > 10) { p._Latencies.RemoveAt(0); } } } else if (data.Name == "Start") { int ids = data["Local Users"].To <int>(); Bunch <int> nids = new Bunch <int>(); for (int i = 0; i < ids; i++) { int id = this._GetNextId(); this._Game._UserIds.Add(id); this._Game.OnlinePlayerIds.Add(id); p.Ids.Add(id); } MekaItem start = new MekaItem("Start", new List <MekaItem>() { new MekaItem("Server IDs", string.Join(", ", this._Game.LocalPlayerIds.Select(item => item.ToString()))), new MekaItem("Player IDs", string.Join(", ", p.Ids.Select(item => item.ToString()))) }); Bunch <int> uids = this._Game.LocalPlayerIds.Clone(); foreach (User user in this.Users.Where(item => item != p)) { uids.Add(user.Ids); } start.Children.Add(new MekaItem("User IDs", string.Join(", ", uids.Select(item => item.ToString())))); start.Children.Add(new MekaItem("Info", this._Game.OnUserConnect(p))); p.Send(start); p._Started = true; this._Game._ClientConnects.Add(p); } //else if (data.Name == "Key") // this._Game._PressKey(data["Name"].Content, data["ID"].To<int>(), data["Pressed"].To<bool>(), false, false); Thread.Sleep(1); } //this._Game.Title = p._ByteReader._Bytes.Count.ToString(); } Thread.Sleep(1); } }