home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / source / theatrix / player.cpp < prev    next >
C/C++ Source or Header  |  1995-04-26  |  3KB  |  137 lines

  1. // ---------- player.cpp
  2.  
  3. #include "scenedir.h"
  4.  
  5. Player::Player(char *gl, char *sl, int intv)
  6. {
  7.     gfxlib = gl;
  8.     sfxlib = sl;
  9.     x = y = 0;
  10.     px = py = 0;
  11.     pw = ph = 0;
  12.     h = w = 0;
  13.     imageno = 0;
  14.     is_visible = 0;
  15.     clipped = 0;
  16.     cx1 = cy1 = cx2 = cy2 = 0;
  17.     ticker = intv;
  18.     interval = intv;
  19.     in_update_position = 0;
  20.     posted_x = posted_y = -1;
  21.     posted_imageno = 0;
  22.     director = SceneDirector::thisscene;
  23.     set_director(director);
  24. }
  25.  
  26. void Player::initialize()
  27. {
  28.     if (gfxlib)
  29.         load_gfxlib(gfxlib);
  30.     if (sfxlib)
  31.         load_sfxlib(sfxlib);
  32.     director->addplayer(*this);
  33. }
  34.  
  35. void Player::setx(short int nx)
  36. {
  37.     if (!in_update_position)
  38.         posted_x = nx;
  39.     else 
  40.         x = nx;
  41. }
  42. void Player::sety(short int ny)
  43. {
  44.     if (!in_update_position)
  45.         posted_y = ny;
  46.     else 
  47.         y = ny;
  48. }
  49. void Player::setxy(short int nx, short int ny)
  50. {
  51.     setx(nx);
  52.     sety(ny);
  53. }
  54. void Player::set_imageno(short int in)
  55. {
  56.     if (!in_update_position)
  57.         posted_imageno = in;
  58.     else     {
  59.         imageno = in;
  60.         if (gfxlib)    {
  61.             h = get_image_height(imageno);
  62.             w = get_image_width(imageno);
  63.         }
  64.     }
  65. }
  66.  
  67. void Player::stillframe(short int im, short int wait)
  68. {
  69.     short int svticker = ticker;
  70.     short int svimageno = imageno;
  71.     ticker = -1;
  72.     imageno = im;
  73.     director->scanframes();
  74.     imageno = svimageno;
  75.     ticker = svticker;
  76.     if (wait)
  77.         fg_waitfor(wait);
  78. }
  79.  
  80. void Player::displayframe()
  81. {
  82.     if (is_visible)    {
  83.         px = x;
  84.         py = y;
  85.         ph = h;
  86.         pw = w;
  87.         if (pw)
  88.             VideoDirector::set_synch_patch(px, py, px+pw-1, py+ph-1);
  89.         if (ticker == interval)    {
  90.             in_update_position++;
  91.             // ---- if x, y, or imageno were changed outside of
  92.             //      update_position, make those changes now
  93.             if (posted_x != -1)
  94.                 setx(posted_x);
  95.             if (posted_y != -1)
  96.                 sety(posted_y);
  97.             if (posted_imageno != 0)
  98.                 set_imageno(posted_imageno);
  99.             posted_imageno = 0;
  100.             posted_x = posted_y = -1;
  101.             // --- call derived player to update screen image, position
  102.             update_position();
  103.             --in_update_position;
  104.             ticker = 0;
  105.         }
  106.         ticker++;
  107.         if (imageno && is_visible)    // update might have changed is_visible
  108.             if (clipped)    {
  109.                 fg_setclip(cx1,cx2,cy1,cy2);
  110.                 show_clipped_image(x, y, imageno);
  111.             }
  112.             else 
  113.                 show_image(x, y, imageno);
  114.     }
  115. }
  116.  
  117. void Player::disappear()
  118. {
  119.     if (is_visible)    {
  120.         if (imageno && pw)    {
  121.             VideoDirector::restore_patch(px, py, px+pw-1, py+ph-1);
  122.             VideoDirector::flush_patch(px, py, px+pw-1, py+ph-1);
  123.         }
  124.         is_visible = 0;
  125.     }
  126. }
  127.  
  128. void Player::clip(int x1, int y1, int x2, int y2)
  129. {
  130.     clipped = 1;
  131.     cx1 = x1;
  132.     cy1 = y1;
  133.     cx2 = x2;
  134.     cy2 = y2;
  135. }
  136.  
  137.