At 12/17/03 02:45 PM, yasowhat wrote:
k could you help me say i want to make a game like snake i need snake to die when it goes of the screen how do i do that
well, there are a few ways to do this, i will explain 3 of them for you;
(1) : Lines
Draw a line, it doesn't hav to be a thick one, then convert it to an MC. Then change the instance name of the line to "wall" (it doesn't have to be wall, this is just for this example). Then add this code to the snake
onClipEvent(enterFrame){
if (this.hitTest(_root.wall))
this.gotoAndPlay"snake die" //this is only if you have a snake die frame
}
the lines can be put anywhere on the screen, so any obsticles can be made in the same way.
also, so that the lines cannot be seen, add this code to the line:
onClipEvent(enterFrame){
this._visible = false
}
(2): A box
Draw a box that covers the entire stage, then covert it to an MC, one again, we need to give it an instance name, for this example i will call it "box";
now add the following code to the snake;
onClipEvent(enterFrame){
if(!this.hitTest(_root.box)) // the ! makes it mean if it doesn't
this.gotoAndPlay "snake die" //this is only if you have a snake die frame
}
once again, we dont want this to be seen, so use;
onClipEvent(enterFrame){
this._visible = false
}
(3) : x,y coordinates
This one is probobly the most complicated of them all to use as you use the x,y coordinates of the stage to see if the snake will die or not.
the following code will need to be inputed in the the actions of the snake MC;
onClipEvent(enterFrame){
if (this._x>a){ //a = stage width
this.gotoAndPlay"snake die"
} else if(this._x<0){
this.gotoAndPlay "snake die"
} else if(this._y>b){ //b = stage height
this.gotoAndPlay"snake die"
} else if(this._y<0){
this.gotoAndPlay "snake die"
}
}
there you have it, obviously you dont need to use all three scripts,just pick the one that you think will bennefit you the most, and use it.
-Dan