kinderspiele1/www/js/home_controller.js

144 lines
3.4 KiB
JavaScript

appControllers.controller('home', function($scope, $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;
/*
* Hintergrundmusik laden und starten
*/
$ionicPlatform.ready(function() {
//Globale-Sounddatei
var gamesound='';
$scope.baumhaus_action=[];
$scope.mediastartesuchspiel='';
/*
* 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=='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;
playsound($scope.mediastartesuchspiel, suchspiel_intro_finish,'1.0');
}
/*
* Suchspiel Sound ist beendet, Mentor-Animation ausschalten, Suchspiel starten
*/
function suchspiel_intro_finish() {
//Soundfile freigeben
gamesound.release();
$scope.CSSKlickSuchspiel=false;
$scope.showmentor=false;
$state.go('suchspiel');
}
$scope.animate_farmhaus=function(){
$scope.CSSFarmhaus=true;
$timeout(function () {
$scope.CSSFarmhaus=false;
}, 2000);
}
$scope.animate_windrad=function(){
$scope.CSSWindrad=true;
$timeout(function () {
$scope.CSSWindrad=false;
}, 2000);
}
$scope.animate_kornspeicher=function(){
$scope.CSSKornspeicher=true;
$timeout(function () {
$scope.CSSKornspeicher=false;
}, 2000);
}
$scope.baumhaus_actiondo=function(){
$scope.baumhauszufallaction=getRandomInt(1,2);
if ($scope.baumhauszufallaction==2){
$scope.showmentor=true;
playsound($scope.baumhaus_action[getRandomInt(0, $scope.baumhaus_action.length - 1)], baumhaus_mentor,'1.0');
}
}
/*
* Play-Sound
*/
function playsound(soundfile, callbackfunction, volume){
$ionicPlatform.ready(function() {
gamesound = new Media(soundfile, callbackfunction ,null);
gamesound.play();
gamesound.setVolume(volume);
});
}
function baumhaus_mentor(){
//Soundfile freigeben
gamesound.release();
//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;
}
});