2015-12-19 00:44:03 (edited by Hrvoje 2015-12-19 00:45:37)

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.

2015-12-19 02:45:19 (edited by Brynify 2015-12-19 02:45:42)

Hi,

Did you make sure to call pool.update_listener_1d?

I've been going by Bryn, which is now reflected in my profile. Please do your best to respect this :) Mess ups are totally OK though, I don't mind and totally understand!
Follow on twitter! @ItsBrynify
Thanks, enjoy, thumbs up, share, like, hate, exist, do what ya do,
my website: brynify.me

2015-12-19 12:16:10

Yes I did, but it doesn't fix the problem. And when I try to run example in BGT manual for update_sound_1d, the thing works properly, but not in my game for unknown reason to me.

2015-12-19 23:14:34

Can you add me to skype or something and so we can discuss it that way?

masonasons

I've been going by Bryn, which is now reflected in my profile. Please do your best to respect this :) Mess ups are totally OK though, I don't mind and totally understand!
Follow on twitter! @ItsBrynify
Thanks, enjoy, thumbs up, share, like, hate, exist, do what ya do,
my website: brynify.me

2015-12-20 00:50:55

I can'find your Skype name in your audiogames profile, but My Skype is hrvojekatic so you can send me request and I'll accept you when I sign online.

2015-12-20 13:45:28

It's hard to debug without the full program. I didn't notice any obvious errors when looking at the code you posted here, but that doesn't mean I didn't miss anything.

I like to use the clipboard for debug messages that might come up too often for alerts, which is probably what I'd try in this case: adding a way to check how the enemy is moving, to make sure that it's moving as expected, and maybe another set in the method that updates the position, to make sure all the ifs are working right. (Notice that this requires that any important single-line ifs get put into braces, unless there's a way to check afterward--checking the change in the enemy's position, for example.).

If you already know that the enemy is moving correctly, and the problem is only with the sound, I'd check the part that updates the sound's position, to make sure it's being called. A lot of times, it'll seem like the problem comes from one part of the code, when it turns out to be something else entirely. (Why yes; this does tend to end in a mess of debug messages that I sometimes forget to clean up and thereby accidentally polute people's clipboards; why do you ask?)

看過來!
"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.

2015-12-20 17:33:13

Hello,
Well, I finally got it. The simple wait(5); fixed my problem. I just had to write this before changing enemies direction from left to right and then magic happened. Thanks anyway.