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 / Some functions to make your day happier :)

Starshyne Emir
Years of Service
User Offline
Joined: 27th Nov 2016
Location: Porto Alegre, southern Brazil
Posted: 20th Oct 2018 05:52
Here I leave another set of functions that I am using on my current project.
I'll explain them as well as possible. Some of them may require Matrix1 Utils plugin.


1. makeshot(n,w,h,c1,c2)
>> This one makes graphics that you can use as shot graphics for a space shooter or another game with 2d guns.

int n - the number of the image that will be generated (you'll need to keep track of this variable to put the image on a sprite)

int w, int h - the width and height of the image.
It's important to observe that the picture drawn is symmetrical, so, the w variable must be divisible by 2 and greater than 4. Smaller values may produce underisable results. Ah, and both w and h must be smaller than 30, because I imagined everything for a retro game with low resolution (and greater resolutions don't produce the same results).

dword c1, dword c2 - the two color variables that will be used to draw the image. I believe no one needs explanation on that.

2. makeship(n,w,h,c1,c2)
>> It draws a retro styled spaceship like those in games like Space Invaders (but a bit cooler). I've already posted a function with the same purpose, but it was bigger, slower and the results weren't as interesting. Ah, it also cuts off the empty spaces from the image, ensuring that the sprite you'll make from it is the same size of the image produced (to avoid collisions with nothing).

The variables follow the pattern of the previous function. By the way, I always use the same names for the variables to help me on reusing and implementing my projects.

IMPORTANT: for w and h, don't use anything smaller than 5 or bigger than 256. You can try anything outside this range, but it wasn't how the function was thought to work.

3. makeplanet(n,s,c1,c2)
>> It draws a small 2D planet. I had a lot of trouble to make the circular mask to produce the transparent boundaries of the pictures, and achieved it with a sprite with diffuse set to rgb(0,0,0) pasted over the rest of the graphics.

All vars are the same as before, except that instead of w and h, now we use "s" - a size variable that is the same for w and h because, well, we want round planets. Use a value bigger than 50 and smaller than 300 for best results.

4. and 5. (two functions that work together)

You'll need to add this one to use the other:

>> It basically draws 4 dots. Pretty useful to draw things that need both horizontal and vertical symmetry.

int x, int y - the center of where you want to plot the dots to.
int w, int h - the horizontal and vertical distances from the center you want the dots are drawn to.
dword c - the color of the dots.

And this is the other function.

>> Since DBPro doesn't have a 2D particle system and I needed to make explosions, I came up with this function to solve my problem. It just draw a pixelated boom image you can put on a sprite and then zoom in and fade out to produce the illusion of an explosion.
No need to explain the parameters, they are the same as above.

6. txt$(n,t$,f$,size,color)
>> This one draws text with the specified font, size and color to an image. Useful to produce sprites with text on them.

int n - the image number.
string t$ - the text you want to write
string f$ - the font name
int size - the text size (use 100 for the highest possible definition)
dword color - the rgb color of the text.


1. indexfonts()
>> Use this at the beginning of your code to index all your installed fonts and store them into an array for further reference.

IMPORTANT: this functions sets up an array and a global integer, that you will use through your program. The array is font(), that lists all your installed fonts, and the integer fq, which stores the fonts' amount.

2. randomfont()
>> This one is just for fun. It returns a string containing a random font name retrieved from the fonts you have installed.
IMPORTANT: Doesn't work without indexfonts()

3. makesprite(n,x,y,img,w,h,ox,oy)
>> This one is just to speed up things. It combines all the main sprite functions into only one. Useful if you don't want to alter sprite attributes after placing it.

int n - the number of the sprite
int x, int y - the sprite position
int img - the number of the image you'll use on the sprite
int w, int h - the width and height of the sprite
int ox, int oy - the offset x and y of the sprite.

They are small, and even though there are no comments and poor indention, I believe you won't find it difficult to read and understand how they work.

IMPORTANT: No functions in here mess with internal files or whatever on your machine. You can use them safely or I am not Emir Starshyne.

[size=+2]Forever and one[/size]


Login to view attachments
Derek Darkly
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 24th Oct 2018 00:06

Hey not bad! I like the planets. I love anything randomly generated ,really.
I took a stab at my own planet generator not too long ago;

Send your parents to noisy sprite demo hell... enter the D-Zone

Login to post a reply

Server time is: 2024-03-01 00:56:13
Your offset time is: 2024-03-01 00:56:13