HGE Wrapper tip #1,#1A (update 12 JUN 2008)
Posted: Wed Jun 11, 2008 8:54 pm
I have just now started poking into the HGE wrapper located (for DL purposes) on thread:
http://www.purebasic.fr/english/viewtop ... ge+wrapper
And I have chopped together a PLINKO style starter to display how to set up objects and utilize them...
This example meerly shows how to create a series of sprites that you can bounce boxes off of...
I had to redo the includes because they kept giving me LINK errors as someone seems to think we are all going to dump every library in a folder called /include/Libraries/PBLIBS/... etc!!!
If you need help on that, post I will attempt to remember what I did and if I can't I will post the includes I modified.
I didn't do anything amazing... I was just playing with it to see how it was constructed. 
http://www.purebasic.fr/english/viewtop ... ge+wrapper
And I have chopped together a PLINKO style starter to display how to set up objects and utilize them...
This example meerly shows how to create a series of sprites that you can bounce boxes off of...
I had to redo the includes because they kept giving me LINK errors as someone seems to think we are all going to dump every library in a folder called /include/Libraries/PBLIBS/... etc!!!
If you need help on that, post I will attempt to remember what I did and if I can't I will post the includes I modified.
Code: Select all
; adapted from Tutorial 9 with the boxes and chain bridge
; just wanted to see how it works - Rook Zimbabwe (Ralph Dunn)
; cannot seem to set up walls!
XIncludeFile "HGEWrapper_include.pbi"
Structure sPh
*spr
*body
EndStructure
Global *fnt
Global Dim phObj.sPh(1)
Global NumPhObj=0,Car,Wheel1,Wheel2,Axel1,Axel2,*spr1,*spr2
Global tex1,tex2,tex3,tex4,tex5
Global *sprCur, *gui
Global mx.f,my.f
Global *phWorld
Macro RandomArea(StartValue, EndValue, StepValue=0.1)
( Random(Int(((EndValue)-(StartValue))/(StepValue)))*(StepValue)+(StartValue) )
EndMacro
Procedure.d rnd_range(first.d, last.d)
ProcedureReturn RandomArea(first,last)
EndProcedure
Procedure CreatePhObjBox(tex.l, ScaleX.f, ScaleY.f, PosX.f, PosY.f, Angle.f, Density.f=0, Restitution.f=0, Friction.f=0)
ReDim phObj.sPh(NumPhObj)
phObj(NumPhObj)\spr = hge_Sprite(tex,0,0,ScaleX,ScaleY)
hge_Sprite_SetHotSpot(phObj(NumPhObj)\spr,ScaleX*0.5,ScaleY*0.5)
phObj(NumPhObj)\body = Ph_CreateBoxBody(*phWorld,ScaleX,ScaleY,Density,Restitution,Friction)
Ph_SetPosBody(phObj(NumPhObj)\body,PosX,PosY)
Ph_SetAngleBody(phObj(NumPhObj)\body,Angle)
NumPhObj = NumPhObj + 1
ProcedureReturn phObj(NumPhObj-1)\body
EndProcedure
Procedure CreatePhObjCircle(tex.l, Radius.f, PosX.f,PosY.f,Angle.f, Density.f=0, Restitution.f=0, Friction.f=0)
ReDim phObj.sPh(NumPhObj)
phObj(NumPhObj)\spr = hge_Sprite(tex,96,64,Radius,Radius)
; phObj(NumPhObj)\spr = hge_Sprite(tex1,0,0,Radius,Radius)
hge_Sprite_SetColor(phObj(NumPhObj)\spr,$FF000000| RGB(rnd_range(1,255),rnd_range(1,255),rnd_range(1,255)))
hge_Sprite_SetHotSpot(phObj(NumPhObj)\spr,Radius*0.5,Radius*0.5)
phObj(NumPhObj)\body = Ph_CreateCircleBody(*phWorld,Radius,Density,Restitution,Friction)
Ph_SetPosBody(phObj(NumPhObj)\body,PosX,PosY)
Ph_SetAngleBody(phObj(NumPhObj)\body,Angle)
;CallDebugger
NumPhObj = NumPhObj + 1
ProcedureReturn phObj(NumPhObj-1)\body
EndProcedure
Procedure UpdatePhObj()
For i = 0 To NumPhObj-1
hge_Sprite_RenderEx(phObj(i)\spr,Ph_GetBodyX(phObj(i)\body),Ph_GetBodyY(phObj(i)\body),Ph_GetBodyAngle(phObj(i)\body))
Next
EndProcedure
ProcedureCDLL frameFunc()
dt.f = hge_Timer_GetDelta()
Ph_WorldStep(*phWorld,dt)
hge_Input_GetMousePos(@mx,@my)
If (hge_Input_GetKeyState(#HGEK_ESCAPE)) : ProcedureReturn #True : EndIf
If (hge_Input_KeyDown(#HGEK_LBUTTON)) ; mouse LFT button is pressed
CreatePhObjCircle(tex4,32,mx,my,0,1,0.5,2) ; make a circle
EndIf
If (hge_Input_KeyDown(#HGEK_RBUTTON))
CreatePhObjBox(tex2,32,32,mx,my,0,1,0.5,2) ; make a square
EndIf
id=hge_GUI_Update(*gui,dt)
ProcedureReturn #False
EndProcedure
ProcedureCDLL RenderFunc()
; // Render graphics
hge_Gfx_BeginScene(#Null)
hge_Gfx_Clear(0)
UpdatePhObj()
hge_GUI_Render(*gui)
fps.l = hge_Timer_GetFPS()
hge_Font_SetColor(*fnt, ARGB(255,255,0,0)); RGB(255,255,255))
hge_Font_Render(*fnt,10,10, #HGETEXT_LEFT, "FPS: "+Str(fps)+"(const)")
hge_Gfx_EndScene()
ProcedureReturn #False
EndProcedure
Procedure Main()
hge_Create(#HGE_VERSION)
; // maybe a bug - somtime hge could Not load from current dir
Path.s = GetCurrentDirectory()+"\Res\";
Debug "path opened..."
; // Set up log file, frame function, render function And window title
hge_System_SetStateString(#hge_LOGFILE, Path+"pbhge_plonk.log");
hge_System_SetStateFunc(#HGE_FRAMEFUNC, @frameFunc())
hge_System_SetStateFunc(#hge_RENDERFUNC, @RenderFunc())
hge_System_SetStateString(#HGE_TITLE, "PloNK 0.0a LOG")
; // Set up video mode
hge_System_SetStateBool(#HGE_WINDOWED,#True)
hge_System_SetStateInt(#hge_SCREENWIDTH,1024)
hge_System_SetStateInt(#hge_SCREENHEIGHT,768)
hge_System_SetStateInt(#hge_SCREENBPP,32)
hge_System_SetStateInt(#hge_FPS, 100)
Debug "System set..."
hge_System_SetStateBool(#HGE_USESOUND , #False)
If hge_System_Initiate()
; // Load sound And texture
tex1=hge_Texture_Load(Path+"bg2.png",0,#False);
tex2=hge_Texture_Load(Path+"bg.png",0,#False);
tex3=hge_Texture_Load(Path+"cursor.png",0,#False);
tex4=hge_Texture_Load(Path+"particles.png",0,#False);
tex5=hge_Texture_Load(Path+"zazaka.png",0,#False); buggy.png
Debug "Textures loaded..."
*fnt = hge_Font(Path+"font2.fnt",0)
*phWorld=Ph_CreateWorld(0,0,1024,768,0,100,1)
Debug "Font loaded..."
; *** CreatePhObjBox(tex.l = texture name
;ScaleX.f = how wide object is
; ScaleY.f = how thick object is (theese two I am going to play with
; PosX.f = X start position
; PosY.f = Y start position
; Angle.f = angle of object (especially if rectangle!) for some reason 45 does not = up down nor does 90
; **** angle appears to work from CENTER of object
; Density.f= how heavy the object is (0 = no move or 0 gravity effect!)
; Restitution.f= I HAVE NO IDEA YET
; Friction.f= how well objects collide with it... I think it is amount of rebound!
CreatePhObjBox(tex1,1024,32,512,752,0,0,0.25,6) ; bottom was 0.3
CreatePhObjBox(tex1,15,720,10,375,0,0,0.25,1) ; my really cruddy attempt at a wall 66 is closest to vertical
CreatePhObjBox(tex1,15,720,1015,375,0,0,0.25,1)
y = 130
For times = 0 To 5
For x = 35 To 960 Step 100
CreatePhObjBox(tex2,6,6,x,y,40, 0, 0.2, 1)
CreatePhObjBox(tex2,6,6,x+50,y+50,40, 0, 0.2, 1)
Next
y = y + 100
Next
*sprCur=hge_Sprite(tex3, 0, 0, 32, 32)
*gui=hge_GUI()
hge_GUI_SetCursor(*gui,*sprCur)
Debug "cursor init..."
hge_System_Start()
hge_Font_Delete(*fnt)
For i = 0 To NumPhObj-1
hge_Sprite_Delete(phObj(i)\spr)
Next
hge_Sprite_Delete(*sprCur)
hge_GUI_Delete(*gui)
hge_Texture_Free(tex1)
hge_Texture_Free(tex2)
hge_Texture_Free(tex3)
hge_Texture_Free(tex4)
EndIf
Ph_DeleteWorld(*phWorld)
hge_System_Shutdown()
hge_Release()
EndProcedure
Main()
; next we feature a complete rewrite to see if we can get this into a REAL framework like PB uses
; in stead of this bastard C style version!!! (WHICH I HATE!!!)
End
