public static int _update_pl_ori_move(IBaseUnit sprite, long cur_clock_tm) { var pl = sprite.get_pack_data(); var dflag = true; var speed = pl.speed; var tmleft = cur_clock_tm - pl.moving.start_tm; if (dflag) Utility.debug("_update_pl_ori_move speed[" + speed + "] tmleft[" + tmleft + "]"); if (tmleft <= 0) { return 0; } // moving var to_end = false; var move_distance = tmleft * speed / 1000.0; if (move_distance >= pl.moving.max_r) { to_end = true; move_distance = pl.moving.max_r; } var to_x = pl.moving.stx + (move_distance * pl.moving.ori_cos); var to_y = pl.moving.sty + (move_distance * pl.moving.ori_sin); if (dflag) { Utility.debug(" move_distance[" + move_distance + "] tmleft[" + tmleft + "] speed[" + speed + "] cur_clock_tm[" + cur_clock_tm + "] pl.moving.start_tm[" + pl.moving.start_tm + "] pl.x[" + pl.x + "] pl.y[" + pl.y + "] to_x[" + to_x + "] to_y[" + to_y + "]"); } if (to_end) { Utility.debug("_update_pl_ori_move to_end !!! "); pl.moving = null; } pl.x = (int)to_x; pl.y = (int)to_y; if (sprite.get_sprite_type() == map_sprite_type.MstPlayer && !sprite.is_in_lvl) { pl.lx = pl.x; pl.ly = pl.y; } sprite.on_pos_change(pl.x, pl.y); return 0; }
public static int _update_pl_pt_move(IBaseUnit sprite, long cur_clock_tm) { var pl = sprite.get_pack_data(); var speed = pl.speed; // moving var tmleft = cur_clock_tm - pl.moving.start_tm; if (tmleft <= 0) { return 0; } var move_distance = (tmleft * speed) / 1000.0; for (; move_distance > 0 && pl.moving.pts.Count > 0;) { var pt = pl.moving.pts.pop(); var to_x = pt.x * game_const.map_grid_pixel + 16; var to_y = pt.y * game_const.map_grid_pixel + 16; //Utility.trace_err("pt.x: [" + pt.x + "] pt.y["+pt.y+"] to_x["+to_x+"] to_y["+to_y+"]\n"); if (to_x == pl.x && to_y == pl.y) { continue; } var x_dis = to_x - pl.x; var y_dis = to_y - pl.y; var distance = Math.Sqrt((x_dis) * (x_dis) + (y_dis) * (y_dis)); if (distance > move_distance) { pl.moving.float_x += (x_dis) / distance * move_distance; pl.moving.float_y += (y_dis) / distance * move_distance; pl.x = (int)(pl.moving.float_x); pl.y = (int)(pl.moving.float_y); //pl.x += ((to_x - pl.x)/distance * move_distance); //pl.y += ((to_y - pl.y)/distance * move_distance); //pl.x += (to_x - pl.x)/distance * move_distance; //pl.y += (to_y - pl.y)/distance * move_distance; move_distance = 0; pl.moving.pts.push(pt); if (sprite.get_sprite_type() == map_sprite_type.MstPlayer && !sprite.is_in_lvl) { pl.lx = pl.x; pl.ly = pl.y; } //Utility.trace_err("moving x: [" + pl.x +"] y:[" + pl.y + "] float_x["+pl.moving.float_x+"] float_y["+pl.moving.float_y+"] \n"); } else { move_distance -= distance; pl.x = (int)to_x; pl.y = (int)to_y; pl.moving.float_x = (to_x); pl.moving.float_y = (to_y); if (sprite.get_sprite_type() == map_sprite_type.MstPlayer) { if (!sprite.is_in_lvl) { pl.lx = pl.x; pl.ly = pl.y; } if (pl.moving.ppts == null) pl.moving.ppts = new List<Point2D>(); pl.moving.ppts.push(pt); // 记录历史经过的节点 } //Utility.trace_err("Rich x: [" + pl.x +"] y:[" + pl.y + "] float_x["+pl.moving.float_x+"] float_y["+pl.moving.float_y+"] \n"); } } sprite.on_pos_change(pl.x, pl.y); if (pl.moving.pts.Count <= 0) { if (pl.moving.ppts != null) pl.last_mvpts = pl.moving.ppts; pl.moving = null; //Utility.trace_err("Stop at x: [" + pl.x +"] y:[" + pl.y + "] \n"); return (int)(move_distance * 1000 / pl.speed); // 停止后剩余时间 } else { pl.moving.start_tm = cur_clock_tm; } return 0; }