=BGMC17= Wiggly Fish

Hi nines, will you submit the game for the contest? there’s still a day or two until I put together an all games pack. If the game is mostly done I think it would be worth putting it in. It doesn’t have to be polished…

I will submit what I have. It is nowhere near done, but it’s better than nothing.

The music is not really procedural. I recorded each track (drums, brass, strings, etc) as their own mp3 file, and they’re all playing simultaniously through Sound Actuators. All the code is doing is mixing the volumes based on your distance to a list of music-affecting objects (the different colored cubes in my game there). Those objects have properties for the track they affect, and the value of that property is the ‘weight’ of their influence.

In my game, there are three musical affectors: DANGER, EPIC, and BEAT (drums). The main arpeggio playing (i dubbed the PEACE track) is mixed as an inverse of the average weights of DANGER and EPIC. That is, as DANGER/EPIC go down, PEACE goes up, and vice versa.


from bge import logic


AMP = 0.05	#music level constant


cont = logic.getCurrentController()
own = cont.owner


if 'cubes' not in own:
	ob = logic.getCurrentScene().objects   
	own['cubes'] = [ob['DANGER CUBE'], ob['EPIC CUBE'], ob['EPIC CUBE.001'], ob['BEAT CUBE']]
	own['critter'] = ob['Critter']
	for a in cont.actuators:
		cont.activate(a)
else:
	DANGER = 0
	EPIC = 0
	BEAT = 0


 	for o in own['cubes']:
		DANGER += o.get('DANGER', 0) / (o.getDistanceTo(own['critter']) **2)
		EPIC += o.get('EPIC', 0) / (o.getDistanceTo(own['critter']) **2)
		BEAT += o.get('BEAT', 0) / (o.getDistanceTo(own['critter']) **2)
	
	total = sum([DANGER,EPIC,BEAT])
	
	cont.actuators['Music DANGER'].volume = max(0, DANGER/total) * AMP
	cont.actuators['Music EPIC'].volume = max(0,EPIC/total) * AMP
	cont.actuators['Music BEAT'].volume = max(0,BEAT/total) * AMP
	cont.actuators['Music PEACE'].volume = max(0, 1.0 - ((cont.actuators['Music DANGER'].volume+cont.actuators['Music EPIC'].volume)/2)) * AMP
	cont.actuators['Music MAIN'].volume = 1.0 * AMP
	
	own['danger'] = cont.actuators['Music DANGER'].volume 
	own['epic'] = cont.actuators['Music EPIC'].volume 
	own['beat'] = cont.actuators['Music BEAT'].volume 
	own['peace'] = cont.actuators['Music PEACE'].volume 

So the weights/distances are tallied up for each Mood. A grand total is summed, and each Mood is divided by the total to get a ratio. These are then multiplied by a global Amplitude for across-the-board volume control (my music ended up being really loud in BGE!). The last lines of code are just for displaying the volumes in debug info.
It is dirty and hackish, but that’s how she works :slight_smile: