1. Pedro Ferreira
  2. space_ship_game

Commits

drk  committed 61ac809

- add a message in the beginning of each level
- trying to have it with a transition (tweenjs)

  • Participants
  • Parent commits 91a922b
  • Branches default

Comments (0)

Files changed (4)

File home.html

View file
         
         <script type+"text/javascript" src="libraries/jquery-1.7.2.min.js"></script>
         
-        <!--
+        
         <script type="text/javascript" src="http://code.createjs.com/preloadjs-0.1.0.min.js"></script>
         <script type="text/javascript" src="http://code.createjs.com/easeljs-0.4.2.min.js"></script>
+        <script type="text/javascript" src="
+http://code.createjs.com/tweenjs-0.2.0.min.js"></script>
         <script type="text/javascript" src="http://code.createjs.com/soundjs-0.2.0.min.js"></script>
-        -->
+        
+        
+<!--
         <script type="text/javascript" src="libraries/preloadjs-0.1.0.min.js"></script>
         <script type="text/javascript" src="libraries/easeljs-0.4.2.min.js"></script>
+        <script type="text/javascript" src="libraries/tweenjs-0.2.0.min.js"></script>
         <script type="text/javascript" src="libraries/soundjs-0.2.0.min.js"></script>
-        
+-->        
         
         <script type="text/javascript" src="js/utilities.js"></script>
         <script type="text/javascript" src="js/ship.js"></script>

File js/enemy_move_horizontally.js

View file
 
 enemy.gotoAndPlay("spawn");
 
+Tween.get( enemy, { loop: true } ).to( { alpha: 0.4 }, 200, Ease.get(1) )
+                                  .to( { alpha: 1   }, 200, Ease.get(1) );  //HERE 
+
 this.shape = enemy;
 };
 

File js/maps.js

View file
 
 (function(window)
 {
+    // has the levels configurations
+var LEVELS = [];
+
+var NUMBER_OF_LEVELS = 1;
+
+
+var CURRENT_LEVEL = 0;
+
+
+var COUNT_TICKS = 0;
+
+
+var LEVEL_PHASE = 0;
+
+
+var ENDING_LEVEL = false;
+
 
 
 function Maps()
         {
         LEVELS.push( data );
         
+        Maps.loadMap( 0 );
+        
         Ticker.addListener( Maps.tick );
         }
     });
 }
 
 
-    // has the levels configurations
-var LEVELS = [];
+/*
+    Arguments:
+    
+        level (int) : which map/level to load (if not provided, load the next map)
+ */
 
-var NUMBER_OF_LEVELS = 1;
+Maps.loadMap = function( level )
+{
+    // load next map
+if (typeof level == 'undefined')
+    {
+    CURRENT_LEVEL++;
+    }
 
+else
+    {
+    CURRENT_LEVEL = 0;
+    }
 
-var CURRENT_LEVEL = 0;
+Maps.greetingMessage( CURRENT_LEVEL );
+};
 
 
-var COUNT_TICKS = 0;
-
-
-var LEVEL_PHASE = 0;
-
-
-var ENDING_LEVEL = false;
-
 
 
 Maps.reset = function()
 
 
 
