2019-08-04 03:03:22

So I'm trying to make a simple enemy, just to see how it works, and for some reason, I can't quite figure out how to make it play a loop over it that moves with it.
The enemy moves completely randomly, full 3d, so it moves forward, backward, left, and right, and 45 degrees maybe for higher level enemies. And I want them to play random loops for each enemy, but I don't know how to have the loops stay on the enemies. Please help?

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-08-04 04:20:26

Update_sound_3d(x,y,z)

2019-08-04 23:25:29

yes but how do I make it just update the p sound_pool position for that specific enemy.

In the enemyloop function I have a for loop that goes through all the enemies and then does all the things, but how would I make it update for

 enemys[i]? 
----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-08-05 00:00:49

for (uint i = 0; i < enemys.length; i++)
{
p.update_sound_3d(enemys[i].sound, enemys[i].x, enemys[i].y, enemys[i].z);
}//cl
That is assuming that you have Sam's modified 3d sound pool, otherwise you will be forced to stick with 2d

2019-08-05 00:23:18

ok, and how do you play a sound using a specific slot, by the name of

 enemys[i].sound?
----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)

2019-08-05 00:42:01 (edited by amerikranian 2019-08-05 00:44:51)

I am not sure what you mean. Consider this code

//I haven't written bgt in a while and thus cannot guarantee error-free code
enemy@ enemies[];
class enemy
{
int x, y, sound;
enemy(x, y)
{
x = x;
y = y;
sound = p.play_3d("enemy.ogg", me.x, me.y, me.z, x, y, z, true);
}//cf
}//cc
//A sample enemy loop.
//Keep in mind that our enemy has a sound slot that they're holding onto for us to use later.
void enemyloop()
{
for (uint i = 0; i < enemies.length; i ++)
{
p.update_sound_3d(enemies[i].sound, enemies[i].x, enemies[i].y, enemies[i].z);
}//cl
}//cf

I should also note that calling update_sound constantly is a bad idea, primarily because your enemy won't move each iteration of the loop. Personally, what I would do is create the enemy class and add a "can_move" method to it that checks if it can move and if so, moves them wherever they need to go. An example using that logic is below

enemy@ enemies[];
class enemy
{
int x, y, sound, movetime;
timer movetimer;
enemy(x, y, mvt)
{
x = x;
y = y;
movetime = mvt;
sound = p.play_3d("enemy.ogg", me.x, me.y, me.z, x, y, z, true);
}//cf
bool can_move()
{
if (movetimer.elapsed >= movetime) return true;
return false;
}//cf
}//cc
void enemyloop()
{
for (uint i = 0; i < enemies.length; i ++)
{
if (enemies[i].can_move() == true)
{
//moving logic goes here
p.update_sound_3d(enemies[i].sound, enemies[i].x, enemies[i].y, enemies[i].z);
}//ci
}//cl
}//cf

This should make your code faster overall when dealing with large groups of enemies on a map.

2019-08-05 00:51:30

The play methods in the sound_pool return an int, for the slot the sound is played in. Have the enemy remember that, as in post 6.

看過來!
"If you want utopia but reality gives you Lovecraft, you don't give up, you carve your utopia out of the corpses of dead gods."
MaxAngor wrote:
    George... Don't do that.

2019-08-05 02:42:18

Yeah. Fox, I also feel like you need to check out game programming in practice part 2 (Virus attack tutorial) because it also does a decent job of showing you how to actually use sound pool.

2019-08-05 03:09:42

Thanks for the help, I will look at that.
The funny thing is, I don't usually have trouble with this, this kind of stuff is kind of below me in ability, but for some reason I just couldn't think of a way to do it.
Also, I couldn't find the function to play a sound with a specific slot, that was my problem.
Thanks for the help...

----------
“Yes, sir. I am attempting to fill a silent moment with non-relevant conversation.”
“You don’t tell me how to behave; you’re not my mother!”
“Could you please continue the petty bickering? I find it most intriguing.” – Data (Star Trek: The Next Generation)