예제 #1
0
	protected ShiftABLevel GenerateRandomLevel() {
		
		ShiftABLevel randomLevel = new ShiftABLevel();
		randomLevel.birdsAmount = Random.Range(0, ABLevel.BIRDS_MAX_AMOUNT); 
		
		int stackIndex = 0;
		int totalObjsAdded = 0;
		float widerObjectInStack = 0;
		
		float randomWidth = Mathf.Abs(ABMath.RandomGaussian(randomLevel.LevelPlayableWidth/2f, randomLevel.LevelPlayableWidth/2f));
		float nextWidth = (randomLevel.WidthOfEmptyStack + randomWidth) % randomLevel.LevelPlayableWidth;
		
		// Loop to generate the game object stacks		
		for(float width = 0f; width + widerObjectInStack < nextWidth; width += widerObjectInStack)
		{
			// Randomly generate new stack based on the dependency graph
			LinkedList<ShiftABGameObject> stack = 
				GenerateStack(randomLevel.LevelPlayableHeight, randomLevel.LevelPlayableWidth, randomLevel.WidthOfEmptyStack);

			randomLevel.AddStack(stack);
			
			widerObjectInStack = randomLevel.GetStackWidth(stackIndex);
			totalObjsAdded += randomLevel.GetTotalObjectsAmount();
			stackIndex++;
		}
		
		if(totalObjsAdded == 0)
		{
			int randomStack = Random.Range(0, randomLevel.GetStacksAmount());
			LinkedList<ShiftABGameObject> stack = 
				GenerateStack(randomLevel.LevelPlayableHeight, randomLevel.LevelPlayableWidth, randomLevel.WidthOfEmptyStack);

			randomLevel.SetStack(randomStack, stack);
		}
		
		randomLevel.FixLevelSize();
		return randomLevel;
	}
예제 #2
0
    protected void ConvertShiftGBtoABGB(ref ShiftABLevel randomLevel)
    {
        float offsetX, offsetY;
        float slingPos = GameWorld.Instance._slingshotTransform.position.x;
        offsetX = slingPos + randomLevel.LevelPlayableWidth/2f - randomLevel.GetLevelBounds().size.x/2.25f;

        for(int i = 0; i < randomLevel.GetStacksAmount(); i++)
        {
            if(i > 0)
            {
                if(randomLevel.GetStack(i - 1).Count > 0)
                {
                    ShiftABGameObject wid = randomLevel.GetWidestObjInStack(i - 1);
                    offsetX = wid.Position.x + wid.GetBounds().size.x/2f;
                }
                else
                    offsetX += randomLevel.WidthOfEmptyStack/2f;
            }

            if(randomLevel.GetStack(i).Count > 0)
            {
                offsetX += randomLevel.GetWidestObjInStack(i).GetBounds().size.x/2f;

                for (LinkedListNode<ShiftABGameObject> obj = randomLevel.GetStack(i).First; obj != randomLevel.GetStack(i).Last.Next; obj = obj.Next)
                {
                    // Define object position
                    if(obj.Previous != null)

                        offsetY = obj.Previous.Value.Position.y +
                            obj.Previous.Value.GetBounds().size.y/2f - obj.Value.UnderObjectsHeight;
                    else
                        offsetY = GameWorld.Instance._groundTransform.GetComponent<Collider2D>().bounds.center.y +
                            GameWorld.Instance._groundTransform.GetComponent<Collider2D>().bounds.size.y/2f;

                    offsetY += obj.Value.GetBounds().size.y/2f;
                    obj.Value.Position = new Vector2(offsetX, offsetY);

                    if(!obj.Value.IsDouble)
                    {
                        ABGameObject baseGameObject = new ABGameObject();

                        baseGameObject.Label =  obj.Value.Label;
                        baseGameObject.Position =  obj.Value.Position;

                        randomLevel.gameObjects.Add(baseGameObject);
                    }
                    else
                    {
                        ABGameObject baseGameObjectA = new ABGameObject();

                        baseGameObjectA.Label =  obj.Value.Label;

                        Vector2 leftObjPos = obj.Value.Position;
                        leftObjPos.x -=  obj.Value.GetBounds().size.x/4f;
                        baseGameObjectA.Position = leftObjPos;

                        randomLevel.gameObjects.Add(baseGameObjectA);

                        ABGameObject baseGameObjectB = new ABGameObject();

                        baseGameObjectB.Label =  obj.Value.Label;
                        Vector2 rightObjPos =  obj.Value.Position;
                        rightObjPos.x +=   obj.Value.GetBounds().size.x/4f;
                        baseGameObjectB.Position = rightObjPos;

                        randomLevel.gameObjects.Add(baseGameObjectB);
                    }
                }
            }
            else
                offsetX += randomLevel.WidthOfEmptyStack/2f;
        }
    }