I don't understand what you mean by "moonwalk". However, the order of your commands doesn't seem to be good. dbMoveObject moves the object in its current direction. In your code, you first move the object, then rotate it afterwards. Try to exchange that: first rotate, then move. (Although this won't change that much because the direction should be already correct on the second loop.) The angles should be 90 for right and 270 (or -90) for left, supposing that your character is facing away from you.
dbLoopObject has nothing to do with rotation but you will have a problem also with that. The animation will not be correct in this way, because you execute dbLoopObject over and over again, as long as the left or right key is pressed. Every time this command is called, it restarts the animation from the beginning, so you will always see the first frame. What you should do is to keep track of when the status of the object changes and then use dbLoopObject only once. You may need to introduce a player status variable which shows if the player is walking or standing and call dbLoopObject only when the status changes. (You might also need dbSetObjectFrame, to start the new animation from the correct starting frame instead of looping through other frames in between until the start frame is reached.)
Here is an example how I would try to implement it. The object is moved always when the left/right keys are pressed but turning and starting the animation happens only when the status changes. You can test if the dbSetObjectFrame is needed or not, I'm not quite sure about that.
I have also changed the coordinate conditions in your coordinate testing commands because if you are moving left, the X coordinates should get smaller and moving right, they should get bigger, so I think the -32 and 32 limits should be the other way around.
You can check also the animation frames because playing frames 25-50 for one direction and 25-47 for the other direction is a bit strange, shouldn't these frame numbers be the same?
Does that help at all? I haven't tested this code but I think it should work. Post again if it doesn't or if I misunderstood your question.
enum ePlayerDirection { eStanding, eLeft, eRight };
ePlayerDirection PlayerDir = eStanding;
if(dbLeftKey() && dbObjectPositionX(1) > -32)
{
if (PlayerDir != eLeft) {
PlayerDir = eLeft;
dbYRotateObject(1,270);
dbSetObjectFrame(1, 25);
dbLoopObject(1,25,50);
}
dbMoveObject(1,0.4f);
}
else if(dbRightKey() && dbObjectPositionX(1) < 32)
{
if (PlayerDir != eRight) {
PlayerDir = eRight;
dbYRotateObject(1,90);
dbSetObjectFrame(1, 25);
dbLoopObject(1,25,47);
}
dbMoveObject(1,0.4f);
}
else
{
if (PlayerDir != eStanding) {
PlayerDir = eStanding;
dbRotateObject(1,0,0,0);
dbSetObjectFrame(0, 25);
dbLoopObject(1,0,25);
}
}