private void CreatePipe(Entity pipeEntity, float startPosX) { var pipe = new PipeSet(pipeEntity, -GameScript.GameSpeed, startPosX, GraphicsDevice.BackBuffer.Width); pipeSetList.Add(pipe); Entity.AddChild(pipe.Entity); }
/// <summary> /// Check if the pipe set is colliding with the character or not. /// </summary> /// <returns></returns> public bool IsColliding(PipeSet nextPipeSet) { for (var i = 0; i < colliders.Length; ++i) { var collider = colliders[i]; collider.X = colliders[i].X + position.X - agentWidth / 2; collider.Y = colliders[i].Y + position.Y - agentHeight / 2; if (collider.Intersects(nextPipeSet.GetTopPipeCollider())) //collider.Intersects(nextPipeSet.GetBottomPipeCollider()) || { return(true); } } return(false); }
/// <summary> /// Get the next pipe set to come. /// </summary> /// <param name="positionX">The position along the X axis</param> /// <returns>The next pipe to come</returns> public PipeSet GetNextPipe(float positionX) { PipeSet nextPipe = null; var nextPipePosition = float.PositiveInfinity; foreach (var pipeSet in pipeSetList) { var pipePosition = pipeSet.Entity.Transform.Position.X; if (!pipeSet.HasBeenPassed(positionX) && pipePosition < nextPipePosition) { nextPipe = pipeSet; nextPipePosition = pipePosition; } } return(nextPipe); }
private void MovePipeToEnd(int pipeSetIndex, PipeSet pipeSet) { // When a pipe is determined to be reset, // get its next position by adding an offset to the position // of a pipe which index is before itself. var prevPipeSetIndex = pipeSetIndex - 1; if (prevPipeSetIndex < 0) { prevPipeSetIndex = pipeSetList.Count - 1; } var nextPosX = pipeSetList[prevPipeSetIndex].Entity.Transform.Position.X + GapBetweenPipe; pipeSet.ResetPipe(nextPosX); ++numberOfPipeMoved; }
/// <summary> /// Check if the pipe set is colliding with the character or not. /// </summary> /// <returns></returns> public bool IsColliding(PipeSet nextPipeSet) { for (var i=0; i<colliders.Length; ++i) { var collider = colliders[i]; collider.X = colliders[i].X + position.X - agentWidth / 2; collider.Y = colliders[i].Y + position.Y - agentHeight / 2; if (collider.Intersects(nextPipeSet.GetBottomPipeCollider()) || collider.Intersects(nextPipeSet.GetTopPipeCollider())) return true; } return false; }
private void MovePipeToEnd(int pipeSetIndex, PipeSet pipeSet) { // When a pipe is determined to be reset, // get its next position by adding an offset to the position // of a pipe which index is before itself. var prevPipeSetIndex = pipeSetIndex - 1; if (prevPipeSetIndex < 0) prevPipeSetIndex = pipeSetList.Count - 1; var nextPosX = pipeSetList[prevPipeSetIndex].Entity.Transform.Position.X + GapBetweenPipe; pipeSet.ResetPipe(nextPosX); ++numberOfPipeMoved; }
private void CreatePipe(Entity pipeEntity, float startPosX) { var pipe = new PipeSet(pipeEntity, -GameScript.GameSpeed, startPosX, GraphicsDevice.Presenter.BackBuffer.Width); pipeSetList.Add(pipe); Entity.AddChild(pipe.Entity); }