public void MovePlayer(int tag, int num) { Tuple <double, double> vect; if (!server.Players[num].IsRemote) { vect = view.AngleByMousePos(); } else { vect = Utily.MakePair <double>(server.Players[num].MousePos.Item1 - arena.map.players[tag].x, server.Players[num].MousePos.Item2 - arena.map.players[tag].y); } if (Utily.Hypot2(vect.Item1, vect.Item2) < Map.RPlayer * Map.RPlayer * 2) { arena.MovePlayer(tag, Utily.MakePair <double>(0, 0)); view.MovePlayer(tag, Utily.MakePair <double>(0, 0)); } else { int Forw = server.Players[num].Forward, Left = server.Players[num].Left; var newvect = Utily.MakePair <double>(vect.Item1 * Forw + vect.Item2 * Left, vect.Item2 * Forw - vect.Item1 * Left); arena.MovePlayer(tag, newvect); view.MovePlayer(tag, newvect); } }
public void ReleaseMouseDown(int tag, int num, int button) { if (state == ControlState.BattleState) { if (button == (int)Mouse.Button.Left) { Tuple <double, double> vect; if (!server.Players[num].IsRemote) { vect = view.AngleByMousePos(); } else { vect = vect = Utily.MakePair <double>(server.Players[num].MousePos.Item1 - arena.map.players[tag].x, server.Players[num].MousePos.Item2 - arena.map.players[tag].y); } if (Utily.Hypot2(vect.Item1, vect.Item2) == 0) { return; } int tagArr = arena.FirePlayer(tag, vect); if (tagArr != -1) { view.AddArrow(tagArr); } } } }
public void MovePlayer(int tag, Tuple <double, double> speed) { double m = players[tag].Speed(); Tuple <double, double> NewVect = Utily.Normalizing(speed, players[tag].Speed()); map.MovePlayer(tag, NewVect); }
public void ApplyString(string s) { if (s == "") { return; } int ind = s.IndexOf('#'); int[] data = s.Substring(0, ind).Split().Select(int.Parse).ToArray(); for (int i = 0; i < data.Length - 2; i += 2) { int code = data[i]; TypeKeyDown tkd = (TypeKeyDown)data[i + 1]; if (tkd == TypeKeyDown.KeyDown) { AddKey(code); } if (tkd == TypeKeyDown.KeyUp) { KeyUp(code); } if (tkd == TypeKeyDown.MouseDown) { MouseDown(code); } } MousePos = Utily.MakePair <int>(data[data.Length - 2], data.Last()); NickName = s.Substring(ind + 1); }
/*public void HealHP(int HPHealed) * { * if (Health + HPHealed >= MAX_HP) * { * Health = MAX_HP; * }else * { * Health += HPHealed; * } * } * public void NextItem() * { * int yk = rightHand + 1; * int cntItem = Inventory.totalNumberofItems; * while (!inventory.isInStock(yk % cntItem) || yk % cntItem == 0 || Items.allItems[yk % cntItem] is Arrow) ++yk; || rightHand = yk % cntItem; ||} ||public void PrevItem() ||{ || int yk = rightHand - 1; || int cntItem = Inventory.totalNumberofItems; || while (!inventory.isInStock((yk + cntItem) % cntItem) || (yk + cntItem) % cntItem == 0 || Items.allItems[(yk + cntItem) % cntItem] is Arrow) || --yk; || rightHand = (yk + cntItem) % cntItem; ||}*/ /* * public void NextArrow() * { * int yk = inventory.getCurrentArrow().id + 1; * int cntItem = Inventory.totalNumberofItems; * while (!inventory.isInStock(yk % cntItem) || !(Items.allItems[yk % cntItem] is Arrow)) ++yk; * inventory.setCurrentArrow(yk % cntItem); * } * public void PrevArrow() * { * int yk = inventory.getCurrentArrow().id - 1; * int cntItem = Inventory.totalNumberofItems; * while (!inventory.isInStock((yk + cntItem) % cntItem) || !(Items.allItems[(yk + cntItem) % cntItem] is Arrow)) * --yk; * inventory.setCurrentArrow(yk % cntItem); * } */ /* * public string LargeString() * { * StringBuilder ans = new StringBuilder(); * ans.Append(Health); * ans.Append(" "); * ans.Append(rightHand); * ans.Append(" "); * ans.Append(RightReloadTimer.ElapsedMilliseconds); * ans.Append(" "); * ans.Append(inventory.LargeString()); * return ans.ToString(); * } * public string SmallString() * { * StringBuilder ans = new StringBuilder(); * ans.Append(Health); * ans.Append(" "); * ans.Append(rightHand); * ans.Append(inventory.SmallString()); * return ans.ToString(); * } */ public void TakeSmallString(string s) { var pla_inv = s.Split('#'); var arr = pla_inv[0].Split(' '); Health = Utily.Parse(arr[0]); rightHand = Utily.Parse(arr[1]); inventory.TakeSmallString(pla_inv[1]); }
private double Length(double x, double y, double x1, double y1, double x2, double y2) { double len = ((y1 - y2) * x + (x2 - x1) * y + (x1 * y2 - x2 * y1)) * ((y1 - y2) * x + (x2 - x1) * y + (x1 * y2 - x2 * y1)) / ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); if (mul(x - x1, y - y1, x2 - x1, y2 - y1) < 0 || mul(x - x2, y - y2, x2 - x1, y2 - y1) < 0) { return(Math.Min(Utily.Hypot2(x - x1, y - y1), Utily.Hypot2(x - x2, y - y2))); } return(len); }
public int AddPlayer(string name) { int tag = Utily.GetTag(); players[tag] = new Player(); players[tag].respawn(); ArenaPlayer[tag] = new APlayer(name); map.AddPlayer(tag); map.SpawnPlayer(tag); return(tag); }
public void Update() { map.UpDate(); MEvent Event; while ((Event = map.NextEvent()) != null) { if (Event.Type == MEvents.PlayerArrow) { int TagArrow = ((MEventArrowHit)Event).TagArrow; int TagPlayer = ((MEventArrowHit)Event).TagPlayer; players[TagPlayer].recieveDamage(Arrows[TagArrow].dmg); if (players[TagPlayer].isDead()) { if (ArenaPlayer.ContainsKey(Arrows[TagArrow].creater)) { ArenaPlayer[Arrows[TagArrow].creater].AddKill(); } ArenaPlayer[TagPlayer].AddDeath(); if (players[TagPlayer].rightHand != 1) { int NewTag = Utily.GetTag(); Drops.Add(NewTag, new ADrop(1, players[TagPlayer].rightHand)); map.SpawnDrops(NewTag, map.players[TagPlayer].x, map.players[TagPlayer].y); } map.SpawnPlayer(TagPlayer); players[TagPlayer].respawn(); } Arrows.Remove(TagArrow); } if (Event.Type == MEvents.PlayerDrop) { var drop = Drops[((MEventDrop)Event).TagDrop]; players[((MEventDrop)Event).TagPlayer].pickedUpItem(drop.id, drop.Count); Drops.Remove(((MEventDrop)Event).TagDrop); if (((MEventDrop)Event).BySpawner) { DropForRespawn.Enqueue(Utily.MakePair <long, int>(timer.ElapsedMilliseconds, ((MEventDrop)Event).NumSpawner)); } } if (Event.Type == MEvents.DestroyArrow) { Arrows.Remove(((MEventDestroyArrow)Event).TagArrow); } } while (DropForRespawn.Count > 0 && DropForRespawn.Peek().Item1 + WaitRespawnDrop < timer.ElapsedMilliseconds) { int num = DropForRespawn.Dequeue().Item2; int tag = Utily.GetTag(); map.SpawnDrops(num, tag); Drops.Add(tag, new ADrop(map.dropSpawners[num].count, map.dropSpawners[num].id)); } }
public void TakeLargeString(string s) { var arr = s.Split(' '); Mana = Utily.Parse(arr[0]); currentArrow = Utily.Parse(arr[1]); totalNumberofItems = Utily.Parse(arr[2]); for (int i = 0; i < totalNumberofItems; ++i) { inventory[i] = Utily.Parse(arr[3 + i]); } }
public int TakeAllString(string s) { var BigBlock = s.Split('#'); //map.TakeString(BigBlock[0]); TakeString(BigBlock[1], BigBlock[2], BigBlock[3]); var pla = BigBlock[4].Split(';'); HashSet <int> IsUsed = new HashSet <int>(); for (int i = 0; i < pla.Length; i++) { int ind = pla[i].IndexOf(' '); int tag = Utily.Parse(pla[i].Substring(0, ind)); if (!players.ContainsKey(tag)) { players.Add(tag, new Player()); } else { IsUsed.Add(tag); } players[tag].TakeSmallString(pla[i].Substring(ind + 1)); } int MainPlayerTag; { int ind = BigBlock[5].IndexOf(' '); int tag = Utily.Parse(BigBlock[5].Substring(0, ind)); if (!players.ContainsKey(tag)) { players.Add(tag, new Player()); } else { IsUsed.Add(tag); } players[tag].TakeLargeString(BigBlock[5].Substring(ind + 1)); MainPlayerTag = tag; } List <int> ForRemove = new List <int>(); foreach (var i in players) { if (!IsUsed.Contains(i.Key)) { ForRemove.Add(i.Key); } } foreach (var i in ForRemove) { players.Remove(i); } return(MainPlayerTag); }
public static MPlayer Load(string save) { string[] args = save.Split().ToArray(); bool tmp; bool Exist = Boolean.TryParse(args[0], out tmp); double x = double.Parse(args[1]), y = double.Parse(args[2]); Tuple <double, double> Speed = new Tuple <double, double>(double.Parse(args[3]), double.Parse(args[4])); MPlayer Pl = new MPlayer(Utily.GetTag(), x, y); Pl.Speed = Speed; Pl.Exist = Exist; return(Pl); }
private bool IsCrossCircleSquare(double x, double y, double r, double x1, double y1, double x2, double y2) { if (y1 > y2) { Utily.Swap <double>(ref y1, ref y2); } if (x1 > x2) { Utily.Swap <double>(ref x1, ref x2); } double dist1 = GetDistToVertSegm(x1, y1, y2, x, y); double dist3 = GetDistToVertSegm(x2, y1, y2, x, y); double dist2 = GetDistToVertSegm(-y1, x1, x2, -y, x); double dist4 = GetDistToVertSegm(-y2, x1, x2, -y, x); double len = Math.Min(Math.Min(dist1, dist2), Math.Min(dist3, dist4)); return(len < r * r); }
public void NewMap(string name) { map = new Map("./data/Maps/" + name + ".txt"); foreach (var i in players) { map.AddPlayer(i.Key); players[i.Key].respawn(); } Arrows.Clear(); Drops.Clear(); DropForRespawn.Clear(); for (int i = 0; i < map.dropSpawners.Count; ++i) { int tag = Utily.GetTag(); map.SpawnDrops(i, tag); Drops.Add(tag, new ADrop(map.dropSpawners[i].count, map.dropSpawners[i].id)); } timer.Restart(); }
public int FirePlayer(int tag, Tuple <double, double> vect) { int dmg = players[tag].attack(); if (dmg <= 0) { return(-1); } Tuple <double, double> NewVect = Utily.Normalizing(vect, players[tag].ArrowSpeed()); int arTag = Utily.GetTag(); int nowid = players[tag].inventory.getCurrentArrow().id; if (players[tag].getItemRight() is Magic) { nowid = players[tag].rightHand; } Arrows[arTag] = new AArow(tag, dmg, nowid); map.FirePlayer(tag, arTag, NewVect.Item1, NewVect.Item2); return(arTag); }
public void SpawnPlayer(int Tag) { List <Tuple <double, double> > ListOfGoodPlace = new List <Tuple <double, double> >(); foreach (var p in spawners) { Entity e = new Entity(0, p.Item1, p.Item2, RPlayer); bool bol = true; foreach (var pl in players) { bol = bol && !IsCrossEntity(e, pl.Value); } if (bol) { ListOfGoodPlace.Add(p); } } int i = Utily.Next() % ListOfGoodPlace.Count; SpawnPlayer(Tag, (int)ListOfGoodPlace[i].Item1, (int)ListOfGoodPlace[i].Item2); }
public void AddKey(int key) { KeyDown.Enqueue(Utily.MakePair <int, TypeKeyDown>(key, TypeKeyDown.KeyDown)); if (key == (int)Keyboard.Key.W) { isW = true; } if (key == (int)Keyboard.Key.S) { isS = true; } if (key == (int)Keyboard.Key.A) { isA = true; } if (key == (int)Keyboard.Key.D) { isD = true; } UpdateDir(); }
public void MouseDown(int button) { KeyDown.Enqueue(Utily.MakePair <int, TypeKeyDown>(button, TypeKeyDown.MouseDown)); }
public Tuple <double, double> AngleByMousePos() { var mp = viewPlayers[MainPlayer]; return(Utily.MakePair <double>(NowMouseX - mp.x + CameraPosX, NowMouseY - mp.y + CameraPosY)); }
public void LoadMap(string path) { using (StreamReader sr = File.OpenText(path)) { string s = ""; List <string> args = new List <string>(); while ((s = sr.ReadLine()) != null) { args.Add(s); } int[] tmp = args[0].Split().Select(x => int.Parse(x)).ToArray(); this.width = tmp[0]; this.height = tmp[1]; int couPl = int.Parse(args[1]); this.players = new Dictionary <int, MPlayer>(); for (int i = 2; i < couPl + 2; ++i) { string stmp = args[i]; string[] Tmp = stmp.Split().ToArray(); this.players.Add(int.Parse(Tmp[0]), MPlayer.Load(stmp)); } int couArr = int.Parse(args[couPl + 2]); this.arrows = new Dictionary <int, MArrow>(); for (int i = couPl + 3; i < couPl + 3 + couArr; ++i) { string stmp = args[i]; string[] Tmp = stmp.Split().ToArray(); this.arrows.Add(int.Parse(Tmp[0]), MArrow.Load(stmp)); } int couDro = int.Parse(args[couArr + couPl + 3]); this.drops = new Dictionary <int, MDrop>(); for (int i = couPl + 4 + couArr; i < couPl + 4 + couArr + couDro; ++i) { string stmp = args[i]; string[] Tmp = stmp.Split().ToArray(); this.drops.Add(int.Parse(Tmp[0]), MDrop.Load(stmp)); } int nowline = 4 + couArr + couDro + couPl; int countSpawn = int.Parse(args[nowline]); ++nowline; spawners = new List <Tuple <double, double> >(); for (int i = 0; i < countSpawn; ++i) { int x = int.Parse(args[nowline].Split()[0]), y = int.Parse(args[nowline].Split()[1]); ++nowline; spawners.Add(Utily.MakePair <double>(x, y)); } int countSpawnDrop = int.Parse(args[nowline]); ++nowline; dropSpawners = new List <DropSpawner>(); for (int i = 0; i < countSpawnDrop; ++i) { int x = int.Parse(args[nowline].Split()[0]), y = int.Parse(args[nowline].Split()[1]); int cnt = int.Parse(args[nowline].Split()[2]), id = int.Parse(args[nowline].Split()[3]); ++nowline; dropSpawners.Add(new DropSpawner(x, y, id, cnt)); } tmp = args[nowline].Split().Select(x => int.Parse(x)).ToArray(); this.Pwidth = tmp[0] + 2; this.Pheight = tmp[1] + 2; this.Field = new List <List <Square> >(); for (int x = 0; x < this.Pwidth; ++x) { this.Field.Add(new List <Square>()); } for (int i = 0; i < this.Pwidth; i++) { this.Field[i].Add(new Square(i, 0, 1)); } for (int i = 1; i < this.Pheight - 1; i++) { this.Field[0].Add(new Square(0, i, 1)); this.Field[this.Pwidth - 1].Add(new Square(this.Pwidth - 1, i, 1)); } for (int y = 1; y < this.Pheight - 1; ++y) { string line = args[y + nowline].Trim(); int[] agrs = line.Split().Select(x => int.Parse(x)).ToArray(); for (int x = 1; x < Pwidth - 1; ++x) { this.Field[x].Add(new Square(x, y, agrs[x - 1])); } } for (int i = 0; i < this.Pwidth; i++) { this.Field[i].Add(new Square(i, this.Pheight - 1, 1)); } } }
public void KeyUp(int key) { KeyDown.Enqueue(Utily.MakePair <int, TypeKeyDown>(key, TypeKeyDown.KeyUp)); }
/* * public string LargeString() * { * StringBuilder ans = new StringBuilder(); * ans.Append(Mana); * ans.Append(" "); * ans.Append(currentArrow); * ans.Append(" "); * ans.Append(totalNumberofItems); * for (int i = 0; i < totalNumberofItems; i++) * { * ans.Append(" "); * ans.Append(inventory[i]); * } * return ans.ToString(); * } * public string SmallString() * { * return currentArrow.ToString(); * } */ public void TakeSmallString(string s) { currentArrow = Utily.Parse(s); }
public void TakeString(string Arrow, string Drop, string Player) { var arr = Arrow.Split(','); HashSet <int> IsUsed = new HashSet <int>(); for (int i = 0; i < arr.Length; i++) { var small = arr[i].Split(' '); int tag = Utily.Parse(small[0]); int dmg = Utily.Parse(small[1]); int id = Utily.Parse(small[2]); if (Arrows.ContainsKey(tag)) { Arrows[tag].dmg = dmg; Arrows[tag].id = id; } else { Arrows.Add(tag, new AArrow(dmg, id)); ArrowEvent.Enqueue(tag); } IsUsed.Add(tag); } List <int> ForRemove = new List <int>(); foreach (var i in Arrows) { if (!IsUsed.Contains(i.Key)) { ForRemove.Add(i.Key); ArrowEvent.Enqueue(-i.Key); } } foreach (var i in ForRemove) { Arrows.Remove(i); } var dro = Drop.Split(','); IsUsed.Clear(); for (int i = 0; i < arr.Length; i++) { var small = dro[i].Split(' '); int tag = Utily.Parse(small[0]); int cnt = Utily.Parse(small[1]); int id = Utily.Parse(small[2]); if (Drops.ContainsKey(tag)) { Drops[tag].Count = cnt; Drops[tag].id = id; } else { Drops.Add(tag, new ADrop(cnt, id)); DropEvent.Enqueue(tag); } IsUsed.Add(tag); } ForRemove.Clear(); foreach (var i in Drops) { if (!IsUsed.Contains(i.Key)) { ForRemove.Add(i.Key); DropEvent.Enqueue(-i.Key); } } foreach (var i in ForRemove) { Drops.Remove(i); } var pla = Player.Split(','); IsUsed.Clear(); for (int i = 0; i < arr.Length; i++) { var small = pla[i].Split(' '); int tag = Utily.Parse(small[0]); int kill = Utily.Parse(small[1]); int death = Utily.Parse(small[2]); if (ArenaPlayer.ContainsKey(tag)) { ArenaPlayer[tag].RealName = small[3]; IsUsed.Add(tag); } else { ArenaPlayer.Add(tag, new APlayer(small[3])); } ArenaPlayer[tag].Kill = kill; ArenaPlayer[tag].Death = death; } ForRemove.Clear(); foreach (var i in ArenaPlayer) { if (!IsUsed.Contains(i.Key)) { ForRemove.Add(i.Key); } } foreach (var i in ForRemove) { ArenaPlayer.Remove(i); } }