+/*
+    A message in the beginning of each level
+ */
+
+Maps.greetingMessage = function( levelNumber )
+{
+var message = new Text("Level " + levelNumber, "30px Arial", "rgb(255, 255, 255)");
+
+message.textAlign = 'center';
+
+message.x = CANVAS.width / 2;
+message.y = CANVAS.height / 2;
+
+Tween.get( message ).to( { alpha: 0 }, 100, Ease.get( 1 ) );    //HERE doesnt work...
+
+STAGE.addChild( message );
+
+
+setTimeout( function() { STAGE.removeChild( message ); }, 2000 );
+};
+
+
+
+
 Maps.tick = function()
 {  
 COUNT_TICKS++;
     
 var phase = currentLevel[ LEVEL_PHASE ];
 
-
+	
 
 if ( !ENDING_LEVEL && COUNT_TICKS >= phase.tick)
     {

File libraries/tweenjs-0.2.0.min.js

View file
+/*
+* TweenJS
+* Visit http://createjs.com/ for documentation, updates and examples.
+*
+* Copyright (c) 2011 gskinner.com, inc.
+* 
+* Distributed under the terms of the MIT license.
+* http://www.opensource.org/licenses/mit-license.html
+*
+* This notice shall be included in all copies or substantial portions of the Software.
+*/
+(function(k){var b=function(g,a){this.initialize(g,a)},a=b.prototype;b.NONE=0;b.LOOP=1;b.REVERSE=2;b.IGNORE={};b._tweens=[];b._plugins={};b.get=function(g,a,c){return new b(g,a,c)};b.tick=function(g,a){for(var c=b._tweens,e=c.length-1;e>=0;e--){var d=c[e];if(!a||d.ignoreGlobalPause)d.tick(d._useTicks?1:g)}};Ticker&&Ticker.addListener(b,false);b.removeTweens=function(g){if(g.tweenjs_count){for(var a=b._tweens,c=a.length-1;c>=0;c--)a[c]._target==g&&a.splice(c,1);g.tweenjs_count=0}};b.installPlugin=
+function(g,a){var c=g.priority;if(c==null)g.priority=c=0;for(var e=0,d=a.length,f=b._plugins;e<d;e++){var i=a[e];if(f[i]){for(var l=f[i],j=0,k=l.length;j<k;j++)if(c<l[j].priority)break;f[i].splice(j,0,g)}else f[i]=[g]}};b._register=function(g,a){var c=g._target;if(a){if(c)c.tweenjs_count=c.tweenjs_count?c.tweenjs_count+1:1;b._tweens.push(g)}else c&&c.tweenjs_count--,c=b._tweens.indexOf(g),c!=-1&&b._tweens.splice(c,1)};a.ignoreGlobalPause=false;a.loop=false;a.duration=0;a.pluginData=null;a._paused=
+false;a._curQueueProps=null;a._initQueueProps=null;a._steps=null;a._actions=null;a._prevPosition=0;a._stepPosition=0;a._prevPos=-1;a._target=null;a._useTicks=false;a.initialize=function(g,a,c){this._target=g;if(a)this._useTicks=a.useTicks,this.ignoreGlobalPause=a.ignoreGlobalPause,this.loop=a.loop,a.override&&b.removeTweens(g);this.pluginData=c||{};this._curQueueProps={};this._initQueueProps={};this._steps=[];this._actions=[];a&&a.paused?this._paused=true:b._register(this,true);a&&a.position!=null&&
+this.setPosition(a.position,b.NONE)};a.wait=function(g){if(g==null||g<=0)return this;var a=this._cloneProps(this._curQueueProps);return this._addStep({d:g,p0:a,e:this._linearEase,p1:a})};a.to=function(a,b,c){if(isNaN(b)||b<0)b=0;return this._addStep({d:b||0,p0:this._cloneProps(this._curQueueProps),e:c,p1:this._cloneProps(this._appendQueueProps(a))})};a.call=function(a,b,c){return this._addAction({f:a,p:b?b:[this],o:c?c:this._target})};a.set=function(a,b){return this._addAction({f:this._set,o:this,
+p:[a,b?b:this._target]})};a.play=function(a){return this.call(a.setPaused,[false],a)};a.pause=function(a){a||(a=this);return this.call(a.setPaused,[true],a)};a.setPosition=function(a,b){a<0&&(a=0);b==null&&(b=1);var c=a,e=false;if(c>=this.duration)this.loop?c%=this.duration:(c=this.duration,e=true);if(c==this._prevPos)return e;if(this._target)if(e)this._updateTargetProps(null,1);else if(this._steps.length>0){for(var d=0,f=this._steps.length;d<f;d++)if(this._steps[d].t>c)break;d=this._steps[d-1];this._updateTargetProps(d,
+(this._stepPosition=c-d.t)/d.d,c)}d=this._prevPos;this._prevPos=c;this._prevPosition=a;b!=0&&this._actions.length>0&&(this._useTicks?this._runActions(c,c):b==1&&c<d?(d!=this.duration&&this._runActions(d,this.duration),this._runActions(0,c,true)):this._runActions(d,c));e&&this.setPaused(true);return e};a.tick=function(a){this._paused||this.setPosition(this._prevPosition+a)};a.setPaused=function(a){if(this._paused!=!!a)this._paused=!!a,b._register(this,!a);return this};a.w=a.wait;a.t=a.to;a.c=a.call;
+a.s=a.set;a.toString=function(){return"[Tween]"};a.clone=function(){throw"Tween can not be cloned.";};a._updateTargetProps=function(a,h,c){var e,d,f,i;!a&&h==1?e=d=this._curQueueProps:(a.e&&(h=a.e(h,0,1,1)),e=a.p0,d=a.p1);for(n in this._initQueueProps){if((f=e[n])==null)e[n]=f=this._initQueueProps[n];if((i=d[n])==null)d[n]=i=f;f=f==i||h==0||h==1||typeof f!="number"?h==1?i:f:f+(i-f)*h;var l=false;if(i=b._plugins[n])for(var j=0,k=i.length;j<k;j++){var m=i[j].tween(this,n,f,e,d,h,c,!a);m==b.IGNORE?l=
+true:f=m}l||(this._target[n]=f)}};a._runActions=function(a,b,c){var e=a,d=b,f=-1,i=this._actions.length,k=1;a>b&&(e=b,d=a,f=i,i=k=-1);for(;(f+=k)!=i;){var b=this._actions[f],j=b.t;(j==d||j>e&&j<d||c&&j==a)&&b.f.apply(b.o,b.p)}};a._appendQueueProps=function(a){var h,c,e,d;for(d in a){if(this._initQueueProps[d]==null){c=this._target[d];if(h=b._plugins[d])for(var f=0,i=h.length;f<i;f++)e=h[f].init(this,d,c),e!=b.IGNORE&&(c=e);this._initQueueProps[d]=c}this._curQueueProps[d]=a[d]}return this._curQueueProps};
+a._cloneProps=function(a){var b={},c;for(c in a)b[c]=a[c];return b};a._addStep=function(a){if(a.d>0)this._steps.push(a),a.t=this.duration,this.duration+=a.d;return this};a._addAction=function(a){a.t=this.duration;this._actions.push(a);return this};a._set=function(a,b){for(var c in a)b[c]=a[c]};k.Tween=b})(window);(function(k){var b=function(a,b,c){this.initialize(a,b,c)},a=b.prototype;a.ignoreGlobalPause=false;a.duration=0;a.loop=false;a._paused=true;a._tweens=null;a._labels=null;a._prevPosition=0;a._prevPos=-1;a._useTicks=false;a.initialize=function(a,b,c){this._tweens=[];if(c)this._useTicks=c.useTicks,this.loop=c.loop,this.ignoreGlobalPause=c.ignoreGlobalPause;a&&this.addTween.apply(this,a);this.setLabels(b);(!c||!c.paused)&&Tween._register(this,true);c&&c.position!=null&&this.setPosition(c.position,Tween.NONE)};
+a.addTween=function(a){var b=arguments.length;if(b>1){for(var c=0;c<b;c++)this.addTween(arguments[c]);return arguments[0]}else if(b==0)return null;this.removeTween(a);this._tweens.push(a);a.setPaused(true);a._paused=false;a._useTicks=this._useTicks;if(a.duration>this.duration)this.duration=a.duration;this._prevPos>=0&&a.setPosition(this._prevPos,Tween.NONE);return a};a.removeTween=function(a){var b=arguments.length;if(b>1){for(var c=true,e=0;e<b;e++)c=c&&this.removeTween(arguments[e]);return c}else if(b==
+0)return false;b=this._tweens.indexOf(a);return b!=-1?(this._tweens.splice(b,1),a.duration>=this.duration&&this.updateDuration(),true):false};a.addLabel=function(a,b){this._labels[a]=b};a.setLabels=function(a){this._labels=a?a:{}};a.gotoAndPlay=function(a){this.setPaused(false);this._goto(a)};a.gotoAndStop=function(a){this.setPaused(true);this._goto(a)};a.setPosition=function(a,b){a<0&&(a=0);var c=this.loop?a%this.duration:a,e=!this.loop&&a>=this.duration;if(c==this._prevPos)return e;this._prevPosition=
+a;this._prevPos=c;for(var d=0,f=this._tweens.length;d<f;d++)if(this._tweens[d].setPosition(c,b),c!=this._prevPos)return false;e&&this.setPaused(true);return e};a.setPaused=function(a){if(this._paused!=!!a)this._paused=!!a,Tween._register(this,!a)};a.updateDuration=function(){for(var a=this.duration=0,b=this._tweens.length;a<b;a++)if(tween=this._tweens[a],tween.duration>this.duration)this.duration=tween.duration};a.tick=function(a){this.setPosition(this._prevPosition+a)};a.resolve=function(a){var b=
+parseFloat(a);isNaN(b)&&(b=this._labels[a]);return b};a.toString=function(){return"[Timeline]"};a.clone=function(){throw"Timeline can not be cloned.";};a._goto=function(a){a=this.resolve(a);a!=null&&this.setPosition(a)};k.Timeline=b})(window);(function(k){var b=function(){throw"Ease cannot be instantiated.";};b.linear=function(a){return a};b.none=b.linear;b.get=function(a){a<-1&&(a=-1);a>1&&(a=1);return function(b){return a==0?b:a<0?b*(b*-a+1+a):b*((2-b)*a+(1-a))}};b.getPowIn=function(a){return function(b){return Math.pow(b,a)}};b.getPowOut=function(a){return function(b){return 1-Math.pow(1-b,a)}};b.getPowInOut=function(a){return function(b){return(b*=2)<1?0.5*Math.pow(b,a):1-0.5*Math.abs(Math.pow(2-b,a))}};b.quadIn=b.getPowIn(2);b.quadOut=
+b.getPowOut(2);b.quadInOut=b.getPowInOut(2);b.cubicIn=b.getPowIn(3);b.cubicOut=b.getPowOut(3);b.cubicInOut=b.getPowInOut(3);b.quartIn=b.getPowIn(4);b.quartOut=b.getPowOut(4);b.quartInOut=b.getPowInOut(4);b.quintIn=b.getPowIn(5);b.quintOut=b.getPowOut(5);b.quintInOut=b.getPowInOut(5);b.sineIn=function(a){return 1-Math.cos(a*Math.PI/2)};b.sineOut=function(a){return Math.sin(a*Math.PI/2)};b.sineInOut=function(a){return-0.5*(Math.cos(Math.PI*a)-1)};b.getBackIn=function(a){return function(b){return b*
+b*((a+1)*b-a)}};b.backIn=b.getBackIn(1.7);b.getBackOut=function(a){return function(b){return--b*b*((a+1)*b+a)+1}};b.backOut=b.getBackOut(1.7);b.getBackInOut=function(a){a*=1.525;return function(b){return(b*=2)<1?0.5*b*b*((a+1)*b-a):0.5*((b-=2)*b*((a+1)*b+a)+2)}};b.backInOut=b.getBackInOut(1.7);b.circIn=function(a){return-(Math.sqrt(1-a*a)-1)};b.circOut=function(a){return Math.sqrt(1- --a*a)};b.circInOut=function(a){return(a*=2)<1?-0.5*(Math.sqrt(1-a*a)-1):0.5*(Math.sqrt(1-(a-=2)*a)+1)};b.bounceIn=
+function(a){return 1-b.bounceOut(1-a)};b.bounceOut=function(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+0.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+0.9375:7.5625*(a-=2.625/2.75)*a+0.984375};b.bounceInOut=function(a){return a<0.5?b.bounceIn(a*2)*0.5:b.bounceOut(a*2-1)*0.5+0.5};b.getElasticIn=function(a,b){var h=Math.PI*2;return function(c){if(c==0||c==1)return c;var e=b/h*Math.asin(1/a);return-(a*Math.pow(2,10*(c-=1))*Math.sin((c-e)*h/b))}};b.elasticIn=b.getElasticIn(1,0.3);b.getElasticOut=
+function(a,b){var h=Math.PI*2;return function(c){if(c==0||c==1)return c;var e=b/h*Math.asin(1/a);return a*Math.pow(2,-10*c)*Math.sin((c-e)*h/b)+1}};b.elasticOut=b.getElasticOut(1,0.3);b.getElasticInOut=function(a,b){var h=Math.PI*2;return function(c){var e=b/h*Math.asin(1/a);return(c*=2)<1?-0.5*a*Math.pow(2,10*(c-=1))*Math.sin((c-e)*h/b):a*Math.pow(2,-10*(c-=1))*Math.sin((c-e)*h/b)*0.5+1}};b.elasticInOut=b.getElasticInOut(1,0.3*1.5);k.Ease=b})(window);