home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 13
/
mediashare_13.zip
/
mediashare_13
/
ZIPPED
/
PROGRAM
/
WTJ9403.ZIP
/
BARNHART
/
SO_CREEP.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-21
|
3KB
|
130 lines
// so_creep.cpp - Implements Creepers - thos little bugs running along
// platforms giving our hero a hard time
// Andy Barnhart
// This program is provided as a sample to accompany an article on graphics
// animation using C++
// This seems to work for me and I hope it works for you. No other warranty
// is expressed or implied.
#include <so_all.hpp>
#define CR_UP 0
#define CR_DN 1
#define CR_DEAD 2
Creeper::Creeper( char *res, Wall *wall, int ibx, int iex) : ScreenItem( NULL)
{
int i;
char acIc[32];
int len;
strcpy( acIc, res);
len = strlen( acIc);
strcat( acIc, "0");
for(i = 0; i < 3; i++)
{
acIc[len]++;
frames[i] = LoadBitmap( hInst, acIc);
}
SelectBM( frames[0]);
state = CR_UP;
live = TRUE;
if( ibx == -1)
{
bx = wall->x + width/2;
ex = (bx + (wall->width * wall->mems)) - width;
}
else
{
bx = ibx;
ex = iex;
}
Move( bx, wall->y);
OnTop( wall->y);
SetTarget( ex, y + height/2);
}
Creeper::~Creeper(void)
{
int i;
for(i = 0; i < 3; i++)
{
if (frames[i]) DeleteObject( frames[i]);
}
hbmImage = NULL;
}
BOOL Creeper::Update()
{
ScreenObj *SONxt;
RECT rc;
if( !live) return( FALSE);
if( state == CR_UP)
state = CR_DN;
else
state = CR_UP;
SelectBM( frames[state]);
SetRect( &rc);
for( SONxt = Background->Next(); SONxt != NULL; SONxt = SONxt->Next())
{
if( (SONxt != this) && (SONxt->shown) && (SONxt->InRect( &rc)))
{
int hit;
SONxt->Hit( TYPE_HAZARD);
hit = SONxt->Type();
if( (hit == TYPE_MISSILE) || (hit == TYPE_HAZARD) )
{
Hit( hit);
return( FALSE);
}
}
}
if (! ScreenItem::Update())
{
if(x > bx)
SetTarget( bx, y + height/2);
else
SetTarget( ex, y + height/2);
}
SetRect( &rc);
for( SONxt = Background->Next(); SONxt != NULL; SONxt = SONxt->Next())
{
if( (SONxt != this) && (SONxt->shown) && (SONxt->InRect( &rc)))
{
int hit;
SONxt->Hit( TYPE_HAZARD);
hit = SONxt->Type();
if( (hit == TYPE_MISSILE) || (hit == TYPE_HAZARD) )
{
Hit(hit);
return( FALSE);
}
}
}
return( TRUE);
}
int Creeper::Type()
{
if( live) return( TYPE_HAZARD);
return(NULL);
}
BOOL Creeper::Hit( int type)
{
if( (type == TYPE_MISSILE) || (type == TYPE_HAZARD) )
{
state = CR_DEAD;
live = FALSE;
SelectBM( frames[state]);
Paint();
return( TRUE);
}
return( FALSE);
}