INVENTORY

The use of inventory is a tradition in games. The player needs to have some object in the inventory like:

Try our sample. Click in the figure to activate.Use the arrow keys to walk. Try to find and click the key to put it in the inventory. If you have the key in the inventory you can click the door and it will open!

The carpet is a movie-clip. To be dragable the program glued to it is:


onClipEvent(enterFrame){
 this.onPress=function(){  
  this.startDrag(); 
 } 
	
 this.onRelease=function(){
  this.stopDrag(); 
 }
}

We have 2 keys, two movie-clips. One under the carpet and the other in the Inventory (invisible at charge) whose name is: keyininvent.

We have a general flag: haskey that changes when the player clicks the key under the carpet. The program of this key is:

onClipEvent(enterFrame){
 this.onPress=function(){
  this._visible = false;
  _root.keyininvent._visible = true; 
  _root.haskey = 1;
 } 
}

The door is an animated movie-clip. He has a program glued to it:

onClipEvent(load){
 this.stop();
}

onClipEvent (enterFrame) {
 //to run the clip only one time
 if(this._currentframe == this._totalframes){  
  this.stop(); 
 }	 
 	 
 this.onPress=function(){
  if(_root.haskey==1){	
  this.play();
  _root.dooropen = 1; //another flag  
  _root.keyininvent._visible=false;
 }
}

We have a little "shadow-for-collision" in front of the door that needs to be desactivated when the door opens (the flag dooropen = 1).


PREVIOUS LESSON NEXT LESSON
T. CONTENTS HOMEPAGE