[SOLVED] Boxing Game - The punch/sound logic

G

Gustavo Purificação

Guest
Hi!

I'm from Brazil. I'm not totally fluent in english, but I'll try my best:

I'm working on my very first game (a very simple boxing match). I never coded before but I studied a lot these last couple of weeks and was able to make the basic scope of the game work very well.

I'm happy with it, but since it's my first project I think a lot of what I did was messy and maybe out of place.
I decided to code the player and enemy again from scratch, and keep everything clean.

My first question is:

When a certain button is pressed, player attacks. If I play the sound of the punch at this same event (the movement, not the hit) too, the sound will play even if the player gets punched at the very beggining of the movement (when the punch has actually not been thrown yet).

Is there a way to solve it without giving this task to the step event? I think the first version of the game has too much there.
 
G

Gustavo Purificação

Guest
Hi!

That one would play when the punch actually lands. I'm talking about having a sound for the movement. If the punch lands, then a hit sound plays too. This one I can easily put in the colision event.

What I want to avoid is this: the player can get hit at the exact moment he starts a punch action... so if I put a sound action at the press button event, the sound will play even if the punch movement was not actually performed. I've seen this issue in a lot of games, and I think its awful...

So the question is: would I be able to solve this out of the step event?
 
T

trentallain

Guest
Hi!

That one would play when the punch actually lands. I'm talking about having a sound for the movement. If the punch lands, then a hit sound plays too. This one I can easily put in the colision event.

What I want to avoid is this: the player can get hit at the exact moment he starts a punch action... so if I put a sound action at the press button event, the sound will play even if the punch movement was not actually performed. I've seen this issue in a lot of games, and I think its awful...

So the question is: would I be able to solve this out of the step event?
If punching but then gets hit: https://docs.yoyogames.com/source/dadiospice/002_reference/game assets/sounds/audio_stop_sound.html
 
J

Jmation

Guest
Just like trentallain said. As soon as you switch to a different sprite, like spr_player_hit the sound should stop. Here is a rough code example:

Code:
step event
==========
//if sprite not punching
if sprite_index!=spr_punching
    {
    //stop punching sound   
    audio_stop_sound(snd_punching);
    }
 
G

Gustavo Purificação

Guest
Thank you guys very much.
It works perfectly.
 
Top