Results 1 to 1 of 1

Thread: TBEM sample - Zones

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    thinBasic MVPs Michael Hartlef's Avatar
    Join Date
    Sep 2006
    Location
    Germany
    Age
    58
    Posts
    3,299
    Rep Power
    348

    TBEM sample - Zones

    Hi folks,

    I just have uploaded the extended TBEM module (Version 1.10). Here is a little sample about using the new zone command set.

    [code=thinbasic]'
    ' TBEM sample script - Zones
    ' Michael Hartlef
    ' October 18th, 2008

    USES "TBGL", "TBEM"

    DIM TBGL_useInfo AS TBGL_tUseInfo
    DIM myEvent, myEvent2 AS LONG
    DIM mx, my AS LONG
    DIM zcount, maincount AS LONG

    'Define all event types we need.

    BEGIN CONST
    %evtZone1 = 100
    %evtZone2
    END CONST

    '**************************************************
    FUNCTION TBMAIN( )
    '**************************************************
    LOCAL hWnd AS DWORD
    LOCAL FrameRate AS DOUBLE

    ' -- Create and show window
    hWnd = TBGL_CREATEWINDOWEX( "TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED OR %TBGL_WS_CLOSEBOX )
    TBGL_SHOWWINDOW

    ' -- Initialize lighting
    TBGL_USELIGHTING %TRUE
    TBGL_USELIGHTSOURCE %GL_LIGHT0, %TRUE
    TBGL_SETLIGHTPARAMETER %GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 10, 15, 1

    'Add two events
    myEvent = TBEM_ADDEVENT( "ZoneHit", %evtZone1 )
    myEvent2 = TBEM_ADDEVENT( "ZoneHit2", %evtZone2 )

    'Add two zones
    TBEM_ADDZONE( 10, 10, 0, 200, 200, 0, %evtZone1 )
    TBEM_ADDZONE( 410, 10, 0, 600, 200, 0, %evtZone2 )

    ' -- Main loop
    WHILE TBGL_ISWINDOW( hWnd )
    'FrameRate = TBGL_GETFRAMERATE
    TBGL_CLEARFRAME
    TBGL_CAMERA 15, 15, 15, 0, 0, 0
    TBGL_COLOR 255, 128, 0
    TBGL_BOX 1, 1, 1

    'Draw the two rectangles that visually represent the zones
    gui_draw( )
    mx = TBGL_MOUSEGETPOSX
    my = TBGL_MOUSEGETPOSY
    zcount = TBEM_GETZONECOUNT
    TBGL_DRAWFRAME

    IF TBGL_GETWINDOWKEYSTATE( hWnd, %VK_ESCAPE ) THEN EXIT WHILE

    'Now check the zones with the mouse coordinates
    TBEM_CHECKZONES( mx, my, 0 )

    'Now check and run any activated events
    TBEM_RUN( )
    TBGL_SETWINDOWTITLE( hWnd, "zcount:" + zcount + " maincount:" + maincount + " fps:" + getfps )
    WEND
    TBGL_DESTROYWINDOW
    END FUNCTION

    '**************************************************
    SUB GUI_Draw( )
    '**************************************************
    LOCAL i, j, k AS LONG
    TBGL_USEQUERY( tbgl_useinfo )
    TBGL_PUSHMATRIX
    IF tbgl_useinfo.RenderMatrixMode = %TBGL_3D THEN TBGL_RENDERMATRIX2D
    TBGL_USELIGHTING %FALSE
    TBGL_USEDEPTH %FALSE
    render_rect( 10, 10, 190, 190 )
    render_rect( 410, 10, 190, 190 )
    IF tbgl_useinfo.RenderMatrixMode = %TBGL_3D THEN TBGL_RENDERMATRIX3D
    TBGL_POPMATRIX
    TBGL_USELIGHTING tbgl_useinfo.lighting
    TBGL_USEDEPTH tbgl_useinfo.depth
    END SUB

    '**************************************************
    SUB render_Rect( x, y, w, h AS LONG )
    '**************************************************
    TBGL_BEGINPOLY %GL_line_loop
    TBGL_VERTEX x, 480 - y - h, 0
    TBGL_VERTEX x + w, 480 - y - h, 0
    TBGL_VERTEX x + w, 480 - y, 0
    TBGL_VERTEX x, 480 - y, 0
    TBGL_ENDPOLY
    END SUB

    '**************************************************
    FUNCTION zonehit( ) AS LONG
    '**************************************************
    IF TBGL_MOUSEGETLBUTTON = 1 THEN maincount += 1
    RETURN %TRUE
    END FUNCTION

    '**************************************************
    FUNCTION zonehit2( ) AS LONG
    '**************************************************
    maincount -= 1
    RETURN %TRUE
    END FUNCTION

    '**************************************************
    FUNCTION getFPS( ) AS LONG
    '**************************************************
    STATIC gfps AS LONG
    STATIC gdtime, gltime, gctime AS LONG
    STATIC gfpsi AS LONG
    gctime = GETTICKCOUNT
    gdtime = gctime - gltime
    IF gdtime >= 1000 THEN
    gltime = gctime
    gfps = gfpsi
    gfpsi = 0
    ENDIF
    gfpsi += 1
    RETURN gfps
    END FUNCTION
    [/code]

    Have fun
    Michael Hartlef
    Attached Files Attached Files

Similar Threads

  1. TBEM sample - Add an event
    By Michael Hartlef in forum TBEM module - thinBasic Event Manager module
    Replies: 0
    Last Post: 18-10-2008, 19:07

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •