After 2 weeks of no responses but 200 page views i am making a new thread....
//Tonypa- Basically you need to go through these steps:
*detect if hero hits movable block (like the code you posted)
*detect if block can be pushed in the direction hero is trying to move.
Meaning if hero is going down and there is block in next tile below hero you have to check if there is walkable tile below block tile. It usually means if there is another movable block below first block they will not move.
*if block can not be moved in that direction hero should not be allowed to move as
if he had hit the wall
*if block can be pushed in that direction the both block and the hero should move by same speed in same direction
i have only been able to make your steps work with one block. if i add 2, the second block doesnt even run through any of the hittests and i just move through it. my code can move both objects, but only one of the blocks prevents the character from moving. the other thing i can do, is make all of them move at the same time but not individually.
this may be because i am horrible at actionscript. im not so good at just reading implied ideas.
sorry i couldnt get it to work.
Code:function moveChar(ob, dirx, diry) { getMyCorners (ob.x, ob.y+ob.speed*diry, ob); if (diry == -1) { if (ob.upleft and ob.upright and ob.moveup==true) { ob.y += ob.speed*diry; } else { ob.y = ob.ytile*game.tileH+ob.height; } } if (diry == 1) { if (ob.downleft and ob.downright and ob.movedown==true) { ob.y += ob.speed*diry; } else { ob.y = (ob.ytile+1)*game.tileH-ob.height; } } getMyCorners (ob.x+ob.speed*dirx, ob.y, ob); if (dirx == -1) { if (ob.downleft and ob.upleft and ob.moveleft==true) { ob.x += ob.speed*dirx; } else { ob.x = ob.xtile*game.tileW+ob.width; } } if (dirx == 1) { if (ob.upright and ob.downright and ob.moveright==true) { ob.x += ob.speed*dirx; }else { ob.x = (ob.xtile+1)*game.tileW-ob.width; } } ob.clip._x = ob.x; ob.clip._y = ob.y; ob.clip.gotoAndStop(dirx+diry*2+3); ob.xtile = Math.floor(ob.clip._x/game.tileW); ob.ytile = Math.floor(ob.clip._y/game.tileH); if (game["t_"+ob.ytile+"_"+ob.xtile].door and ob==_root.char) { changeMap (ob); } var itemname=game["item"+ob.ytile+"_"+ob.xtile]; if (itemname and ob == _root.char) { game.points=game.points+itemname.points; _root.points=game.points; removeMovieClip(itemname.clip); game.items[itemname.position]=0; delete game["item"+ob.ytile+"_"+ob.xtile]; } return (true); }Code:function specialtilebrain(){ heroymin=char.y-1-(char.height); heroymax=char.y+1+(char.height); heroxmax=char.x+1+(char.width); heroxmin=char.x-1-(char.width); for (var i = 0; i<game.currentstp; ++i) { var name = "specialtile"+i; var ob = game[name]; xdist = ob.x - char.x; ydist = ob.y - char.y; ob.tileymax=ob.y+ob.height; ob.tileymin=ob.y-ob.height; ob.tilexmax=ob.x+ob.width; ob.tilexmin=ob.x-ob.width; //allowmoveright if(heroxmax+1>ob.tilexmin and heroymin+1<ob.tileymax and heroymax-1>ob.tileymin and heroxmin<ob.tilexmin){ checkBlocks(1, 0, ob) } else{char.moveright=true} //allowmoveup if(heroxmax-1>ob.tilexmin and heroymin-1<ob.tileymax and heroxmin+1<ob.tilexmax and heroymax>ob.tileymax){ checkBlocks(0, -1, ob) } else{char.moveup=true} //allowmovedown if(heroxmax-1>ob.tilexmin and heroymax+1>ob.tileymin and heroxmin+1<ob.tilexmax and heroymin<ob.tileymin){ checkBlocks(0, 1, ob); } else{char.movedown=true} //moveleft if(heroxmax>ob.tilexmax and heroymin+1<ob.tileymax and heroymax-1>ob.tileymin and heroxmin-1<ob.tilexmax){ checkBlocks(-1, 0, ob); } else{char.moveleft=true} } }Code:function checkBlocks(xx, yy, ob){ newob=ob if (xx==1){ getMyCorners(newob.x+16 *xx, newob.y , newob) if (newob.upright and newob.downright) { moveBlock(newob, xx, yy) } else{char.moveright=false} } if (xx==-1){ getMyCorners(newob.x+16 *xx, newob.y , newob) if (newob.upleft and newob.downleft) { moveBlock(newob, xx, yy) } else{char.moveleft=false} } if (yy==1){ getMyCorners(newob.x , newob.y+16*yy , newob) if (newob.downright and newob.downleft) { moveBlock(newob, xx, yy) } else{char.movedown=false} } if (yy==-1){ getMyCorners(newob.x , newob.y+16*yy , newob) if (newob.upright and newob.upleft) { moveBlock(newob, xx, yy) } else{char.moveup=false} } }http://flycow.completelyfreehosting....nginetest2.swfCode:function moveBlock(ob, dirx, diry) { if (diry == -1 ) { if (Key.isDown(Key.UP)) { ob.y += 16*diry; } else { //ob.y = ob.ytile*game.tileH+ob.height; } } if (diry == 1) { if (Key.isDown(Key.DOWN)) { ob.y += 16*diry; } else { //ob.y = (ob.ytile+1)*game.tileH-ob.height; } } if (dirx == -1){ if(Key.isDown(Key.LEFT)) { ob.x += 16*dirx; } else { //ob.x = ob.xtile*game.tileW-ob.width; } } if (dirx == 1){ if(Key.isDown(Key.RIGHT)) { ob.x += 16*dirx; } else { //ob.x = (ob.xtile+1)*game.tileW-ob.width; } } ob.clip._x = ob.x; ob.clip._y = ob.y; ob.xtile = Math.floor(ob.clip._x/game.tileW); ob.ytile = Math.floor(ob.clip._y/game.tileH); }
newob=ob probably isnt necessary but it was worth a try.
the code above only works for one block. the second block moves, but the hero can walk through it. i can private message the source file if anyone needs it to help me.
any would be appreciated.
later on ill probably reduce the margins of being able to push the tiles but this will work for now.
edit:I fixed a minor error in the if statements but it doesnt change anything




Reply With Quote