[Home]DDD/GoldDigger

ec2-44-220-44-148.compute-1.amazonaws.com | ToothyWiki | DDD | RecentChanges | Login | Webcomic

[Click to play]

ToothyGDL

logic
{
    /* Play area size */
    int boardWidth  {40}
    int boardHeight {40}

    /* Tiles on play area */
    int TILE_EMPTY  {0}
    int TILE_EARTH  {1}
    int TILE_GOLD   {2}
    int TILE_PLAYER {3}
    int TILE_ROCK   {8}
    int TILE_WALL   {9}

    /* bit 3 indicates whether the player can "move into" a tile */ 
    int TILE_SOLID_FLAG {8}

    /* Write your level here */
    array board
    {
        9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 
        9, 3, 9, 1, 1, 9, 1, 1, 1, 8, 1, 1, 8, 1, 8, 1, 8, 1, 1, 1, 1, 1, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
        9, 1, 9, 2, 1, 9, 2, 9, 8, 1, 1, 8, 0, 0, 8, 1, 1, 9, 1, 1, 1, 1, 9, 0, 1, 1, 1, 9, 1, 1, 1, 1, 0, 0, 1, 1, 1, 9, 1, 1, 
        9, 1, 9, 9, 8, 9, 9, 9, 1, 8, 1, 2, 8, 8, 8, 2, 8, 9, 1, 1, 1, 1, 9, 8, 1, 1, 1, 9, 1, 1, 1, 1, 0, 8, 1, 1, 1, 9, 1, 1, 
        9, 1, 1, 1, 1, 1, 1, 9, 8, 2, 1, 8, 1, 2, 8, 8, 8, 9, 9, 1, 1, 1, 9, 1, 1, 1, 1, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 1, 1, 
        9, 9, 9, 9, 9, 1, 9, 9, 9, 2, 8, 1, 1, 8, 2, 8, 1, 8, 9, 1, 1, 1, 9, 8, 1, 8, 1, 1, 9, 1, 1, 1, 1, 8, 1, 8, 1, 1, 9, 1,
        9, 8, 2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, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 
    }

    /* Player's start position */
    int playerX {1}
    int playerY {1}




    /* Gold remaining */
    int goldRemaining {58}

    /*
     * Enumerate possible moves a player can make
     *    (none - left - right - up - down )
     */
    array xMoves { 0, -1, 1, 0,  0 }
    array yMoves { 0,  0, 0, -1, 1 }

    /**
     * Display viewport is 10x10 of 40x40
     */
    int displayX {0}
    int displayY {0}
    int displayWidth {10}
    int displayHeight {10}

    /* Is the player still alive? */
    int dead    {0}

    /* Internal variable */
    int y2  {0}

    /* Decide which of the five possible player moves are legal */
    for p (0..4)
    {
        /* Trivial player move - allow any move into a non-solid tile */
        when 
        {
                ((playerX + xMoves[p]) >= 0)
            and ((playerX + xMoves[p]) < boardWidth)
            and ((playerY + yMoves[p]) >= 0)
            and ((playerY + yMoves[p]) < boardHeight)
            and ((board[ (playerX + xMoves[p]) + ((playerY + yMoves[p]) * boardWidth ) ] & TILE_SOLID_FLAG) == 0)
            and ( dead == 0 )
        }
        allow
        {
            board[ playerX + (playerY * boardWidth ) ] = TILE_EMPTY;
            playerX = (playerX + xMoves[p]);
            playerY = (playerY + yMoves[p]);
            board[ playerX + (playerY * boardWidth ) ] = TILE_PLAYER;
        }
        label 
        {
            "Player dx=" xMoves[p] " dy=" yMoves[p] "."
        }

        /* Handle player pushing rocks left and right (into empty space only!) */
        when 
        {
                ((playerX + (xMoves[p]*2)) >= 0)
            and ((playerX + (xMoves[p]*2)) < boardWidth )
            and ( yMoves[p] == 0 )
            and ( board[ (playerX +  xMoves[p]     ) + (playerY * boardWidth ) ] == TILE_ROCK )
            and ( board[ (playerX + (xMoves[p] * 2)) + (playerY * boardWidth ) ] == TILE_EMPTY )
            and ( dead == 0 )
        }
        allow
        {

            board[ playerX + (playerY * boardWidth ) ] = TILE_EMPTY;
            board[ (playerX + (xMoves[p] * 2)) + (playerY * boardWidth ) ] = TILE_ROCK;
            playerX = (playerX + xMoves[p]);
            board[ playerX + (playerY * boardWidth ) ] = TILE_PLAYER;
        }
        label 
        {
            "Player dx=" xMoves[p] " dy=" yMoves[p] "."
        }

        /* Count the remaining Gold */
        when 
        {
                ((playerX + xMoves[p]) >= 0)
            and ((playerX + xMoves[p]) < boardWidth)
            and ((playerY + yMoves[p]) >= 0)
            and ((playerY + yMoves[p]) < boardHeight)
            and (board[ (playerX + xMoves[p]) + ((playerY + yMoves[p]) * boardWidth ) ] == TILE_GOLD)
            and ( dead == 0 )
            and ( goldRemaining > 0 )
        }
        allow
        {
            goldRemaining = goldRemaining - 1;
        }
        label
        {
            "Player dx=" xMoves[p] " dy=" yMoves[p] "."
        }


        /* Handle horizontal view port scrolling.  This is fiddly as it playerX is going to be
         * different when the allow block is calculated!
         */
        when
        {
                ( ( playerX + xMoves[p] - (displayWidth/2) ) >= 0 )
            and ( ( playerX + xMoves[p] - (displayWidth/2) ) <= (boardWidth - displayWidth ) )
        }
        allow
        {
            displayX = ( playerX - (displayWidth/2) );
        }
        label
        {
            "Player dx=" xMoves[p] " dy=" yMoves[p] "."
        }

        /* Handle vertical view port scrolling.  As horizontal case... */
        when
        {
                ( ( playerY + yMoves[p] - (displayHeight/2) ) >= 0 )
            and ( ( playerY + yMoves[p] - (displayHeight/2) ) <= (boardHeight - displayHeight ) )
        }
        allow
        {
            displayY = ( playerY - (displayHeight/2) );
        }
        label
        {
            "Player dx=" xMoves[p] " dy=" yMoves[p] "."
        }

        when
        {
            goldRemaining > 0
        }
        allow
        {
            /* Handle falling rocks!  We need to find them first hence the for/for nest...
             * This is technically O(n^2) with the size of the board.  I have cheated and
             * only move rocks the player can actually see on screen :).  Ideally, I would
             * track the individual rocks O(n) with number of rocks
             */
            for y ( 0 .. (boardHeight - 1 )  )
            {
                y2 = (boardHeight - 1 ) - y;
                for x ( displayX .. (displayX + displayWidth - 1) )
                {
                    /** Is this a rock? */
                    if ( board[ x + ( y2 * boardWidth ) ] == TILE_ROCK )
                    {
                        /* Is the player about to get splatted? */
                        if
                        (
                                ( y2 < (boardHeight - 2) )
                            and ( board[ x + ( ( y2 + 1 ) * boardWidth ) ] == TILE_EMPTY )
                            and ( board[ x + ( ( y2 + 2 ) * boardWidth ) ] == TILE_PLAYER )
                        )
                        {
                            dead = 1;
                        }


                        /* This is the simple rock falling down case... */
                        if
                        (
                            ( board[ x + ( ( y2 + 1 ) * boardWidth ) ] == TILE_EMPTY )
                        )
                        {
                            board[ x + ( ( y2     ) * boardWidth ) ] = TILE_EMPTY;
                            board[ x + ( ( y2 + 1 ) * boardWidth ) ] = TILE_ROCK;
                        }

                        /* Handle rocks that are going to fall left to a space to the bottom-left */
                        if
                        (
                                ( x != 0 )
                            and ( board[ x + ( y2 * boardWidth ) ] == TILE_ROCK )
                            and ( board[ x     + ( ( y2 + 1 ) * boardWidth ) ] != TILE_EMPTY )
                            and ( board[ x - 1 + ( ( y2     ) * boardWidth ) ] == TILE_EMPTY )
                            and ( board[ x - 1 + ( ( y2 + 1 ) * boardWidth ) ] == TILE_EMPTY )
                        )
                        {
                            board[ x     + ( ( y2     ) * boardWidth ) ] = TILE_EMPTY;
                            board[ x - 1 + ( ( y2 + 1 ) * boardWidth ) ] = TILE_ROCK;
                        }

                        /* Handle rocks that are going to fall right to a space to the bottom-right */
                        if
                        (
                                ( x != (boardWidth - 1) )
                            and ( board[ x + ( y2 * boardWidth ) ] == TILE_ROCK )
                            and ( board[ x     + ( ( y2 + 1 ) * boardWidth ) ] != TILE_EMPTY )
                            and ( board[ x + 1 + ( ( y2     ) * boardWidth ) ] == TILE_EMPTY )
                            and ( board[ x + 1 + ( ( y2 + 1 ) * boardWidth ) ] == TILE_EMPTY )
                        )
                        {
                            board[ x     + ( y2 * boardWidth ) ] = TILE_EMPTY;
                            board[ x + 1 + ( (y2 + 1) * boardWidth ) ] = TILE_ROCK;
                        }
                    }
                }




            }
        }
        label
        {
            "Player dx=" xMoves[p] " dy=" yMoves[p] "."
        }
    }

}

