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.
FUNCTIONS THAT DRAW STUFF:
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:
d4(x,y,w,h,c)
>> 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.
boom(n,w,h,c)
>> 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.
FUNCTIONS THAT MAKE USEFUL THINGS:
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.
AND HERE'S THE FUNCTIONS.
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.
function makeshot(n,w,h,c1,c2)
w2= ceil((w-1)/2)
create bitmap n,w,h
lock pixels
for x = 0 to w2 step rnd(2)+1
for y = 0 to h-1 step rnd(2)+1
if rnd(1) = 0 then c = c1 else c = c2
dot w2+x,y,c
dot w2-x,y,c
next
NEXT
unlock pixels
if image exist(n) = 1 then delete image n
get image n,0,0,w,h,1
delete bitmap n
endfunction
function makeship(n,w,h,c1,c2)
w2= ceil((w-1)/2)
create bitmap n,w,h
lock pixels
sz = RND((W2*H)-(w2+h))+(w2+h)
x = 0
y = rnd(h-1)
up = y : dn = y
d = rnd(1)
cv = rnd(4)+1
repeat
if rnd(cv) = 0 then d = wrap(d + 1,0,1)
if d = 0 then c = c1 else c = c2
dot w2+x,y,c
dot w2-x,y,c
x = clamp(x + rnd(1) - rnd(1),0,w2)
y = clamp(y + rnd(1) - rnd(1),0,h-1)
if x > side then side = x
if y < up then up = y
if y > dn then dn = y
dec sz,1
until sz = 0
unlock pixels
if image exist(n) = 1 then delete image n
get image n,w2-side,up,w2+side+1,dn+1,1
delete bitmap n
ENDFUNCTION
function makeplanet(n,s,c1,c2)
create bitmap n,s,s
cls rgb(255,255,255)
fill circle int(s/2),int(s/2),int(s/2),rgb(0,0,0)
if image exist(n) = 1 then delete image n
get image n,0,0,s,s,1
if sprite exist(n) = 1 then delete sprite n
sprite n,0,0,n
set sprite n,1,1
set sprite diffuse n,0,0,0
sz = s^2
is = rnd(15)+5
cls c1
lock pixels
for i = 1 to is
x = rnd(s) : y = rnd(s)
isz = INT((sz/is)/(RND(4)+1))
repeat
dot x,y,c2
x = wrap(x + rnd(1) - rnd(1),0,s)
y = wrap(y + rnd(1) - rnd(1),0,s)
dec isz,1
UNTIL isz = 0
next
unlock pixels
BLUR BITMAP N,RND(6)
paste sprite n,0,0
delete sprite n
delete image n
get image n,0,0,s,s,1
delete bitmap n
ENDFUNCTION
function d4(x,y,w,h,c)
dot x-w,y-h,c
dot x+w,y-h,c
dot x-w,y+h,c
dot x+w,y+h,c
ENDFUNCTION
function boom(n,w,h,c)
create bitmap n,w,h
lock pixels
sz = (w*h)/2
x = ceil((w-1)/2)
y = ceil((h-1)/2)
dw = rnd(x-1)
dh = rnd(y-1)
repeat
d4(x,y,dw,dh,c)
dw = wrap(dw + rnd(1) - rnd(1),0,x-1)
dh = wrap(dh + rnd(1) - rnd(1),0,y-1)
dec sz,1
until sz = 0
unlock pixels
if image exist(n) = 1 then delete image n
get image n,0,0,w,h,1
delete bitmap n
ENDFUNCTION
function txt$(n,t$,f$,size,color)
set text size size
set text font f$
ink color
w = text width(t$)
h = text height(t$)
create bitmap n,w,h
text 0,0,t$
if image exist(n) = 1 then delete image n
get image n,0,0,w,h,1
delete bitmap n
ENDFUNCTION
function indexfonts()
global fq as integer
perform checklist for fonts
fq = checklist quantity()
dim font(fq) as string
for f = 1 to fq
font(f) = checklist string$(f)
NEXT
ENDFUNCTION
function randomfont()
f = rnd(fq-1)+1
f$ = font(f)
ENDFUNCTION f$
function makesprite(n,x,y,img,w,h,ox,oy)
if sprite exist(n) = 1 then delete sprite n
sprite n,x,y,img
set sprite n,1,1
size sprite n,w,h
offset sprite n,ox,oy
ENDFUNCTION
[size=+2]Forever and one[/size]