Range() public static méthode

public static Range ( float low, float high ) : float
low float
high float
Résultat float
Exemple #1
0
    override public void Update()
    {
        hopper.Update();

        attackCooldown -= Time.deltaTime;

        if (attackCooldown < 0)
        {
            attackCooldown = RXRandom.Range(0.9f, 1.0f) * Config.VILLAGER_ATTACK_COOLDOWN;

            if (Arena.instance != null && Arena.instance.dayManager.isDay)
            {
                CheckForAttack();
            }
        }

        float scaleXMultiplier = body.scaleX < 0 ? -1f : 1f;
        float scaleMultiplier  = 1.0f;

        if (hopper.jumpTime > 0)
        {
            scaleXMultiplier = (hopper.speedX < 0) ? -1.0f : 1.0f;
            scaleMultiplier  = 0.75f + 0.3f * hopper.jumpY;
        }

        body.scaleX = scaleXMultiplier / scaleMultiplier;
        body.scaleY = scaleMultiplier;

        bodySprite.y  = offsetY + hopper.jumpY * hopper.config.jumpHeight;
        colorSprite.y = bodySprite.y;
        weapon.x      = bodySprite.x + 4;
        weapon.y      = bodySprite.y + 4;

        pushSpeed *= 0.93f;

        if (pushSpeed.sqrMagnitude > 0.05f)
        {
            float newX = x + pushSpeed.x;
            float newY = y + pushSpeed.y * Config.ISO_RATIO;

            if (!entityArea.CheckVillPointHit(newX, newY))
            {
                x = newX;
                y = newY;
            }
            else if (!entityArea.CheckVillPointHit(x, newY))
            {
                pushSpeed.x = -pushSpeed.x * 0.5f;
                y           = newY;
            }
            else if (!entityArea.CheckVillPointHit(newX, y))
            {
                x           = newX;
                pushSpeed.y = -pushSpeed.y * 0.5f;
            }
        }

        body.SetPosition(x, y);
        shadowSprite.SetPosition(x, y);
    }
Exemple #2
0
    public Vector2 randomSpawnPosition()
    {
        // random col between 16 and 19
        // random row between 2 and 8

        int   horzMin = (16 * 64) + 32;
        int   horzMax = (19 * 64) - 32;
        int   vertMin = (2 * 64) + 32;
        int   vertMax = (8 * 64) - 32;
        float x       = RXRandom.Range(horzMin, horzMax);
        float y       = RXRandom.Range(vertMin, vertMax);

        // lets make sure the crew don't spawn on the wall between the spawning zones
        if (y >= (4 * 64) + 32 && y <= (5 * 64))
        {
            y = 4 * 64;
        }

        if (y >= (5 * 64) && y <= (5 * 64) + 32)
        {
            y = (5 * 64) + 34;
        }

        return(new Vector2(x, y));
    }
    void HandleUpdate()
    {
        timeUntilNextParticle -= Time.deltaTime;

        while (timeUntilNextParticle <= 0)
        {
            timeUntilNextParticle += timePerParticle;

            float angle    = RXRandom.Range(0.0f, RXMath.DOUBLE_PI);
            float radius   = innerRadius * RXRandom.Range(0.9f, 1.0f);
            float useSpeed = speed * RXRandom.Range(0.7f, 1.0f);
            particleDef.lifetime = lifetime * RXRandom.Range(0.7f, 1.0f);

            particleDef.x      = Mathf.Cos(angle) * radius;
            particleDef.y      = Mathf.Sin(angle) * radius;
            particleDef.speedX = Mathf.Cos(angle) * useSpeed;
            particleDef.speedY = Mathf.Sin(angle) * useSpeed;

            if (shouldRotate)
            {
                particleDef.startRotation = RXRandom.Range(-180.0f, 180.0f);
                particleDef.endRotation   = RXRandom.Range(-180.0f, 180.0f);
            }

            AddParticle(particleDef);
        }
    }
