home *** CD-ROM | disk | FTP | other *** search
- #include <fastgraf.h>
- #include <string.h>
- #include "demo.h"
-
- const int IMAGENO = 1;
-
- Sprite::Sprite(char* gfxlibname,char* sfxlibname)
- {
- strcpy(gfxlib,gfxlibname);
- strcpy(sfxlib,sfxlibname);
- image=IMAGENO;
- }
-
- void Sprite::initialize()
- {
- load_gfxlib(gfxlib);
- load_sfxlib(sfxlib);
- w=get_image_width(image);
- h=get_image_height(image);
- xq[0]=xq[1]=0;
- yq[0]=yq[1]=0;
- }
-
- void Sprite::bounce()
- {
- play_sound_clip(1);
- }
-
- void Sprite::move_to(int newx,int newy)
- {
- static int qi;
- VideoDirector::restore_patch(xq[qi],yq[qi],xq[qi]+w-1,yq[qi]+h-1);
- show_image(newx,newy,image);
- xq[qi]=newx;
- yq[qi]=newy;
-
- qi=(qi+1)%2;
- }
-
- CUELIST(DemoDirector)
- TIMER(18,on_timer)
- KEYSTROKE(ESC,on_esc)
- ENDCUELIST
-
- DemoDirector::DemoDirector()
- {
- moon=new Sprite("demo.gfx","demo.sfx");
- x=y=20;
- xinc=yinc=INC;
- }
-
- void DemoDirector::display()
- {
- init_video();
- show_pcx("planet.pcx");
- swap_video_pages();
- synch_video_pages();
- fill_background_buffer(active_page());
- }
-
- void DemoDirector::on_timer()
- {
- moon->move_to(x+=xinc,y+=yinc);
- swap_video_pages();
-
- if (x<5 || x>280)
- {
- xinc=-xinc;
- moon->bounce();
- }
- if (y<5 || y>190)
- {
- yinc=-yinc;
- moon->bounce();
- }
- }
-
- void DemoDirector::on_esc(int)
- {
- stop_director();
- }
-
- class PlanetDemo : public Theatrix
- {
- public:
- PlanetDemo() : Theatrix("Planet")
- {
- demo=new DemoDirector;
- }
- ~PlanetDemo()
- {
- delete demo;
- }
- private:
- DemoDirector* demo;
- };
-
- void main()
- {
- PlanetDemo demo;
- demo.go();
- }
-