public override void OnLoad() { Paint += OnPaint; _listBoxs = new List <HorizontalListBox>(); HipsterEngine.Physics.Initialize(-1000, -1000, 1000, 1000, 0, 0f, true); var h = new HorizontalListBox(HipsterEngine, Width / 2, Height - 100, Width - 100, 100, 8); _listBoxs.Add(h); HipsterEngine.Physics.Initialize(-1000, -1000, 1000, 1000, 0, 0f, true); var ph = Height / 2; var py = Height / 2 + ph / 2 - 20; Earth = new LevelPlatform(HipsterEngine, Width / 2, py, Width / 2, 40); Robots = new List <IRobot>(); var robot = new Robot(HipsterEngine, Earth); robot.Initialize(new TwoWheels(), new Box2(), new Gun1()) .Build(Width / 2, 120, 90, 20); Robots.Add(robot); float x = HipsterEngine.Surface.Width / 2; float y = HipsterEngine.Surface.Height / 2; }
public void GenerateNextPlatform(float distance, float width) { var lastPlatform = _platformsOnScreen[_platformsOnScreen.Count - 1]; lastPlatform.IsActive = true; LevelPlatform platfom = ObjectCreator.CreateObject(_platformPrefab, transform).GetComponent <LevelPlatform>(); platfom.Init(width); _platformsOnScreen.Add(platfom); float newXCoordinate = lastPlatform.Width * 0.5f + lastPlatform.transform.localPosition.x + distance + width * 0.5f; platfom.transform.localPosition = new Vector3(newXCoordinate, platfom.transform.localPosition.y, platfom.transform.localPosition.z); if (_platformsOnScreen.Count > 2) { _platformsOnScreen[0].gameObject.ReturnToPool(); _platformsOnScreen.Remove(_platformsOnScreen[0]); } float bonusPosition = _platformsOnScreen[_platformsOnScreen.Count - 2].RightPosition.x + (_platformsOnScreen[_platformsOnScreen.Count - 1].RightPosition - _platformsOnScreen[_platformsOnScreen.Count - 2].LeftPosition).x; BonusManager.Instance.SpawnBonus(new Vector3(bonusPosition, 100f, 100f)); }
private void GenerateFirstPlatform() { float width = 200; LevelPlatform platfom = ObjectCreator.CreateObject(_platformPrefab, transform).GetComponent <LevelPlatform>(); platfom.Init(width); platfom.IsActive = true; _platformsOnScreen.Add(platfom); }
private void GameManager_OnPlayerStartMove() { float speed = 900; LevelPlatform nextPlatform = LevelManager.Instance.LastBlockForUser; Vector3 endStickPosition = LevelManager.Instance.CurrentBlockForUser.StickController.EndStickPosition; Vector3 perfectPosition = LevelManager.Instance.LastBlockForUser.PerfectPosition; Vector2 perfectSize = LevelManager.Instance.LastBlockForUser.PerfectSize; if (nextPlatform.transform.position.x - nextPlatform.Width * 0.5f > endStickPosition.x) { Debug.Log("Nedohod"); stopPlayerAt = StopPlayerAt.Stick; } else if (nextPlatform.transform.position.x + nextPlatform.Width * 0.5f < endStickPosition.x) { Debug.Log("Perehod"); stopPlayerAt = StopPlayerAt.Stick; } else { Debug.Log("StopAtPlatform"); stopPlayerAt = StopPlayerAt.Platform; if (endStickPosition.x < perfectPosition.x + perfectSize.x && endStickPosition.x > perfectPosition.x - perfectSize.x) { GameManager.Instance.PerfectStick(); nextPlatform.Perfect(); } } float distance = 0f; switch (stopPlayerAt) { case StopPlayerAt.Platform: distance = Mathf.Abs((transform.position - nextPlatform.transform.position).x); break; case StopPlayerAt.Stick: distance = Mathf.Abs((transform.position - endStickPosition).x); break; } float time = distance / speed; allowToMove = false; GetComponent <Rigidbody2D>().velocity = Vector2.zero; Vector2 position = new Vector3(transform.position.x + distance, transform.position.y, transform.position.z); transform.DOMove(position, time).OnComplete(() => { if (stopPlayerAt == StopPlayerAt.Stick) { GameManager.Instance.TryKillPlayer(); } else { allowToMove = true; GameManager.Instance.PlayerStoped(); } }); }
/// <summary> /// attempts to move the character to position + deltaMovement. Any colliders in the way will cause the movement to /// stop when run into. /// 尝试将角色移动到position + deltaMovement。 任何碰撞方式都会导致运行停止。 /// </summary> /// <param name="deltaMovement">Delta movement.</param> public void Move(Vector2 deltaMovement, bool standingOnPlatform = false) { if (!this.enabled) { return; } collisionState.CopyTo(previousCollisionState); // save off our current grounded state which we will use for wasGroundedLastFrame and becameGroundedThisFrame // 节省我们目前的接地状态,我们将用于wasGroundedLastFrame并成为GroundedThisFrame collisionState.wasGroundedLastFrame = collisionState.below; // clear our state // 清理上一帧的状态 collisionState.reset(); _raycastHitsXThisFrame.Clear(); _raycastHitsYThisFrame.Clear(); _isGoingUpSlope = false; //if (deltaMovement.x != 0f) { // collisionState.faceDir = (int)Mathf.Sign(deltaMovement.x); //} primeRaycastOrigins(); // first, we check for a slope below us before moving // only check slopes if we are going down and grounded // 首先,我们在移动之前检查我们下方的一个坡度 // 如果我们正在下降并接地,只能检查斜坡 if (deltaMovement.y < 0f && collisionState.wasGroundedLastFrame) { handleVerticalSlope(ref deltaMovement); } // now we check movement in the horizontal dir // 检查水平方向的位移 if (deltaMovement.x != 0f) { moveHorizontally(ref deltaMovement); } //moveHorizontally(ref deltaMovement); // next, check movement in the vertical dir // 然后检查竖直方向的位移 if (deltaMovement.y != 0f) { moveVertically(ref deltaMovement); } //moveVertically( ref deltaMovement ); //if (deltaMovement.x != 0f) // handleBlockLayer(ref deltaMovement); // move then update our state // 移动然后更新我们的状态 //deltaMovement.z = 0; transform.Translate(deltaMovement, Space.World); // only calculate velocity if we have a non-zero deltaTime // 如果我们有一个非零deltaTime,只计算速度 if (Time.deltaTime > 0f) { velocity = deltaMovement / Time.deltaTime; } if (standingOnPlatform) { collisionState.below = true; } // set our becameGrounded state based on the previous and current collision state // 根据前一帧的和当前的碰撞状态设置我们的接地状态 if (!collisionState.wasGroundedLastFrame && collisionState.below) { collisionState.becameGroundedThisFrame = true; } // if we are going up a slope we artificially set a y velocity so we need to zero it out here // 如果我们正在上坡,我们人为地设置一个y轴速度,所以我们需要在这里清零 if (_isGoingUpSlope) { velocity.y = 0; } // send off the collision events if we have a listener // 推送碰撞事件 if (onControllerCollidedEvent != null) { for (var i = 0; i < _raycastHitsXThisFrame.Count; i++) { onControllerCollidedEvent(_raycastHitsXThisFrame[i]); } } ignoreOneWayPlatformsThisFrame = false; // 检查MovePlatform Attach if (collisionState.becameGroundedThisFrame && collisionState.belowObject != null) { LevelPlatform movePlatform = collisionState.belowObject.GetComponent <LevelPlatform>(); if (movePlatform != null) { _movingPlatform = movePlatform; _movingPlatform.AddChild(transform); //Debug.Log($"Attach {collisionState.belowObject}"); } } // 检查MovePlatform Detach if (collisionState.wasGroundedLastFrame && !collisionState.below) { if (_movingPlatform) { //Debug.Log($"Detach {_movingPlatform} !!!!!!!!!!!!!!!!!!!"); _movingPlatform.OnPlayerExit(transform); transform.SetParent(null, true); _movingPlatform = null; } } //else if(collisionState.wasGroundedLastFrame && collisionState.below) //{ // if (_movingPlatform && !_movingPlatform.enabled) // { // //Debug.Log($"Detach {_movingPlatform} !!!!!!!!!!!!!!!!!!!"); // _movingPlatform.OnPlayerExit(transform); // transform.SetParent(null, true); // _movingPlatform = null; // } //} }