Saludos a todos, estoy haciendo un juego en flash i con el personaje ya echo y sus movimientos, quiero que no pueda andar cuando se encuentra con una pared. Por eso he echo una matriz que sera mi mapa
Entonces si por ejemplo ando hacia la derecha:
Cuando ando hacia la derecha, consulto a la matriz la posicion en que estoy y miro si en x+1 tenemos un 1 o un 0 para movernos o no. La cuestion es que no se me mueve hacia la derecha. Que hago mal?
gracias
Código [Seleccionar]
myMap = [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]];
Entonces si por ejemplo ando hacia la derecha:
Código [Seleccionar]
else if(estat == RIGHT){
if(Key.isDown(Key.UP)){
gotoAndPlay("UP")
estat = UP
}
else if(Key.isDown(Key.LEFT)){
gotoAndPlay("LEFT")
estat = LEFT
}
else if(Key.isDown(Key.DOWN)){
gotoAndPlay("DOWN")
estat = DOWN
}
else if(Key.isDown(Key.RIGHT)){
x=this._x/30
y=this._y/30
trace(x)
if((myMap[x+1][y])==0){
this._x += speed
}else if((myMap[x+1][y])!=0){
}
if(Key.isDown(Key.UP)){
gotoAndPlay("D_UPRIGHT")
estat = D_UPRIGHT
}
else if(Key.isDown(Key.DOWN)){
gotoAndPlay("D_DOWNRIGHT")
estat = D_DOWNRIGHT
}
else if(Key.isDown(Key.SPACE)){
_root.attack1r.duplicateMovieClip("attack1r"+depth_laser,depth_laser)
_root["attack1r"+depth_laser]._x = this._x + 100
_root["attack1r"+depth_laser]._y = this._y
depth_laser++
}
}
else{
gotoAndPlay("RRIGHT")
estat = RRIGHT
}
}
Cuando ando hacia la derecha, consulto a la matriz la posicion en que estoy y miro si en x+1 tenemos un 1 o un 0 para movernos o no. La cuestion es que no se me mueve hacia la derecha. Que hago mal?
gracias