OLPCities/Using the Time-Space Portal: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
(No difference)

Revision as of 23:06, 13 February 2007

Many of the residents of the OLPCity (it's the case of our heroe, the avatar, you...) works for the "Time-Space Inc." This company developed the "Time-Space Portal" for travels in the time and space.

Tut6-1.jpg
Timespace.gif
TimespaceS0.gif
TimespaceS.gif


The Portal is used to go to some place/time of the past and is the "support" for many activities of History. Going to some place in time, the kid needs to enterview all the characters at the Lot to know how they live etc. etc. The company only send a new Portal for the return when the kid ends his mission.





The "Time-Space Portal" is used also for space travels, to go to (and return from) another planet . Usually he will go to the planet "Pink" where there are the "gold beans" he needs to collect - they are very valuable. But he will have some chalenges to do it. The PINK planet's residents are the "echoos", monsters that like to send people to the near past. These space travels are the non-educational part of the OLPCity project. Only funny games.


A "Time-Sapace Portal" is an animation and a link. It has two "shadows" One for collison and the other to do the link.

To do the animation we have the lines:

  ts.setAnimationLoop(0,3);	 
  ts.setAnimationSpeed(4); 					 
  ts.setAnimation(0);	 
  ts.setAnimationRepeat(-1);


Tut6-2.jpg


At this lesson we will present the code of a Lot having a "Time-Space Portal". Using the Portal, you will go to the Lot (code at the next lesson) of the Pink planet. At the next lesson we will explain how to write the code of the "shoot" against the "echoo" and some other tricks.










The code:

<html>
<head>
<script language="Javascript" 

src="http://www.dmu.com/olpc/gamelib_core.js"></script> 
<script language="Javascript"  

src="http://www.dmu.com/olpc/gamelib_sprites.js"></script>
<script language="Javascript" 

src="http://www.dmu.com/olpc/gamelib_keyboard.js"></script>
<script language="Javascript">

 function init(){

  Sp_linuxcompatible=true;

  Gl_preloader("floorW05N07.gif"); 
  Gl_preloader("transit.gif"); 
  Gl_preloader("avat1.gif"); 
  Gl_preloader("timespace.gif"); 
  Gl_preloader("timespaceS.gif"); 
  Gl_preloader("timespaceS0.gif"); 

  entryt = new Gl_cookie("entt");

   upkey=Kb_trapkey("UP");				 
   downkey=Kb_trapkey("DOWN");			  
   rightkey=Kb_trapkey("RIGHT");	
   leftkey=Kb_trapkey("LEFT");
 
   av=new Sp_Sprite();	 
   av.setImage("avat1.gif",32,32,4,2);  
   av.setXlimits(5,610);
   av.setYlimits(5,385);
   if(entryt.value=="E"){	  
    av.moveTo( 550,165);	 
    av.setFrame(0);
    entryt.setvalue("G");
    }
    else if(entryt.value=="W"){	 
     av.moveTo(30,175);	 
     av.setFrame(1);
     entryt.setvalue("G");
   }
   else{
    av.moveTo( 300,170);	 
    av.setFrame(3);
   }			 
   av.setFrameByDirection(90,90,1,180,180,3,270,270,0,0,0,2);
   av.setAnimation(0);
   av.setZ(10);
   av.collides=true;
   av.useHitEvents(true);
   av.setAnimationSpeed(3);
   av.switchOn();

  floor=new Sp_Sprite();			 
  floor.setImage("floorW05N07.gif",614,390,1,1); 
  floor.setXlimits( 0,616);	 
  floor.setYlimits( 0,390);
  floor.setFrame(0);	 
  floor.moveTo(0 , 0 );				 
  floor.setZ(5);  
  floor.switchOn();				 

  transitW=new Sp_Sprite();			 
  transitW.setImage("transit.gif",20,20,1,1); 
  transitW.setXlimits( 0,614);	 
  transitW.setYlimits( 0,390);
  transitW.setFrame(0);	 
  transitW.moveTo(5 , 180 );		 
  transitW.setZ(12);  
  transitW.makeHard();
  transitW.switchOn();
  
  ts=new Sp_Sprite();	 
  ts.setImage("timespace.gif",114,110,1,4);  
  ts.setXlimits(0,614);	 
  ts.setYlimits(5,280);	 
  ts.moveTo(345, 80);	 
  ts.setFrame(0);		 
  ts.setAnimationLoop(0,3);	 
  ts.setAnimationSpeed(4); 					 
  ts.setAnimation(0);	 
  ts.setZ(6);
  ts.setAnimationRepeat(-1);	 
  ts.collides=true;
  ts.switchOn();
   
  tsS=new Sp_Sprite();			 
  tsS.setImage("timespaceS.gif",62,14,1,1); 
  tsS.setXlimits( 0,614);	 
  tsS.setYlimits( 0,390);
  tsS.setFrame(0);	 
  tsS.moveTo( 385 ,  150 );	
  tsS.setZ(0);  
  tsS.makeHard();
  tsS.switchOn();
   

  tsS0=new Sp_Sprite();			 
  tsS0.setImage("timespaceS0.gif",95,79,1,1); 
  tsS0.setXlimits( 0,614);	 
  tsS0.setYlimits( 0,390);
  tsS0.setFrame(0);	 
  tsS0.moveTo( 355 ,  80 );
  tsS0.setZ(0);  
  tsS0.makeHard();
  tsS0.switchOn();
   
  Gl_hook("timestep()"); 
  Gl_start();	
 } 

 function timestep(){
    av.setSpeed(0); 
    av.setAnimationRepeat(0);
   if(rightkey.pressed){
     av.setDir(1,0);
     av.setAnimationRepeat(-1);
     av.setSpeed(2);
   }
   else if(leftkey.pressed){
    av.setDir(-1,0);
    av.setAnimationRepeat(-1);
    av.setSpeed(2);
   }
   else if(downkey.pressed){
    av.setDir(0,1);
    av.setAnimationRepeat(-1);
    av.setSpeed(2);
   }
   else if(upkey.pressed){
    av.setDir(0,-1);
    av.setAnimationRepeat(-1);
    av.setSpeed(2);
   }

   
   if(av.hasHit(transitW)){
    entryt.setvalue("E");   
    window.location="tut5.html";
   } 

    if(av.hasHit(tsS)){
  window.location="tut6.html";
 } 
 }//timestep

</script>
</head>

<title>TUTCITY  </title>
<body  bgcolor="black"  onload="init()" >
</html>

Look the Lot of the exercice at our web server: http://www.dmu.com/olpctut/tut5e.html.


PREVIOUS LESSON: Using Transit...........TOC :OLPCities Tutorials..........NEXT LESSON : Shooting in the bad guys