display
{
    /* Icons to display */
    stringtable items
    {
        " ",
        "~",
        "$",
        "&",
        "", "", "", ""
        "*",

        "#"
    }


    /* Display the game state */
    stringtable gameState
    {
        "Rock on...",
        "Game Over"
    }

    /* Title */
    box
    {
        content { "Gold Digger!" }
    }
    newline
    /* Play area */
    for y ( 0 .. ( displayWidth - 1 ) )
    {
        for x ( 0 .. ( displayHeight - 1 ) )
        {
            box
            {
                width { 2em }

                height { 2em }
                border { 1px solid black }

                /* Choose colour.  TODO - figure out how to get an array to work! */
                if ( board[ ( x + displayX ) + ( ( y + displayY ) * boardWidth )] == TILE_EARTH ) 
                {
                    background { #999 }
                }
                if ( board[ ( x + displayX ) + ( ( y + displayY ) * boardWidth )] == TILE_GOLD ) 
                {
                    background { #F0F }
                }
                if ( board[ ( x + displayX ) + ( ( y + displayY ) * boardWidth )] == TILE_ROCK ) 
                {
                    background { #777 }
                }
                if ( board[ ( x + displayX ) + ( ( y + displayY ) * boardWidth )] == TILE_WALL ) 
                {
                    background { #555 }
                }
                /* Display icon */
                content { items[ board[ ( x + displayX ) + ( ( y + displayY ) * boardWidth )] ] }
            }
        }
        newline
    }
    newline
    newline
    /* Display direction options */
    box
    {
        width { 2em }
        height { 2em }
        border { 1px solid black }
        content { " " }
        bind_action { "Player dx=0 dy=0." }
    }
    box
    {

        width { 2em }



        height { 2em }
        border { 1px solid black }
        content { "Up" }
        bind_action { "Player dx=0 dy=-1." }
    }
    box
    {
        width { 2em }
        height { 2em }
        border { 1px solid black }
        content { "Wait" }
        bind_action { "Player dx=0 dy=0." }
    }
    newline
    box
    {
        width { 2em }
        height { 2em }
        border { 1px solid black }
        content { "Left" }
        bind_action { "Player dx=-1 dy=0." }
    }
    box
    {
        width { 2em }
        height { 2em }
        border { 1px solid black }
        content { "Down" }
        bind_action { "Player dx=0 dy=1." }
    }
    box
    {
        width { 2em }
        height { 2em }
        border { 1px solid black }
        content { "Right" }
        bind_action { "Player dx=1 dy=0." }
    }
    newline
    /* Show the player state */
    box
    {
        content { gameState[ dead ] }
    }
    box
    {
      content { goldRemaining }
    }
}



[Recompile this page]
[Compiler error log]






The first rock did not fall, my avatar seemed to consume it when I moved back to the left.  --Vitenka
Should now be fixed -- there were some language features I "misunderstood" --DDD

ec2-44-220-44-148.compute-1.amazonaws.com | ToothyWiki | DDD | RecentChanges | Login | Webcomic
Edit this page | View other revisions | Recently used referrers
Last edited September 1, 2006 9:46 am (viewing revision 5, which is the newest) (diff)
Search: