274 lines
6.8 KiB
JavaScript
274 lines
6.8 KiB
JavaScript
appControllers.controller('home', function($scope, $rootScope, $ionicPlatform, $cordovaMedia, $state, backgroundsounds_mediahandler, $timeout, $http ) {
|
|
|
|
/*
|
|
* Mentor-Anitmation ausschalten
|
|
*/
|
|
$scope.showmentor=false;
|
|
$scope.CSSKlickSuchspiel=false;
|
|
$scope.CSSFarmhaus=false;
|
|
$scope.CSSWindrad=false;
|
|
$scope.CSSKornspeicher=false;
|
|
$scope.baumhauszufallaction=99;
|
|
|
|
|
|
//Globale-Sounddatei
|
|
var mentorsound='';
|
|
var farmhaussound='';
|
|
var windradsound='';
|
|
var kornspeichersound='';
|
|
|
|
var mentor_is_speakting=false;
|
|
var farmhaus_is_sounding=false;
|
|
var windrad_is_sounding=false;
|
|
var kornspeicher_is_sounding=false;
|
|
|
|
$scope.$on("$ionicView.beforeEnter", function(event, data){
|
|
/*
|
|
* Hintergrundbild setzen
|
|
*/
|
|
$rootScope.backgroundimage = "img/Background/background.svg";
|
|
});
|
|
|
|
|
|
/*
|
|
* Hintergrundmusik laden und starten
|
|
*/
|
|
$ionicPlatform.ready(function() {
|
|
|
|
$scope.baumhaus_action=[];
|
|
$scope.mediastartesuchspiel='';
|
|
$scope.boingsound_action=[];
|
|
|
|
/*
|
|
* Spiele IntroSounds laden
|
|
*/
|
|
$http.get('spielsets/introsounds.json').success(function(data) {
|
|
|
|
for(var i = 0; i < data.length; i++) {
|
|
|
|
if (data[i].type=='baumhaus'){
|
|
$scope.baumhaus_action.push(data[i].sound);
|
|
}
|
|
else if (data[i].type=='boingsound'){
|
|
$scope.boingsound_action.push(data[i].sound);
|
|
}
|
|
else if (data[i].type=='startgamesuchspiel'){
|
|
$scope.mediastartesuchspiel=data[i].sound;
|
|
}
|
|
else if (data[i].type=='backgroundmusic'){
|
|
backgroundsounds_mediahandler.setbackgroundsoundfile(data[i].sound);
|
|
backgroundsounds_mediahandler.playbackgroundmusic();
|
|
}
|
|
|
|
}//for-Schleife
|
|
|
|
|
|
});//$http
|
|
|
|
});//$ionicPlatform
|
|
|
|
/*
|
|
* Suchspiel wurde angeklickt, Sound abspielen, Mentor-Animation starten
|
|
*/
|
|
$scope.suchspiel_intro = function(){
|
|
$scope.CSSKlickSuchspiel=true;
|
|
$scope.showmentor=true;
|
|
mentor_is_speakting=false;
|
|
playsound('mentorsound', $scope.mediastartesuchspiel, suchspiel_intro_finish,'1.0');
|
|
}
|
|
|
|
/*
|
|
* Suchspiel Sound ist beendet, Mentor-Animation ausschalten, Suchspiel starten
|
|
*/
|
|
function suchspiel_intro_finish() {
|
|
|
|
//Soundfile freigeben
|
|
mentorsound.release();
|
|
mentor_is_speakting=false;
|
|
$scope.CSSKlickSuchspiel=false;
|
|
$scope.showmentor=false;
|
|
$state.go('suchspiel');
|
|
}
|
|
|
|
$scope.animate_farmhaus=function(){
|
|
$scope.CSSFarmhaus=true;
|
|
playsound('farmhaussound', $scope.boingsound_action[getRandomInt(0, $scope.boingsound_action.length - 1)], farmhaussound_stop,'1.0');
|
|
}
|
|
|
|
|
|
$scope.animate_windrad=function(){
|
|
$scope.CSSWindrad=true;
|
|
playsound('windradsound', $scope.boingsound_action[getRandomInt(0, $scope.boingsound_action.length - 1)], windradsound_stop,'1.0');
|
|
}
|
|
|
|
|
|
$scope.animate_kornspeicher=function(){
|
|
$scope.CSSKornspeicher=true;
|
|
playsound('kornspeichersound', $scope.boingsound_action[getRandomInt(0, $scope.boingsound_action.length - 1)], kornspeichersound_stop,'1.0');
|
|
}
|
|
|
|
$scope.baumhaus_actiondo=function(){
|
|
|
|
$scope.baumhauszufallaction=getRandomInt(1,2);
|
|
if ($scope.baumhauszufallaction==2){
|
|
$scope.showmentor=true;
|
|
playsound('mentorsound', $scope.baumhaus_action[getRandomInt(0, $scope.baumhaus_action.length - 1)], baumhaus_mentor,'1.0');
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Play-Sound
|
|
*/
|
|
function playsound(playtype, soundfile, callbackfunction, volume){
|
|
|
|
$ionicPlatform.ready(function() {
|
|
|
|
|
|
if (playtype=='farmhaussound'){
|
|
|
|
|
|
if (farmhaus_is_sounding==false){
|
|
|
|
try{
|
|
|
|
//versuchen Soundfile freizugeben
|
|
farmhaussound.release();
|
|
}
|
|
catch(e){
|
|
|
|
//Soundfile Objekt gabs nicht oder Freigabefehler
|
|
console.log("Sounddatei nicht da");
|
|
}
|
|
|
|
farmhaussound = new Media(soundfile, callbackfunction ,null);
|
|
farmhaussound.play();
|
|
farmhaussound.setVolume(volume);
|
|
farmhaus_is_sounding=true;
|
|
}
|
|
}
|
|
else if (playtype=='windradsound'){
|
|
|
|
|
|
if (windrad_is_sounding==false){
|
|
|
|
try{
|
|
|
|
//versuchen Soundfile freizugeben
|
|
windradsound.release();
|
|
}
|
|
catch(e){
|
|
|
|
//Soundfile Objekt gabs nicht oder Freigabefehler
|
|
console.log("Sounddatei nicht da");
|
|
}
|
|
|
|
windradsound = new Media(soundfile, callbackfunction ,null);
|
|
windradsound.play();
|
|
windradsound.setVolume(volume);
|
|
windrad_is_sounding=true;
|
|
}
|
|
}
|
|
else if (playtype=='kornspeichersound'){
|
|
|
|
|
|
if (kornspeicher_is_sounding==false){
|
|
|
|
try{
|
|
|
|
//versuchen Soundfile freizugeben
|
|
kornspeichersound.release();
|
|
}
|
|
catch(e){
|
|
|
|
//Soundfile Objekt gabs nicht oder Freigabefehler
|
|
console.log("Sounddatei nicht da");
|
|
}
|
|
|
|
kornspeichersound = new Media(soundfile, callbackfunction ,null);
|
|
kornspeichersound.play();
|
|
kornspeichersound.setVolume(volume);
|
|
kornspeicher_is_sounding=true;
|
|
}
|
|
}
|
|
else if (playtype=='mentorsound'){
|
|
|
|
if (mentor_is_speakting==false){
|
|
|
|
try{
|
|
|
|
//versuchen Soundfile freizugeben
|
|
mentorsound.release();
|
|
|
|
}
|
|
catch(e){
|
|
|
|
//Soundfile Objekt gabs nicht oder Freigabefehler
|
|
console.log("Sounddatei nicht da");
|
|
}
|
|
|
|
mentorsound = new Media(soundfile, callbackfunction ,null);
|
|
mentorsound.play();
|
|
mentorsound.setVolume(volume);
|
|
mentor_is_speakting=true;
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function windradsound_stop(){
|
|
|
|
$timeout(function () { $scope.CSSWindrad=false; }, 0);
|
|
windradsound.release();
|
|
windrad_is_sounding=false;
|
|
|
|
}
|
|
|
|
function kornspeichersound_stop(){
|
|
|
|
$timeout(function () { $scope.CSSKornspeicher=false; }, 0);
|
|
kornspeichersound.release();
|
|
kornspeicher_is_sounding=false;
|
|
|
|
}
|
|
|
|
function farmhaussound_stop(){
|
|
|
|
$timeout(function () { $scope.CSSFarmhaus=false; }, 0);
|
|
farmhaussound.release();
|
|
farmhaus_is_sounding=false;
|
|
|
|
}
|
|
|
|
|
|
function baumhaus_mentor(){
|
|
//Soundfile freigeben
|
|
mentorsound.release();
|
|
mentor_is_speakting=false;
|
|
//Baumhausmentor ausblenden
|
|
$timeout(function () {
|
|
$scope.showmentor=false;
|
|
}, 0);
|
|
}
|
|
|
|
/*
|
|
* Zufall für Baumhausaction
|
|
*/
|
|
function getRandomInt(min, max) {
|
|
var tmpInt=0;
|
|
min = Math.ceil(min);
|
|
max = Math.floor(max);
|
|
tmpInt = Math.floor(Math.random() * (max - min + 1)) + min;
|
|
|
|
if (tmpInt > max){
|
|
tmpInt=max;
|
|
}
|
|
|
|
if (tmpInt < min){
|
|
tmpInt=min;
|
|
}
|
|
return tmpInt;
|
|
}
|
|
|
|
}); |