Re: Enemy update sound question for bgt.

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.



-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : redfox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : redfox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : redfox via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : CAE_Jones via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : redfox via Audiogames-reflector

Reply via email to