PDA

View Full Version : four. sides. scrolling. test



peter
13-03-2009, 01:02
Hi Petr,

if you want and if you have time, may you this translate to TBGL ?
use arrow keys to move the circles.

******* Code ******
Uses "UI","FBGFX"
FBGFX_ScreenRes 640,480,32

Global x,y,ax,bx,cx,dx,yPos,xPos,xScr,yScr as long
Dim Map(1200) as Byte

For y = 0 To 29
For x = 0 To 39
bx = y*40 + x +1
Map(bx) =1
Next
Next
yPos = 480/32:xPos = 640/32
While %True
FbgFx_Cls
dx = Int(xScr /32)
cx = Int(yScr /32)
For y = cx To cx + yPos
For x = dx To dx + xPos
bx = y*20 + x +1
iF Map(bx) =1 Then
FbgFx_Circle x*32 -xScr,y*32 -yScr,10,Rgb(80,170,255)
End iF
Next
Next
iF GetAsyncKeyState(%vk_Left) Then xScr = xScr -4
iF GetAsyncKeyState(%vk_Up) Then yScr = yScr -4
iF GetAsyncKeyState(%vk_Right) Then xScr = xScr +4
iF GetAsyncKeyState(%vk_Down) Then yScr = yScr +4
iF xScr < 0 Then xScr = 0
iF yScr < 0 Then yScr = 0
iF xScr > 640 Then xScr = 640
iF yScr > 480 Then yScr = 480
IF GetAsyncKeyState(%vk_escape) Then Exit While
Sleep 10
Wend
********** End of Code ***********

Hi Eros,
i want to find out more about "FBGFX". where can i find
more about this theme?

Thank you.

ErosOlmi
13-03-2009, 01:12
Hi Eros,
i want to find out more about "FBGFX". where can i find
more about this theme?

Thank you.


Peter,

FBGFX was an old project I started to show how to develop thinBasic modules using FreeBasic.
You can find full info here in forum at http://community.thinbasic.com/index.php?topic=1215.0
Attached to that post you will find full FBGFX FreeBasic sources.

Developing thinBasic module you will have complete access to thinBasic Core engine.

Let me know if you need more info.

Ciao
Eros

peter
13-03-2009, 01:40
thank you Eros.

but a question, why is the command "GetAsyncKeyState" not in the Core ?
and in the core i will find no primitives [ cirlce, line, dot or box]. this all would be good.
and always i would ask you how do we to create a window ?

Peter

ErosOlmi
13-03-2009, 07:52
thinBasic is a modular language. It means every module has its duty and specific purposes.

In particular Core engine (thinCore.dll) is the central part of the language and gives support to all other modules. This also means that Core engine MUST not be specialized on a specific aspect (window, user interface, graphics).
Core engine IS thinBasic. It is in change of tokenizing, parsing, memory and data handling, script flow, library interfaces.
The rest is demanded to modules, each for its duty and specification.

GetAsyncKeyState (http://msdn.microsoft.com/en-us/library/ms646293(VS.85).aspx) is a WIN32 API function interfacing with the keyboard at a general level. At the time of its development it seemed right to have it inside the User Interface module. But is is very easy to have it also in any script not using UI module, just declare it as external function with another name and us it. Example:




DECLARE FUNCTION my_GetAsyncKeyState LIB "USER32.DLL" ALIAS "GetAsyncKeyState" (BYVAL vKey AS LONG) AS INTEGER

'...Virtual keys are defined into UI module so to use them into a script not using UI module
'...we have o redefine in script
%my_VK_LEFT = &H25
%my_VK_UP = &H26
%my_VK_RIGHT = &H27
%my_VK_DOWN = &H28

IF my_GetAsyncKeyState(%my_VK_LEFT) THEN
'...
END IF



Anyhow, moving it into Core engine can be an idea not to bin immediately. There are situations where knowing the keyboard keys state even if not using UI module can help. I will think about it.

Graphic primitives (circle, line, box) is something very specific to graphics and for this reason they are not present in Core engine. Latest thinBasic 1.7.7.0 has started to develop the CANVAS control that let you work with some basic graphic primitive but its purpose is not for gaming but for drawing simple graphics in UI scripts. I know for sure that new coming TBGL will have a lot of new features for 2D and sprites but I cannot say more ;)

