Float() public static méthode

public static Float ( ) : float
Résultat float
Exemple #1
0
    public Player(bool isControllable = false)
        : base("player")
    {
        playerBlip          = new FSprite("playerBlip");
        hair                = new FSprite("hair");
        this.isControllable = isControllable;
        addAnimation(new FAnimation("idle", new int[] { 0 }, 100, true));
        addAnimation(new FAnimation("pistol", new int[] { 1 }, 100, true));
        addAnimation(new FAnimation("shotgun", new int[] { 2 }, 100, true));
        addAnimation(new FAnimation("machinegun", new int[] { 3 }, 100, true));


        powerupClock = new PowerupClock();
        if (isControllable)
        {
            playerBlip.color = Color.green;
            play("pistol");
            shadow     = new FSprite("player_1");
            hair.color = Color.black;

            powerupClock.percentage = 0;
        }
        else
        {
            playerBlip.color = Color.red;
            play("idle");
            hair.color = new Color(RXRandom.Float() * .5f, RXRandom.Float() * .5f, RXRandom.Float() * .5f);
            float randomColorMult = .5f + RXRandom.Float() * .5f;
            this.color = new Color(randomColorMult, randomColorMult, randomColorMult);
            shadow     = new FSprite("player_0");
        }

        shadow.color = new Color(0, 0, 0, .5f);
    }
Exemple #2
0
    public void addPlayer(Player p)
    {
        p.addToMiniMap(miniMap);
        if (p.isControlled)
        {
            p.SetPosition(playerSpawn.GetPosition());
        }
        else
        {
            p.SetPosition(spawnPoints[RXRandom.Int(spawnPoints.Count)].GetPosition());
        }
        float scaleChance = RXRandom.Float();

        if (scaleChance < .15f)
        {
            p.setScale(3.0f);
        }
        else if (scaleChance < .4f)
        {
            p.setScale(2.0f);
        }
        playerLayer.AddChild(p);
        playerList.Add(p);
        p.setWorld(this);
    }
    public void AddHeart()
    {
        FSprite heart = new FSprite("heart.psd");

        heart.x        = Random.Range(heart.width / 2f, Futile.screen.width - heart.width / 2f);
        heart.y        = Random.Range(heart.height / 2f, Futile.screen.height - heart.height / 2f - 50f /*UI bar*/);
        heart.scale    = 0;
        heart.rotation = Random.Range(0, 359f);
        heart.color    = new Color(1.0f, Random.Range(0.0f, 0.3f), Random.Range(0.0f, 0.3f), 1.0f);
        AddChild(heart);
        hearts.Add(heart);

        Go.to(heart, Random.Range(1.0f, 5.0f), new TweenConfig()
              .setIterations(-1)
              .floatProp("rotation", 360 * (RXRandom.Float() < 0.5f ? 1 : -1), true));

        float inflationDuration = Random.Range(1.0f, 2.0f);
        Tween tweenUp           = new Tween(heart, inflationDuration, new TweenConfig()
                                            .floatProp("scale", Random.Range(0.3f, 1.0f))
                                            .setEaseType(EaseType.SineInOut));

        Tween tweenDown = new Tween(heart, inflationDuration, new TweenConfig()
                                    .floatProp("scale", 0)
                                    .onComplete(OnHeartDisappearedWithoutBeingTouched)
                                    .setEaseType(EaseType.SineInOut));

        TweenChain chain = new TweenChain();

        chain.append(tweenUp);
        chain.append(tweenDown);

        Go.addTween(chain);
        chain.play();
    }
    public void UpdatePostFoundEachOther()
    {
        if (!whit.isJumping && RXRandom.Float() > 0.5f)
        {
            whit.decelAmt = 150f;
            whit.Jump();
        }

        if (!dana.isJumping && RXRandom.Float() > 0.5f)
        {
            dana.decelAmt = 150f;
            dana.Jump();
        }

        if (!whit.isTurning && RXRandom.Float() > 0.95f)
        {
            whit.TurnAround();
        }

        if (!dana.isTurning && RXRandom.Float() > 0.95f)
        {
            dana.TurnAround();
        }

        for (int i = 0; i < heartShowerHearts.Count; i++)
        {
            FSprite heart = heartShowerHearts[i];
            float   newY  = heart.y - (float)(i + 50) / 100.0f * Time.deltaTime * 200.0f;
            if (newY < -heart.height / 2f)
            {
                newY += Futile.screen.width + heart.height / 2f;
            }
            heart.y = newY;
        }
    }
    public void PrepareNewHeartTokenForEntry(bool isBroken)
    {
        THeartToken token;

        token = GetUnusedHeartToken(isBroken);

        if (token == null)
        {
            return;
        }

        token.sprite.isVisible = true;
        float rand = RXRandom.Float();

        if (rand < 0.5f)
        {
            token.sprite.y = 150f;
        }
        else if (rand >= 0.5f && rand < 0.8f)
        {
            token.sprite.y = 350f;
        }
        else
        {
            token.sprite.y = 550f;
        }
        token.sprite.x = Futile.screen.width + token.sprite.width / 2f;
    }
