I am trying to make a game with kind of fancy windows style hud. I am using types for the buttons. I need some advise on how to do this the best way. Right now I am makeing nine buttons that will be used to ad energy taken from one of three user selected energy bars to compensate for damage done to the ships nine sections. Does that make sence?
Here is the code so far.
My main question is for buttons, am I better off using a for each next loop to create the nine buttons? Or should I continue the way I have started? Or should I abandon types and use data array?
Here is the code so far.
Graphics 800,600 HidePointer ;make the imiges to be used for the hud mouseimage=CreateImage(20,20) makemouse(mouseimage) mousepoint=CreateImage(1,1) makepoint(mousepoint) ;button=CreateImage(45,15) ;makebutton(button) ;make types to control size, location and function of each button Type buttons Field x Field y Field length Field height Field image Field mesage$ Field if_clicked# Field energy# Field num# End Type Global repair1.buttons = New buttons repair1\x = GraphicsWidth()-150 repair1\y = GraphicsHeight()-300 repair1\length = 30 repair1\height = 15 repair1\image = CreateImage(30,20) repair1\mesage$ = "F1 " SetBuffer ImageBuffer(repair1\image) Color 100,100,255 Rect 0,0,repair1\length,repair1\height,0 Color 140,140,255 Line 0,0,0,repair1\height-3 Line 0,0,repair1\length,0 ;message$ Text 0,0,repair1\mesage$ Global repair2.buttons = New buttons repair2\x = GraphicsWidth()-110 repair2\y = GraphicsHeight()-300 repair2\length = 30 repair2\height = 15 repair2\image = CreateImage(30,20) repair2\mesage$ = "F2 " SetBuffer ImageBuffer(repair2\image) Color 100,100,255 Rect 0,0,repair2\length,repair2\height,0 Color 140,140,255 Line 0,0,0,repair2\height-3 Line 0,0,repair2\length,0 ;message$ Text 0,0,repair2\mesage$ SetBuffer BackBuffer() While Not KeyHit(1) Cls drawimages(mouseimage,mousepoint) DrawImage repair1\image,repair1\x,repair1\y DrawImage repair2\image,repair2\x,repair2\y If ImagesOverlap (mousepoint,MouseX(),MouseY(),repair1\image,repair1\x,repair1\y) Then If MouseDown(1) Then ;subtract points from selected energy bar and aply it to repair damaged ship Print "Its got focus!" End If End If Flip Wend WaitKey() End Function makemouse(mouseimage) SetBuffer ImageBuffer(mouseimage) Color 100,60,250 Line 0,0,20,10 Line 0,0,10,20 Line 20,10,10,20 End Function Function makepoint(mousepoint) SetBuffer ImageBuffer(mousepoint) Plot 0,0 End Function Function drawimages(mouseimage,mousepoint) DrawImage mouseimage,MouseX(),MouseY() DrawImage mousepoint,MouseX(),MouseY() End Function
My main question is for buttons, am I better off using a for each next loop to create the nine buttons? Or should I continue the way I have started? Or should I abandon types and use data array?