home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C++ Games Programming
/
CPPGAMES.ISO
/
thx
/
source
/
theatrix
/
player.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-26
|
3KB
|
137 lines
// ---------- player.cpp
#include "scenedir.h"
Player::Player(char *gl, char *sl, int intv)
{
gfxlib = gl;
sfxlib = sl;
x = y = 0;
px = py = 0;
pw = ph = 0;
h = w = 0;
imageno = 0;
is_visible = 0;
clipped = 0;
cx1 = cy1 = cx2 = cy2 = 0;
ticker = intv;
interval = intv;
in_update_position = 0;
posted_x = posted_y = -1;
posted_imageno = 0;
director = SceneDirector::thisscene;
set_director(director);
}
void Player::initialize()
{
if (gfxlib)
load_gfxlib(gfxlib);
if (sfxlib)
load_sfxlib(sfxlib);
director->addplayer(*this);
}
void Player::setx(short int nx)
{
if (!in_update_position)
posted_x = nx;
else
x = nx;
}
void Player::sety(short int ny)
{
if (!in_update_position)
posted_y = ny;
else
y = ny;
}
void Player::setxy(short int nx, short int ny)
{
setx(nx);
sety(ny);
}
void Player::set_imageno(short int in)
{
if (!in_update_position)
posted_imageno = in;
else {
imageno = in;
if (gfxlib) {
h = get_image_height(imageno);
w = get_image_width(imageno);
}
}
}
void Player::stillframe(short int im, short int wait)
{
short int svticker = ticker;
short int svimageno = imageno;
ticker = -1;
imageno = im;
director->scanframes();
imageno = svimageno;
ticker = svticker;
if (wait)
fg_waitfor(wait);
}
void Player::displayframe()
{
if (is_visible) {
px = x;
py = y;
ph = h;
pw = w;
if (pw)
VideoDirector::set_synch_patch(px, py, px+pw-1, py+ph-1);
if (ticker == interval) {
in_update_position++;
// ---- if x, y, or imageno were changed outside of
// update_position, make those changes now
if (posted_x != -1)
setx(posted_x);
if (posted_y != -1)
sety(posted_y);
if (posted_imageno != 0)
set_imageno(posted_imageno);
posted_imageno = 0;
posted_x = posted_y = -1;
// --- call derived player to update screen image, position
update_position();
--in_update_position;
ticker = 0;
}
ticker++;
if (imageno && is_visible) // update might have changed is_visible
if (clipped) {
fg_setclip(cx1,cx2,cy1,cy2);
show_clipped_image(x, y, imageno);
}
else
show_image(x, y, imageno);
}
}
void Player::disappear()
{
if (is_visible) {
if (imageno && pw) {
VideoDirector::restore_patch(px, py, px+pw-1, py+ph-1);
VideoDirector::flush_patch(px, py, px+pw-1, py+ph-1);
}
is_visible = 0;
}
}
void Player::clip(int x1, int y1, int x2, int y2)
{
clipped = 1;
cx1 = x1;
cy1 = y1;
cx2 = x2;
cy2 = y2;
}