Request for Pseudo Code -- sprite anims

Started by
2 comments, last by Dim_Yimma_H 19 years, 6 months ago
Ok. So I've read my C primer books and my Allegro books and I'm confident enough about what I'm doing to start my game. Only one thing eludes me: multiple sprite animations. I've got a big .bmp file with all the idle, running, jumping, crouching anims for my platformer guy, and I've got the necessary frame grabbing algorithm sorted. All I need is some pseudo code to help me organise what I'm doing -- how should I set up my code so that the appropriate anim plays when running left, right, standing, shooting etc? Any help very much appreciated...! Dan
Dan Marshallwww.gibbage.co.ukhttp://gibbage.blogspot.com
Advertisement
There are many ways to do it here's one:

//data//enum all the parts of the animation (parts in your bitmap)enum moves{STAND1,STAND2,STAND3,RUNLEFT1,RUNLEFT2,JUMP1 //and so on};//structure for source image data (where to copy from in the bitmap)struct sourceCoordinates{int x1, y1, x2, y2;};//array of source image data (source rectangles)source mySourceCoordinates ={{0, 0, 10, 10}, //corresponds to STAND1{10, 0, 20, 10}, //corresponds to STAND2{20, 0, 30, 10} //and so on}//variable that keeps track of the current animation of a playerint playerMove;//animation functionvoid Animate(){//setup sequence (pressing keys, moving around)//in this case the result of it was RUNLEFT1playerMove = RUNLEFT1;int x1 = mySourceCoordinates[playerMove].x1;int y1 = mySourceCoordinates[playerMove].y1;int x2 = mySourceCoordinates[playerMove].x2;//...and so on//draw the image from your source rectangle here!}


That's it, a simple method, probably there are more effective ones but this one works fine to start with.

\Jimmy H
Fantastic. Many thanks for your help... can't wait to get started, now...

Have booked saturday as "the big off" for this project...!
Dan Marshallwww.gibbage.co.ukhttp://gibbage.blogspot.com
Good luck with your game!

This topic is closed to new replies.

Advertisement