   raycasting problem
  I have been following the tutorial http://www.permadi.com/tutorial/raycast/ but my program has some problem which i dunno why.I'm using Flash to do the raycasting.http://others.betaruce.com/raycasting2.flahttp://others.betaruce.com/raycasting2.swfas u can see from the swf, if you press the Right arrow on ur keyboard to rotate to the right (the 1st 90 deg), it works very good. however, all other quadrants are mess up.But if you move around using the rest of the arrow keys, sometimes the walls did show up "normally". I don't know where the problem lies...only the 1st quadrant (player angle <90) works normally in all situation.Can someone pls my code and give me a hand? thanks.import flash.display.*;import flash.geom.*;//var trans:Number = Math.PI/180;var size:Number = 64;var map:Array = new Array();var map_width:Number;var map_height:Number;var fov:Number = 60;var p_ht:Number = 32;var player:Point = new Point();var p_angle:Number;var screen_width:Number = 320;var screen_height:Number = 200;var distance_to_screen:Number;var angle_between_rays:Number;var oldmx:Number = mouseX;var oldmy:Number = mouseY;//map.push([1, 1, 1, 1, 1, 1, 1, 1]);map.push([1, 1, 0, 0, 0, 0, 1, 1]);map.push([1, 0, 0, 0, 0, 0, 0, 1]);map.push([1, 0, 0, 0, 0, 0, 0, 1]);map.push([1, 0, 0, 0, 0, 0, 0, 1]);map.push([1, 0, 0, 0, 0, 0, 0, 1]);map.push([1, 1, 0, 0, 0, 0, 1, 1]);map.push([1, 1, 1, 1, 1, 1, 1, 1]);map_width = map[0].length;map_height = map.length;// initial player positionplayer.x = 250;player.y = 250;p_angle = 0;//distance_to_screen = (screen_width/2)/Math.tan(fov*trans);angle_between_rays = fov/screen_width;//onEnterFrame = function () {clear();var tempGrid:Point = new Point();var temp:Point = new Point();//var horizontal:Point = new Point();var vertical:Point = new Point();//var distPH:Number;var distPV:Number;var dist:Number;var beta:Number = fov/2;//var Xa:Number;var Ya:Number;//var ray_angle:Number = p_angle-fov/2;if (ray_angle<0) {ray_angle += 360;}//    var projected_height:Number;var const:Number = size*distance_to_screen;//for (var i = 0; i<screen_width; i++) {//if (ray_angle>=360) {ray_angle -= 360;}if (ray_angle<0) {ray_angle += 360;}//    // ===== Finding horizontal intersection =====//Xa = Math.floor(size/Math.tan(ray_angle*trans));if (ray_angle>0 && ray_angle<180) {temp.y = Math.ceil(player.y/size)*size;Ya = size;temp.x = player.x+(temp.y-player.y)/Math.tan(ray_angle*trans);} else {temp.y = Math.floor(player.y/size)*size;Ya = -size;temp.x = player.x+(temp.y-player.y)/Math.tan(ray_angle*trans);temp.y--;}// raycasting for horizontal intersectionif (ray_angle == 0 || ray_angle == 180) {distPH = 99999999;} else {while (true) {tempGrid.x = Math.floor(temp.x/size);tempGrid.y = Math.floor(temp.y/size);if (tempGrid.x<0 || tempGrid.y<0 || tempGrid.x>=map_width || tempGrid.y>=map_height) {distPH = 99999999;break;} else if (map[tempGrid.y][tempGrid.x] != 0) {horizontal.x = temp.x;horizontal.y = temp.y;distPH = Point.distance(player, horizontal);break;} else {temp.x += Xa;temp.y += Ya;}}}//// ===== Finding vertical intersection =====//Ya = Math.floor(size*Math.tan(ray_angle*trans));if (ray_angle>270 || ray_angle<90) {temp.x = Math.ceil(player.x/size)*size;Xa = size;temp.y = player.y+(temp.x-player.x)*Math.tan(ray_angle*trans);} else {temp.x = Math.floor(player.x/size)*size;Xa = -size;temp.y = player.y+(temp.x-player.x)*Math.tan(ray_angle*trans);temp.x--;}//  raycasting for vertical intersectionif (ray_angle == 270 || ray_angle == 90) {distPV = 99999999;} else {while (true) {tempGrid.x = Math.floor(temp.x/size);tempGrid.y = Math.floor(temp.y/size);if (tempGrid.x<0 || tempGrid.y<0 || tempGrid.x>=map_width || tempGrid.y>=map_height) {distPV = 99999999;break;} else if (map[tempGrid.y][tempGrid.x] != 0) {vertical.x = temp.x;vertical.y = temp.y;distPV = Point.distance(player, vertical);break;} else {temp.x += Xa;temp.y += Ya;}}}//dist = Math.min(distPH, distPV);dist *= Math.cos((i*fov/screen_width-fov/2)*trans);//ray_angle += angle_between_rays;//projected_height = const/dist;(distPH == Math.min(distPH, distPV)) ? linestyle(1, 0) : linestyle(1, 0x777777);moveTo(i, screen_height/2-projected_height/2);lineTo(i, screen_height/2+projected_height/2);}};//// Key events//Key.addListener(_root);onKeyDown = function () {var walk:Number = 10;var rot:Number = 10;if (Key.isDown(Key.UP)) {player.x += walk*Math.cos(p_angle*trans);player.y += walk*Math.sin(p_angle*trans);}if (Key.isDown(Key.DOWN)) {player.x -= walk*Math.cos(p_angle*trans);player.y -= walk*Math.sin(p_angle*trans);}if (Key.isDown(Key.LEFT)) {p_angle -= rot;//trace(p_angle);}if (Key.isDown(Key.RIGHT)) {p_angle += rot;}if (p_angle>=360) {p_angle -= 360;}if (p_angle<0) {p_angle += 360;}trace(p_angle);};