diff options
author | Roshan Karki <roshan@olenepal.org> | 2009-09-11 07:39:29 (GMT) |
---|---|---|
committer | Roshan Karki <roshan@olenepal.org> | 2009-09-11 07:39:29 (GMT) |
commit | 114b1d183d3e5e7fdccd1805ec4431996e41993b (patch) | |
tree | a97db3b779707be10e7d9c9cc445d1a282cae895 | |
parent | a1f485461b3f95308061c3c8c327d8a7b91a7356 (diff) | |
parent | 4dd9173b0c9cd14f01bbb8582aaa96930180ddb9 (diff) |
Merge branch 'master' of gitorious@git.sugarlabs.org:karma/mainline
-rw-r--r--[-rwxr-xr-x] | examples/adding_up_to_10/assets/es-MX/sounds/es-MX_correct.ogg (renamed from examples/adding_up_to_10/assets/es-MX/sounds/es_correct.ogg) | bin | 14432 -> 14432 bytes | |||
-rw-r--r--[-rwxr-xr-x] | examples/adding_up_to_10/assets/es-MX/sounds/es-MX_incorrect.ogg (renamed from examples/adding_up_to_10/assets/es-MX/sounds/es_incorrect.ogg) | bin | 13705 -> 13705 bytes | |||
-rwxr-xr-x | examples/adding_up_to_10/js/lesson.js | 57 | ||||
-rwxr-xr-x | examples/adding_up_to_10/js/lesson_multiple.js | 11 | ||||
-rwxr-xr-x | js/jquery.karma.js | 34 |
5 files changed, 52 insertions, 50 deletions
diff --git a/examples/adding_up_to_10/assets/es-MX/sounds/es_correct.ogg b/examples/adding_up_to_10/assets/es-MX/sounds/es-MX_correct.ogg Binary files differindex a54f738..a54f738 100755..100644 --- a/examples/adding_up_to_10/assets/es-MX/sounds/es_correct.ogg +++ b/examples/adding_up_to_10/assets/es-MX/sounds/es-MX_correct.ogg diff --git a/examples/adding_up_to_10/assets/es-MX/sounds/es_incorrect.ogg b/examples/adding_up_to_10/assets/es-MX/sounds/es-MX_incorrect.ogg Binary files differindex 0474b93..0474b93 100755..100644 --- a/examples/adding_up_to_10/assets/es-MX/sounds/es_incorrect.ogg +++ b/examples/adding_up_to_10/assets/es-MX/sounds/es-MX_incorrect.ogg diff --git a/examples/adding_up_to_10/js/lesson.js b/examples/adding_up_to_10/js/lesson.js index 15ed461..c67dbb1 100755 --- a/examples/adding_up_to_10/js/lesson.js +++ b/examples/adding_up_to_10/js/lesson.js @@ -108,13 +108,13 @@ k.main(function() { var imgId = imgNames[ level ] ; - var card = function (ctx, n, minx, miny, d ) { - ctx.save(); + var card = function (surface, n, minx, miny, d ) { + surface.save(); var r = k.rectangle({x:minx, y:miny, width:maskd, height:maskd, - stroke:false,fill:false}).draw(ctx); + stroke:false,fill:false}).draw(surface); //do the clip - ctx.clip(); + //surface.clip(); var pos = []; var x, y, flag; @@ -126,7 +126,7 @@ k.main(function() { y = k.math.rand( 0, d ); for ( var j=0; j<pos.length; j++) { if ( k.geometry.distance2( pos[j], - {"x": x, "y": y} ) < 80 ) { + {"x": x, "y": y} ) < 120 ) { flag = true; break; } @@ -134,32 +134,32 @@ k.main(function() { }while ( flag === true ); pos.push( { "x":x, "y": y } ); - k.library.images[ imgId ].draw(ctx, x, y ) + k.library.images[ imgId ].draw(surface, x, y ) } - ctx.restore(); + surface.restore(); } //put the cards - card(k.surfaces["topLt"].ctx, n0 , 0, 0, d); - card(k.surfaces["topRt"].ctx, n1 , 0, 0, d); - card(k.surfaces["bottomLt"].ctx, choices[ 0 ] , 0, 0, d); - card(k.surfaces["bottomMd"].ctx, choices[ 1 ] , 0, 0, d); - card(k.surfaces["bottomRt"].ctx, choices[ 2 ] , 0, 0, d); + card(k.surfaces["topLt"], n0 , 0, 0, d); + card(k.surfaces["topRt"], n1 , 0, 0, d); + card(k.surfaces["bottomLt"], choices[ 0 ] , 0, 0, d); + card(k.surfaces["bottomMd"], choices[ 1 ] , 0, 0, d); + card(k.surfaces["bottomRt"], choices[ 2 ] , 0, 0, d); } var writeScore = function (){ - k.surfaces["scorebox"].ctx.save(); - k.surfaces["scorebox"].clear(); - k.surfaces["scorebox"].ctx.font = "bold 50px sans-serif white"; - k.surfaces["scorebox"].ctx.fillStyle = "#fff"; - k.surfaces["scorebox"].ctx.textBaseline = "middle"; - k.surfaces["scorebox"].ctx.fillText("" + score, 30, 100); - k.surfaces["scorebox"].ctx.restore(); + k.surfaces["scorebox"].save(). + clear(). + font("bold 50px sans-serif white"). + fillStyle("#fff"). + textBaseline("middle"). + fillText("" + score, 30, 100). + restore(); }; var answer = function (correct, tooSlow) { @@ -191,17 +191,14 @@ k.main(function() { var animateChimp = function (answer) { k.surfaces["chimp"].clear(); if( answer === true){ - k.library.images["happyChimp"].draw(k.surfaces["chimp"]. - ctx, 0, 0); + k.library.images["happyChimp"].draw(k.surfaces["chimp"], 0, 0); } else { - k.library.images["sadChimp"].draw(k.surfaces["chimp"]. - ctx, 0, 0); + k.library.images["sadChimp"].draw(k.surfaces["chimp"], 0, 0); } var restoreChimp = function () { k.surfaces["chimp"].clear(); - k.library.images["normalChimp"].draw(k.surfaces["chimp"]. - ctx, 0, 0); + k.library.images["normalChimp"].draw(k.surfaces["chimp"], 0, 0); }; timerId = setTimeout(restoreChimp, 800); @@ -228,12 +225,12 @@ k.main(function() { //put the buttons var buttons=[]; - buttons[ 0 ] = { "canvas": k.surfaces["bottomLt"].canvas, "id": 0}; - buttons[ 1 ] = { "canvas": k.surfaces["bottomMd"].canvas, "id": 1}; - buttons[ 2 ] = { "canvas": k.surfaces["bottomRt"].canvas, "id": 2}; + buttons[ 0 ] = { "surface": k.surfaces["bottomLt"], "id": 0}; + buttons[ 1 ] = { "surface": k.surfaces["bottomMd"], "id": 1}; + buttons[ 2 ] = { "surface": k.surfaces["bottomRt"], "id": 2}; $.each(buttons, function( key, item ) { - item.canvas.addEventListener('click', function( ev ) { + item.surface.canvas.addEventListener('click', function( ev ) { if ( choices[ item.id ] === total){ answer(true); }else { answer(false); } @@ -241,7 +238,7 @@ k.main(function() { }, true); }); timerId = setInterval (timerFn, 2000); - k.library.images["normalChimp"].draw(k.surfaces["chimp"].ctx, 0, 0); + k.library.images["normalChimp"].draw(k.surfaces["chimp"], 0, 0); game(); //end of Karma.main }); diff --git a/examples/adding_up_to_10/js/lesson_multiple.js b/examples/adding_up_to_10/js/lesson_multiple.js index 318649f..b3aa652 100755 --- a/examples/adding_up_to_10/js/lesson_multiple.js +++ b/examples/adding_up_to_10/js/lesson_multiple.js @@ -1,5 +1,5 @@ $(document).ready(function(){ -var k = $.karma ({container: "#karma-main"}); +var k = $.karma ({container: "#karma-main", lang:"es-MX"}); k.init({ images: [ {id: "ball", file: "ball37px.png", localized : false }, @@ -12,6 +12,12 @@ k.init({ {id: "happyMonkey", file: "happyMonkey.jpg", localized : false }, {id: "scorebox", file: "scorebox.png", localized : false } ], + sounds: [ + {id: "correct", file: "correct.ogg", localized:false}, + {id: "incorrect", file: "incorrect.ogg"}, + {id: "trigger", file: "trigger1.ogg", localized:false} + + ], surfaces: [ {id: "card1", width:250, height:250}, {id: "card2", width:250, height:250}, @@ -26,8 +32,9 @@ k.main(function() { var library = k.library; var surfaces = k.surfaces; + var sounds = library.sounds; - + sounds["trigger"].play(); library.images["ball"].draw( surfaces["card1"].ctx ); library.images["balloon"].draw( surfaces["card2"].ctx ); library.images["banana"].draw( surfaces["card3"].ctx ); diff --git a/js/jquery.karma.js b/js/jquery.karma.js index 98571c4..261e9f8 100755 --- a/js/jquery.karma.js +++ b/js/jquery.karma.js @@ -31,7 +31,7 @@ /** * @fileOverview Contains karma library -* @version 0.5 +* @version 0.08 * @author Felipe Lopez Toledo <zer.subzero@gmail.com> */ @@ -90,16 +90,17 @@ var clone = function( obj ){ } /** - * Karma - * @name Karma - * @class Represents a Karma (master) object. - * @param {String | Object } options Constructor arguments - * @param {String | Object } [options.container] Target DIV-class that will contain any canvas element created using Karma functions - * @param {String} [options.language] +Karma +@name Karma +@class Represents a Karma (master) object. +@param {String | Object } options Constructor arguments +@param {String | Object } [options.container] Target DIV-class that will contain + any canvas element created using Karma functions +@param {String} [options.language] */ var Karma = function(options ) { var that = this; - this.version = "0.3 alpha"; + this.version = "0.08"; // //relative path to the po, images, sounds, etc. from the html //defined here: http://wiki.sugarlabs.org/go/Karma/Bundle_layout @@ -201,9 +202,8 @@ var Karma = function(options ) { toFix[ i ] ].localized.replace('\$', lang ); } //dirty hack to support {lang}_AudioFile - var prefix = lang.substring(0, 2)+"_"; + var prefix = lang+"_"; that.paths[ "sounds" ].localized+=prefix; - that.paths[ "sounds" ].generic+=prefix; } /** It will attempt to load a language file, the posible languages are defined @@ -457,7 +457,7 @@ Karma.prototype.main = function ( cb ) { statusUpdate( counters.loaded, counters.error, totalItems); if ( counters.loaded + counters.error === totalItems ) { if ( counters.error > 0 ){ - throw ( "Images not found: " + errors ); + throw ( "Media files not found: " + errors ); } $("#karma-loader:hiden:first").fadeOut("slow",function(){ $(this).remove();}); @@ -637,7 +637,7 @@ var KSurface = Class( //mainContainer: '',//must be overwritten by Karma.container id: '',//must be overwritten by the Karma.surface OR user container: '', //must be overwritten by Karma.container OR user - paths: '', //must be overwritten by Karma.paths + width: 100, height: 100, fps: 24, @@ -659,7 +659,7 @@ var KSurface = Class( this.width = this.canvas.width; this.height = this.canvas.height; if (!this.id){ - this.id = this.canvas.id; + this.id = this.canvas.id; } } if ( this.canvas.getContext ) { @@ -744,9 +744,10 @@ var KSurface = Class( this.ctx.clearRect( x || 0, y || 0, - width || this.canvas.width, - height || this.canvas.height + width || this.width, + height || this.height ); + return this; }, draw: function ( ) { @@ -1066,9 +1067,6 @@ Karma function. It's a shotcut for calling 'new Karma(..)' **/ $.karma = function (options) { var k =new Karma( options ); - //var x = new KMedia( "file1", "image", {localized: true} ); - //var x = new KImage({file: "ball.png", localized: false, z: 0}); - return k; } })(jQuery);
\ No newline at end of file |