Ejemplo n.º 1
0
    public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game)
    {
        if (sprite1 == null || sprite2 == null)
        {
            throw new ArgumentException("Neither the 1st nor 2nd sprite can be EOS with CollectResource interaction.");
        }

        if (!sprite1.is_resource)
        {
            return;
        }

        var r = (Resource)sprite1;

        applyScore = false;

        var numResources = sprite2.getAmountResource(r.resource_name);

        if (numResources >= game.getResourceLimit(r.resource_name))
        {
            return;
        }

        var topup = Mathf.Min(r.value, game.getResourceLimit(r.resource_name) - numResources);

        applyScore = true;
        sprite2.modifyResource(r.resource_name, topup);

        if (killResource)
        {
            //boolean variable set to false to indicate the sprite was not transformed
            game.killSprite(sprite1, true);
        }
    }
Ejemplo n.º 2
0
    public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game)
    {
        if (sprite1 == null || sprite2 == null)
        {
            throw new ArgumentException("Neither the 1st nor 2nd sprite can be EOS with CollectResourceIfHeld interaction.");
        }

        if (sprite1.is_resource)
        {
            var r = (Resource)sprite1;
            applyScore = false;

            //Check if we have the secondary resource first
            var numResourcesHeld = sprite2.getAmountResource(heldResource);
            if (numResourcesHeld < value)
            {
                return;
            }

            var numResources = sprite2.getAmountResource(r.resource_name);
            if (numResources + r.value <= game.getResourceLimit(r.resource_name))
            {
                applyScore = true;
                sprite2.modifyResource(r.resource_name, r.value);
            }

            if (killResource)
            {
                //boolean variable set to false to indicate the sprite was not transformed
                game.killSprite(sprite1, false);
            }
        }
    }
Ejemplo n.º 3
0
    private void setSpriteFields(VGDLGame game, VGDLSprite newSprite, VGDLSprite oldSprite)
    {
        //Orientation
        if (newSprite.is_oriented && oldSprite.is_oriented)
        {
            newSprite.orientation = oldSprite.orientation;
        }

        //Last position of the avatar.
        newSprite.lastrect = new Rect(oldSprite.lastrect.x, oldSprite.lastrect.y,
                                      oldSprite.lastrect.width, oldSprite.lastrect.height);

        //Copy resources
        if (oldSprite.resources.Count > 0)
        {
            foreach (var entry in oldSprite.resources)
            {
                var resType  = entry.Key;
                var resValue = entry.Value;
                newSprite.modifyResource(resType, resValue);
            }
        }


        //Avatar handling (I think considering avatars here is weird...)
        var transformed = true;

        if (oldSprite.is_avatar)
        {
            try {
                var id    = ((MovingAvatar)oldSprite).playerID;
                var p     = game.avatars[id].player;
                var score = game.avatars[id].score;
                var win   = game.avatars[id].winState;
                game.avatars[id]        = (MovingAvatar)newSprite;
                game.avatars[id].player = p;
                game.avatars[id].setKeyHandler(game.inputHandler);
                game.avatars[id].score    = score;
                game.avatars[id].winState = win;
                game.avatars[id].playerID = id;
                transformed = true;
            } catch (Exception) {
                transformed = false; // new sprite is not an avatar, don't kill the current one}
            }
        }

        //boolean variable set to true to indicate the sprite was transformed
        game.killSprite(oldSprite, transformed);
    }
Ejemplo n.º 4
0
    public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game)
    {
        if (sprite1 == null)
        {
            throw new ArgumentException("1st sprite can't be EOS with SpawnIfHasMore interaction.");
        }

        applyScore = false;

        if (Random.value >= prob)
        {
            return;
        }

        if (sprite1.getAmountResource(resource) >= limit)
        {
            game.addSprite(stype, sprite1.getPosition());
            applyScore = true;

            sprite1.modifyResource(resource, -spend); //0 by default.
        }
    }
Ejemplo n.º 5
0
    public override void execute(VGDLSprite sprite1, VGDLSprite sprite2, VGDLGame game)
    {
        if (sprite1 == null || sprite2 == null)
        {
            throw new ArgumentException("Neither the 1st nor 2nd sprite can be EOS with ChangeResource interaction.");
        }

        var numResources = sprite1.getAmountResource(resource);

        applyScore = false;
        if (numResources + value <= game.getResourceLimit(resource))
        {
            sprite1.modifyResource(resource, value);
            applyScore = true;

            if (killResource)
            {
                //boolean variable set to true, as the sprite was transformed
                game.killSprite(sprite2, true);
            }
        }
    }