Everything is functioning, though a bit boring, due to the lack of sound. The Debris being destroyed so quickly is also not very satisfying. Let's fix both of these issues.
snd_Shatter_Glass
, and load Chapter 6/Sounds/Shatter_Glass.wav
. The default values will work, just make sure that Kind is set to Normal Sound. This effect will be for when the Glass breaks apart.snd_Impact_Glass
and load Chapter 6/Sounds/Impact_Glass.wav
.scr_Pillar_Glass_Create
and add the following at the end of the script:impact = snd_Impact_Glass; shatter = snd_Shatter_Glass; isTapped = false; isActive = false; alarm[0] = room_speed;
We start by assigning variables to the Impact
and Shatter
sounds. We will only want to allow the impact sound to play a single time, so we have created the isTapped
variable. The isActive
variable and the alarm are going to be used, so that no sound is made when the game starts. When the physics system begins, all active instances in the world will have gravity applied, which will cause collisions. This in turn means that the impact sound will occur when nothing appears to be moving.
scr_Pillar_Wood_Create
and scr_Pillar_Steel_Create
, and add the same code with the appropriate sounds.scr_Pillar_BreakApart
and insert the following line of code before the instance is destroyed:sound_play(shatter);
When the Debris spawns, we will play the Shatter sound a single time. Notice that we have given this sound a priority of 10, which means that if too many sounds need to be played, this sound will be chosen over lower priority sounds.
else
statement immediately after the instance is destroyed.} else { if (!isTapped) { sound_play(impact); isTapped = true; } }
If only a minor collision has occurred, we check to see if we have run the sound before. If we haven't, then we play the impact sound, with a low priority, and stop this code from executing again.
if (isActive) { if (abs(other.phy_linear_velocity_x) > myDamage || abs(other.phy_linear_velocity_y) > myDamage) { if (phy_mass < other.phy_mass) { p1 =instance_create(x, y, debris01); p1.phy_speed_x = phy_speed_x; p1.phy_speed_y = phy_speed_y; p1.phy_rotation = phy_rotation; p2 =instance_create(x, y, debris02); p2.phy_speed_x = phy_speed_x; p2.phy_speed_y = phy_speed_y; p2.phy_rotation = phy_rotation; p3 =instance_create(x, y, debris03); p3.phy_speed_x = phy_speed_x; p3.phy_speed_y = phy_speed_y; p3.phy_rotation = phy_rotation; sound_play(shatter); instance_destroy(); } else { if (!isTapped) { sound_play(impact); isTapped = true; } } } }
scr_Pillar_Destroy
, so that the shatter sound is played on destruction, the impact sound on a light collision, and all of this when the instance is active. Here is the code in its entirety:if (isActive) { if (abs(other.phy_linear_velocity_x) > myDamage || abs(other.phy_linear_velocity_y) > myDamage) { if (phy_mass < other.phy_mass) { sound_play(shatter); instance_destroy(); } else { if (!isTapped) { sound_play(impact); isTapped = true; } } } }
scr_Pillar_Alarm0
and set isActive
to true
.obj_Pillar_Parent
. This will not cause any conflicts because the alarm will only be run once per instance and only changes a variable.18.119.136.84