Process MyCharacter (x,y);// Or whatever you want really
PRIVATE
dir=3;
speed=-7;
status=0;
incx,incy;
//Working speed:
runspeed = 4;
animspeed = 2;
//Wait for a given amount of frames, looking in the specified direction
waitframes = 0;
waitdir;
i;
STRUCT run[3] //four directions
STRUCT anim[5] //6 frames each animation
f;
END
END=2,3,4,5,6,7, //right
9,10,11,12,13,14, //left
16,17,18,19,20,21, //up
23,24,25,26,27,28; //down
STRUCT stop[3] //four directions
f;
END=1,8,15,22;
BEGIN
ctype=c_scroll; // He'll scroll with the background
scroll.camera=id; // The camera will focus on him during the scroll
LOOP
IF (key(_left)) // left-key
dir=1; //look at the correct direction
status=1; //run
incx=-runspeed; //move horizontally
ELSE
IF (key(_right)) //right-key
dir=0;
status=1;
incx=runspeed;
ELSE //neither left nor right are pressed
incx=0; //the chara's not moving horizontally
IF (key(_up)) //up-key
dir=2;
status=1;
incy=-runspeed;
ELSE
IF (key(_down)) //down-key
dir=3;
status=1;
incy=runspeed;
ELSE //no key is pressed
incy=0; //don't move vertically
status=0; //keep still
i=0; //re-start animation
END
END
END
END
if(waitframes > 0)
status = 0;
waitframes--;
//Set direction to the desired one
dir = waitdir;
//No moving!
incx = 0;
incy = 0;
end
x+=incx; //increase x
y+=incy; //increase y
//let's give a graph to the chara
SWITCH (status)
CASE 0: //stopped
graph=stop[dir].f;
END
CASE 1: //running
graph=run[dir].anim[i/animspeed].f;
i=(i+1) % (6*animspeed); //i goes from 0 to 6*animspeed :)
END
END
FRAME;
END
END