Hello Midget_BlasterxXx420BLAZEWEED,
I do have to admit, that you have the longest name I saw here for a while. Even the board can't handle it, but maybe we can.
Your problem is the basic structure, it won't work like you did, but here is a good solution:
First, you have to create an array holding all information of the enemies. If you use a type, you can add additional information like amount of armor or life.
type EnemyDef
spr as integer // holds the sprite of the enemy
life as integer // life of the enemy
armor as integer // armor of the enemy
endtype
// create an empty array, so you just have to adjust the length
dim Enemy[] as EnemyDef
Alright! Most of the stuff is already done! Now we want to create a function, that can add an enemy.
function CreateEnemy(posx, posy, image)
Enemy.length = Enemy.length +1 // if a new enemy is created, we need to grow the enemy array
arr = Enemy.length // the current position to write in the array is the last position in the array
spr = CreateSprite(image) // create a sprite with the image given in the function call
setspriteposition(spr,posx,posy) // position sprite at the given position
// Define Array
Enemy[arr].spr = spr // set spr to the created sprite
Enemy[arr].life = 100 // set life to 100
Enemy[arr].armor = 50 // set armor to 50
endfunction
Alright, now we can add simple enemies. If you want to update them properly, you will need an update function inside your main loop:
function update_enemies()
for i=0 to Enemy.length // loop though all Enemies inside the array
// get position of the enemy
ox=GetSpriteX(Enemy[i].spr)
oy=GetSpriteY(Enemy[i].spr)
// update enemy sprite position
setspriteposition(Enemy[i].spr,ox+sin(timer())*10,oy+cos(timer())*10)
next i
endfunction
That's all!
The basic structure in a code should look like this:
type EnemyDef
spr as integer // holds the sprite of the enemy
life as integer // life of the enemy
armor as integer // armor of the enemy
endtype
dim Enemy[] as EnemyDef
enemy1=loadimage("enemy1.png")
for i=0 to 19 // create 20 enemies on random positions
posx=random(0,400)
posy=random(0,200)
CreateEnemy(posx, posy, enemy1)
next i
do
update_enemies()
sync()
loop
// put the functions here!
I have not tested the code, but the concept is correct.