private IEnumerator SmoothDash(DashComp competence, float dx = 0, float dy = 0) { competence.Usable = false; _playerData.CanMove = false; Vector3 dir = dx == 0 && dy == 0 ? Direction() : new Vector3(dx, dy, 0); if ((string)Coffre.Regarder("mode") == "multi" && _playerData.MultiID + "" == (string)Coffre.Regarder("id")) { MultiManager.socket.Send("PINFO DASH " + dir.x + " " + dir.y); } Debug.Log(_playerData.MultiID + " dashing to " + dir.x + " " + dir.y + " ( " + dx + " " + dy); Vector3 direction = CheckObstacles(dir, competence); float step = competence.DistDash * Time.fixedDeltaTime; float t = 0; Vector3 end = transform.position + direction - direction * 0.01f; while ((end - transform.position).magnitude > 0.1f) { t += step; transform.position = Vector3.Lerp(transform.position, end, t); yield return(new WaitForFixedUpdate()); } transform.position = end; _playerData.CanMove = true; yield return(new WaitForSeconds(competence.Cooldown)); competence.Usable = true; }
private void UseCompetence(CompetencesData competence, int index, float dx = 0, float dy = 0) { if (competence.Usable && competence.ManaCost <= _playerData.Mana || _playerData.MultiID + "" != (string)Coffre.Regarder("id")) { StartCoroutine(AfkCoroutine()); if (_playerData.MultiID + "" == (string)Coffre.Regarder("id")) { Comp.Raise(new EventArgsDoubleInt((int)competence.Cooldown, index)); } switch (competence.Id) { case "OneProj": InstantiateOneProjectiles(competence as ProjComp, dx, dy); break; case "ArcProj": InstantiateArcProjectiles(competence as ProjComp, dx, dy); break; case "CirProj": InstantiateCircleAttack(competence as ProjComp, dx, dy); break; case "Boost": BoostPlayer(competence as BoostComp); break; case "CacAtt": AttackEvent.Raise(new EventArgsInt(_playerData.MultiID)); StartCoroutine(CoolDownCoroutine(competence, true)); break; } } }
private Vector3 ProjectilesDirection(float dx = 0, float dy = 0) { if ((string)Coffre.Regarder("mode") == "solo") { Vector3 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); cursorPos.z = 0; Vector3 n = (cursorPos - transform.position).normalized; return(n); } else { bool by = dy == 0; if (dx != 0 || dy != 0) { return(new Vector3(dx, dy, 0)); } else { Vector3 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); cursorPos.z = 0; Vector3 n = (cursorPos - transform.position).normalized; return(n); } } }
private void Update() { if (reset) { reset = false; MultiManager.socket.Send("PINFO TP " + transform.position.x + " " + transform.position.y); } if ((string)Coffre.Regarder("mode") == "solo" || _playerData.MultiID + "" == (string)Coffre.Regarder("id")) { PlayerMove(); } else { Move(mxDir, myDir); } int xDir = (int)Input.GetAxisRaw("Horizontal"); int yDir = (int)Input.GetAxisRaw("Vertical"); if ((xDir != cX || yDir != cY) && "multi" == (string)Coffre.Regarder("mode") && _playerData.MultiID + "" == (string)Coffre.Regarder("id")) { cX = xDir; cY = yDir; MultiManager.socket.Send("PINFO TP " + transform.position.x + " " + transform.position.y + ";JINFO " + xDir + " " + yDir); } if (tp) { tp = false; transform.position = new Vector3(fx, fy); } }
private void Start() { Coffre.Créer(); Transform o = Instantiate(PlayerManager, new Vector3(5, 5, 0), Quaternion.identity); o.GetComponent <PlayerManager>().Create(10, 2, int.Parse((string)Coffre.Regarder("id")), (string)Coffre.Regarder("mode") == "solo"); }
// Update is called once per frame void Update() { if (s) { s = false; int[] copy = new int[playersToAdd.Count]; playersToAdd.CopyTo(copy); foreach (int i in copy) { playersToAdd.Remove(i); if (playersAlreadyInGame.Contains(i)) { continue; } playersAlreadyInGame.Add(i); Debug.Log("asked to add " + i); MapGridCreation mgc = GameObject.Find("MapManager").GetComponent <MapGridCreation>(); if (i + "" == (string)Coffre.Regarder("id")) { mgc.AddPlayer(i, false); } else { Debug.Log("Adding multi player: " + i); mgc.AddMultiPlayer(i); } } } }
private void FixedUpdate() { if (_playerData.MultiID + "" == (string)Coffre.Regarder("id")) { Vector3 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); cursorPos.z = 0; Vector3 n = (cursorPos - transform.position).normalized; if (Input.GetMouseButton(0)) { UseCompetence(_playerData.Competences[1], 1); if ((string)Coffre.Regarder("mode") == "multi") { MultiManager.socket.Send("PINFO AA " + n.x + " " + n.y); } } if (Input.GetKey(KeyCode.Mouse1)) { UseCompetence(_playerData.Competences[2], 2); if ((string)Coffre.Regarder("mode") == "multi") { MultiManager.socket.Send("PINFO A1 " + n.x + " " + n.y); } } if (Input.GetKey(KeyCode.LeftShift)) { UseCompetence(_playerData.Competences[3], 3); if ((string)Coffre.Regarder("mode") == "multi") { MultiManager.socket.Send("PINFO A2 " + n.x + " " + n.y); } } } if (aa) { aa = false; UseCompetence(_playerData.Competences[1], 1, dx, dy); } if (a1) { a1 = false; UseCompetence(_playerData.Competences[1], 2, dx, dy); } if (a2) { a2 = false; UseCompetence(_playerData.Competences[2], 3, dx, dy); } }
public void Create(Weapons weapon) { _playerData = StaticData.actualData; comp = _playerData.Name == "Warrior" ? _playerData.Competences[1] as CacComp : null; _sprite = GetComponent <SpriteRenderer>(); _sprite.sprite = weapon.icon; if (!weapon.inPlayerInventory) { _sprite.sortingOrder = (int)((transform.position.y + 0.7) * -10); } Weapon = weapon; EdgeCollider2D collider = GetComponent <EdgeCollider2D>(); collider.points = weapon.ColliderPoints; PlayerMoveEvent.Raise(new EventArgsCoor(0, -1, int.Parse((string)Coffre.Regarder("id")))); }
private IEnumerator Dash(DashComp competence, float dx = 0, float dy = 0) { competence.Usable = false; _playerData.CanMove = false; Vector3 dir = dx == 0 && dy == 0 ? Direction() : new Vector3(dx, dy, 0); if ((string)Coffre.Regarder("mode") == "multi" && _playerData.MultiID + "" == (string)Coffre.Regarder("id")) { MultiManager.socket.Send("PINFO DASH " + dir.y + " " + dir.x); } Vector3 direction = CheckObstacles(dir, competence); transform.position += direction - direction * 0.01f; _playerData.CanMove = true; yield return(new WaitForSeconds(competence.Cooldown)); competence.Usable = true; }
public void PlayerMovingAnimation(IEventArgs args) { EventArgsCoor coor = args as EventArgsCoor; if (_playerData.MultiID != coor.Id && (string)Coffre.Regarder("mode") == "multi") { return; } int speed = coor.X != 0 ? coor.X : coor.Y; bool dir = coor.X == 0; if (speed == 0) { _a.SetInteger("Speed", 0); return; } _a.SetInteger("Speed", speed); _a.SetBool("Direction", dir); }
private void FixedUpdate() { if (_playerData.MultiID + "" == (string)Coffre.Regarder("id")) { if (!_playerData.CanMove) { return; } } if (Input.GetKey("space") && _playerData.Competences[0].Usable) { Comp.Raise(new EventArgsDoubleInt((int)_playerData.Competences[0].Cooldown, 0)); if (_playerData.MultiID + "" == (string)Coffre.Regarder("id")) { if (_playerData.Name == "Mage") { StartCoroutine(Dash(_playerData.Competences[0] as DashComp)); } else { StartCoroutine(SmoothDash(_playerData.Competences[0] as DashComp)); } } } if (this.shouldDash) { this.shouldDash = false; Debug.Log(_playerData.MultiID + " dash got true"); if (_playerData.MultiID == 3) { StartCoroutine(Dash(_playerData.Competences[0] as DashComp, dx, dy)); } else { StartCoroutine(SmoothDash(_playerData.Competences[0] as DashComp, dx, dy)); } } }
private void InstantiateProjectiles(ProjComp competence, Vector3 dir) { Transform o = Instantiate(Proj, transform.position + dir / 4, Quaternion.identity); o.name = competence.Name; ProjectilesData projectilesData = ScriptableObject.CreateInstance <ProjectilesData>(); int dP = 25; int dM = 25; if (_playerData.MultiID + "" == (string)Coffre.Regarder("id")) { dP = _playerData.PhysicsDamage + _playerData.Inventory.Weapon.PhysicsDamage + competence.AdDamage; dM = _playerData.MagicDamage + _playerData.Inventory.Weapon.MagicDamage + competence.ApDamage; } projectilesData.Created(dir.normalized, competence.Speed, dP, dM, competence.EnemyTag, _playerData.AnimProj(), competence.Live, _playerData.AnimColor(), _playerData.Prob(), _playerData.Effect(), _playerData.EffectDamage(), _playerData.Duration()); Projectiles script = o.GetComponent <Projectiles>(); script.Create(projectilesData); }
private void Awake() { //Coffre.Remplir("seed", "1"); if ((string)Coffre.Regarder("mode") == "solo") { seed = Random.Range(1, int.MaxValue); } else { seed = int.Parse((string)Coffre.Regarder("seed")); } Random.InitState(seed); int lvl = Random.Range(StaticData.LevelMap[0], StaticData.LevelMap[1]); MapHeight = 100 + lvl / 2; MapWidth = 100 + lvl / 2; RoomNumber = MapHeight / 5; DistanceRoom = 100; fusion = MapHeight / 20; _grid = new bool[MapHeight, MapWidth]; _instances = new bool[MapHeight, MapWidth]; _roomData = new List <RoomData>(); _rooms = new List <Transform>(); AllNodes.Grid = _grid; AllNodes.Height = MapHeight - 1; AllNodes.Width = MapWidth - 1; GetComponentInChildren <MiniMapPos>().Pos(new Vector3(MapHeight / 2, MapHeight / 2)); GetComponentInChildren <MiniMapFog>().Create(MiniMap, _grid, MapTextureData); try { CreateGrid(); ConstructCorridor(); RoomInstanceWall(); FillGap(); CreateFloor(); CreateWall(); RoomInstanceDeco(); AddChest(); AddPikes(); AddPortal(); AddBossPortal(); if ((string)Coffre.Regarder("mode") == "solo") { AddPlayer(1, true); } } catch (Exception e) { Debug.Log("Err"); Console.WriteLine(e); throw; } GenerateEnemies.RoomData = _roomData; GenerateEnemies.availablePosGrid = _grid; }
IEnumerator Attack(string dir) { if (Weapon._class == "Warrior") { isAttacking = true; WaitForSeconds frame = new WaitForSeconds(0.008f); switch (dir) { case "right": PlaceWeapon(0.314f, 0.258f, 90); yield return(frame); PlaceWeapon(0.349f, 0.229f, 70); yield return(frame); PlaceWeapon(0.357f, 0.216f, 50); yield return(frame); PlaceWeapon(0.357f, 0.216f, 30); yield return(frame); PlaceWeapon(0.336f, 0.171f, 10); yield return(frame); PlaceWeapon(0.299f, 0.131f, -10); yield return(frame); PlaceWeapon(0.264f, 0.076f, -30); yield return(frame); PlaceWeapon(0.244f, 0.07f, -50); yield return(frame); PlaceWeapon(0.209f, 0.048f, -70); yield return(frame); PlaceWeapon(0.165f, 0.018f, -90); yield return(frame); break; case "down": _sprite.sortingOrder = 1000; PlaceWeapon(-0.004f, -0.011f, 26); yield return(frame); PlaceWeapon(0.082f, -0.021f, 2); yield return(frame); PlaceWeapon(0.12f, -0.049f, -22); yield return(frame); PlaceWeapon(0.106f, -0.097f, -46); yield return(frame); PlaceWeapon(0.072f, -0.124f, -70); yield return(frame); PlaceWeapon(0.012f, -0.106f, -94); yield return(frame); PlaceWeapon(-0.101f, -0.12f, 252); yield return(frame); PlaceWeapon(-0.126f, -0.086f, 228); yield return(frame); PlaceWeapon(-0.197f, -0.062f, 204); yield return(frame); PlaceWeapon(-0.232f, -0.007f, 180); yield return(frame); break; case "up": PlaceWeapon(-0.113f, 0.264f, 90); yield return(frame); PlaceWeapon(-0.091f, 0.383f, 70); yield return(frame); PlaceWeapon(-0.002f, 0.455f, 50); yield return(frame); PlaceWeapon(0.09f, 0.47f, 30); yield return(frame); PlaceWeapon(0.208f, 0.426f, 10); yield return(frame); PlaceWeapon(0.307f, 0.358f, -10); yield return(frame); PlaceWeapon(0.365f, 0.258f, -30); yield return(frame); PlaceWeapon(0.382f, 0.161f, -50); yield return(frame); PlaceWeapon(0.346f, 0.04f, -70); yield return(frame); PlaceWeapon(0.265f, -0.041f, -90); yield return(frame); break; case "left": PlaceWeapon(-0.314f, 0.258f, 45 + (45 - 90)); yield return(frame); PlaceWeapon(-0.349f, 0.229f, 45 + (45 - 70)); yield return(frame); PlaceWeapon(-0.357f, 0.216f, 45 + (45 - 50)); yield return(frame); PlaceWeapon(-0.357f, 0.216f, 45 + (45 - 30)); yield return(frame); PlaceWeapon(-0.336f, 0.171f, 45 + (45 - 10)); yield return(frame); PlaceWeapon(-0.299f, 0.131f, 45 + (45 - -10)); yield return(frame); PlaceWeapon(-0.264f, 0.076f, 45 + (45 - -30)); yield return(frame); PlaceWeapon(-0.244f, 0.07f, 45 + (45 - -50)); yield return(frame); PlaceWeapon(-0.209f, 0.048f, 45 + (45 - -70)); yield return(frame); PlaceWeapon(-0.165f, 0.018f, 45 + (45 - -90)); yield return(frame); break; } isAttacking = false; } if (Weapon._class == "Archer") { switch (dir) { case "right": _sprite.sortingOrder = 100; PlaceWeapon(0.369f, 0.146f, 0); yield return(new WaitForSeconds(0.16f)); break; case "up": PlaceWeapon(0.008f, 0.396f, 90); _sprite.sortingOrder = -10000; yield return(new WaitForSeconds(0.16f)); break; case "down": _sprite.sortingOrder = 100; PlaceWeapon(-0.06f, -0.18f, -90); yield return(new WaitForSeconds(0.16f)); break; case "left": _sprite.sortingOrder = 100; PlaceWeapon(-0.359f, 0.157f, 180); yield return(new WaitForSeconds(0.16f)); break; } } switch (dir) { case "down": PlayerMoveEvent.Raise(new EventArgsCoor(0, -1, int.Parse((string)Coffre.Regarder("id")))); yield break; case "up": PlayerMoveEvent.Raise(new EventArgsCoor(0, 1, int.Parse((string)Coffre.Regarder("id")))); yield break; case "left": PlayerMoveEvent.Raise(new EventArgsCoor(-1, -1, int.Parse((string)Coffre.Regarder("id")))); yield break; case "right": PlayerMoveEvent.Raise(new EventArgsCoor(1, 1, int.Parse((string)Coffre.Regarder("id")))); yield break; } }