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); }
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); }
void OnJump() { Platform platform = GetOnPlatform(); if (platform != null) { MovementFunc jf = platform.GetJumpFunction(); StartMovementFunction(jf); character.Jump(jf.duration); Jumped.Invoke(platform); } }
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)); }
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); }
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); }; }
// 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; } }
public void SetMovementFunction(MovementFunc func) { _func = func; }
public void Follow(MovementFunc path, float startTime) { followPath.Follow(path, startTime); }
private void StartMovementFunction(MovementFunc f) { currMovementFunction = f; movementFunctionTime = 0; movementFunctionStartPos = rb.position; }
public void Follow(MovementFunc path, float startTime) { movementPath = path; time = startTime; }