OLPCities/Using 3D objects: Difference between revisions

From OLPC
Jump to navigation Jump to search
No edit summary
No edit summary
Line 152: Line 152:




<center>PREVIOUS LESSON: [[The avatar]]...........TOC :[[OLPCities Tutorials]]..........NEXT LESSON : [[Links]]</center>
<center>PREVIOUS LESSON: [[The avatar]]...........TOC :[[OLPCities Tutorials]]..........NEXT LESSON : [[Using Links]]</center>



Revision as of 20:12, 21 September 2006

You can find "3D objects" at our Inventory. The link is: 3D objects.

You can use one of them or create a new . Remember to put it available for everybody.

A "3D object" is created using 3 sprites.

Tut3-1.jpg

Only that using the image having the sufix "S" ("shadow for collision" or only "shadow") is "hard". And they have different levels of "Z". So, the avatar will go over that with the image having sufix "D" (down) and behind that of the sufix "U" (up).

At this lesson we will add a 3D object (this bonfire) to the Lot of the previous. We will use (take a look) elements of the same Classes of the previous lesson:

The code is also similat to that of the previous lesson having only the 3 new sprites of the 3D object.

<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("plaquehello.gif"); 
  Gl_preloader("avat1.gif");
  Gl_preloader("fogueiraS.gif"); 
  Gl_preloader("fogueiraU.gif"); 
  Gl_preloader("fogueiraD.gif"); 


   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);	 
   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();				 

  pl=new Sp_Sprite();			 
  pl.setImage("plaquehello.gif",179,101,1,1); 
  pl.setXlimits( 0,614);	 
  pl.setYlimits( 0,390);
  pl.setFrame(0);	 
  pl.moveTo(355 , 45 );				 
  pl.setZ(12); 
  pl.makeHard(); 
  pl.switchOn()

   bfU=new Sp_Sprite();	 
   bfU.setImage("fogueiraU.gif",62,27,1,1); 
   bfU.setXlimits( 0,614);	 
   bfU.setYlimits( 0,390);
   bfU.setFrame(0);	 
   bfU.moveTo(180 , 248 );				 
   bfU.setZ(15);  
   bfU.switchOn();		

   bfS=new Sp_Sprite();		 
   bfS.setImage("fogueiraS.gif",62,14,1,1); 
   bfS.setXlimits( 0,614);	 
   bfS.setYlimits( 0,390);
   bfS.setFrame(30);	 
   bfS.moveTo(182 , 263 );				 
   bfS.setZ(0);  
   bfS.makeHard();
   bfS.switchOn();

   bfD=new Sp_Sprite();			 
   bfD.setImage("fogueiraD.gif",56,10,1,1); 
   bfD.setXlimits( 0,614);	 
   bfD.setYlimits( 0,390);
   bfD.setFrame(0);	 
   bfD.moveTo(181 , 275 );				 
   bfD.setZ(6);  
   bfD.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);
   }
 }//timestep

</script>
</head>

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

Look the Lot of the exercice (it's a web page) at our web server: http://www.dmu.com/olpctut/tut3.html


PREVIOUS LESSON: The avatar...........TOC :OLPCities Tutorials..........NEXT LESSON : Using Links