Exemple #6
0
 public void ResetBall()
 {
     ball.x = 0;
     ball.y = 0;
     // grabbed the following from the tutorial. it gives the ball a default velocity in a random direction, within 45 degrees on either side. there's likely a better way to do it.
     ball.yVelocity = (ball.defaultVelocity / 2) - (RXRandom.Float() * ball.defaultVelocity);
     ball.xVelocity = Mathf.Sqrt((ball.defaultVelocity * ball.defaultVelocity) - (ball.yVelocity * ball.yVelocity)) * (RXRandom.Int(2) * 2 - 1);
 }
Exemple #7
0
 private void ResetBall()
 {
     _ball.x = 0;
     _ball.y = 0;
     // Ensure that the ball starts at a random angle that is never greater than 45 degrees from 0 in either direction
     _ball.yVelocity = (_ball.defaultVelocity / 2) - (RXRandom.Float() * _ball.defaultVelocity);
     // Make sure that the defaultVelocity (hypotenuse) is honored by setting the xVelocity accordingly, then choose a random horizontal direction
     _ball.xVelocity = Mathf.Sqrt((_ball.defaultVelocity * _ball.defaultVelocity) - (_ball.yVelocity * _ball.yVelocity)) * (RXRandom.Int(2) * 2 - 1);
 }
Exemple #8
0
	override public void PopulateRenderLayer()
	{
		if(_isOnStage && _firstFacetIndex != -1) 
		{
			_isMeshDirty = false;
			
			Vector3[] vertices = _renderLayer.vertices;
			Vector2[] uvs = _renderLayer.uvs;
			Color[] colors = _renderLayer.colors;
			
			List<Vector2[]> vertexPolygons = _mesh2D.polygonalData.vertexPolygons;
			List<int[]> trianglePolygons = _mesh2D.polygonalData.trianglePolygons;
		
			int polyCount = trianglePolygons.Count;
			
			int nextTriangleIndex = _firstFacetIndex;
			
			for(int p = 0; p<polyCount; p++)
			{
				Vector2[] polyVertices = vertexPolygons[p];
				int[] polyTriangleIndices = trianglePolygons[p];
				
				int polyTriangleCount = polyTriangleIndices.Length /3;
				
				Color drawColor = RXColor.ColorFromHSL(0.8f+RXRandom.Float(p) * 0.3f,1f,0.5f);
				
				for(int t = 0; t < polyTriangleCount; t++)
				{
					int vertexIndex0 = nextTriangleIndex*3;
					int vertexIndex1 = vertexIndex0 + 1;
					int vertexIndex2 = vertexIndex0 + 2;
					int threeT = t*3;
					
					_concatenatedMatrix.ApplyVector3FromLocalVector2(ref vertices[vertexIndex0], polyVertices[polyTriangleIndices[threeT]],0);
					_concatenatedMatrix.ApplyVector3FromLocalVector2(ref vertices[vertexIndex1], polyVertices[polyTriangleIndices[threeT+1]],0);
					_concatenatedMatrix.ApplyVector3FromLocalVector2(ref vertices[vertexIndex2], polyVertices[polyTriangleIndices[threeT+2]],0);
					
					uvs[vertexIndex0] = _uvBottomLeft;
					uvs[vertexIndex1] = _uvTopLeft;
					uvs[vertexIndex2] = _uvBottomRight;
					
					colors[vertexIndex0] = drawColor;
					colors[vertexIndex1] = drawColor;
					colors[vertexIndex2] = drawColor;
					
//					colors[vertexIndex0] = _alphaColor;
//					colors[vertexIndex1] = _alphaColor;
//					colors[vertexIndex2] = _alphaColor;
					
					nextTriangleIndex++;
				}
			}
			
			_renderLayer.HandleVertsChange();
		}
	}
