Well, guys, I know my participation in here is near to null, so I made three functions that I use a lot and I believe that they'll be useful to beginners, since they solve three problems people always find:
1) Lines based in angle
2) Health bars
3) Clickable buttons
HERE'S THE THING ITSELF:
Angleline(x,y,angle,lenght,clock)
function angleline(x,y,angle as float,lenght,clock as boolean)
//make lines based in angle given
//clock parameter set to 1 to make angle 0 point up
if clock = 1
angle = wrapvalue(angle-90)
ENDIF
nx = (cos(angle)*lenght)+x
ny = (sin(angle)*lenght)+y
line x,y,nx,ny
ENDFUNCTION
x and y are quite self-explanative, they are the starting position of the line.
angle is the angle you want the line to be (in degrees)
lenghtr is the lenght in pixels of the line
clock is a boolean, it is 0 or 1, leaving it in zero will make the 0 degree angle be drawn pointing to the left of the screen, and if it is 1, it will point the 0 degree upwards, useful to make clocks, since their initial position is pointing upwards.
Bar(x1,y1,x2,y2,color1,color2,actual_value,max_value,mirror)
function bar(x1,y1,x2,y2,color1 as dword,color2 as dword,current_value,max_value,mirror as boolean)
//use it for life bars or progress bars
box x1,y1,x2,y2,color1
scope = abs(x1 - x2)
perc = (current_value*scope)/max_value
if mirror = 0
box x1,y1,x1+perc,y2,color2
else
box x2-perc,y1,x2,y2,color2
endif
ENDFUNCTION
x1 and y1 are the starting x and y values to draw the bar, the top-left corner of it
x2 and y2 are, obviously, the bottom-right position o0f the bar, where it ends
color1 and color2 are dwords, they are rgb values - for instance something like rgb(255,255,255) - the color1 is the color of the background and color2 is the color of the filled bar
current_value and max_value are the current and maximum values that the bar will use, can be floats or ints
mirror is a special parameter that mirrors the bar to make it face the opposite direction - useful for fighting gamees or anything that needs two bars pointing each other
return integer = Button_click(x1,y1,x2,y2)
function button_click(x1,y1,x2,y2)
//look for mouseclick in the delimited area
//useful for buttons
if mousex() >= x1 and mousex() <= x2 and mousey() >= y1 and mousey() <= y2
inside = 1
else
inside = 0
endif
if mouseclick() = 1 and inside
clicked = 1
else
clicked = 0
ENDIF
ENDFUNCTION clicked
x1 and y1 are the top-left corner of the clickable button
x2 and y2 are the bottom-right cornr of the clickable button
This function is quite simple: it will return 0 if you didn't click in the specified area and 1 if you had clicked in it. It doesn't actually draw the button, it must be done separately - i saw functions that draw the button, but most of times we just need to track the mouse clicking over things we already made appear on screen, so i did this function to help in this task.
Hope someone find these functions useful!
<b><i>The mind is the compiler of dreams.</i></b>