Exemple #4
0
    public void Generate(Chunk chunk)
    {
        Vector2Int coordination = chunk.coordination;

        Block blockStone = Block.GetBlockByKey("stone");
        Block blockDirt  = Block.GetBlockByKey("dirt");

        for (int i = 0; i < Chunk.Length; i++)
        {
            for (int j = 0; j < Chunk.Length; j++)
            {
                Vector2 perlinCoordination = (new Vector2(i, j) + coordination * Chunk.Length + Vector2.one * 1024f) * 0.1f;
                int     y = Mathf.CeilToInt(Mathf.PerlinNoise(perlinCoordination.x, perlinCoordination.y) * 10f) + 2;

                // int y = 1;
                // if ((i == 2 && j > 2 && j < 6) || (i > 0 && i < 4 && j == 3)) y = 3;//Hi

                for (int k = 0; k < Chunk.Height; k++)
                {
                    Block block = Block.BlockAir;

                    if (k < y)
                    {
                        block = k > 2 + RXRandom.Range(0, 5) ? blockStone : blockDirt;
                    }

                    if (chunk[i, k, j].block == Block.BlockAir)
                    {
                        chunk[i, k, j].SetBlock(block);
                    }
                }
            }
        }
    }
Exemple #5
0
    public BBanana() : base("Banana")
    {
        _rotationSpeed = RXRandom.Range(-3.0f, 3.0f);
        _speedY        = RXRandom.Range(-0.1f, -0.5f);

        ListenForUpdate(HandleUpdate);
    }
    public HumanDeathCloud(Human human) : base(human.entityArea)
    {
        this.human = human;

        this.x = human.x;
        this.y = human.y + 4;

        frames = new FAtlasElement[]
        {
            Futile.atlasManager.GetElementWithName("Arena/Vill_Death1"),
            Futile.atlasManager.GetElementWithName("Arena/Vill_Death2"),
            Futile.atlasManager.GetElementWithName("Arena/Vill_Death3"),
            Futile.atlasManager.GetElementWithName("Arena/Vill_Death4")
        };

        cloudHolder = new FContainer();

        cloudSprite        = new FSprite(frames[0]);
        cloudSprite.scaleX = RXRandom.Bool() ? -1f : 1f;
        cloudHolder.AddChild(cloudSprite);
        cloudSprite.shader = FShader.Additive;
        cloudSprite.alpha  = RXRandom.Range(0.8f, 0.9f);
        cloudSprite.color  = human.player.player.color.color + new Color(0.1f, 0.1f, 0.1f, 0.0f);
        cloudSprite.scale  = 2.0f;

        graveHolder = new FContainer();
        graveSprite = new FSprite("Arena/Human_Grave_1");
        graveHolder.AddChild(graveSprite);
        graveSprite.color = human.player.player.color.color + new Color(0.5f, 0.5f, 0.5f);

        graveSprite.y = 16;

        Update();
    }
Exemple #7
0
    void InitPhysics()
    {
        Rigidbody rb = gameObject.AddComponent <Rigidbody>();

        rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY;
        rb.angularDrag = 5.0f;
        rb.mass        = 1.0f;
        rb.drag        = 0.8f;

        boxCollider      = gameObject.AddComponent <BoxCollider>();
        boxCollider.size = new Vector3(sprite.width, sprite.height, 100) * FPhysics.POINTS_TO_METERS;

        PhysicMaterial mat = new PhysicMaterial();

        mat.bounciness      = 0.3f;
        mat.dynamicFriction = 0.5f;
        mat.staticFriction  = 0.5f;
        mat.frictionCombine = PhysicMaterialCombine.Maximum;
        collider.material   = mat;

        float   speed       = 30.0f;
        float   angle       = RXRandom.Range(0, RXMath.DOUBLE_PI);
        Vector2 startVector = new Vector2(Mathf.Cos(angle) * speed, Mathf.Sin(angle) * speed);

        rb.velocity = startVector.ToVector3InMeters();
    }
Exemple #8
0
    override public void Start()
    {
        Futile.atlasManager.LoadImage("chopper");
        Futile.atlasManager.LoadImage("man");

        this.AddChild(persons = new FContainer());

        ListenForUpdate(HandleUpdate);
        root = FPWorld.Create(64.0f);


        for (int i = 0; i < 50; i++)
        {
            Platform p = Platform.Create();
            p.Init(new Vector2(i * 250, RXRandom.Range(-100, 100) * i), this);
            Person b = Person.Create();
            b.Init(new Vector2(p.sprite.x, p.sprite.y + 532), this);
            b.GameOver = HandleGameOver;
        }


        c = Chopper.Create();
        c.Init(new Vector2(0, 128), this);

        RXWatcher.Watch(this);
        Futile.stage.Follow(c.sprite, false, false);
    }