Exemple #9
0
    public SparkleSprite(Rect rect) : base("Extra/Sparkle_Big")
    {
        this.rect      = rect;
        this.scale     = 0.0f;
        isReadyToSpark = false;

        Futile.instance.StartDelayedCallback(DoSpark, RXRandom.Float());        //first start will be delayed

        ListenForUpdate(HandleUpdate);
    }
Exemple #10
0
    private List <Bullet> shootBullet()
    {
        List <Bullet> result = new List <Bullet>();

        switch (powerUpType)
        {
        case Powerup.PowerupType.NONE:
            FSoundManager.PlaySound("shoot 1", .3f);
            float rotationRadians = -(rotation + 90) * C.PIOVER180;
            float xDisp           = -10;
            float yDisp           = -8;
            for (int x = 0; x < 1; x++)
            {
                float  directionRotation = (rotation - 90 + RXRandom.Float()) * C.PIOVER180;
                Bullet b = new Bullet(this.GetPosition() + new Vector2(Mathf.Cos(rotationRadians) * xDisp + Mathf.Sin(rotationRadians) * yDisp, -Mathf.Cos(rotationRadians) * yDisp + Mathf.Sin(rotationRadians) * xDisp), new Vector2(Mathf.Cos(directionRotation) * bulletSpeed, -Mathf.Sin(directionRotation) * bulletSpeed));
                b.rotation = directionRotation * C.PIOVER180_INV + 90;
                b.setPlayer(this);
                result.Add(b);
            }
            break;

        case Powerup.PowerupType.SHOTGUN:
            FSoundManager.PlaySound("shoot", .2f);
            rotationRadians = -(rotation + 90) * C.PIOVER180;
            xDisp           = -20;
            yDisp           = -5;
            float randomAngle = 20;
            for (int x = 0; x < 5; x++)
            {
                float  directionRotation = (rotation - 90 + RXRandom.Float() * randomAngle * 2 - randomAngle) * C.PIOVER180;
                Bullet b = new Bullet(this.GetPosition() + new Vector2(Mathf.Cos(rotationRadians) * xDisp + Mathf.Sin(rotationRadians) * yDisp, -Mathf.Cos(rotationRadians) * yDisp + Mathf.Sin(rotationRadians) * xDisp), new Vector2(Mathf.Cos(directionRotation) * bulletSpeed, -Mathf.Sin(directionRotation) * bulletSpeed));
                b.rotation = directionRotation * C.PIOVER180_INV + 90;
                b.setPlayer(this);
                result.Add(b);
            }
            break;

        case Powerup.PowerupType.MACHINEGUN:
            FSoundManager.PlaySound("shoot", .1f);
            rotationRadians = -(rotation + 90) * C.PIOVER180;
            xDisp           = -12;
            yDisp           = -12;
            randomAngle     = 6;
            for (int x = 0; x < 1; x++)
            {
                float  directionRotation = (rotation - 90 + RXRandom.Float() * randomAngle * 2 - randomAngle) * C.PIOVER180;
                Bullet b = new Bullet(this.GetPosition() + new Vector2(Mathf.Cos(rotationRadians) * xDisp + Mathf.Sin(rotationRadians) * yDisp, -Mathf.Cos(rotationRadians) * yDisp + Mathf.Sin(rotationRadians) * xDisp), new Vector2(Mathf.Cos(directionRotation) * bulletSpeed, -Mathf.Sin(directionRotation) * bulletSpeed));
                b.rotation = directionRotation * C.PIOVER180_INV + 90;
                b.setPlayer(this);
                result.Add(b);
            }
            break;
        }
        return(result);
    }
