关闭

QB实现Matrix字幕

标签: matrixintegerfunctiontimerstring
1168人阅读 评论(0) 收藏 举报
分类:

那段时间因为《Matrix》的火热,所以都流行用程序做出那种字幕效果。

我就用QB做了个,02年做的。

Matrix

CONST MatrixTextStreamLength% = 15  'REM 0<It<MaxColor

CONST LowestSpeed! = .3             'REM The lowest speed

CONST TextStreamCount% = 20         'REM Count of text streams



TYPE MatrixTextStreamType

    X AS INTEGER

    Y AS SINGLE

    Speed AS SINGLE

    Text AS STRING * MatrixTextStreamLength

END TYPE



CONST ScreenMode% = 12              'REM G:640*480*16, T:80*30

CONST ScreenTextWidth% = 80

CONST ScreenTextHeight% = 30

CONST FALSE% = 0

CONST TRUE% = NOT FALSE



DECLARE FUNCTION UpdateTextStream% (TextStream AS MatrixTextStreamType)

DECLARE SUB DisplayTextStream (TextStream AS MatrixTextStreamType)

DECLARE SUB GenerateTextStream (TextStream AS MatrixTextStreamType)

DECLARE SUB ChangeText (TextStream AS MatrixTextStreamType)

DECLARE SUB GenerateMatrixPalette ()



DIM MatrixTextStream(TextStreamCount) AS MatrixTextStreamType



SCREEN ScreenMode

CLS



DIM Count AS INTEGER



FOR Count = 1 TO TextStreamCount

    GenerateTextStream MatrixTextStream(Count)

NEXT



GenerateMatrixPalette



WHILE INKEY$ <> CHR$(27)

    FOR Count = 1 TO TextStreamCount

        DisplayTextStream MatrixTextStream(Count)

        IF UpdateTextStream(MatrixTextStream(Count)) THEN

            GenerateTextStream MatrixTextStream(Count)

        END IF

    NEXT

WEND



END



SUB ChangeText (TextStream AS MatrixTextStreamType)



    DIM Count AS INTEGER

    DIM TempText AS STRING



    RANDOMIZE TIMER

    FOR Count = 1 TO MatrixTextStreamLength - 1

        TempText = TempText + CHR$(RND * 222 + 33)

    NEXT



    TextStream.Text = " " + TempText



END SUB



SUB DisplayTextStream (TextStream AS MatrixTextStreamType)



    DIM Count AS INTEGER

    DIM CharX AS INTEGER, CharY AS SINGLE



    FOR Count = 1 TO MatrixTextStreamLength



        CharX = TextStream.X

        CharY = TextStream.Y + Count



        IF CharY < ScreenTextHeight + 1 AND CharY > 1 THEN

            IF CharX <= ScreenTextWidth AND CharX > 0 THEN

                LOCATE INT(CharY), CharX

                COLOR (MatrixTextStreamLength - Count + 1)

                PRINT MID$(TextStream.Text, Count, 1);

            END IF

        END IF



    NEXT



END SUB



SUB GenerateMatrixPalette

    DIM Count AS INTEGER

    DIM Red AS INTEGER, Green AS INTEGER, Blue AS INTEGER



    FOR Count = 1 TO MatrixTextStreamLength

        Red = 0

        Green = 63 - (Count - 1) * (64 / MatrixTextStreamLength)

        Blue = 43 - (Count - 1) * (44 / MatrixTextStreamLength)

        PALETTE Count, Red + Green * 256 + Blue * 65536

    NEXT



END SUB



SUB GenerateTextStream (TextStream AS MatrixTextStreamType)

    

    RANDOMIZE TIMER

    TextStream.X = INT(RND * ScreenTextWidth) + 1

    TextStream.Y = -RND * MatrixTextStreamLength

    TextStream.Speed = RND + LowestSpeed

    ChangeText TextStream



END SUB



FUNCTION UpdateTextStream% (TextStream AS MatrixTextStreamType)



    TextStream.Y = TextStream.Y + TextStream.Speed

    ChangeText TextStream

    IF TextStream.Y > ScreenTextHeight + 1 THEN

        UpdateTextStream = TRUE

        EXIT FUNCTION

    END IF

    UpdateTextStream = FALSE



END FUNCTION
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:46711次
    • 积分:802
    • 等级:
    • 排名:千里之外
    • 原创:31篇
    • 转载:7篇
    • 译文:0篇
    • 评论:18条
    最新评论
    游戏开发
    游戏引擎