Exemple #9
0
    public void ShowParticleBurst(float startX, float startY, int count, string elementName, float startScale, float endScale, params Color[] colors)
    {
        FParticleDefinition pd = new FParticleDefinition(elementName);

        pd.x          = startX;
        pd.y          = startY;
        pd.startScale = startScale;
        pd.endScale   = endScale;

        //somewhat evenly spread the particles in a circle

        float radiansPerParticle = RXMath.DOUBLE_PI / (float)count;
        float nextAngle          = 0.0f;

        for (int c = 0; c < count; c++)
        {
            pd.lifetime = RXRandom.Range(0.3f, 0.5f);

            float speed    = RXRandom.Range(30.0f, 80.0f);
            float useAngle = nextAngle + RXRandom.Range(-0.01f, 0.01f);

            pd.speedX = Mathf.Cos(useAngle) * speed;
            pd.speedY = Mathf.Sin(useAngle) * speed;

            nextAngle += radiansPerParticle;

            pd.startColor = RXRandom.GetRandomItem(colors);
            pd.endColor   = RXRandom.GetRandomItem(colors).CloneWithNewAlpha(0.0f);

            particleSystem.AddParticle(pd);
        }
    }
Exemple #10
0
    public VillDeathCloud(Vill vill) : base(vill.entityArea)
    {
        this.vill = vill;

        this.x = vill.x;
        this.y = vill.y + 4;

        frames = new FAtlasElement[]
        {
            Futile.atlasManager.GetElementWithName("Arena/Vill_Death1"),
            Futile.atlasManager.GetElementWithName("Arena/Vill_Death2"),
            Futile.atlasManager.GetElementWithName("Arena/Vill_Death3"),
            Futile.atlasManager.GetElementWithName("Arena/Vill_Death4")
        };

        cloudHolder = new FContainer();

        cloudSprite        = new FSprite(frames[0]);
        cloudSprite.scaleX = RXRandom.Bool() ? -1f : 1f;
        cloudHolder.AddChild(cloudSprite);
        cloudSprite.shader = FShader.Additive;
        cloudSprite.alpha  = RXRandom.Range(0.8f, 0.9f);
        cloudSprite.color  = vill.player.player.color.color + new Color(0.1f, 0.1f, 0.1f, 0.0f);

        graveHolder = new FContainer();
        graveSprite = new FSprite("Arena/VillGrave1_body");
        graveHolder.AddChild(graveSprite);
        graveSpriteColor = new FSprite("Arena/VillGrave1_color");
        graveHolder.AddChild(graveSpriteColor);
        graveSpriteColor.color = vill.player.player.color.color + new Color(0.5f, 0.5f, 0.5f);

        graveSprite.y = graveSpriteColor.y = 5;

        Update();
    }
Exemple #11
0
    public BFood(string food_type) : base(food_type)
    {
        _rotationSpeed = RXRandom.Range(-3.0f, 3.0f);
        _speedY        = RXRandom.Range(-0.1f, -0.5f);
        name           = food_type;

        ListenForUpdate(HandleUpdate);
    }
Exemple #12
0
    public Bomba() : base(mBombaColors[(int)RXRandom.Range(0, mBombaColors.Length)])
    {
        this.x = RXRandom.Range(-Futile.halfWidth + this.width / 2, Futile.halfWidth - this.width / 2);

        this.y = -Futile.halfHeight - this.height / 2;

        mYSpeed = RXRandom.Range(5, 10);
    }
Exemple #13
0
    private void AddEntityRandomPosition(Chunk chunk, Entity entity)
    {
        Vector2 coordination = (chunk.coordination * Chunk.Length) + new Vector2(RXRandom.Range(0f, 16f), RXRandom.Range(0f, 16f));

        float y = chunk.GetSurface(coordination);

        entity.worldPosition = new Vector3(coordination.x, y, coordination.y);

        chunk.AddEntity(entity);
    }