Exemple #11
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 #12
0
    public T GetRandomItem(bool shouldAdjustWeights)
    {
        float totalWeight = 0.0f;

        T foundThing = default(T);

        int itemCount = items.Count;

        for (int i = 0; i < itemCount; i++)
        {
            totalWeight += items[i].liveWeight;
        }

        float randomWeight = RXRandom.Float() * totalWeight;

        totalWeight = 0;         //we'll use the same var to measure cumulative total weight

        for (int i = 0; i < itemCount; i++)
        {
            totalWeight = totalWeight + items[i].liveWeight;
            if (randomWeight <= totalWeight)
            {
                foundThing = items[i].thing;
                if (shouldAdjustWeights)
                {
                    items[i].liveWeight = 0;
                }
                break;
            }
        }

        if (shouldAdjustWeights)
        {
            for (int i = 0; i < itemCount; i++)
            {
                Item item = items[i];
                item.liveWeight += item.weight;
            }
        }

        return(foundThing);
    }
Exemple #13
0
    override public void Start()
    {
        var startPos = RXRandom.GetRandomItem(arena.mapData.startPoses) as StartPosMI;

        arena.mapData.startPoses.Remove(startPos);

        Vector2 center   = new Vector2(startPos.x, startPos.y);
        float   radius   = 40;
        int     failsafe = 0;

        while (vills.Count < initialVillCount && failsafe++ < 1000)
        {
            Vector2 checkPos = center + (RXRandom.Vector2Normalized() * radius * RXRandom.Float());
            if (!arena.entityArea.CheckPointHit(checkPos.x, checkPos.y))
            {
                Vill vill = new Vill(this, arena.entityArea);
                vill.SetPosition(checkPos);
                vill.AddToArea();
                vills.Add(vill);
                arena.vills.Add(vill);
            }
        }
    }
