diff --git a/source/enemy/nanemone.cpp b/source/enemy/nanemone.cpp index b9b574610..6055ec417 100644 --- a/source/enemy/nanemone.cpp +++ b/source/enemy/nanemone.cpp @@ -133,6 +133,7 @@ void CNpcEnemy::processCloseAnemone1Attack( int _frames ) CProjectile *projectile; projectile = new( "test projectile" ) CProjectile; projectile->init( Pos, m_heading ); + projectile->setLayerCollision( m_layerCollision ); m_controlFunc = NPC_CONTROL_MOVEMENT; m_timerTimer = GameState::getOneSecondInFrames(); @@ -200,6 +201,7 @@ void CNpcEnemy::processCloseAnemone2Attack( int _frames ) projectile = new( "anemone lev2 projectile" ) CProjectile; projectile->init( spikePos, heading, CProjectile::PROJECTILE_FIXED, CProjectile::PROJECTILE_INFINITE_LIFE ); + projectile->setLayerCollision( m_layerCollision ); addChild( projectile ); } @@ -230,6 +232,7 @@ void CNpcEnemy::processCloseAnemone3Attack( int _frames ) CProjectile::PROJECTILE_GAS_CLOUD, CProjectile::PROJECTILE_FINITE_LIFE, lifetime * GameState::getOneSecondInFrames() ); + projectile->setLayerCollision( m_layerCollision ); m_controlFunc = NPC_CONTROL_MOVEMENT; m_timerFunc = NPC_TIMER_ATTACK_DONE; diff --git a/source/enemy/ndogfish.cpp b/source/enemy/ndogfish.cpp index 30feb908b..d0c6e4ecd 100644 --- a/source/enemy/ndogfish.cpp +++ b/source/enemy/ndogfish.cpp @@ -136,6 +136,7 @@ void CNpcEnemy::processStandardIronDogfishAttack( int _frames ) CProjectile *projectile; projectile = new( "test projectile" ) CProjectile; projectile->init( Pos, headingToPlayer ); + projectile->setLayerCollision( m_layerCollision ); m_state++; diff --git a/source/enemy/nfdutch.cpp b/source/enemy/nfdutch.cpp index daaf6a039..9eff5015f 100644 --- a/source/enemy/nfdutch.cpp +++ b/source/enemy/nfdutch.cpp @@ -151,6 +151,7 @@ void CNpcEnemy::processCloseFlyingDutchmanAttack( int _frames ) CProjectile *projectile; projectile = new( "test projectile" ) CProjectile; projectile->init( Pos, heading ); + projectile->setLayerCollision( m_layerCollision ); m_controlFunc = NPC_CONTROL_MOVEMENT; m_movementTimer = GameState::getOneSecondInFrames() * 3; diff --git a/source/enemy/ngpirate.cpp b/source/enemy/ngpirate.cpp index b8a008eac..af9dc31a1 100644 --- a/source/enemy/ngpirate.cpp +++ b/source/enemy/ngpirate.cpp @@ -68,6 +68,7 @@ void CNpcEnemy::processCloseGhostPirateAttack( int _frames ) projectile = new( "test projectile" ) CProjectile; projectile->init( Pos, heading ); + projectile->setLayerCollision( m_layerCollision ); } } else if ( m_extendDir == EXTEND_DOWN ) diff --git a/source/enemy/npc.cpp b/source/enemy/npc.cpp index eba19c922..19d24c882 100644 --- a/source/enemy/npc.cpp +++ b/source/enemy/npc.cpp @@ -437,6 +437,7 @@ void CNpcEnemy::postInit() CProjectile *projectile; projectile = new ( "eyeball projectile" ) CProjectile; projectile->init( Pos, m_fireHeading, CProjectile::PROJECTILE_FIXED, CProjectile::PROJECTILE_INFINITE_LIFE ); + projectile->setLayerCollision( m_layerCollision ); addChild( projectile ); @@ -461,6 +462,7 @@ void CNpcEnemy::postInit() projectile = new( "anemone lev2 projectile" ) CProjectile; projectile->init( spikePos, heading, CProjectile::PROJECTILE_FIXED, CProjectile::PROJECTILE_INFINITE_LIFE ); + projectile->setLayerCollision( m_layerCollision ); addChild( projectile ); } diff --git a/source/enemy/nsshark.cpp b/source/enemy/nsshark.cpp index f8c7a1240..17f0a2a5b 100644 --- a/source/enemy/nsshark.cpp +++ b/source/enemy/nsshark.cpp @@ -59,6 +59,7 @@ void CNpcEnemy::processSubSharkMovement( int _frames ) CProjectile *projectile; projectile = new( "test projectile" ) CProjectile; projectile->init( Pos, 1024 ); + projectile->setLayerCollision( m_layerCollision ); m_salvoCount--; diff --git a/source/projectl/projectl.cpp b/source/projectl/projectl.cpp index bc6e8ec98..6355c4fed 100644 --- a/source/projectl/projectl.cpp +++ b/source/projectl/projectl.cpp @@ -230,30 +230,38 @@ void CProjectile::think(int _frames) case PROJECTILE_USER_SEEK: { - switch( m_state ) + if ( m_layerCollision->Get( Pos.vx >> 4, Pos.vy >> 4 ) ) { - case PROJECTILE_RETURN: + shutdown(); + delete this; + } + else + { + switch( m_state ) { - if ( processTargetSeek( _frames, Parent->getPos() ) ) + case PROJECTILE_RETURN: { - Parent->processEvent( PROJECTILE_RETURNED_TO_SOURCE_EVENT, this ); + if ( processTargetSeek( _frames, Parent->getPos() ) ) + { + Parent->processEvent( PROJECTILE_RETURNED_TO_SOURCE_EVENT, this ); + } + + break; } - break; - } - - case PROJECTILE_ATTACK: - default: - { - CPlayer *player = GameScene.getPlayer(); - DVECTOR playerPos = player->getPos(); - - if ( processTargetSeek( _frames, playerPos ) ) + case PROJECTILE_ATTACK: + default: { - m_state = PROJECTILE_RETURN; - } + CPlayer *player = GameScene.getPlayer(); + DVECTOR playerPos = player->getPos(); - break; + if ( processTargetSeek( _frames, playerPos ) ) + { + m_state = PROJECTILE_RETURN; + } + + break; + } } } @@ -283,8 +291,16 @@ void CProjectile::think(int _frames) case PROJECTILE_DUMBFIRE: default: { - Pos.vx += ( _frames * 3 * rcos( m_heading ) ) >> 12; - Pos.vy += ( _frames * 3 * rsin( m_heading ) ) >> 12; + if ( m_layerCollision->Get( Pos.vx >> 4, Pos.vy >> 4 ) ) + { + shutdown(); + delete this; + } + else + { + Pos.vx += ( _frames * 3 * rcos( m_heading ) ) >> 12; + Pos.vy += ( _frames * 3 * rsin( m_heading ) ) >> 12; + } break; } @@ -416,8 +432,16 @@ void CPlayerProjectile::think(int _frames) case PLAYER_PROJECTILE_DUMBFIRE: default: { - Pos.vx += ( _frames * 3 * rcos( m_heading ) ) >> 12; - Pos.vy += ( _frames * 3 * rsin( m_heading ) ) >> 12; + if ( m_layerCollision->Get( Pos.vx >> 4, Pos.vy >> 4 ) ) + { + shutdown(); + delete this; + } + else + { + Pos.vx += ( _frames * 3 * rcos( m_heading ) ) >> 12; + Pos.vy += ( _frames * 3 * rsin( m_heading ) ) >> 12; + } break; } diff --git a/source/projectl/projectl.h b/source/projectl/projectl.h index 044bfdfc4..13fdc10e6 100644 --- a/source/projectl/projectl.h +++ b/source/projectl/projectl.h @@ -56,6 +56,10 @@ public: void setState( PROJECTILE_STATE newState ); void setLifeTime( PROJECTILE_LIFETIME_TYPE lifeType ); void setPosition( DVECTOR newPos ); + void setLayerCollision( class CLayerCollision *_layer ) {m_layerCollision=_layer;} + +private: + class CLayerCollision *m_layerCollision; protected: DVECTOR getScreenOffset(); @@ -100,6 +104,10 @@ public: PLAYER_PROJECTILE_MOVEMENT_TYPE getMovementType(); void setLifeTime( PLAYER_PROJECTILE_LIFETIME_TYPE lifeType ); void setPosition( DVECTOR newPos ); + void setLayerCollision( class CLayerCollision *_layer ) {m_layerCollision=_layer;} + +private: + class CLayerCollision *m_layerCollision; protected: DVECTOR getScreenOffset();