This commit is contained in:
Charles 2001-06-19 18:07:05 +00:00
parent 535bf66251
commit 46b712d98d
3 changed files with 132 additions and 7 deletions

View File

@ -259,23 +259,26 @@ void CNpcIronDogfishEnemy::processStandardIronDogfishAttack( int _frames )
startPos.vy -= 20; startPos.vy -= 20;
projectile->init( startPos, headingToPlayer );*/ projectile->init( startPos, headingToPlayer );*/
m_laserTimer = GameState::getOneSecondInFrames(); m_laserTimer = 60 * GameState::getOneSecondInFrames();
m_effect = (CFXLaser*) CFX::Create( CFX::FX_TYPE_LASER, this ); m_effect = (CFXLaser*) CFX::Create( CFX::FX_TYPE_LASER, this );
DVECTOR targetPos = GameScene.getPlayer()->getPos();
targetPos.vy -= 45;
m_effect->setTarget( targetPos );
DVECTOR offsetPos; DVECTOR offsetPos;
if ( m_heading == 0 ) if ( m_heading == 0 )
{ {
offsetPos.vx = 30; offsetPos.vx = 60;
} }
else else
{ {
offsetPos.vx = -30; offsetPos.vx = -60;
} }
offsetPos.vy = -45; offsetPos.vy = -45;
m_effect->setOffset( offsetPos ); m_effect->setOffset( offsetPos );
DVECTOR targetPos = GameScene.getPlayer()->getPos();
targetPos.vy -= 45;
m_effect->setTarget( targetPos );
m_effect->setRGB( 255, 0, 0 ); m_effect->setRGB( 255, 0, 0 );
m_state++; m_state++;

View File

@ -14,6 +14,10 @@
#include "FX\FXLaser.h" #include "FX\FXLaser.h"
#ifndef __PLAYER_PLAYER_H__
#include "player\player.h"
#endif
int LaserWidth=1; int LaserWidth=1;
/*****************************************************************************/ /*****************************************************************************/
@ -80,10 +84,125 @@ POLY_F4 *P=GetPrimF4();
int W=renderPos1.vx-renderPos0.vx; int W=renderPos1.vx-renderPos0.vx;
int H=renderPos1.vy-renderPos0.vy; int H=renderPos1.vy-renderPos0.vy;
setCollisionCentreOffset( (W>>1) + Offset.vx, (H>>1) + Offset.vy );
if (W<0) W=-W; if (W<0) W=-W;
if (H<0) H=-H; if (H<0) H=-H;
setCollisionCentreOffset(W>>1,H>>1);
setCollisionSize(W,H); setCollisionSize(W,H);
} }
/*****************************************************************************/
/*** checkCollisionAgainst ***************************************************/
/*****************************************************************************/
int CFXLaser::checkCollisionAgainst(CThing *_thisThing, int _frames)
{
DVECTOR pos,thisThingPos;
int radius;
int collided;
pos=getCollisionCentre();
thisThingPos=_thisThing->getCollisionCentre();
radius=getCollisionRadius()+_thisThing->getCollisionRadius();
collided=false;
if(abs(pos.vx-thisThingPos.vx)<radius&&
abs(pos.vy-thisThingPos.vy)<radius)
{
CRECT thisRect,thatRect;
thisRect=getCollisionArea();
thatRect=_thisThing->getCollisionArea();
if(((thisRect.x1>=thatRect.x1&&thisRect.x1<=thatRect.x2)||(thisRect.x2>=thatRect.x1&&thisRect.x2<=thatRect.x2)||(thisRect.x1<=thatRect.x1&&thisRect.x2>=thatRect.x2))&&
((thisRect.y1>=thatRect.y1&&thisRect.y1<=thatRect.y2)||(thisRect.y2>=thatRect.y1&&thisRect.y2<=thatRect.y2)||(thisRect.y1<=thatRect.y1&&thisRect.y2>=thatRect.y2)))
{
// bounding boxes touch, now check for line vs box collision
s32 w = thatRect.x2 - thatRect.x1;
s32 h = thatRect.y2 - thatRect.y1;
s32 a = ( thatRect.x1 + thatRect.x2 ) >> 1;
s32 b = ( thatRect.y1 + thatRect.y2 ) >> 1;
s32 x1 = Pos.vx + Offset.vx;
s32 y1 = Pos.vy + Offset.vy;
s32 x2 = Target.vx;
s32 y2 = Target.vy;
s32 t1, t2, t3, t4;
if ( x1 == x2 )
{
// vertical line
// bounding boxes already colliding
collided = true;
}
else if ( y1 == y2 )
{
// horizontal line
// bounding boxes already colliding
collided = true;
}
else
{
// see http://www.flipcode.com/tpractice/issue01.shtml
t1 = ( ( ( w >> 1 ) - x1 + a ) << 8 ) / ( x2 - x1 );
t2 = ( ( -( ( w >> 1 ) + x1 - a ) ) << 8 ) / ( x2 - x1 );
t3 = ( ( ( h >> 1 ) - y1 + b ) << 8 ) / ( y2 - y1 );
t4 = ( ( -( ( h >> 1 ) + y1 - b ) ) << 8 ) / ( y2 - y1 );
if ( t1 > t2 )
{
s32 temp = t2;
t2 = t1;
t1 = temp;
}
if ( t3 > t4 )
{
s32 temp = t4;
t4 = t3;
t3 = temp;
}
if ( t1 < t4 && t3 < t2 )
{
collided = true;
}
}
}
}
return collided;
}
/*****************************************************************************/
/*** CollidedWith ************************************************************/
/*****************************************************************************/
void CFXLaser::collidedWith(CThing *_thisThing)
{
switch(_thisThing->getThingType())
{
case TYPE_PLAYER:
{
CPlayer *player = (CPlayer *) _thisThing;
if ( !player->isRecoveringFromHit() )
{
player->takeDamage( DAMAGE__HIT_ENEMY );
}
break;
}
default:
break;
}
}

View File

@ -14,6 +14,8 @@ public:
void init(DVECTOR const &Pos); void init(DVECTOR const &Pos);
void think(int _frames); void think(int _frames);
void render(); void render();
virtual int canCollide() {return true;}
virtual int checkCollisionAgainst(CThing *_thisThing, int _frames);
void setOffset(DVECTOR &Pos); void setOffset(DVECTOR &Pos);
void setTarget(DVECTOR &Pos); void setTarget(DVECTOR &Pos);
@ -21,6 +23,7 @@ public:
void setRGB(u8 r,u8 g,u8 b) {R=r; G=g; B=g;} void setRGB(u8 r,u8 g,u8 b) {R=r; G=g; B=g;}
protected: protected:
virtual void collidedWith(CThing *_thisThing);
DVECTOR Offset,Target; DVECTOR Offset,Target;
u8 R,G,B; u8 R,G,B;
}; };