Пример #1
0
    public IList <PlatformInfo> GeneratePlatforms(System.Random rand, PlatformInfo startPlatform, LevelGeneratorParams p)
    {
        Assert.IsTrue(p.maxEarlyLandMargin + p.maxLateJumpMargin <= 1, "Early landing and late jump margin overlapping");

        IList <PlatformInfo> platforms = new List <PlatformInfo>();

        ChooseActionPoints(rand, p, startPlatform);
        platforms.Add(startPlatform);

        float accumLevelTime = Vector2.Distance(startPlatform.GetStartPoint(), startPlatform.GetJumpPoint()) / p.runSpeed;

        while (accumLevelTime < p.levelDuration)
        {
            float progress = accumLevelTime / p.levelDuration;

            PlatformInfo plat = PlaceNextPlatform(rand, p, platforms[platforms.Count - 1], progress);
            ChooseActionPoints(rand, p, plat);
            platforms.Add(plat);

            MovementFunc jf = SetupJumpFunction(p, platforms, platforms[platforms.Count - 2], platforms[platforms.Count - 1]);

            accumLevelTime += Vector2.Distance(plat.GetLandPoint(), plat.GetJumpPoint()) / p.runSpeed + jf.duration;
        }

        platforms[platforms.Count - 1].jumpFunction = new MovementFunc(_ => Vector2.zero, 0);

        return(platforms);
    }
Пример #2
0
    private MovementFunc SetupJumpFunction(LevelGeneratorParams p, IList <PlatformInfo> platforms, PlatformInfo from, PlatformInfo to)
    {
        Vector2      jumpStart = from.jumpPoint;
        Vector2      jumpEnd   = to.landPoint;
        MovementFunc jf        = GenerateJumpFunction(p, jumpStart, jumpEnd);

        from.jumpFunction = jf;
        return(jf);
    }
Пример #3
0
    void OnJump()
    {
        Platform platform = GetOnPlatform();

        if (platform != null)
        {
            MovementFunc jf = platform.GetJumpFunction();
            StartMovementFunction(jf);
            character.Jump(jf.duration);
            Jumped.Invoke(platform);
        }
    }
Пример #4
0
    public MovementFunc GenerateGuidePath(IList <PlatformInfo> platforms, float runSpeed)
    {
        IList <MovementFunc> segments = new List <MovementFunc>(platforms.Count * 2);

        foreach (var platform in platforms)
        {
            Vector2 runFrom = platform.GetLandPoint(), runTo = platform.GetJumpPoint();
            float   runDuration = Vector2.Distance(runFrom, runTo) / runSpeed;
            segments.Add(new MovementFunc(t => Vector2.Lerp(runFrom, runTo, t / runDuration), runDuration));

            MovementFunc jf = platform.GetJumpFunction();
            segments.Add(new MovementFunc(t => runTo + jf.f(t), jf.duration));
        }

        return(MovementFunc.combine(segments));
    }
Пример #5
0
    private (IList <Platform> platforms, MovementFunc guidePath) ConstructLevel(LevelGeneratorParams levelGenParams)
    {
        LevelGenerator levelGen = new LevelGenerator();

        // Generate platforms
        IList <PlatformInfo> platformInfos = levelGen.GeneratePlatforms(new System.Random(), PlatformInfo.FromLength(Vector2.zero, startPlatformLength), levelGenParams);
        IList <Platform>     platforms     = new List <Platform>(platformInfos.Count);

        PlacePlatforms(platforms, platformInfos);

        // Generate guide path
        float        jumpDuration  = platformInfos.Sum(p => p.GetJumpFunction().duration);
        float        runDuration   = levelGenParams.levelDuration - jumpDuration;
        float        runDistance   = platformInfos.Sum(p => Vector3.Distance(p.GetLandPoint(), p.GetJumpPoint()));
        float        guideRunSpeed = runDistance / runDuration;
        MovementFunc guidePath     = levelGen.GenerateGuidePath(platformInfos, guideRunSpeed);

        return(platforms, guidePath);
    }
Пример #6
0
    public virtual void Init(Vector2 initialSpeed)
    {
        if (destructionCoroutine != null)
        {
            StopCoroutine(destructionCoroutine);
        }

        _spriteRenderer.enabled = true;
        anim.enabled            = false;
        _spriteRenderer.sprite  = _originalSprite;

        _velocity = initialSpeed;
        active    = true;
        //linear movement function
        _func = delegate(Vector2 vel, float lifetime, float dt)
        {
            return(vel * dt);
        };
    }
Пример #7
0
 // Use this for initialization
 void Awake()
 {
     render = this.GetComponent<Renderer>();
     switch (direccion) {
         case TipoMovimiento.moverEnX:
             movimiento = new MovementFunc(sumX);
             getDistancia = new Distance(getX);
             break;
         case TipoMovimiento.moverEnY:
             movimiento = new MovementFunc(sumY);
             getDistancia = new Distance(getY);
             break;
         case TipoMovimiento.moverEnMinX:
             movimiento = new MovementFunc(resX);
             getDistancia = new Distance(getX);
             break;
         case TipoMovimiento.moverEnMinY:
             movimiento = new MovementFunc(resY);
             getDistancia = new Distance(getY);
             break;
     }
 }
Пример #8
0
 public void SetMovementFunction(MovementFunc func)
 {
     _func = func;
 }
Пример #9
0
 public void Follow(MovementFunc path, float startTime)
 {
     followPath.Follow(path, startTime);
 }
Пример #10
0
 private void StartMovementFunction(MovementFunc f)
 {
     currMovementFunction     = f;
     movementFunctionTime     = 0;
     movementFunctionStartPos = rb.position;
 }
Пример #11
0
 public void Follow(MovementFunc path, float startTime)
 {
     movementPath = path;
     time         = startTime;
 }