public static LemmingRunRecord Crossover(this LemmingRunRecord record1, LemmingRunRecord record2)
        {
            var random = new Random();
            var size   = Math.Max(record1.Size, record2.Size);
            var result = new LemmingMovementDirection[size];

            for (var i = 0; i < size; i++)
            {
                result[i] = random.Next(0, 2) == 0 ? record1[i] : record2[i];
            }
            return(new LemmingRunRecord(result));
        }
    private void FixedUpdate()
    {
        if (Simulate)
        {
            _input = Record.GetOrGenerateNextMovement(SimualtionFrameId++);
        }
        else if (RecordRun)
        {
            Record.AddMovement(_input);
        }

        Leming.ManualFixedUpdate(_input);
//        if (Save)
//        {
//            Save = false;
//            RecordsStorage.Records.Add(Record);
//        }
    }
    public void ManualFixedUpdate(LemmingMovementDirection input)
    {
        if (this == null)
        {
            return;
        }

        if (Time.fixedTime - whenWokeUp < doNothingInterval)
        {
            return;
        }

        CheckUnstuck();

        _groundHit = Physics2D.BoxCast(transform.position, _boxCollider2D.size * transform.lossyScale.x, 0, Vector2.down, _groundCollisionVectorLength,
                                       CollisitonMask.value);

        HittedCollider = _groundHit.collider;
        if (HittedCollider != null)
        {
            var colliderPosition = _groundHit.point;
            _collisionSide = colliderPosition.y <= transform.position.y ? CollisionSide.Ground : CollisionSide.Ceiling;
        }
        else
        {
            _collisionSide = CollisionSide.None;
        }

        motion = (input & LemmingMovementDirection.Right) > 0 ? 1 : (input & LemmingMovementDirection.Left) > 0 ? -1 : 0;
        jump   = (input & LemmingMovementDirection.Jump) > 0;

        CurrentState.Move(motion);
        if (jump)
        {
            CurrentState.Jump();
        }
        CurrentState.Update();


        motion = 0;
        jump   = false;
    }
    private void Update()
    {
        KillLemmingsOnMouseClick();

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Leming.transform.position = SpawnPosition;
        }


        _input = 0;
        var horizontal = Input.GetAxis("Horizontal");

        _input |= ((horizontal > 0)
            ? LemmingMovementDirection.Right
            : horizontal < 0
                ? LemmingMovementDirection.Left
                : LemmingMovementDirection.None);
        var vertical = Input.GetAxis("Vertical");

        _input |= (vertical > 0 ? LemmingMovementDirection.Jump : LemmingMovementDirection.None);
    }
Example #5
0
 public void AddMovement(LemmingMovementDirection direciton)
 {
     _data.Add(direciton);
 }