Exemple #14
0
    public OldHopper(Entity entity, OldHopperConfig config)
    {
        this.entity  = entity;
        this.config  = config;
        jumpHeight   = config.jumpHeight;
        jumpDistance = config.jumpDistance;
        baseSpeed    = config.baseSpeed;

        timeToWait = 0.001f + RXRandom.Range(config.waitMinTime, config.waitMaxTime) * 0.5f;      //wait less the first time
    }
Exemple #15
0
    public void CreateBanana()
    {
        BBanana banana = new BBanana();

        _bananaContainer.AddChild(banana);
        banana.x = RXRandom.Range(-Futile.screen.width / 2 + 50, Futile.screen.width / 2 - 50); //padded inside the screen width
        banana.y = Futile.screen.height / 2 + 60;                                               //above the screen
        _bananas.Add(banana);
        _totalBananasCreated++;
    }
Exemple #16
0
    public Hopper(Entity entity)
    {
        this.entity = entity;
        this.config = new HopperConfig();
        jumpTime    = 0;
        jumpPercent = 0;
        jumpY       = 0;

        delayUntilFirstJump = RXRandom.Range(0, 0.4f);
    }
Exemple #17
0
    public void Inflate()
    {
        float newScale = RXRandom.Range(0.2f, 0.6f);

        if (isGood_)
        {
            newScale = 0.6f;
        }

        Go.to(this, 0.3f, new TweenConfig().addTweenProperty(new FloatTweenProperty("scale", newScale, false)).setEaseType(EaseType.BackOut));
    }
Exemple #18
0
    public Enemy() : base("Monkey_0")
    {
        this.x     = Futile.screen.halfWidth;
        this.y     = RXRandom.Range(-Futile.screen.halfHeight, Futile.screen.halfHeight);
        this.scale = 0.25f;


        //Debug.Log ("ENEMY CREATED");
        ///////TOUCHIN IT
        //Futile.touchManager.AddMultiTouchTarget(this);
    }
Exemple #19
0
    public Crew() : base("walkRight0")
    {
        this.defaultVelocity = 100;
        this.currentVelocity = this.defaultVelocity;

        int randomDirection = RXRandom.Range(0, 4);

        this.direction = VectorDirection.Up;         // (VectorDirection)randomDirection;

        if (randomDirection == 1)
        {
            this.direction = VectorDirection.Left;
        }
        else if (randomDirection == 2)
        {
            this.direction = VectorDirection.Right;
        }
        else if (randomDirection == 3)
        {
            this.direction = VectorDirection.Down;
        }


        _leftFrameElements  = new FAtlasElement[4];
        _rightFrameElements = new FAtlasElement[4];
        _upFrameElements    = new FAtlasElement[4];
        _downFrameElements  = new FAtlasElement[4];

        FAtlasManager am = Futile.atlasManager;

        _rightFrameElements[0] = am.GetElementWithName("walkRight0");
        _rightFrameElements[1] = am.GetElementWithName("walkRight1");
        _rightFrameElements[2] = am.GetElementWithName("walkRight2");
        _rightFrameElements[3] = am.GetElementWithName("walkRight3");

        _leftFrameElements[0] = am.GetElementWithName("walkLeft0");
        _leftFrameElements[1] = am.GetElementWithName("walkLeft1");
        _leftFrameElements[2] = am.GetElementWithName("walkLeft2");
        _leftFrameElements[3] = am.GetElementWithName("walkLeft3");

        _upFrameElements[0] = am.GetElementWithName("walkUp0");
        _upFrameElements[1] = am.GetElementWithName("walkUp1");
        _upFrameElements[2] = am.GetElementWithName("walkUp2");
        _upFrameElements[3] = am.GetElementWithName("walkUp3");

        _downFrameElements[0] = am.GetElementWithName("walkDown0");
        _downFrameElements[1] = am.GetElementWithName("walkDown1");
        _downFrameElements[2] = am.GetElementWithName("walkDown2");
        _downFrameElements[3] = am.GetElementWithName("walkDown3");


        ListenForUpdate(HandleUpdate);
    }
Exemple #20
0
    public MoveTile() : base("moveTileUp0")
    {
        _leftFrameElements  = new FAtlasElement[4];
        _rightFrameElements = new FAtlasElement[4];
        _upFrameElements    = new FAtlasElement[4];
        _downFrameElements  = new FAtlasElement[4];

        FAtlasManager am = Futile.atlasManager;

        _leftFrameElements[0] = am.GetElementWithName("moveTileLeft0");
        _leftFrameElements[1] = am.GetElementWithName("moveTileLeft1");
        _leftFrameElements[2] = am.GetElementWithName("moveTileLeft2");
        _leftFrameElements[3] = am.GetElementWithName("moveTileLeft3");

        _rightFrameElements[0] = am.GetElementWithName("moveTileRight0");
        _rightFrameElements[1] = am.GetElementWithName("moveTileRight1");
        _rightFrameElements[2] = am.GetElementWithName("moveTileRight2");
        _rightFrameElements[3] = am.GetElementWithName("moveTileRight3");

        _upFrameElements[0] = am.GetElementWithName("moveTileUp0");
        _upFrameElements[1] = am.GetElementWithName("moveTileUp1");
        _upFrameElements[2] = am.GetElementWithName("moveTileUp2");
        _upFrameElements[3] = am.GetElementWithName("moveTileUp3");

        _downFrameElements[0] = am.GetElementWithName("moveTileDown0");
        _downFrameElements[1] = am.GetElementWithName("moveTileDown1");
        _downFrameElements[2] = am.GetElementWithName("moveTileDown2");
        _downFrameElements[3] = am.GetElementWithName("moveTileDown3");

        _placedAt = 0.0f;

        int randomDirection = RXRandom.Range(0, 4);

        this.direction = VectorDirection.Up;         // (VectorDirection)randomDirection;

        if (randomDirection == 1)
        {
            this.direction = VectorDirection.Left;
            this.element   = _leftFrameElements[0];
        }
        else if (randomDirection == 2)
        {
            this.direction = VectorDirection.Right;
            this.element   = _rightFrameElements[0];
        }
        else if (randomDirection == 3)
        {
            this.direction = VectorDirection.Down;
            this.element   = _downFrameElements[0];
        }

        ListenForUpdate(HandleUpdate);
    }
Exemple #21
0
    public Candy()
    {
        mStickSprite         = new FSprite(mStickName);
        mStickSprite.anchorY = 1.0f;
        this.AddChild(mStickSprite);

        pointValue = (int)RXRandom.Range(0, mCandyColors.Length);

        mCandySprite         = new FSprite(mCandyColors[pointValue]);
        mCandySprite.anchorY = 2.5f;
        this.AddChild(mCandySprite);
    }
Exemple #22
0
    public void AllocateRunes()
    {
        int num = Mathf.CeilToInt(RuneNum / 5f);
        List <EntityBossRune> runes = GetRunesByState(RuneState.Hold);

        for (int i = 0; i < num && runes.Count > 0; i++)
        {
            SetRuneState(runes[RXRandom.Range(0, runes.Count)], RuneState.ReadyDrop);
        }

        SetAttackPattern(DropRunes, 5f);
    }
Exemple #23
0
        public EntityBossRune(EntityBoss boss, int index) : base(1f, 3f, 50f)
        {
            _boss           = boss;
            _index          = index;
            _state          = RuneState.Hold;
            _targetPosition = Vector3.zero;
            _onControl      = true;
            _offsetPosition = new Vector3(RXRandom.Range(-3f, 3f), 0f, RXRandom.Range(-3f, 3f));

            _entityParts.Add(new EntityPart(this, "bossrune"));
            _entityParts.Add(new EntityPart(this, string.Concat("bossrunemark", index + 1)));
            _entityParts[1].sortZOffset = 0.1f;
        }
Exemple #24
0
    public static void Shuffle <T>(this List <T> list)
    {
        //list.Sort(RandomComparison);

        // Fisher-Yates/Knuth/Durstenfeld Shuffle implementation: https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
        for (int i = list.Count - 1; i >= 1; i--)
        {
            int j    = RXRandom.Range(0, i + 1);
            var temp = list[j];
            list[j] = list[i];
            list[i] = temp;
        }
    }
