I’m trying to make it so my character (named guy) can’t walk through walls but I can’t get the wall’s x value. this[“tile”+i]._x comes up as undefined when put through a trace. How do I check if he’s hitting the walls? I’ve searched through the tutorials and I’m pretty sure this will be a easy quick fix up.
Heres my code:
map1 = [[0,0,0,0,0,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1],
[0,0,0,0,0,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1],
[0,0,0,0,0,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1],
[0,0,0,0,0,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1],
[0,0,0,0,0,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1,1]];
function placeTile(x,y,type,count){
if(type==1){
this.attachMovie("block", "tile"+c,c);
this["tile"+c]._x = x+this["tile"+c]._width/2;
this["tile"+c]._y = y+this["tile"+c]._height/2;
}
}
c = 0;
for(i = 0; i <= 10; i++){
for(j = 0; j <= 10; j++){
placeTile(j*20,i*20,map1*[j],c);
c++;
}
}
this.attachMovie("guy","guy",1);
guy._x=1;
speed = 5;
function checkRight(x,y){
for(i = 0; i <= 100; i++){
if(this["tile"+i].hitTest(x,y,true)){
trace(this["tile"+i]._x);
return false;
}
else{
trace(this["tile"+i]._x);
trace("Not Touching...");
return true;
}
}
}
guy.onEnterFrame = function(){
if(Key.isDown(Key.RIGHT) && checkRight(guy._x+speed,guy._y)==true){
guy._x+=speed;
}
}
if you guys still need FLA (I doubt it…) I will provide it.