Here is what it looks like now which works much better than the code above:
if (ego_on_water) {
set.view(ego,1);
if (!f100) {
if ((ego_dir == 6 || //if ego walking left
ego_dir == 7 ||
ego_dir == 8 )) {
new_ego_x = new_ego_x - 6; //if the width of the side view of the swimming ego is bigger
//than the width of the side ego walking subtract swim view
//from the walking view. I got 6.
object.on.water(ego);
}
if (ego_dir == 5) {
new_ego_y = new_ego_y + 10;
}
erase(ego);
position.v(ego,new_ego_x,new_ego_y);
draw(ego);
}
get.posn(ego,new_ego_x,new_ego_y);
if (new_ego_y == 72 && ego_dir == 1) {
new_ego_y = new_ego_y - 10;
erase(ego);
position.v(ego,new_ego_x,new_ego_y);
draw(ego);
}
set(f100);
set(always_animate_ego);
}
else {
set.view(ego,0);
if (f100) {
if ((ego_dir == 2 ||
ego_dir == 3 ||
ego_dir == 4)) {
new_ego_x = new_ego_x + 11; //set 11 to the size of the width of the swimming view's side
object.on.land(ego);
}
erase(ego);
position.v(ego,new_ego_x,new_ego_y);
draw(ego);
object.on.land(ego);
}
reset(f100);
reset(always_animate_ego);
}
You still will need to change some values depending on the size of the ego's view and the ego's swimming view.