Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Three useful snippets for beginners I made

Author
Message
Emir Starshyne
9
Years of Service
User Offline
Joined: 4th Oct 2014
Location: Brazil
Posted: 4th May 2016 16:33
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)



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)



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)



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>
seppgirty
FPSC Developer
14
Years of Service
User Offline
Joined: 3rd Jul 2009
Location: pittsburgh, pa.
Posted: 5th May 2016 00:11
Great work. thanks for sharing with all of us.
gamer, lover, filmmaker
Emir Starshyne
9
Years of Service
User Offline
Joined: 4th Oct 2014
Location: Brazil
Posted: 28th May 2016 11:20
Thank you.
My intention was to be helpful to this community, since this community was too helpful to me and I wanted to give a little something in return.

My intention was to provide a plugin, but I don't have patience and knowledge to do so.

Other functions I crafted (I may share them here if you want me to) include:

1) Random name generator
It makes a string that can be used as a name, with vowels and consonants organized in a way you can spell it.
return String = Name(size)

2) 2D coordinates seed extractor:
This is a little something I invented to produce a procedurally generated 2D map with seeds for each position without having to store them in an arraw eating tons of memory. Great for huge game worlds when each tile is a full map and you need to generate a seed for each one without repeating them.
Return double int = Map_Seed(x,y)

Tilemap assembler:
This I produced to make procedural imagery from tiled bitmaps.
I am still working in a generic version to it, but the idea is the following:
You make a bmp image divided into tiles. Each line is a category (for drawing monsters, for example, line 1 could be head, 2 body, 3 arms, 4 legs, tc) and then it get the bitmap, breaks it into tiles and then pick random pieces from each category to produce a smaller image that is an assembled picture formed from them.
The syntax is something like:
Proc_image(bitmap number,tile_width,tile_height,output_image)

Capitalization:
A simple function that gets an string and capitalizes it.
Ex: STRING, String, StRiNg, sTRING, etc

return string = Capitalize(source_string,type_of_capitalization)

Get random entry from file:
It reads a file, gets one entry (a name, a value, etc) and returns it as a variable.
return string = RandomEntry(filename$)

Space Invaders-like spaceships:
Self-explanatory, it draws a space invaders-esque ship into an image
SpaceInvaders(image_number,width,height)

Float trimmer:
Simple like this: it trims a float to be the size you choose. Useful when a division goes wrong.
return float = Trim_float(float,trim_size)

Random Color Generator:
It produces a random color. You specify a step (the number of different values possible to achieve R, G, B and it does the work).
For instance, to simulate 16-bit color, you specify a step of 32.
return dword = RandColor(step)

I'll provide those functions, some of them I already have ready to be posted, others I'll have to modify or re-create.
<b><i>The mind is the compiler of dreams.</i></b>

Login to post a reply

Server time is: 2024-04-26 16:06:58
Your offset time is: 2024-04-26 16:06:58