You have declared two different types for similar objects:
Type DOOR
Field x,y
End Type
Type DOOR2
Field x,y
End Type
Why not declare a single, generic 'door' type and create two instances of it? you don't need to know which door collided if you keep a handle to the loaded music in the types themselves:
Global MusicChannel%
Type TDoor
Field x%, y%
Field song
End Type
Door1.TDoor = New TDoor
Door1\x = [...] : Door1\y = [...]
Door1\song = LoadSound( ... )
Door2.TDoor = New TDoor
Door2\x = [...] : Door2\y = [...]
Door2\song = LoadSound( ... )
;Two instances of the same type, but the variable holding the objects is named differently.
This way, your main loop door collision code can be:
For d.TDoor = Each TDoor
;If the player collides with any door, doesn't matter which.
If ImagesCollide( playerImage, pX, pY, frame, doorImage, d\x, d\y, 0) Then
StopChannel MusicChannel ;Stop whatever might be previously playing (even if 'nothing at all').
MusicChannel = PlaySound d\song ;Play the door's music\sound.
EndIf
Next
Much simpler, isn't it? If you want a real challenge, try doing a fade-out and a fade-in in the volumes for the song already playing and the song to be played, respectively. This will require you storing their state (that is, 'playing' or 'not playing') so that you can make the appropriate changes. Doing a fade-out\fade-in is much more natural than that 'snap' changing of song - which might even lead to cracks due to suddenly stopping a playing sound.
Last edited 2011
|