Re: Help regarding enemies in BGT.

Hi,
In the future, for managing multiple sounds, your best bet is sound_pool. But I will now give you a simple enemy class(example, not actual class), that should hopefully get you in the direction of creating multiple enemies. I believe from what I read is what you're trying to do is make multiple enemies, but correct me if I'm wrong. If this is the case however, look at this class.
//First what you need to do is create a constructor that holds the array of enemies. To put this simply, we are going to make an array which stores the amount of enemies. Note, since audiogames.net is flagging brackets as BBCode, I've put the arrays as underscores for the brackets instead.
//First what you need to do is create a constructor that holds the array of enemies. To put this simply, we are going to make an array which stores the amount of enemies.
enemy@[]enemies(0);
class enemy {
int health;
int ex,ey;
int speed;
bool marked_for_removal; //I'll explain this later.
int damage;
timer walktimer,firetimer;
//Now we need to give the enemy default values.
enemy(int emx,int emy,int sp,int dam,int hp)
{
//Now assign the values.
ex=emx;
ey=emy;
speed=sp;
damage=dam;
health=hp;
}
}
//Now that we are done with our class we need to create a loop for the enemy.
void enemyloop()
{
//Create an array for the enemies.
for(uint i=0; i<enemies.length(); i++)
{
//Now let's make the enemy move according to where the player is. This class assumes the player int variables are represented as x and y.
if(enemies_i_.walktimer.elapsed>enemies_i_.speed) //Making the timer based on the enemy's speed, we don't want another version of The Flash from DC Comics.
{
enemies_i_.walktimer.restart();
//Step sound goes here. Maybe you want to do something like p.play_2d("step1.ogg",x,y,enemies_i_.ex,enemies_i_.ey,false) or stepsound.play() your choice, not sure what you are trying to do in your game so i'll leave it up to you :).
//Now let's make the enemy move around. NOTE: I will only be using x axis to move the enemy, not y, again not sure what your goal is.
if(enemies_i_.ex>x and enemies_i_.x>0) //The enemies_i_.x>0 prevents the enemy from going into negative numbers.
{
enemies_i_.ex--;
}
if(enemies_i_.ex<x)
{
enemies_i_.ex++;
}
//Now close the moving code with a right brace, because remember we are still in the timer statement, so we have to use an extra brace to terminate that part of the loop.
}
//Now we have to make a thing to check for the enemy's health.
if(enemies_i_.health<=0)
{
//Remove that enemy. What I do is have a bool to mark it for removal, a little trick I learned from Omar Alverado. If the bool is true, then it is removed from the array of enemies. Like so.
enemies_i_.marked_for_removal=true;
//We will later need to create a function to check for that, but for now let's move on.
}
//Now we are to the firing code. I am not going to write this out since there are many different ways of writing firing/weapon systems, but it could be something like this, this is just my way of doing it.
if(enemies_i_.firetimer.elapsed>750 and absolute(enemies_i_.ex-x)<=10)
{
enemies_i_.firetimer.restart();
//Play a sound and Now damage the player.
}
//Now close the loop completely.
}
}
//Now to check for the marked removal.

void check_enemies()
{
//Make another array.
for(uint i=0; i<enemies.length(); i++)
{
if(enemies_i_.marked_for_removal==true)
{
enemies.remove_at(i);
}
}
}
//In cases where its needed, you might want to destroy all enemies. You could do something like this.
void destroy_all_enemies()
{
enemies.resize(0);
}
//And finally, to spawn the enemy.
void spawn_enemy(int x, int y,int speed,int damage,int health)
{
//Insert it into the array of enemies.
enemies.insert_last(enemy(x,y,speed,damage,health));
}
I hope this helps, and sorry for the lengthy post.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : Cocoa via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Meatbag via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ty via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Cocoa via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Cocoa via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ty via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Jaidon Of the Caribbean via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Cocoa via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : kianoosh via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : tunmi13 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Meatbag via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : TheTrueSwampGamer via Audiogames-reflector

Reply via email to