Hi all,
Well, I'm trying not to ask as many questions, and instead I'm trying to experiment and fix bugs on my own as much as possible, but this time I'm stuck so I really have to ask.
So, I'm making a game, and I already created a map and all the pits to jump over and so on, and there sound updating relative to player's position works properly. Then I've decided to start creating my first enemy, and it's AI works as I wanted, but it's sound is not updating properly as it's flying forwards and backwards.
In short, I'm creating a type of insect who's gonna fly around player's head, then it'll attack and fly away, and then it'll fly back to the player for another attack and it'll do it like so until it's dead, of course. Similar to bats in Q9, for example. The problem is, the enemie's sound is updating properly when it's flying towards me from my right to my center, but it's not updated when it's moving away from me, which means opposite, from my center back to my right. Here's the code for my enemy class.
class insect
{
int health;
int position;
int speed;
bool dead=false;
timer moving_speed;
insect(int init_health, int init_speed, int init_pos)
{
this.health=init_health;
this.position=init_pos;
this.speed=init_speed;
moving_speed.pause();
moving_speed.force(0);
}
void make_sound()
{
sound_insect=pool.play_1d("sounds/insect.wav", player_position, this.position, true, true);
}
void move()
{
if(moving_speed.elapsed>=this.speed)
{
moving_speed.restart();
this.position--;
}
if(this.position==player_position)
{
this.position+=50;
}
pool.update_sound_1d(sound_insect, this.position);
}
void die()
{
dead=true;
}
}
P.s., my sound handles and player variables are declared in other .bgt files, since I'm using multiple modules for my game to simplify coding for myself.
So, I've called this enemy class with it's parameters on the first line of my enemies.bgt file like this:
insect enemy_insect(100, 50, 200);
Then, I've called enemy_insect.make_sound(); in game.bgt, inside my game_start function, just before entering do-while loop, and I wrote enemy_insect.move(); inside my do-while loop block.
So, it works and enemy is moving properly, just confirmed with my debug code, but it's sound is not updated properly as I described above.