Exemple #14
0
    public void Update()
    {
        float x = entity.x;
        float y = entity.y;

        float deltaTime = Time.deltaTime;

        if (delayUntilFirstJump > 0)
        {
            delayUntilFirstJump -= deltaTime;
            return;
        }

        if (jumpTime > 0)
        {
            jumpTime += deltaTime;
        }

        if (jumpTime >= curJumpDuration)
        {
            jumpTime = 0;
            speedX   = 0;
            speedY   = 0;
        }

        if (jumpTime <= 0)
        {
            if (inputDirection.sqrMagnitude > 1)
            {
                inputDirection.Normalize();
            }

            bool shouldMove = false;

            Vector2 moveVector = Vector2.zero;

            if (inputDirection.sqrMagnitude > 0.1f)
            {
                moveVector = inputDirection;
                shouldMove = true;
            }
            else if (RXRandom.Float() < 0.01f)
            {
                moveVector = RXRandom.Vector2Normalized() * 0.1f;
                shouldMove = true;
            }

            if (shouldMove)
            {
                Vector2 farOffset   = moveVector * config.jumpDist;
                Vector2 closeOffset = moveVector * config.jumpDist * 0.5f;

                bool canJumpClose = !entity.entityArea.CheckVillPointHit(x + closeOffset.x, y + closeOffset.y);
                bool canJumpFar   = !entity.entityArea.CheckVillPointHit(x + farOffset.x, y + farOffset.y);

                Vector2 winningOffset = closeOffset;

                if (canJumpClose)
                {
                    winningOffset = closeOffset;

                    if (canJumpFar)
                    {
                        winningOffset = farOffset;
                    }
                }
                else
                {
                    canJumpClose = !entity.entityArea.CheckVillPointHit(x, y + closeOffset.y);
                    canJumpFar   = !entity.entityArea.CheckVillPointHit(x, y + farOffset.y);

                    if (canJumpClose)
                    {
                        winningOffset = new Vector2(0, closeOffset.y);

                        if (canJumpFar)
                        {
                            winningOffset = new Vector2(0, farOffset.y);
                        }
                    }
                    else
                    {
                        canJumpClose = !entity.entityArea.CheckVillPointHit(x + closeOffset.x, y);
                        canJumpFar   = !entity.entityArea.CheckVillPointHit(x + farOffset.x, y);

                        if (canJumpClose)
                        {
                            winningOffset = new Vector2(closeOffset.x, 0);

                            if (canJumpFar)
                            {
                                winningOffset = new Vector2(farOffset.x, 0);
                            }
                        }
                        else
                        {
                            shouldMove = false;
                        }
                    }
                }

                if (shouldMove)
                {
                    //do the jump!
                    curJumpDuration = RXRandom.Range(0.9f, 1.1f) * config.jumpDuration;
                    jumpTime        = 0.0001f;
                    speedX          = winningOffset.x / curJumpDuration;
                    speedY          = winningOffset.y / curJumpDuration;
                }
            }
        }

        if (jumpTime > 0)
        {
            x += speedX * deltaTime;
            y += speedY * deltaTime * Config.ISO_RATIO;
        }

        jumpPercent = Mathf.Clamp01(jumpTime / curJumpDuration);
        jumpY       = -4.0f * jumpPercent * (-1.0f + jumpPercent);

        entity.x = x;
        entity.y = y;
    }
Exemple #15
0
    internal void loadMap(string mapName)
    {
        this.clearMap();
        this.LoadTMX("Maps/" + mapName);

        tilemap = (FTilemap)(getLayerNamed("Tilemap"));

        for (int x = 0; x < 3; x++)
        {
            otherTilemaps[x] = new FTilemap(tilemap.BaseElementName + "_" + (x + 1), 1);
            otherTilemaps[x].LoadText(tilemap.dataString, false);
        }

        tilemapCollision = (FTilemap)(getLayerNamed("Meta"));
        objectGroup      = (FContainer)(getLayerNamed("Objects"));



        foreach (XMLNode xml in this.objects)
        {
            switch (xml.attributes["type"])
            {
            case "Spawn":
                FNode spawnPoint = new FNode();
                spawnPoint.SetPosition(int.Parse(xml.attributes["x"]) + 8, -int.Parse(xml.attributes["y"]) + 8);
                spawnPoints.Add(spawnPoint);
                player.SetPosition(spawnPoint.GetPosition());
                break;

            case "Warp":
                int     warpX          = 0;
                int     warpY          = 0;
                XMLNode propertiesNode = (XMLNode)xml.children[0];
                foreach (XMLNode property in propertiesNode.children)
                {
                    switch (property.attributes["name"])
                    {
                    case "warpTileX":
                        warpX = int.Parse(property.attributes["value"]);
                        break;

                    case "warpTileY":
                        warpY = int.Parse(property.attributes["value"]);
                        break;
                    }
                }
                WarpPoint warpPoint = new WarpPoint(warpX, warpY, xml.attributes["name"], int.Parse(xml.attributes["x"]) + 8, -int.Parse(xml.attributes["y"]) + 8);
                warpPoints.Add(warpPoint);
                break;
            }
        }
        for (int x = 0; x < 100; x++)
        {
            Scientist s = new Scientist(tilemap.width * RXRandom.Float(), -tilemap.height * RXRandom.Float());
            while (BaseGameObject.isWalkable(tilemap, s.x, s.y))
            {
                s.SetPosition(tilemap.width * RXRandom.Float(), -tilemap.height * RXRandom.Float());
            }
            addEnemy(s);
        }

        backgroundLayer.AddChild(tilemap);
        foreach (FTilemap f in otherTilemaps)
        {
            backgroundLayer.AddChild(f);
        }
        backgroundLayer.AddChild(tilemapCollision);
        backgroundLayer.AddChild(objectGroup);

        player.setMap(this);
        playerLayer.AddChild(player);
    }