Regarding creating Windows it depends by what you want to do. in thinBasic the creation of a Window is demanded again to UI module suing DIALOG NEW ... statement. But you can create your own windows and controls using API functions like CreateWindow (http://msdn.microsoft.com/en-us/library/ms632679(VS.85).aspx) or CreateWindowEX (http://msdn.microsoft.com/en-us/library/ms632680.aspx). In this case you would go into a "strange" direction very close to what compiled languages use.

If you want instead develop your own compiled module you will all the power of the compiled language you will use to compile your module. So if you go with FreeBasic you will have all the functionalities of FreeBasic available in your module and link them with thinBasic Core engine using thinBasic SDK. For all our modules we have used PowerBasic.

Ciao
Eros

Petr Schreiber
13-03-2009, 09:35
Hi Peter,

here is TBGL code equivalent:



Uses "TBGL" , "Math"

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

Local x,y,ax,bx,cx,dx,yPos,xPos,xScr,yScr as long
Local Map(1200) as Byte

For y = 0 To 29
For x = 0 To 39
bx = y*40 + x +1
Map(bx) =1
Next
Next
yPos = 480/32
xPos = 640/32

' -- Create and show window
hWnd = TBGL_CreateWindowEx("Code for Peter - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow

' -- Resets status of all keys
TBGL_ResetKeyState()

' -- Main loop
While TBGL_IsWindow(hWnd)
FrameRate = TBGL_GetFrameRate

' -- Begin 2D frame, keeping 640x480 even when resized
TBGL_RenderMatrix2D(0, 479, 639, 0)
TBGL_ClearFrame

dx = Int(xScr / 32)
cx = Int(yScr / 32)

For y = cx To cx + yPos
For x = dx To dx + xPos

bx = y*20 + x +1
iF Map(bx) =1 Then
tbgl_PushMatrix
tbgl_color 80, 170, 255
tbgl_translate x*32, y*32
myCircle(10)
tbgl_PopMatrix
End iF

Next
Next

TBGL_DrawFrame

' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While

iF TBGL_GetWindowKeyState(hWnd, %vk_Left) Then xScr = xScr -4
iF TBGL_GetWindowKeyState(hWnd, %vk_Up) Then yScr = yScr -4
iF TBGL_GetWindowKeyState(hWnd, %vk_Right) Then xScr = xScr +4
iF TBGL_GetWindowKeyState(hWnd, %vk_Down) Then yScr = yScr +4
iF xScr < 0 Then xScr = 0
iF yScr < 0 Then yScr = 0
iF xScr > 640 Then xScr = 640
iF yScr > 480 Then yScr = 480
Wend

TBGL_DestroyWindow
END FUNCTION

SUB MyCircle(radius as long)
LOCAL i as double
TBGL_BeginPoly %GL_LINE_LOOP
For i = 0 to 359 step 5
tbgl_vertex cos(DegToRad(i))*radius, sin(DegToRad(i))*radius
next
TBGL_EndPoly
END SUB


I think FBGFX uses BGR instead of RGB, that is why colors are different.

For such a tasks CANVAS from UI is more than enough of course, as Eros prophecy says ;), you can await "something on 2D" in next TBGL release.


Petr

peter
13-03-2009, 12:14
Thank you Petr, well done.

this will show some good things to me.
I will try to write a little demo with TBGL.
Wether it is operates, we let us surprise.
If i have some questions, i will cry to you to help me.

Hi Eros,
your description will give me a deeper understanding to the thinBasic Modules. Very interesting stuff.
Thank you.

ErosOlmi
13-03-2009, 13:45
your description will give me a deeper understanding to the thinBasic Modules. Very interesting stuff.


If you will ever want to start developing a thinBasic module, check TBJ issue 2: http://community.thinbasic.com/index.php?topic=2310.0
There is an articole describing the inside of what is happening under the curtains of thinBasic Core engine when you load a module.

Ciao
Eros