Copy to Clipboard Test

Morse Code Player Code

const int SFX_MORSE_DASH = 63;//Sound to play on playong Morse Dash.
const int SFX_MORSE_DOT = 62;//Sound to play on playing Morse Dot
const int SFX_MORSE_START = 47;//Sound to play at the beginning of morse code playback.
const int SFX_MORSE_END = 46;//Sound to play at the end of morse code playback.

const int CF_MORSE_INPUT = 98;//Combo Flag to read characters for morse code

const int MORSE_DELAY_BETWEEN_BITS = 30;//Delay between playing elements of morse code, in frames.
const int MORSE_DELAY_BETWEEN_CHARACTERS = 60;//Delay between playing characters encoded in morse code, in frames.
const int MORSE_DELAY_BETWEEN_WORDS = 180;//Delay caused by hitting spacebar character, in frames.

//Morse code player. Stand in front of it and press Ex1 to play message encoded in binary Morse Code, using two different sounds called Dash and Dot. Decipher message and use it to solve another puzzle.

//1. Set up sounds for constants in script file.
//2. Set up a sequence of 37 combos for defining alphabet and digits to read from. A-Z then 1,2,3,4,5,6,7,8,9,0 and finally spacebar.
//3. Build a message using these combos on another background layer. Make sure it`s hidden
//4. Place invisible FFC with 1st combo from step 2 where you want to place Morse playback trigger.
// D0 - Layer from step 3.
//5. Set up puzzle that uses encoded message.

ffc script MorseCodePlayer{
	void run(int layer){
		int pos = ComboAt(CenterX(this),CenterY(this));
		int cmb = 0;
		int origdata = this->Data;
		int morse[216] = {//Load Morse Code, 2-dash, 1-dot, 0-end character
			1,2,0,0,0,0,//A
			2,1,1,1,0,0,//B
			2,1,2,1,0,0,//C
			2,1,1,0,0,0,//D
			1,0,0,0,0,0,//E
			1,1,2,1,0,0,//F
			2,2,1,0,0,0,//G
			1,1,1,1,0,0,//H
			1,1,0,0,0,0,//I
			1,2,2,2,0,0,//J
			2,1,2,0,0,0,//K
			1,2,1,1,0,0,//L
			2,2,0,0,0,0,//M
			2,1,0,0,0,0,//N
			2,2,2,0,0,0,//O
			1,2,2,1,0,0,//P
			2,2,1,2,0,0,//Q
			1,2,1,0,0,0,//R
			1,1,1,0,0,0,//S
			2,0,0,0,0,0,//T
			1,1,2,0,0,0,//U
			1,1,1,2,0,0,//V
			1,2,2,0,0,0,//W
			2,1,1,2,0,0,//X
			2,1,2,2,0,0,//Y
			2,2,1,1,0,0,//Z
			1,2,2,2,2,0,//1
			1,1,2,2,2,0,//2
			1,1,1,2,2,0,//3
			1,1,1,1,2,0,//4
			1,1,1,1,1,0,//5
			2,1,1,1,1,0,//6
			2,2,1,1,1,0,//7
			2,2,2,1,1,0,//8
			2,2,2,2,1,0,//9
			2,2,2,2,2,0 //0
		};
		while(true){
			cmb = ComboAt (CenterLinkX(), CenterLinkY()-2);
			if (cmb==pos){
				if (Link->PressEx1){
					Game->PlaySound(SFX_MORSE_START);
					for (int i=0;i<176;i++){
						if (!(ComboFI(i, CF_MATRIX_PUZZLE_PIECE) || GetLayerComboF(layer, i)==CF_MATRIX_PUZZLE_PIECE|| GetLayerComboI(layer, i)==CF_MATRIX_PUZZLE_PIECE)) continue;
						if (GetLayerComboD(layer, i)<origdata)continue;
						if ((GetLayerComboD(layer, i)-origdata)==36)Waitframes(MORSE_DELAY_BETWEEN_WORDS);
						else PlayMorseCharacter(morse, GetLayerComboD(layer, i)-origdata);
					}
					Game->PlaySound(SFX_MORSE_END);
				}
			}
			Waitframe();
		}
	}
}

void PlayMorseCharacter(int morse, int character){
	int orig = character*6;
	// Trace(character);
	for (int i=orig; i<(orig+6);i++){
		if (morse[i]==2){
			Game->PlaySound(SFX_MORSE_DASH);
			Waitframes(MORSE_DELAY_BETWEEN_BITS);
		}
		else if (morse[i]==1){
			Game->PlaySound(SFX_MORSE_DOT);
			Waitframes(MORSE_DELAY_BETWEEN_BITS);
		}
		else{
			Waitframes(MORSE_DELAY_BETWEEN_CHARACTERS);
			return;
		}
	}
}