Exemple #25
0
    public Vill(VillagerActivePlayer player, EntityArea entityArea) : base(entityArea)
    {
        this.player = player;

        attackCooldown = RXRandom.Float();         //random cooldown to start so they're not synced

        offsetY = 6f;

        int numArts = 8;

        artIndex = RXRandom.Range(0, numArts) + 1;

        body       = new FContainer();
        bodySprite = new FSprite("Arena/Vill" + artIndex + "_body");
        body.AddChild(bodySprite);

        colorSprite       = new FSprite("Arena/Vill" + artIndex + "_color");
        colorSprite.color = player.player.color.color;
        body.AddChild(colorSprite);

        weapon = new FContainer();
        body.AddChild(weapon);

        string weaponName = RXRandom.GetRandomString("RollingPin", "Torch", "Pitchfork", "", "", "", "");   //Rake, FryingPan

        if (weaponName != "" && artIndex != 8)
        {
            if (weaponName == "Torch")
            {
                var torch = new VillTorch();
                weapon.AddChild(torch);
            }
            else
            {
                FSprite weaponSprite = new FSprite("Arena/" + weaponName + "_1");
                weapon.AddChild(weaponSprite);
            }
        }


        shadowSprite        = new FSprite("Arena/VillShadow");
        shadowSprite.alpha  = 0.2f;
        shadowSprite.scaleX = 0.7f;
        shadowSprite.scaleY = 0.5f;

        hopper = new Hopper(this);
        hopper.config.jumpDist     = RXRandom.Range(18f, 19f);
        hopper.config.jumpDuration = RXRandom.Range(0.2f, 0.24f);
        hopper.config.jumpHeight   = RXRandom.Range(3f, 4f);
    }
Exemple #26
0
 protected void HandleUpdate()
 {
     curDuration -= Time.deltaTime;
     if (curDuration < 0)
     {
         Stop();
     }
     else
     {
         curAmplitude = amplitude * curDuration / duration;
         node.x       = oPosition.x + RXRandom.Range(-curAmplitude, curAmplitude);
         node.y       = oPosition.y + RXRandom.Range(-curAmplitude, curAmplitude);
     }
 }
Exemple #27
0
    void generateParticles()
    {
        int part = RXRandom.Range(2, 4);

        for (int x = 0; x < part; x++)
        {
            pd.x = gameObject.rigidbody.position.x * FPhysics.METERS_TO_POINTS + RXRandom.Range(-10.0f, 10.0f);;
            pd.y = (gameObject.rigidbody.position.y) * FPhysics.METERS_TO_POINTS - 10;
            Vector2 speed = RXRandom.Vector2Normalized() * RXRandom.Range(20.0f, 80.0f);
            pd.speedX   = speed.x;
            pd.speedY   = speed.y;
            pd.lifetime = RXRandom.Range(0.2f, 0.5f);
            this.GamePage.impactParticles.AddParticle(pd);
        }
    }
Exemple #28
0
    void DoSpark()
    {
        isReadyToSpark = false;
        rotationSpeed  = RXRandom.Range(-2.0f, 2.0f);

        x     = RXRandom.Range(rect.x + padding, rect.x + rect.width - padding * 2);
        y     = RXRandom.Range(rect.y + padding, rect.y + rect.height - padding * 2);
        scale = 0;

        Go.to(this, 0.5f, new TweenConfig().scaleXY(1.0f).setDelay(0.2f).backOut().onComplete((t) => {
            Go.to(this, 0.2f, new TweenConfig().scaleXY(0, 0f).onComplete((tw) => {
                isReadyToSpark = true;
            }));
        }));
    }
Exemple #29
0
    private void HandleUpdate()
    {
        if (!gameOver)
        {
            UpdateThingyPositions();

            timer += Time.deltaTime;

            if (thingies.Count < maxThingies && timer >= RXRandom.Range(0.1f, 0.5f))
            {
                timer = 0;
                AddNewThingy(true);
                MoveGoodThingiesToBottom();
            }
        }
    }
Exemple #30
0
    public void Generate(Chunk chunk)
    {
        int spawnCount = (int)RXRandom.Range(0f, 5f);

        for (int i = 0; i < spawnCount; i++)
        {
            AddEntityRandomPosition(chunk, new EntityPpyongppyong());
        }

        spawnCount = (int)RXRandom.Range(0f, 1.05f);

        for (int i = 0; i < spawnCount; i++)
        {
            AddEntityRandomPosition(chunk, new EntityDipper());
        }
    }