TGC Codebase Backup



Dynamic view by Blendman

27th May 2014 10:06
Summary

Move dynamically a screen, like on android



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    
SetVirtualresolution(800,600)
global viewy, newy, map_h, y, y2, move as integer


Screen()



Function SetTheView() '{

    if viewy < 0
        viewy = 0
    endif
    if viewy > map_h
        viewy = map_h
    endif

    SetViewOffset(0, viewy)

EndFunction '}


Function Screen() '{


    Dim Sp[100] as integer
    h = 120
    x1 = 150
    W = 200
    H = 100
    i = 0
    nb = 30
    for i = 0 to nb
        y1 = h+ (H+10)*i/2
        x2 = x1 + mod(i,2)*(W+10)
        Sp[i] = CreateSprite(0)
        SetSpritePosition(Sp[i], x2, y1)
        SetSpriteSize(Sp[i], 200,H)
        SetSpriteColor(Sp[i], 200,200,200,255)
    next i

    // for the view offset (max height)
    map_h= H * nb/2 +100

    SetClearColor(120,120,120)


    repeat

        if GetRawKeyPressed(27) = 1
            quit = 1
        endif

        if GetPointerPressed() = 1

            ResetTimer()

            if move = 0
                move = 1
                // Store the location of input
                y = viewy + GetPointerY()
                y2 = GetPointerY()
            endif

        Endif

        if getpointerState() = 1

            newy = GetPointerY()

            if move = 1
                viewy = (y - newy)
                // scroll the screen
                SetTheView()
            endif

        endif

        if GetPointerReleased() = 1
            move = 0
            Time2# = Timer()
            DynMovH# = newy - y2
            vitesse# = DynMovH#/(Time2#*50)
        endif

        // dynamic move
        if move = 0
            If abs(vitesse#) > 1
                if vitesse# > 0
                    vitesse# = vitesse# - 2
                else
                    vitesse# = vitesse# + 2
                endif
                viewy = viewy - vitesse#
                SetTheView()
            endif
        endif

        sync()

    until quit >= 1

EndFunction
'}