コード例 #1
0
    public override VGDLMovementTypes passiveMovement(VGDLSprite sprite)
    {
        if (sprite.isFirstTick)
        {
            sprite.isFirstTick = false;
            return(VGDLMovementTypes.STILL);
        }

        //This needs to be thoroughly tested when continuous physics are added
        //Specially the returned type.

        if (sprite.speed != 0)
        {
            sprite.updatePos(sprite.orientation, (int)sprite.speed);

            if (sprite.gravity > 0 && sprite.mass > 0 && !sprite.on_ground)
            {
                Vector2 gravityAction = new Vector2(0, sprite.gravity * sprite.mass);
                activeMovement(sprite, gravityAction, 0);
            }
            sprite.speed *= (1 - sprite.friction);
            return(VGDLMovementTypes.MOVE);
        }
        return(VGDLMovementTypes.STILL);
    }
コード例 #2
0
    public override VGDLMovementTypes activeMovement(VGDLSprite sprite, Vector2 action, float speed = -1)
    {
        if (!sprite.stationary)
        {
            if (speed == 0)
            {
                if (sprite.speed <= 0)
                {
                    speed = 1;
                }
                else
                {
                    speed = sprite.speed;
                }
            }

            if (speed != 0 && !action.Equals(Vector2.negativeInfinity) && !(action.Equals(Vector2.zero)))
            {
                if (sprite.rotateInPlace)
                {
                    bool change = sprite.updateOrientation(action);
                    if (change)
                    {
                        return(VGDLMovementTypes.ROTATE);
                    }
                }

                if (sprite.updatePos(action, (int)(speed * gridSize.x)))
                {
                    return(VGDLMovementTypes.MOVE);
                }
            }
        }
        return(VGDLMovementTypes.STILL);
    }
コード例 #3
0
    public override VGDLMovementTypes passiveMovement(VGDLSprite sprite)
    {
        if (sprite.isFirstTick)
        {
            sprite.isFirstTick = false;
            return(VGDLMovementTypes.STILL);
        }

        var speed = 1f;

        if (sprite.speed != -1)
        {
            speed = sprite.speed;
        }

        if (speed != 0 && sprite.is_oriented)
        {
            if (sprite.updatePos(sprite.orientation, (int)(speed * gridSize.x)))
            {
                return(VGDLMovementTypes.MOVE);
            }
        }

        return(VGDLMovementTypes.STILL);
    }
コード例 #4
0
ファイル: pullWithIt.cs プロジェクト: sysnet-ai/UnityVGDL
    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 PullWithIt interaction.");
        }

        //Keep in the list, for the current cycle, the sprites that have triggered this event.
        var currentGameTime = game.getGameTick();

        if (currentGameTime > lastGameTime)
        {
            spritesThisCycle.Clear();
            lastGameTime = currentGameTime;
        }

        //the event gets triggered only once per time-step on each sprite.
        if (spritesThisCycle.Contains(sprite1))
        {
            return;
        }

        spritesThisCycle.Add(sprite1);

        //And go on.
        var r = sprite1.lastrect;
        var v = sprite2.lastDirection();

        v.Normalize();

        var gridsize = 1f;

        if (sprite1.physicstype.CompareAndIgnoreCase(VGDLPhysics.GRID))
        {
            GridPhysics gp = (GridPhysics)(sprite1.physics);
            gridsize = gp.gridSize.x;
        }
        else
        {
            ContinuousPhysics gp = (ContinuousPhysics)(sprite1.physics);
            gridsize = gp.gridSize.x;
        }

        sprite1.updatePos(new Vector2(v.x, v.y), (int)(sprite2.speed * gridsize));

        if (sprite1.physicstype.CompareAndIgnoreCase(VGDLPhysics.GRID))
        {
            sprite1.rect.y      = sprite2.rect.y - sprite2.rect.height;
            sprite1.orientation = new Vector2(sprite1.orientation.x, 0.0f);
        }

        sprite1.lastrect = new Rect(r);

        if (pixelPerfect)
        {
            sprite1.rect = new Rect(sprite2.rect);
        }
    }