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 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 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 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 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 void MouseDown(int button) { KeyDown.Enqueue(Utily.MakePair <int, TypeKeyDown>(button, TypeKeyDown.MouseDown)); }