Exemple #16
0
    private void UpdateThingyPositions()
    {
        foreach (Thingy thingy in thingies)
        {
            if (thingy.isGood)
            {
                int maxVelocity = 250;

                if (RXRandom.Float() < 0.2f)
                {
                    thingy.xVelocity += RXRandom.Range(-100, 100);
                }
                if (RXRandom.Float() < 0.2f)
                {
                    thingy.yVelocity += RXRandom.Range(-100, 100);
                }

                if (thingy.xVelocity > maxVelocity)
                {
                    thingy.xVelocity = maxVelocity;
                }
                if (thingy.xVelocity < -maxVelocity)
                {
                    thingy.xVelocity = -maxVelocity;
                }

                if (thingy.yVelocity > maxVelocity)
                {
                    thingy.yVelocity = maxVelocity;
                }
                if (thingy.yVelocity < -maxVelocity)
                {
                    thingy.yVelocity = -maxVelocity;
                }
            }

            float deltaX = thingy.xVelocity * Time.deltaTime;
            float deltaY = thingy.yVelocity * Time.deltaTime;

            FSprite sprite = thingy.GetChildAt(0) as FSprite;
            Vector2 maxes  = sprite.GetGlobalTextureRectMaxes();
            Vector2 mins   = sprite.GetGlobalTextureRectMins();

            if (maxes.x + deltaX > playAreaRect.width)
            {
                deltaX            = playAreaRect.width - maxes.x;
                thingy.xVelocity *= -1;
            }
            else if (mins.x + deltaX < 0)
            {
                deltaX            = -mins.x;
                thingy.xVelocity *= -1;
            }

            if (maxes.y + deltaY > playAreaRect.height)
            {
                deltaY            = playAreaRect.height - maxes.y;
                thingy.yVelocity *= -1;
            }
            else if (mins.y + deltaY < 0)
            {
                deltaY            = -mins.y;
                thingy.yVelocity *= -1;
            }

            thingy.x += deltaX;
            thingy.y += deltaY;
        }
    }
Exemple #17
0
 public static Color Color(float alpha)
 {
     return(new Color(RXRandom.Float(), RXRandom.Float(), RXRandom.Float(), alpha));
 }
Exemple #18
0
 public static Color ColorHSL(float sat = 1f, float lum = 0.5f, float alpha = 1f)
 {
     return(RXColor.ColorFromHSL(RXRandom.Float(), sat, lum, alpha));
 }
    protected override void Update()
    {
        if (CurrentState == State.HIT)
        {
            base.Update();
            return;
        }
        lastDecision += Time.deltaTime;
        if (lastDecision >= MIN_DECISION)
        {
            if (RXRandom.Float() < .3f)
            {
                moving = !moving;
            }
            else
            if (RXRandom.Float() > .7f)
            {
                if (RXRandom.Bool())
                {
                    currentDirection += 1;
                }
                else
                {
                    currentDirection -= 1;
                }

                if (currentDirection < 0)
                {
                    currentDirection = Dir.RIGHT;
                }
                else
                if (!Enum.IsDefined(typeof(Dir), currentDirection))
                {
                    currentDirection = 0;
                }
            }
            lastDecision = 0;
            nextDecision = MIN_DECISION + (MAX_DECISION - MIN_DECISION) * RXRandom.Float();
            base.Update();
        }

        if (moving)
        {
            switch (currentDirection)
            {
            case Dir.UP:
                walkUp();
                break;

            case Dir.LEFT:
                walkLeft();
                break;

            case Dir.DOWN:
                walkDown();
                break;

            case Dir.RIGHT:
                walkRight();
                break;
            }
        }
        base.Update();
    }
 void StartHeartShower()
 {
     foreach (FSprite heart in heartShowerHearts)
     {
         heart.x         = Random.Range(0, Futile.screen.width);
         heart.y         = Futile.screen.height + heart.height + Random.Range(0, 500);
         heart.isVisible = true;
         Go.to(heart, Random.Range(1.0f, 4.0f), new TweenConfig().setIterations(-1).floatProp("rotation", 360 * (RXRandom.Float() < 0.5 ? 1 : -1), true));
     }
 }
Exemple #21
0
    public void Update()
    {
        if (beginCount < beginTime)
        {
            beginCount      += UnityEngine.Time.deltaTime;
            clock.percentage = 1.0f;
        }
        else if (beginningLabel.alpha > 0)
        {
            beginningLabel.alpha      -= .3f * UnityEngine.Time.deltaTime;
            beginningLabelShadow.alpha = beginningLabel.alpha;
        }
        enemyClock.percentage = (playerList.Count - 1) / startNumPlayers;
        if (playerList.Count == 1)
        {
            clock.disableClock();
            if (endScreen == null)
            {
                FSoundManager.PlaySound("win");
                endScreen = new LevelOverScreen(true, currentLevelNum + 1 >= enemiesOnLevel.Length);
                gui.AddChild(endScreen);
            }
            else
            {
                if (endScreen.readyToStart)
                {
                    Futile.instance.SignalUpdate -= Update;
                    Futile.stage.RemoveAllChildren();
                    if (this.currentLevelNum + 1 < enemiesOnLevel.Length)
                    {
                        World newWorld = new World(++this.currentLevelNum);
                        Futile.instance.SignalUpdate += newWorld.Update;
                    }
                    else
                    {
                        TitleScreen titleScreen = new TitleScreen();
                        Futile.stage.AddChild(titleScreen);
                    }
                }
            }
        }
        else if (clock.percentage <= 0)
        {
            if (endScreen == null)
            {
                FSoundManager.PlaySound("lose");
                endScreen = new LevelOverScreen(false);
                gui.AddChild(endScreen);
            }
            else
            {
                endScreen.MoveToFront();
                if (endScreen.readyToStart)
                {
                    Futile.instance.SignalUpdate -= Update;
                    Futile.stage.RemoveAllChildren();

                    World newWorld = new World(this.currentLevelNum);
                    Futile.instance.SignalUpdate += newWorld.Update;
                }
            }
        }
        for (int ind = 0; ind < powerups.Count; ind++)
        {
            Powerup powerup = powerups[ind];
            foreach (Player p in playerList)
            {
                if (p.isControlled)
                {
                    if (powerup.checkCollision(p))
                    {
                        FSoundManager.PlaySound("powerup");
                        p.collectPowerUp(powerup.PType);
                        powerup.RemoveFromContainer();
                        powerups.Remove(powerup);
                        ind--;
                    }
                }
            }
        }
        for (int ind = 0; ind < bulletList.Count; ind++)
        {
            Bullet b = bulletList[ind];
            b.Update();
            for (int playerInd = 0; playerInd < playerList.Count; playerInd++)
            {
                Player p = playerList[playerInd];
                if (clock.percentage > 0 && b.checkCollision(p))
                {
                    p.setScale(p.scale - 1.0f, false);
                    if (p.scale <= 0)
                    {
                        FSoundManager.PlaySound("dead", .3f);
                        p.RemoveFromContainer();
                        playerList.Remove(p);
                        playerInd--;
                        FloatIndicator floatInd = new FloatIndicator("+00:00:0" + p.secondValue, p.GetPosition());
                        playerLayer.AddChild(floatInd);
                        clock.percentage += p.secondValue / 10.0f;      //Add the seconds to the clock
                        if (p.secondValue == 3)
                        {
                            float   powerupChance = RXRandom.Float();
                            Powerup powerup       = null;
                            if (powerupChance < .4f)
                            {
                                powerup = new Powerup(Powerup.PowerupType.MACHINEGUN);
                            }
                            else if (powerupChance < .8f)
                            {
                                powerup = new Powerup(Powerup.PowerupType.SHOTGUN);
                            }
                            if (powerup != null)
                            {
                                powerups.Add(powerup);
                                powerup.SetPosition(p.GetPosition());
                                playerLayer.AddChild(powerup);
                            }
                        }
                    }
                    else
                    {
                        FSoundManager.PlaySound("hit", .3f);
                    }
                    b.RemoveFromContainer();
                    bulletList.Remove(b);
                    ind--;
                    break;
                }
                else
                if (tilemap.getFrameNum((int)(b.x / tilemap._tileWidth), (int)(-b.y / tilemap._tileHeight)) == 1)
                {
                    b.RemoveFromContainer();
                    bulletList.Remove(b);
                    ind--;
                    break;
                }
            }
        }
    }
