Really, I have this figured out. Or so I thought. No matter how many times I go over this code it appears solid. A little background: the heirarchy goes
[font=Fixedsys][size=2]_root
…main
…terrain
…user
[/size][/font]
The user is essentially a 30 by 60 pixel rectangle controlled by arrow keys. At this point, all I’m trying to accomplish is to have the user move around without going through the terrain.
Here’s the code on the terrain. If any of the user’s points are more than 0.2 pixels deep into the ground, the user is moved 0.1 pixels out. That’s the idea, anyhow.
onClipEvent (load) {
z = 0.2;
y = 0.1;
}
onClipEvent (enterFrame) {
for (i=0; i<=6; i++) {
//Left
if (hitTest(_parent.user._x+_parent._x, i*10+_parent.user._y+_parent._y, true)) {
_parent.user.leftClear = false;
} else {
_parent.user.leftClear = true;
}
while (hitTest(_parent.user._x+_parent._x-z, i*10+_parent.user._y+_parent._y, true)) {
_parent.user._x += y;
}
//Right
if (hitTest(_parent.user._x+_parent._x+30, i*10+_parent.user._y+_parent._y, true)) {
_parent.user.rightClear = false;
} else {
_parent.user.rightClear = true;
}
while (hitTest(_parent.user._x+_parent._x+30+z, i*10+_parent.user._y+_parent._y, true)) {
_parent.user._x -= y;
}
if (i<=3) {
//Up
if (hitTest(i*10+_parent.user._x+_parent._x, _parent.user._y+_parent._y, true)) {
_parent.user.upClear = false;
} else {
_parent.user.upClear = true;
}
while (hitTest(i*10+_parent.user._x+_parent._x, _parent.user._y+_parent._y-z, true)) {
_parent.user._y += y;
}
//Down
if (hitTest(i*10+_parent.user._x+_parent._x, _parent.user._y+_parent._y+60, true)) {
_parent.user.downClear = false;
} else {
_parent.user.downClear = true;
}
while (hitTest(i*10+_parent.user._x+_parent._x, _parent.user._y+_parent._y+60+z, true)) {
_parent.user._y -= y;
}
}
}
}