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 / Space Invaders-like creatures - procedural approach

Author
Message
Emir Starshyne
11
Years of Service
User Offline
Joined: 4th Oct 2014
Location: Brazil
Posted: 6th Oct 2014 17:10
Hi! I made a procedural approach to Space Invaders creatures based in what is seen in the game Corruption Invaders, and it is the following:

I'll put it step by step to make things easy:

1) Make an array with three dimensions: one for the amount of creatures you will use at an instance (a level, for example) and two for the "creature" you want to generate.

I'll use "creatures" of 7x7 pixels, but you can do it with as many pixels you wish, just obeying the simmetry rule I'll explain later.

dim enemy(100,7,7) as integer //i am creating 100 enemies to be used, but you can use as many or as fewer you want!

2) After the array is declared, you need to design each creature, and it is done in the following way:

for countenemies = 1 to 100 //we used 100 in the first dimension of the array, so it's 100 here)
for y = 1 to 7
for x = 1 to 4 //just to 4, not to 7, since 4 is the central point
enemy(countenemies,x,y) = RND(2) //you can use RND(1) if you want it monocolor
next x
enemy(countenemy,5,y) = enemy(countenemy,3,y) //here we equals the sides)
enemy(countenemy,6,y) = enemy(countenemy,2,y)
enemy(countenemy,7,y) = enemy(countenemy,1,y)
next y
next countenemy

3) Now we have the enemies generated, we can call them in the way we want. I will show only how to draw them directly onscreen:

I'll show how to draw one of them, not all of them

countenemy = 1 //i'll draw the first generated "sprite"
for x = 1 to 7
for y = 1 to 7
if enemy(countenemy,x,y) > 0 then box x*20,y*20,x*20+20,y*20+20 //it draws every pixels as a 20x20 box (values can be changed at will)
next y
next x

Well, you can use this in any way. You can draw them to bitmaps, turn them into images and turn them into sprites or draw directly the bitmaps on screen (don't forget to use colorkey).

To use colors for each enemy, you can do the following:

TYPE colorset


DIM colors(howmanyenemies)

<b><i>The mind is the compiler of dreams.</i></b>

Login to post a reply

Server time is: 2026-07-18 09:00:53
Your offset time is: 2026-07-18 09:00:53