Exemple #22
0
    public override void Update()
    {
        if (isControllable)
        {
            xMove = 0;
            yMove = 0;
            if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
            {
                yMove = controlSpeed * UnityEngine.Time.deltaTime;
            }
            if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
            {
                yMove = -(controlSpeed * UnityEngine.Time.deltaTime);
            }
            if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
            {
                xMove = -(controlSpeed * UnityEngine.Time.deltaTime);
            }
            if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
            {
                xMove = controlSpeed * UnityEngine.Time.deltaTime;
            }
            if (Input.GetMouseButton(0))
            {
                state = State.SHOOTING;
            }
            else
            {
                state = State.IDLE;
            }

            rotation = 0;
            rotation = this.GetLocalMousePosition().GetAngle() + 90;
        }
        else
        {
            if (RXRandom.Double() < .03)
            {
                xMove = (RXRandom.Float() * speed * 2 - speed) * UnityEngine.Time.deltaTime;
                yMove = (RXRandom.Float() * speed * 2 - speed) * UnityEngine.Time.deltaTime;

                rotation = new Vector2(xMove, yMove).GetAngle() + 90;
            }
            else if (RXRandom.Double() < .01)
            {
                xMove = 0;
                yMove = 0;
            }
        }

        tryMove();

        if (this.powerupClock.percentage <= 0 && this.powerUpType != Powerup.PowerupType.NONE)
        {
            collectPowerUp(Powerup.PowerupType.NONE);
        }

        if (lastShoot < minShoot)
        {
            lastShoot += UnityEngine.Time.deltaTime;
        }
        switch (state)
        {
        case State.IDLE:
            break;

        case State.SHOOTING:

            if (lastShoot >= minShoot || (powerUpType == Powerup.PowerupType.MACHINEGUN && lastShoot >= minShoot * .05f))
            {
                lastShoot = 0;

                foreach (Bullet b in shootBullet())
                {
                    world.addBullet(b);
                }
            }

            break;
        }
        if (isControllable)
        {
            switch (this.powerUpType)
            {
            case Powerup.PowerupType.NONE:
                play("pistol");
                break;

            case Powerup.PowerupType.SHOTGUN:
                play("shotgun");
                break;

            case Powerup.PowerupType.MACHINEGUN:
                play("machinegun");
                break;
            }
        }

        shadow.rotation = this.rotation;
        shadow.SetPosition(this.GetPosition());
        shadow.y -= 3;
        hair.SetPosition(this.GetPosition());
        hair.rotation = this.rotation;

        playerBlip.SetPosition(GetPosition() * Minimap.BLIP_POS_MULT);
        playerBlip.rotation = this.rotation;
        playerBlip.scale    = this.scale * .5f;

        base.Update();
    }