protected virtual void FixedUpdate() { if (Container == null) { return; } // Debug.LogError(pysicItem.velocity.magnitude); if (pysicItem.velocity.magnitude > 6) { var tiles = Collision.Raycast(pysicItem.Position, size, pysicItem.velocity, true); for (int i = 0; i < tiles.Count; i++) { var tile = tiles[i]; if (Map[tile.x, tile.y].IsDecor()) { TileDataProvider.ChangeTile(tile, 0, 0); } } } else { //pysicItem.AddVelocity(-pysicItem.velocity); } base.FixedUpdate(); }
void Do(Vector3 start, Vector3 end) { var tiles = Collision.Raycast(start, Vector2.one, end - start, true); for (int i = 0; i < tiles.Count; i++) { var tile = tiles[i]; if (Map[tile.x, tile.y].IsDecor()) { TileDataProvider.ChangeTile(tile, 0, 0); } } }
private int _itemsPerRow = 3; // TODO(deccer): add config public MapLandBrowserWindow( IItemProvider itemProvider, TileDataProvider tileDataProvider, MapTileDetailWindow mapTileDetailWindow, MapTilePreviewWindow mapTilePreviewWindow) : base("Lands") { _itemProvider = itemProvider; _tileDataProvider = tileDataProvider; _mapTileDetailWindow = mapTileDetailWindow; _mapTilePreviewWindow = mapTilePreviewWindow; _landTexturesMap = new Dictionary <Texture2D, IntPtr>(); _landIdMap = new Dictionary <IntPtr, int>(); _landNameMap = new Dictionary <int, string>(); _landNameFilter = string.Empty; }
public void FixedUpdate() { pysicItem.SetGravity(Gravity); if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W) /*|| joystickV > 0.4*/) { if (countJampFrame < jampUpdateCount) { countJampFrame++; pysicItem.AddVelocity(jampVelocity - new Vector2(0, countJampFrame)); } } if (joystickV > 0) { if (joystickV - oldJoystickV >= 0.4) //joystickV >= 0.4) { var offset = TileDataProvider.WorldPosToOffsetTile(pysicItem.GetBottomPos()); bool isStairs = MapGenerator.GetTile(new Vector2Int(offset.x, offset.y)).IsStairs(); if (oldJampFrame != Time.frameCount && (Collision.Raycast(pysicItem.Position, viewReciver.size, Vector2.down).Count != 0 || isStairs)) { pysicItem.AddVelocity(new Vector2(0, -pysicItem.velocity.y)); pysicItem.AddVelocity(jampVelocity - new Vector2(0, 0)); pysicItem.AddVelocity(jampVelocity - new Vector2(0, 1)); pysicItem.AddVelocity(jampVelocity - new Vector2(0, 2)); // pysicItem.AddVelocity(jampVelocity - new Vector2(0, 3)); // pysicItem.AddVelocity(jampVelocity - new Vector2(0, 4)); // pysicItem.AddVelocity(jampVelocity - new Vector2(0, 4)); // pysicItem.AddVelocity(jampVelocity - new Vector2(0, 6)); oldJoystickV = joystickV; } } if (joystickV - oldJoystickV < 0) { oldJoystickV = joystickV; } } if (PhysicsManager != null && viewReciver != null && viewReciver.pysicItem != null) { PhysicsManager.ChackCollision(viewReciver.pysicItem); } }
void FixedUpdate() { if (TileDataProvider == null) { return; } var offse = TileDataProvider.WorldPosToOffsetTile(transform.position); if (oldColorSize == colorSize && oldOffset.x == offse.x && oldOffset.y == offse.y) { return; } if (!(offse.x > 0 && offse.y > 0 && offse.x <= countTileMapX && offse.y <= countTileMapY)) { return; } // if (offse.x >= LightRenderer.minPos.x && offse.y >= LightRenderer.minPos.y && // offse.x <= LightRenderer.maxPos.x && offse.y <= LightRenderer.maxPos.y) { if (!ignoreWater && mapGenerator.GetMap()[offse.x, offse.y].IsWater()) { mapGenerator.GetMap()[oldOffset.x, oldOffset.y].lightAlpha = 0; mapGenerator.GetMap()[offse.x, offse.y].lightAlpha = 0; } else { mapGenerator.GetMap()[oldOffset.x, oldOffset.y].lightAlpha = 0; mapGenerator.GetMap()[offse.x, offse.y].lightAlpha = colorSize; } oldOffset = offse; ScreenUpdateManager.RedrawFullScreenLight(); oldColorSize = colorSize; //} }
void CreatePlayer() { var parent = GameObject.Find("Units"); var prefub = PrefubManager.GetPlayer(); player = GameObject.Instantiate(prefub, Vector3.zero, new Quaternion()) as GameObject; player.transform.parent = parent.transform; var controller = player.GetComponent <PlayerController>(); Container.Inject(controller); controller.Init(MapGenerator.CenterPos); PlayerController = controller; var worldPos = TileDataProvider.OffsetTileToWorldPos(MapGenerator.CenterPos); Camera.main.transform.GetComponent <TargetChase>().target = player.transform; controller.Id = 1;// PhotonNetwork.player.ID; otherPlayers.Add(controller); // PhotonManager.inst.SendSpawnUnit(controller.Id, worldPos); }
public void CreateOtherPlayer(int id, Vector3 worldPos) { var offset = TileDataProvider.WorldPosToOffsetTile(worldPos); var parent = GameObject.Find("Units"); var prefub = PrefubManager.GetPlayer(); player = GameObject.Instantiate(prefub, Vector3.zero, new Quaternion()) as GameObject; player.transform.parent = parent.transform; var controller = player.GetComponent <PlayerController>(); Container.Inject(controller); controller.Init(offset); //PlayerController = controller; var joystick = player.GetComponent <IJoystick>(); MonoBehaviour.Destroy(joystick as MonoBehaviour); otherPlayers.Add(controller); controller.Id = id; }
public void Update() { if (Sleep || Collision == null) { return; } /* * if (trace) { * position = oldPos; * velocity = oldVel; * trace = false; * return; * }*/ var offset = TileDataProvider.WorldPosToOffsetTile(position); //GetBottomPos bool isWater = MapGenerator.GetTile(offset).IsWater2(); var offsetBottom = TileDataProvider.WorldPosToOffsetTile(GetBottomPos()); bool isStairs = MapGenerator.GetTile(offsetBottom).IsStairs(); float d = isWater ? 2 : 1; oldVel = velocity; //Эффект поплавка например не тонуть в воде //d = gravity.y; if (isWater && velocity.y >= -5) { velocity += gravity / d; } else { if (!isWater) { velocity += gravity / d; } if (isWater && velocity.y < -5) { velocity = new Vector2(velocity.x, -5); } } velocity = new Vector2(velocity.x * momentVector.x, velocity.y * momentVector.y); if (isStairs) { bool isStairsCenter = MapGenerator.GetTile(offset).IsStairs(); if (!isStairsCenter && velocity.y < 0) { velocity = new Vector2(velocity.x, 0); } if (isStairsCenter) { velocity = new Vector2(velocity.x, 0); } } //урезаем oldVelocity = velocity; var newVelocity = velocity; if (IsCollisionTerrain) { newVelocity = Collision.ChackVelocity(position, velocity, itemWidth, itemHeight); } if (velocity != newVelocity) { OnTerrainCollision.TryCall(); } velocity = newVelocity; oldPos = position; position += velocity; if (ReboundFactor != 0) { if (Math.Abs(oldVelocity.x - velocity.x) > 0.1f) { velocity = new Vector2(-oldVelocity.x * ReboundFactor, velocity.y); } if (Math.Abs(oldVelocity.y - velocity.y) > 0.1f) { velocity = new Vector2(velocity.x, -oldVelocity.y * ReboundFactor); } } PhysicsManager.ChackRect(this); if (Vector2.Distance(oldPos, position) == 0) { countTrySleep++; if (countTrySleep > 10) { Sleep = true; } } else { countTrySleep = 0; } /* * var offset = TileDataProvider.WorldPosToOffsetTile(position); * if (!MapGenerator.GetMap()[offset.x, offset.y].IsEmpty()) { * if (View.name.IndexOf("block") != -1) { * Debug.LogError("type != 0" + View.name + "oldPos = " + oldPos + " position = " + position); * trace = true; * } * }*/ }
void OnTick() { // CreateUnit(0); if (player != null) { int screenSize = 100; var playerOffset = TileDataProvider.WorldPosToOffsetTile(player.transform.position); //1 удаляем юнитов которые слишком далеко for (int i = units.Count - 1; i >= 0; i--) { var unitOffset = TileDataProvider.WorldPosToOffsetTile(units[i].transform.position); if (Mathf.Abs(unitOffset.x - playerOffset.x) > screenSize * 2) { GameObject.Destroy(units[i].gameObject); units.RemoveAt(i); } } if (units.Count < maxUnitts) { for (int j = 0; j < maxUnitts - units.Count; j++) { //2 определяем точку слева и справа Vector2Int L, R; if (playerOffset.x - screenSize > 0) { L = MapGenerator.Surface[playerOffset.x - screenSize]; } else { L = MapGenerator.Surface[0]; } if (playerOffset.x + screenSize < MapGenerator.Surface.Count) { R = MapGenerator.Surface[playerOffset.x + screenSize]; } else { R = MapGenerator.Surface[MapGenerator.Surface.Count - 1]; } var id = Random.Range(0, 7); if (id == 6) { id = 9; } var r = Random.Range(0, 10); if (r > 5) { units.Add(CreateUnit(id, R)); } else { units.Add(CreateUnit(id, L)); } } } } }
void Update() { if (Container == null) { return; } var offset = TileDataProvider.WorldPosToOffsetTile(pysicItem.GetBottomPos()); bool isStairs = MapGenerator.GetTile(new Vector2Int(offset.x, offset.y)).IsStairs(); joystickH = UltimateJoystick.GetHorizontalAxis("Joystick1"); joystickV = UltimateJoystick.GetVerticalAxis("Joystick1"); //jamp if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W) /*|| (joystickV >= 0 && joystickV < 0.4)*/) { if (oldJampFrame != Time.frameCount && (Collision.Raycast(pysicItem.Position, viewReciver.size, Vector2.down).Count != 0 || isStairs)) { countJampFrame = 0; pysicItem.AddVelocity(new Vector2(0, -pysicItem.velocity.y)); oldJampFrame = Time.frameCount; } } //jamp isStairs if (isStairs && (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W) || joystickV > .5)) { pysicItem.ApplayVelocity(new Vector2(0, 4)); } // Down if (oldDownFrame != Time.frameCount && Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S) || joystickV < -.5) { pysicItem.AddVelocity(new Vector2(0, -Speed)); oldDownFrame = Time.frameCount; if (isStairs) { pysicItem.ApplayVelocity(new Vector2(0, -4)); } } // Left if (oldLeftFrame != Time.frameCount && Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A) || (joystickH < -.2)) { var speed = joystickH != 0 ? Speed * joystickH : -Speed; pysicItem.AddVelocity(new Vector2(speed, 0)); oldLeftFrame = Time.frameCount; controller.Rotat(-1); if (!isStairs) { if (Collision.Raycast(pysicItem.Position, viewReciver.size, Vector2.down).Count != 0) { var countTile = MaskManager.GetMaskLJamp(pysicItem.GetBottomLeftPos()); if (countTile > 0) { pysicItem.AddVelocity(new Vector2(0, -pysicItem.velocity.y)); pysicItem.SetPosition(new Vector2(pysicItem.Position.x - 1, pysicItem.Position.y + 16 * countTile + 1)); } } } } // Right if (oldRightFrame != Time.frameCount && Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D) || (joystickH > .2)) { var speed = joystickH != 0 ? Speed * joystickH : Speed; pysicItem.AddVelocity(new Vector2(speed, 0)); oldRightFrame = Time.frameCount; controller.Rotat(1); if (!isStairs) { if (Collision.Raycast(pysicItem.Position, viewReciver.size, Vector2.down).Count != 0) { var countTile = MaskManager.GetMaskRJamp(pysicItem.GetBottomRightPos()); //Debug.LogError(countTile); if (countTile > 0) { pysicItem.AddVelocity(new Vector2(0, -pysicItem.velocity.y)); pysicItem.SetPosition(new Vector2(pysicItem.Position.x + 1, pysicItem.Position.y + 16 * countTile + 1)); } } } } var joystickH2 = UltimateJoystick.GetHorizontalAxis("Joystick2"); var joystickV2 = UltimateJoystick.GetVerticalAxis("Joystick2"); bool joystick = Vector2.Distance(new Vector2(joystickH2, joystickV2), Vector2.zero) > 0.1; bool joystick0 = UltimateJoystick.GetIsDown("Joystick1"); var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (!Settings.IS_EDIT_MOD && ( (!joystick0 || joystick0 && joystick) && (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.LeftControl) || joystick)) && !UICamera.IsGuiClick) { if (model.CurrentWeapon != null) { if (!joystick) { var dir = (pos - transform.position).normalized; controller.Rotat(dir.x); } else { controller.Rotat(joystickH2); } model.CurrentWeapon.Fire(pos, joystick); } } if (((!Settings.IS_EDIT_MOD) && ( (!joystick0 || joystick0 && joystick) && (Input.GetMouseButton(0) || Input.GetKey(KeyCode.LeftControl) || joystick)) && !UICamera.IsGuiClick)) { if (model.CurrentWeapon != null) { if (!joystick) { var dir = (pos - transform.position).normalized; controller.Rotat(dir.x); } else { controller.Rotat(joystickH2); } model.CurrentWeapon.FireCycle(pos, joystick); } } if (model.CurrentWeapon != null) { var rot = pos; if (joystick) { var v = UltimateJoystick.GetVerticalAxis("Joystick2"); var h = UltimateJoystick.GetHorizontalAxis("Joystick2"); rot = transform.position + new Vector3(h, v) * 100; } model.CurrentWeapon.Rotate(rot); } //Bag if (Input.GetKeyDown(KeyCode.Alpha1)) { model.UseItem(1); } if (Input.GetKeyDown(KeyCode.Alpha2)) { model.UseItem(2); } if (Input.GetKeyDown(KeyCode.Alpha3)) { model.UseItem(3); } if (Input.GetKeyDown(KeyCode.Alpha4)) { model.UseItem(4); } if (Input.GetKeyDown(KeyCode.Alpha5)) { model.UseItem(5); } if (Input.GetKeyDown(KeyCode.Alpha6)) { model.UseItem(6); } if (Input.GetKeyDown(KeyCode.Alpha7)) { model.UseItem(7); } if (Input.GetKeyDown(KeyCode.Alpha8)) { model.UseItem(8); } if (Input.GetKeyDown(KeyCode.Alpha9)) { model.UseItem(9); } }