Exemple #1
0
            public MountainGenerator Build()
            {
                var terrain = new MountainGenerator();

                terrain.draw            = draw;
                terrain.maxHeight       = height;
                terrain.gradientSize    = gradSize;
                terrain.tileSize        = tileSize;
                terrain.tileCount       = tileCount;
                terrain.imageSize       = tileCount * tileSize;
                terrain.lightTextureFrq = lightFrequency / terrain.ImageSize;
                terrain.waterTextureFrq = waterFrequency / terrain.ImageSize;
                terrain.randomSeed      = randomSeed;
                terrain.colors          = colors;
                terrain.intervals       = intervals;
                terrain.mapper          = mapper;
                terrain.maxFrequency    = maxFrequency;
                terrain.maxAmplitude    = maxAmplitude;
                var grad      = terrain.GenerateGradient(gradSize);
                var gradWater = terrain.GenerateGradient(gradSize);

                terrain.landscapeTexture = new Perlin(grad);
                terrain.lightTexture     = terrain.landscapeTexture;//use the same noise
                terrain.waterTexture     = new Perlin(gradWater);
                terrain.origin           = new Point(terrain.ImageSize / 2 - 1, terrain.ImageSize / 2 - 1);
                return(terrain);
            }
    public void ShootCannon()
    {
        GameObject thisCannonBall = Instantiate(cannonBall, transform.position, transform.rotation);

        thisCannonBall.GetComponent <Rigidbody>().AddRelativeForce(firePower, 0, 0, ForceMode.Impulse);
        thisCannonBall.GetComponent <CannonBall>().SetMountainTops(MountainGenerator.GetMountainTops());
        thisCannonBall.GetComponent <CannonBall>().SetMountainTop(MountainGenerator.GetMountainTop());
    }
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (_turkey.minX > 8.04)
        {
            Destroy(gameObject);
            TurkeyFactory.DecrementTurkeyAmount();
        }

        jumpTimer += Time.deltaTime;
        if (_turkey.grounded && jumpTimer > jumpPeriod)
        {
            jumpTimer = 0.0f;
            System.Random rnd = new System.Random();
            if (rnd.NextDouble() < 0.6)
            {
                _turkey.TurkeyJump();
            }
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            _turkey.SlightJump();
        }

        float wf = 0;

        if (_turkey.maxX > -8.77)
        {
            wf = -0.008f;
        }

        if (_turkey.minY > MountainGenerator.GetMountainTop())
        {
            _turkey.UpdateTurkey(Wind.currentWind * 0.02f, wf);
        }
        else
        {
            _turkey.UpdateTurkey(0, wf);
        }

        RenderPoints();
        RenderLines();
        time += Time.deltaTime;

        CannonBallCollisionDetection();
        if (time >= interpolationPeriod)
        {
            time = 0.0f;
            if (_turkey.grounded && _turkey.maxX < -8.77)
            {
                TurkeyLateralMove();
            }
        }
        MountainCollisionDetection();
    }
Exemple #4
0
    private void MountainCollisionDetection()
    {
        Dictionary <int, float> mountainTops = MountainGenerator.GetMountainTops();

        float xminPosition        = _turkey.minX;
        float xmaxPosition        = (_turkey.GetAvgLateralVelocity() > 0) ? _turkey.maxX : (_turkey.maxX + _turkey.minX) / 2;
        float yPosition           = _turkey.minY;
        int   roundedXminPosition = (int)Math.Round(xminPosition);
        int   roundedXmaxPosition = (int)Math.Round(xmaxPosition);

        if (mountainTops.Keys.Contains(roundedXminPosition) && yPosition < mountainTops[roundedXminPosition])
        {
            _turkey.MountainBouncing(mountainTops[roundedXminPosition]);
        }
        else if ((mountainTops.Keys.Contains(roundedXmaxPosition) && yPosition < mountainTops[roundedXmaxPosition]))
        {
            _turkey.MountainBouncing(mountainTops[roundedXmaxPosition]);
        }
    }
Exemple #5
0
    void GenerateMountains()
    {
        int radius = 64;         // Mathf.Min(xRes, yRes) / 8;

        int yOrig = (yRes / 3) * 2;
        int xMin  = xRes / 3;
        int xMax  = xMin * 2;

        for (int x_p = xMin; x_p < xMax; x_p += Random.Range(8, 64))
        {
            MountainGenerator gen;
            gen           = new MountainGenerator(radius);
            gen.maxHeight = 1f;
            gen.minHeight = 0.1f;
            gen.Generate();

            gen.ApplyHeights(x_p - radius, Random.Range(-8, 8) + yOrig - radius, (x, y, h) => {
                SetHeight(x, y, Mathf.Max(heights[x, y], h));
            });
        }
    }