A few things that I've added since I posted this:- Added special support
- Added a command and option for toggling sound
Code:
/*
* Class Sounds
*
* Version 1.0
*
* Sunday, November 1, 2009
*
* Created by Aeterna
*/
public class Sounds {
/*
* A reference to the Client class.
*/
public Client c;
/*
* Declares the ID of the sound that will play.
*/
public int weaponSound;
/*
* An array containing the weapon, and it's sound.
* Used as {weapon, normalSound, specialSound}
*/
public final int[][] WEAPON_SOUNDS = {
{4151, 1080, 1081}, {1319, 400, 398}, {1377, 399, 398}, {861, 370, 398},
{4675, 394, 398}, {1333, 396, 398}, {5698, 398, 398}
};
/*
* Class constructor.
*/
public Sounds(Client c) {
this.c = c;
}
/*
* Returns the sound that will play depending on the current weapon, and if they player
* is using a special attack.
*/
public int getSound(int weapon) {
for (int[] WEAPON_SOUNDS : weapons) {
if (weapon == weapons[0]) {
if (c.usingSpecial) {
weaponSound = weapons[1];
} else {
weaponSound = weapons[2];
}
}
}
return weaponSound;
}
}
Code:
/**
* Attempts to play a midi.
* @param sound The sound ID which is going to be played.
* @param distance The distance or 'delay' between the player and the sound.
* @param volume How loud the sound will be played.
*/
public void playSound(int sound, int distance, int volume) {
if (usingSound) {
outStream.createFrame(174);
outStream.writeWord(sound);
outStream.writeByte(distance);
outStream.writeWord(volume);
} else {
sM("You do not have sound enabled. To enable it type ::sound ON");
}
}
Code:
/*
* Attemtps to call the class Sound.
*/
Sound sound = new Sound(this);
Code:
playSound(sound.getSound(playerEquipment[playerWeapon]), 50, 0);
Code:
/*
* A command used for toggling sound on and off.
* Usage: ::sound off, ::sound on
*/
if (command.startsWith("sound")) {
String[] args = command.split(" ");
if (args[1].equalsIgnoreCase("on")) {
usingSound = true;
sendMessag("You have toggled sound on.");
} else if (args[1].equalsIgnoreCase("off")) {
usingSound = false;
sendMessage("You have toggled sound off.");
} else {
sM("Invalid input.");
}
}