178 lines
4.0 KiB
JavaScript
178 lines
4.0 KiB
JavaScript
appControllers.controller('Minispiel1', function($scope, $ionicPlatform, $cordovaMedia, backgroundsounds_mediahandler, $state, $timeout,$q, $http) {
|
|
|
|
|
|
/*
|
|
* Initialisierung
|
|
*/
|
|
|
|
//Minispiel
|
|
$scope.showteddybear=false;
|
|
$scope.teddyback=false;
|
|
|
|
|
|
$ionicPlatform.ready(function() {
|
|
|
|
/*
|
|
* Sounds definieren
|
|
*/
|
|
//Globale MediaVariable fure Soundeffekte
|
|
var gamesound='';
|
|
var lachensound='';
|
|
|
|
|
|
$scope.lachensounds=[];
|
|
$scope.gamesounds=[];
|
|
/*
|
|
* Spiele IntroSounds laden
|
|
* Typen: successsound -> Bravo, super, tollgemacht Sounds
|
|
* Typen: failuresound -> Leider daneben, versuchs nochmal
|
|
* Typen: cardsound -> Kartenlegegeräusch
|
|
* Typen: solutionsound -> Auflösungsgeräusch, das wäre das Tier gewesen
|
|
* Typen: gameoversound -> Spielzu ende Zeit für minispiel etc.
|
|
* Typen: backgroundmusic -> Hintergrundmusik
|
|
*/
|
|
$http.get('spielsets/minispielset1/systemsounds.json').success(function(data) {
|
|
|
|
for(var i = 0; i < data.length; i++) {
|
|
|
|
if (data[i].type=='lachensound'){
|
|
$scope.lachensounds.push(data[i].sound);
|
|
}
|
|
else if (data[i].type=='gamesound'){
|
|
$scope.gamesounds.push(data[i].sound);
|
|
|
|
$timeout(function () {
|
|
playsound('gamesound', $scope.gamesounds[0], minispielstart,'1.0');
|
|
}, 1000);
|
|
}
|
|
else if (data[i].type=='backgroundmusic'){
|
|
backgroundsounds_mediahandler.setbackgroundsoundfile(data[i].sound);
|
|
backgroundsounds_mediahandler.playbackgroundmusic();
|
|
}
|
|
|
|
}//for-Schleife
|
|
|
|
});//$http
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
/*
|
|
* Play-Sound
|
|
* playtype-> Bravo,Falsch oder Gamesound
|
|
* soundfile-> Pfad zur sounddatei
|
|
* callbackfunction-> Funktion die nach erfolgreichem abspielen gestarte wird
|
|
* volume-> Lautstärke z.B. 1.0
|
|
*/
|
|
function playsound(playtype, soundfile, callbackfunction, volume){
|
|
|
|
$ionicPlatform.ready(function() {
|
|
|
|
if (playtype=='lachensound'){
|
|
|
|
try{
|
|
|
|
//versuchen Soundfile freizugeben
|
|
lachensound.release();
|
|
|
|
}
|
|
catch(e){
|
|
|
|
//Soundfile Objekt gabs nicht oder Freigabefehler
|
|
console.log("Sounddatei nicht da");
|
|
}
|
|
|
|
lachensound = new Media(soundfile, callbackfunction ,null);
|
|
lachensound.play();
|
|
|
|
}
|
|
else if (playtype=='gamesound'){
|
|
|
|
try{
|
|
|
|
//versuchen Soundfile freizugeben
|
|
gamesound.release();
|
|
|
|
}
|
|
catch(e){
|
|
|
|
//Soundfile Objekt gabs nicht oder Freigabefehler
|
|
console.log("Sounddatei nicht da");
|
|
}
|
|
|
|
gamesound = new Media(soundfile, callbackfunction ,null);
|
|
gamesound.play();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function minispielstart(){
|
|
$timeout(function () {
|
|
$scope.showteddybear=true;
|
|
$scope.teddyback=true;
|
|
}, 10);
|
|
$timeout(function () {
|
|
$scope.showteddybear=false;
|
|
$state.go('home');
|
|
}, 30000);
|
|
|
|
}
|
|
|
|
|
|
/*
|
|
* MiniSpiel kitzel den Teddy
|
|
*/
|
|
$scope.teddyaction = function() {
|
|
$scope.teddyanimation=getRandomInt(1,4);
|
|
$scope.teddyback=false;
|
|
$scope.teddyani1=false;
|
|
$scope.teddyani2=false;
|
|
$scope.teddyani3=false;
|
|
$scope.teddyani4=false;
|
|
|
|
if ($scope.teddyanimation==1){
|
|
$scope.teddyani1=true;
|
|
playsound('lachensound', $scope.lachensounds[getRandomInt(0, $scope.lachensounds.length - 1)], null,'1.0');
|
|
}
|
|
if ($scope.teddyanimation==2){
|
|
$scope.teddyani2=true;
|
|
playsound('lachensound', $scope.lachensounds[getRandomInt(0, $scope.lachensounds.length - 1)], null,'1.0');
|
|
}
|
|
if ($scope.teddyanimation==3){
|
|
$scope.teddyani3=true;
|
|
playsound('lachensound', $scope.lachensounds[getRandomInt(0, $scope.lachensounds.length - 1)], null,'1.0');
|
|
}
|
|
if ($scope.teddyanimation==4){
|
|
$scope.teddyani4=true;
|
|
playsound('lachensound', $scope.lachensounds[getRandomInt(0, $scope.lachensounds.length - 1)], null,'1.0');
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/*
|
|
* Zufallsgenerator um per Zufall neue Aufgabe definieren
|
|
*/
|
|
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;
|
|
}
|
|
|
|
}); |