stop(); //******SETTINGS****** // Tolerance in pixels in Competition mode DistTolerance = 100; // Map edges in pixels for both yagi and posts map_top = 15; map_bot = 155; map_lef = 15; map_rig = 225; // Get shared object cookie with playerName and language game_so = SharedObject.getLocal("SVMRasor"); // Get language, swe=1, eng=2, fin=3, cze=4, ger=5, fre=6 LanguageSelected = game_so.data.language; if (LanguageSelected>0) { LanguageSettings.LanguageGroup.setValue(LanguageSelected); this["FSetLang_"+LanguageSelected](); } else { // If no Shared Object Available, set language to English, store SO and display LanguageSettings _root.game_so.data.language = 2; FSetLang_2(); mcFirstLanguage._x = 0; mcFirstLanguage._y = 0; LanguageSettings._x = 10; LanguageSettings._y = 30; } //Inital settings varDrawFree = false; setScore = function () { score_txt.text = String(score).addCommas(); }; // Reset some main variables score = 0; gameOver = true; rnd = Math.random; // Adds commas to a string every third character (used on numbers, i.e. "12345" becomes "12,345") String.prototype.addCommas = function() { var len = this.length; var str = ""; for (var i = 0; i<=len; i++) { str = this.charAt(len-i)+str; if (i%3 == 0 && i>0 && imap_bot) { yagi3._y = map_bot; ySpeed = 0; xSpeed = 0; } if (yagi3._xmap_rig) { yagi3._x = map_rig; xSpeed = 0; ySpeed = 0; } } // rotate yagi if (_root.right_dragging) { yagi3._rotation = yagi3._rotation+6; } if (_root.left_dragging) { yagi3._rotation = yagi3._rotation-6; } with (yagi3) { // Calculate distance yagi to post delta_x = initx-_x; delta_y = inity-_y; distance = Math.sqrt((delta_x*delta_x)+(delta_y*delta_y)); // calculate the angle from the yagi to post in radians and convert to degrees radians = Math.atan2(delta_y, delta_x); degrees = radians*180/Math.PI; // calculate volume based on angle diff = Math.abs(yagi3._rotation-degrees); if (diff>=180) { diff = Math.abs(diff-360); } // Set signal strength based on distance distance_variable = 1-Math.pow(distance/150, 2); ljudvolym = Math.abs(Math.round(distance_variable*(Math.pow((100-Math.min(diff, 100)), 2)/100))); foxes_sounding.fox1_sound.setVolume(ljudvolym); foxes_sounding.fox2_sound.setVolume(ljudvolym); foxes_sounding.fox3_sound.setVolume(ljudvolym); foxes_sounding.fox_end.setVolume(ljudvolym); } // TIMER totalTime = getTimer()/1000-pauseLength; goTimeRaw = totalTime-buttonPressTime; // if (timing) { goTime = goTimeRaw; minutes = Math.floor((goTime/3600)*60); seconds = Math.floor(((goTime/3600)*60-minutes)*60); if (seconds<10) { seconds = "0"+seconds; } } //Hide HELP values when no post transmits, or competition mode if ((_root.start_mode == 1) || (_root.ModeCompete == true)) { DispSignal._visible = false; DispPost._visible = false; } }; // // make yagi draggable yagi3.onPress = function() { startDrag(yagi3, true, left, top, right, bottom); }; yagi3.onRelease = function() { stopDrag(); }; // Functions: Show radio flags FShowRadioFlag = function (IntNo) { if (this["post"+IntNo] == false) { this["radio_flag"+IntNo]._x = this["fox"+IntNo+"_x_pos"]; this["radio_flag"+IntNo]._y = this["fox"+IntNo+"_y_pos"]; this["radio_flag"+IntNo].gotoAndPlay(2); } }; // Function Show FShowPosts = function () { goTime = 0; Fpause(); results_plate._visible = true; newtry._visible = true; show._visible = false; DispSignal._visible = false; DispPost._visible = false; foxes_sounding.gotoAndPlay(1); stopAllSounds(); fox1text = String(TxtFoxName+" 1"); fox2text = String(TxtFoxName+" 2"); fox3text = String(TxtFoxName+" 3"); // Hide all drawing buttons for (i=1; i<(4); i++) { this["draw_"+i+"a"]._visible = false; this["draw_"+i+"b"]._visible = false; } FShowRadioFlag(1); FCalcDistance(1); if (value_no_foxes>1) { FShowRadioFlag(2); FCalcDistance(2); } if (value_no_foxes>2) { FShowRadioFlag(3); FCalcDistance(3); } min_fox = Math.min(Math.min(distance1, distance2), distance3); // Determine best fox and show talking fox only if if valid value and not competition mode if ((min_fox != 9999) && (_root.ModeCompete == false)) { for (i=1; i=1000) || (this["distance"+Fox] == NaN)) { this["distance"+Fox] = 9999; this["distance"+Fox+"_disp"] = "---"; this["distance"+Fox+"a"] = 0; } else { this["distance"+Fox+"_disp"] = String(this["distance"+Fox]+" m"); this["distance"+Fox+"a"] = this["distance"+Fox]; FTotalDist(); } }; // Calculate total distance and min fox FTotalDist = function () { distance_total_dis = Number(distance1a+distance2a+distance3a); distance_total_disp = String(distance_total_dis+" m"); }; FInterceptClose = function (PostId) { // If close enough if (this["distance"+PostId]225) { length = length-5; slut_x = length*angle_x; slut_y = length*angle_y; } // Check if line is outside map, over while ((yagi3._y+slut_y)<15) { length = length-5; slut_x = length*angle_x; slut_y = length*angle_y; } // Check if line is outside map, under while ((yagi3._y+slut_y)>165) { length = length-5; slut_x = length*angle_x; slut_y = length*angle_y; } // Fill line with colour with (line) { beginFill(0x0000FF, 50); lineStyle(2, 0xFF00FF, 100); moveTo(yagi3._x+start_x, yagi3._y+start_y); lineTo(yagi3._x+slut_x, yagi3._y+slut_y); endFill(); } // Read start and end of line and locate label this[LineId+"_start_x"] = yagi3._x+start_x; this[LineId+"_start_y"] = yagi3._y+start_y; this[LineId+"_end_x"] = yagi3._x+slut_x; this[LineId+"_end_y"] = yagi3._y+slut_y; this["symbol"+LineId]._x = yagi3._x+((length+8)*angle_x); this["symbol"+LineId]._y = yagi3._y+((length+8)*angle_y); }; // Check if the 3:rd of the found posts, and stop timer FCheckLastPost = function () { if ((post1 == true) && (post2 == true) && (post3 == true)) { CancelButton._visible = false; EnterScore_btn._visible = true; newtry._visible = true; stopAllSounds(); Fpause(); mcTimerStopFlash._visible = true; mcTimerStopFlash.gotoAndPlay(2); } }; // Clear all lines and intersection symbols FClearLines = function () { _root.map_shading.pen.clear(); line.clear(); for (i=1; i1) { draw_2a._visible = true; } else { draw_2a._visible = false; } if (value_no_foxes>2) { draw_3a._visible = true; } else { draw_3a._visible = false; } }; // BUTTON: Show show.onRelease = function() { FShowPosts(); }; // BUTTON: New try newtry.onRelease = function() { FNewTry(); }; // BUTTON: Cancel Competition CancelButton.onRelease = function() { CancelButton._visible = false; EnterScore_btn._visible = false; newtry._visible = true; FShowPosts(); }; // BUTTON: Cancel High Score gameOver_mc.BtnScoreCancel.onRelease = function() { gameOver_mc._y = 600; }; // BUTTON: EnterScore EnterScore_btn.onRelease = function() { FClearLines(); score = 60*_root.minutes+Math.round(_root.seconds); gameOver_mc._x = 20; gameOver_mc._y = 15; EnterScore_btn._visible = false; }; // BUTTON: Quit StartSettings.Quit.onRelease = function() { getURL("javascript:window.close()"); }; // BUTTON: Draw_1a draw_1a.onRelease = function() { draw_1a._visible = false; draw_1b._visible = true; draw_1aX._visible = false; _root.createEmptyMovieClip("line_a1", 1); FCheckDrawline(line_a1, "A1"); }; // BUTTON: Draw_1b draw_1b.onRelease = function() { draw_1b._visible = false; draw_1bX._visible = false; _root.createEmptyMovieClip("line_b1", 2); FCheckDrawline(line_b1, "B1"); //Calculate intersection point and show intersection symbol FIntersect(A1_start_x, A1_start_y, A1_end_x, A1_end_y, B1_start_x, B1_start_y, B1_end_x, B1_end_y); //if ((intersection1_x==yagi3._x) && (intersection1_y==yagi3._y)) { if (intersect_value == false) { intersection1_x = 0; intersection1_y = 0; } else { intersection1_symbol._x = intersection_x; intersection1_symbol._y = intersection_y; // Calculate and show distance delta1_x = intersection_x-fox1_x_pos; delta1_y = intersection_y-fox1_y_pos; distance1 = (4*Math.round(Math.sqrt((delta1_x*delta1_x)+(delta1_y*delta1_y)), 2)); } //If competition mode if (_root.ModeCompete == true) { FInterceptClose(1); } }; // // BUTTON: Draw_2a draw_2a.onRelease = function() { draw_2a._visible = false; draw_2b._visible = true; draw_2aX._visible = false; _root.createEmptyMovieClip("line_a2", 3); FCheckDrawline(line_a2, "A2"); }; // BUTTON: Draw_2b draw_2b.onRelease = function() { draw_2b._visible = false; draw_2bX._visible = false; _root.createEmptyMovieClip("line_b2", 4); FCheckDrawline(line_b2, "B2"); //Calculate intersection point and show intersection symbol FIntersect(A2_start_x, A2_start_y, A2_end_x, A2_end_y, B2_start_x, B2_start_y, B2_end_x, B2_end_y); if (intersect_value == false) { intersection2_x = 0; intersection2_y = 0; } else { intersection2_symbol._x = intersection_x; intersection2_symbol._y = intersection_y; // Calculate and show distance delta2_x = intersection_x-fox2_x_pos; delta2_y = intersection_y-fox2_y_pos; distance2 = (4*Math.round(Math.sqrt((delta2_x*delta2_x)+(delta2_y*delta2_y)), 2)); } //If competition mode if (_root.ModeCompete == true) { FInterceptClose(2); } }; // BUTTON: Draw_3a draw_3a.onRelease = function() { draw_3a._visible = false; draw_3b._visible = true; draw_3aX._visible = false; _root.createEmptyMovieClip("line_a3", 5); FCheckDrawline(line_a3, "A3"); }; // BUTTON: Draw_3b draw_3b.onRelease = function() { draw_3b._visible = false; draw_3bX._visible = false; _root.createEmptyMovieClip("line_b3", 6); FCheckDrawline(line_b3, "B3"); // Calculate intersection point and show intersection symbol FIntersect(A3_start_x, A3_start_y, A3_end_x, A3_end_y, B3_start_x, B3_start_y, B3_end_x, B3_end_y); if (intersect_value == false) { intersection3_x = 0; intersection3_y = 0; } else { intersection3_symbol._x = intersection_x; intersection3_symbol._y = intersection_y; // Calculate and show distance delta3_x = intersection_x-fox3_x_pos; delta3_y = intersection_y-fox3_y_pos; distance3 = (4*Math.round(Math.sqrt((delta3_x*delta3_x)+(delta3_y*delta3_y)), 2)); } //If competition mode if (_root.ModeCompete == true) { FInterceptClose(3); } }; // // HELP MENU, Instructions, Language, High Score, About, StartSettings.HelpSystem.SubHelpSet.HelpSubHelp.onRelease = function() { gotoAndStop("Instructions", "Task"); }; StartSettings.HelpSystem.SubHelpSet.HelpSubScore.onRelease = function() { gotoAndStop("ScoreList", 1); }; StartSettings.HelpSystem.SubHelpSet.HelpSubLanguage.onRelease = function() { LanguageSettings._x = 15; LanguageSettings._y = 70; }; StartSettings.HelpSystem.SubHelpSet.HelpSubAbout.onRelease = function() { mcAbout._x = 0; mcAbout._y = 0; StartSettings.HelpSystem.SubHelpSet._visible = false; _root.mcAbout.gotoAndStop("About"); }; // Function of intersection between 2 lines // (Ay-Cy)(Dx-Cx)-(Ax-Cx)(Dy-Cy) // r = ----------------------------- (eqn 1) // (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx) FIntersect = function (Astart_x, Astart_y, Aend_x, Aend_y, Bstart_x, Bstart_y, Bend_x, Bend_y) { q = (Astart_y-Bstart_y)*(Bend_x-Bstart_x)-(Astart_x-Bstart_x)*(Bend_y-Bstart_y); d = (Aend_x-Astart_x)*(Bend_y-Bstart_y)-(Aend_y-Astart_y)*(Bend_x-Bstart_x); if (d == 0) { intersect_value = false; } else { intersect_value = true; } r = q/d; q = (Astart_y-Bstart_y)*(Aend_x-Astart_x)-(Astart_x-Bstart_x)*(Aend_y-Astart_y); s = q/d; if (r<0 || r>1 || s<0 || s>1) { intersect_value = false; } else { intersect_value = true; } intersection_x = Astart_x+r*(Aend_x-Astart_x); intersection_y = Astart_y+r*(Aend_y-Astart_y); }; //Initial settings FNewTry(); mcDrawFree._visible = false; CancelButton._visible = false; CompetitionButtons._visible = false; _root.ModeCompete = false; DispPost._visible = false; DispSignal._visible = false; randomMap(); yagiStart(); ljudvolym = 0; //Load initial text variabels for language settings FReadInitVar = function () { getinitdata = new XML(); getinitdata.load("rasor_init.xml", ""); getinitdata.ignoreWhite = true; getinitdata.onLoad = FGetInit; }; //Function converting XML file to init variables FGetInit = function (success) { if (success == true) { var i = getinitdata.firstChild; // node_name = i.nodeName; TxtJapanese = i.attributes.TxtJapanese; TxtChinese = i.attributes.TxtChinese; TxtRussian = i.attributes.TxtRussian; // Set labels of buttons after updating variables LanguageSettings.radioJap.setLabel(TxtJapanese); LanguageSettings.radioChi.setLabel(TxtChinese); LanguageSettings.radioRus.setLabel(TxtRussian); } }; //Function converting XML file to variables FReadTextVar = function () { getxmldata = new XML(); getxmldata.load(filetoload, ""); getxmldata.ignoreWhite = true; getxmldata.onLoad = FGetVars; }; //Switch language on button selection LanguageSettings.SweLang = function() { game_so.data.language = 1; FSetLang_1(); }; LanguageSettings.EngLang = function() { game_so.data.language = 2; FSetLang_2(); }; LanguageSettings.FinLang = function() { game_so.data.language = 3; FSetLang_3(); }; LanguageSettings.CzeLang = function() { game_so.data.language = 4; FSetLang_4(); }; GerLang = function () { FSetLang_5(); }; FreLang = function () { FSetLang_6(); }; LanguageSettings.JapLang = function() { game_so.data.language = 7; FSetLang_7(); FUpdateLabels(); }; LanguageSettings.ChiLang = function() { game_so.data.language = 8; FSetLang_8(); FUpdateLabels(); }; LanguageSettings.RusLang = function() { game_so.data.language = 9; FSetLang_9(); FUpdateLabels(); }; //FUNCTION: Set language to Swedish FSetLang_1 = function () { filetoload = "rasor_swe.xml"; FReadTextVar(); Language = 1; }; //FUNCTION: Set language to English FSetLang_2 = function () { filetoload = "rasor_eng.xml"; FReadTextVar(); Language = 2; }; //FUNCTION: Set language to Finnish FSetLang_3 = function () { filetoload = "rasor_fin.xml"; FReadTextVar(); Language = 3; }; //FUNCTION: Set language to Czech FSetLang_4 = function () { filetoload = "rasor_cze.xml"; FReadTextVar(); Language = 4; }; //FUNCTION: Set language to Japanese FSetLang_7 = function () { filetoload = "rasor_jap.xml"; FReadTextVar(); Language = 7; }; //FUNCTION: Set language to Chinese FSetLang_8 = function () { filetoload = "rasor_chi.xml"; FReadTextVar(); Language = 8; }; //FUNCTION: Set language to Russian FSetLang_9 = function () { filetoload = "rasor_rus.xml"; FReadTextVar(); Language = 9; }; FGetVars = function (success) { if (success == true) { var p = getxmldata.firstChild; node_name = p.nodeName; BtnTxtStart = p.attributes.BtnTxtStart; BtnTxtHelp = p.attributes.BtnTxtHelp; BtnTxtShow = p.attributes.BtnTxtShow; BtnTxtNew = p.attributes.BtnTxtNew; BtnTxtCancel = p.attributes.BtnTxtCancel; BtnTxtQuit = p.attributes.BtnTxtQuit; BtnTxtScore = p.attributes.BtnTxtScore; BtnTxtBack = p.attributes.BtnTxtBack; BtnTxtBackRasor = p.attributes.BtnTxtBackRasor; BtnTxtSend = p.attributes.BtnTxtSend; HelpmenuTxt1 = p.attributes.HelpmenuTxt1; HelpmenuTxt2 = p.attributes.HelpmenuTxt2; HelpmenuTxt3 = p.attributes.HelpmenuTxt3; HelpmenuTxt4 = p.attributes.HelpmenuTxt4; HelpmenuTxt5 = p.attributes.HelpmenuTxt5; TxtRasorHeading = p.attributes.TxtRasorHeading; TxtCompetition = p.attributes.TxtCompetition; TxtTraining = p.attributes.TxtTraining; TxtFoxName = p.attributes.TxtFoxName; TxtFoxes = p.attributes.TxtFoxes; TxtDeviation = p.attributes.TxtDeviation; TxtTotal = p.attributes.TxtTotal; TxtStrength = p.attributes.TxtStrength; TxtInterval = p.attributes.TxtInterval; TxtContinue = p.attributes.TxtContinue; TxtNotWithin = p.attributes.TxtNotWithin; TxtFromFox = p.attributes.TxtFromFox; TxtFromFoxB = p.attributes.TxtFromFoxB; TxtGood = p.attributes.TxtGood; TxtScore = p.attributes.TxtScore; TxtHighScore = p.attributes.TxtHighScore; TxtName = p.attributes.TxtName; TxtEnterName = p.attributes.TxtEnterName; TxtSeconds = p.attributes.TxtSeconds; TxtSecondsSmall = p.attributes.TxtSecondsSmall; TxtMap1 = p.attributes.TxtMap1; TxtTerrain1 = p.attributes.TxtTerrain1; TxtMap2 = p.attributes.TxtMap2; TxtTerrain2 = p.attributes.TxtTerrain2; TxtMap3 = p.attributes.TxtMap3; TxtTerrain3 = p.attributes.TxtTerrain3; TxtOne = p.attributes.TxtOne; TxtTwo = p.attributes.TxtTwo; TxtThree = p.attributes.TxtThree; Txt10s = p.attributes.Txt10s; Txt20s = p.attributes.Txt20s; Txt30s = p.attributes.Txt30s; TxtHelpTaskHeading = p.attributes.TxtHelpTaskHeading; TxtHelpTask = p.attributes.TxtHelpTask; TxtHelpSettingsHeading = p.attributes.TxtHelpSettingsHeading; TxtHelpSettings = p.attributes.TxtHelpSettings; TxtHelpPostsHeading = p.attributes.TxtHelpPostsHeading; TxtHelpPosts = p.attributes.TxtHelpPosts; TxtHelpBearingsHeading = p.attributes.TxtHelpBearingsHeading; TxtHelpBearings = p.attributes.TxtHelpBearings; TxtAbout1 = p.attributes.TxtAbout1; TxtAbout2 = p.attributes.TxtAbout2; // Set labels of buttons after updating variables StartSettings.CompetitionButton.setLabel(TxtCompetition); StartSettings.TrainingButton.setLabel(TxtTraining); help_fox.setLabel(TxtFoxName+":"); help_signal.setLabel(TxtStrength+":"); UpdateMapText(); FUpdateInterval(); } }; FReadInitVar();