Main Menu


Sponsored Links

  


  
  
Web Cartoon Maker: a Fun Way to Learn C++ Contents Previous Next

Changing Walking Style

First we derive a new class from Boy and update the walking style:

#include <boy.h>


class BoyEx : public Boy

{

public :


BoyEx () : Boy ()

{

}

void GoesTo ( double dX, double dY, double dDuration,

double dStepDuration = 1 )

{

double dStartTime = GetTime (); // remember start time

SetPos ( GetX (), GetY () ); // initial control point


// lets split a step into 4 stages

for ( int i=0; i<dDuration * 4 / dStepDuration; i++ )

{

// set time for current stage

SetTime ( dStartTime + i * dStepDuration / 4 );


// if this is a first stage

if ( i%4 == 0 )

{

LeftLeg.SetShift ( 0, 0 );

LeftLeg.SetAngle ( 0 );

RightLeg.SetShift ( 0, 0 );

RightLeg.SetAngle ( 0 );

continue ;

}


// if this is a second stage

if ( i%4 == 1 )

{

LeftLeg.SetShift ( 0, -30 );

LeftLeg.SetAngle ( - 45 );

RightLeg.SetShift ( 0, 0 );

RightLeg.SetAngle ( 0 );

continue ;

}


// if this is a third stage

if ( i%4 == 2 )

{

LeftLeg.SetShift ( 0, 0 );

LeftLeg.SetAngle ( 0 );

RightLeg.SetShift ( 0, 0 );

RightLeg.SetAngle ( 0 );

continue ;

}


// if this is a fourth stage

if ( i%4 == 3 )

{

LeftLeg.SetShift ( 0, 0 );

LeftLeg.SetAngle ( 0 );

RightLeg.SetShift ( 0, -30 );

RightLeg.SetAngle ( - 45 );

}

}


// ending control point

SetTime ( dStartTime + dDuration );

SetPos ( dX, dY );

LeftLeg.SetShift ( 0, 0 );

LeftLeg.SetAngle ( 0 );

RightLeg.SetShift ( 0, 0 );

RightLeg.SetAngle ( 0 );

}

};


void Scene1 ()

{

Image Back ( "backgrounds/house.svg" );

Back.SetVisible ( true );


BoyEx Max;

Max.SetVisible ();

Max.SetPos ( 300, 290 );

Max.GoesTo ( -300, 290 , 5 );

}

If you compile the above example you will see that walking style is changed and Boy bends his legs when walking and does not move his hands at all:

Although we have created a new sub-class for Boy, the Boy class is unchanged and can also be used to instantiate “boys” who will swing their arms when walking.


Contents Previous Next
  
News

New Tales Animator Video by Alan Sturgess

Alan Sturgess shared an excellent video he made using Tales Animator! You can still download Tales Animator here. Unfortunately it is only available for Wi

...

Simple Online Character Designer

There is a prototype of simple online character designer available HERE. It is only a prototype, it does not contain many pieces yet but it can already generat

...

Book is updated

Now our book "Web Cartoon Maker: A Fun Way to Learn C++" is fully in synch with WCM 1.5! It is available for download and online reading HERE.

...

Web Cartoon Maker 1.5 is here!

Web Cartoon Maker 1.5 is finally here! You can download it HERE! Here is what was updated in version 1.5: Web Cartoon Maker Desktop Edition is now fully standal

...

read more news...


Poll