Main Menu


Sponsored Links

  


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

Working Example

This example may look little artificial. We'll be able to make it better after getting familiar with iterations and loops. Anyway, let's make a simple cartoon where a boy character is walking for 5 seconds and every half a second he will do some actions. He will wink with his right eye until reaching the screen center, and then he'll say "Switch" and start winking with his left eye:

#include <boy.h>


void DoWinking ( Boy &Who )

{

if ( Who.GetX () < -0.1 )

{

Who.WinksLeft ();

}

else if ( Who.GetX () > 0.1 )

{

Who.WinksRight ();

}

else

{

Who.Says ( "Switch" );

Sleep ( 0.5 );

}

}


void Scene1 ()

{

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

Back.SetVisible ();


Boy Max;

Max.SetVisible ( true );

Max.SetPos ( 200, 290 );

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


SetTime ( 0 );


DoWinking ( Max );

DoWinking ( Max );

DoWinking ( Max );

DoWinking ( Max );

DoWinking ( Max );

DoWinking ( Max );

DoWinking ( Max );

DoWinking ( Max );

DoWinking ( Max );

DoWinking ( Max );

}

Please note that we compare results of method GetX with 0.1 and -01 , not with zero. This is because GetX returns a double value, not an int . During floating point operations precision may be lost a little bit and we do not want to miss the moment when character should say "Switch" . You should see the following movie:




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