home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 13
/
mediashare_13.zip
/
mediashare_13
/
ZIPPED
/
PROGRAM
/
WTJ9403.ZIP
/
BARNHART
/
SO_MISL.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-21
|
2KB
|
76 lines
// so_misl.cpp - Implements class Missile - the bullets the Player fires
// 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>
Missile::Missile( char *res) : ScreenItem( res)
{
SOType = TYPE_MISSILE;
inuse = FALSE;
Show( FALSE);
}
BOOL Missile::Update( void)
{
ScreenObj *SONxt;
RECT rc;
// We move twice per update cause Missiles are fast
// Rather than a convoluted loop (conditional logic would be hard to
// follow) we just do it twice
if( !inuse) return( FALSE);
SetRect( &rc);
inuse = ScreenItem::Update();
if( inuse)
{
// Loop through everything and see if we hit anything
for( SONxt = Background->Next(); SONxt != NULL; SONxt = SONxt->Next())
{
if( (SONxt != this) && (SONxt->InRect( &rc)))
if( SONxt->Hit( TYPE_MISSILE))
{
inuse = FALSE;
}
}
}
if( inuse)
{
SetRect( &rc);
inuse = ScreenItem::Update();
for( SONxt = Background->Next(); SONxt != NULL; SONxt = SONxt->Next())
{
if( (SONxt != this) && (SONxt->InRect( &rc)))
if( SONxt->Hit( TYPE_MISSILE))
{
inuse = FALSE;
}
}
}
if( !inuse && shown) Show( FALSE);
return( inuse);
}
// Being fired - set a target and let 'er rip...
void Missile::Fire( int sx, int sy, int tx, int ty)
{
Move( sx, sy - (height/2));
Show( TRUE);
if( sx > tx) sx -= width;
SetTarget( tx, ty );
inuse = TRUE;
}
// Note that we lie about our type if not in use. That's because we are just
// hidden at the last place we were shown, and not truly a hazard
int Missile::Type( void)
{
if( inuse)return TYPE_MISSILE;
return( NULL);
}