From 50c319cb16e22d0998b4a28ebc844a6ac0a06a9a Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 3 May 2001 22:49:57 +0000 Subject: [PATCH] --- source/enemy/ndogfish.cpp | 235 +++++++++++++++++++++++++++++++------- source/enemy/ndogfish.h | 2 + source/enemy/npcdata.cpp | 2 +- 3 files changed, 198 insertions(+), 41 deletions(-) diff --git a/source/enemy/ndogfish.cpp b/source/enemy/ndogfish.cpp index 3ff810efe..de4516d5a 100644 --- a/source/enemy/ndogfish.cpp +++ b/source/enemy/ndogfish.cpp @@ -39,18 +39,19 @@ void CNpcIronDogfishEnemy::postInit() { m_state = IRON_DOGFISH_THUMP_1; m_extendDir = EXTEND_RIGHT; + m_npcPath.setPathType( CNpcPath::PONG_PATH ); } bool CNpcIronDogfishEnemy::processSensor() { - switch( m_sensorFunc ) + /*switch( m_sensorFunc ) { case NPC_SENSOR_NONE: return( false ); default: { - if ( playerXDistSqr + playerYDistSqr < 10000 ) + if ( playerXDistSqr + playerYDistSqr < 5000 ) { m_controlFunc = NPC_CONTROL_CLOSE; @@ -61,11 +62,17 @@ bool CNpcIronDogfishEnemy::processSensor() return( false ); } } - } + }*/ + + return( false ); } void CNpcIronDogfishEnemy::processMovement( int _frames ) { + s32 moveX = 0, moveY = 0; + s32 moveVel = 0; + s32 moveDist = 0; + if ( m_movementTimer > 0 ) { if ( !m_animPlaying ) @@ -75,36 +82,12 @@ void CNpcIronDogfishEnemy::processMovement( int _frames ) m_frame = 0; } + processGenericFixedPathWalk( _frames, &moveX, &moveY ); + + Pos.vx += moveX; + Pos.vy += moveY; + m_movementTimer -= _frames; - - if ( m_extendDir == EXTEND_RIGHT ) - { - s32 xDist = 300 - Pos.vx; - s32 xDistSqr = xDist * xDist; - - if ( xDistSqr > 100 ) - { - processGenericGotoTarget( _frames, xDist, 0, m_data[m_type].speed ); - } - else - { - m_extendDir = EXTEND_LEFT; - } - } - else - { - s32 xDist = -300 - Pos.vx; - s32 xDistSqr = xDist * xDist; - - if ( xDistSqr > 100 ) - { - processGenericGotoTarget( _frames, xDist, 0, m_data[m_type].speed ); - } - else - { - m_extendDir = EXTEND_RIGHT; - } - } } else { @@ -112,6 +95,60 @@ void CNpcIronDogfishEnemy::processMovement( int _frames ) } } +void CNpcIronDogfishEnemy::processWalkToUser( int _frames, int speed ) +{ + s32 minX, maxX; + m_npcPath.getPathXExtents( &minX, &maxX ); + + if ( playerXDist > 0 ) + { + m_heading = 0; + + if ( Pos.vx + playerXDist > maxX ) + { + // abort + + m_movementTimer = GameState::getOneSecondInFrames() * 3; + } + else + { + Pos.vx += _frames * speed; + } + } + else + { + m_heading = 2048; + + if ( Pos.vx + playerXDist < minX ) + { + // abort + + m_movementTimer = GameState::getOneSecondInFrames() * 3; + } + else + { + Pos.vx -= _frames * speed; + } + } + + s32 fallSpeed = 3; + s8 yMovement = fallSpeed * _frames; + s32 groundHeight = m_layerCollision->getHeightFromGround( Pos.vx, Pos.vy, yMovement + 16 ); + + if ( groundHeight <= yMovement ) + { + // move to ground level + + Pos.vx += groundHeight; + } + else + { + // fall + + Pos.vx += yMovement; + } +} + void CNpcIronDogfishEnemy::processStandardIronDogfishAttack( int _frames ) { if ( playerXDist > 0 ) @@ -137,7 +174,7 @@ void CNpcIronDogfishEnemy::processStandardIronDogfishAttack( int _frames ) m_frame = 0; } - processGenericGotoTarget( _frames, playerXDist, 0, m_data[m_type].speed ); + processWalkToUser( _frames, m_data[m_type].speed ); } else { @@ -168,7 +205,9 @@ void CNpcIronDogfishEnemy::processStandardIronDogfishAttack( int _frames ) CProjectile *projectile; projectile = new( "test projectile" ) CProjectile; - projectile->init( Pos, headingToPlayer ); + DVECTOR startPos = Pos; + startPos.vy -= 20; + projectile->init( startPos, headingToPlayer ); projectile->setLayerCollision( m_layerCollision ); m_state++; @@ -196,12 +235,21 @@ void CNpcIronDogfishEnemy::processStandardIronDogfishAttack( int _frames ) m_frame = 0; } - processGenericGotoTarget( _frames, playerXDist, 0, 6 ); + processWalkToUser( _frames, m_data[m_type].speed ); } else { - m_movementTimer = GameState::getOneSecondInFrames() * 3; - m_state++; + if ( m_animNo != ANIM_IRONDOGFISH_TAILSMASH ) + { + m_animPlaying = true; + m_animNo = ANIM_IRONDOGFISH_TAILSMASH; + m_frame = 0; + } + else if ( !m_animPlaying ) + { + m_movementTimer = GameState::getOneSecondInFrames() * 3; + m_state++; + } } break; @@ -213,6 +261,113 @@ void CNpcIronDogfishEnemy::processClose( int _frames ) { // swipe at player - m_movementTimer = GameState::getOneSecondInFrames() * 3; - m_controlFunc = NPC_CONTROL_MOVEMENT; -} \ No newline at end of file + if ( m_animNo != ANIM_IRONDOGFISH_PUNCH ) + { + m_animPlaying = true; + m_animNo = ANIM_IRONDOGFISH_PUNCH; + m_frame = 0; + } + else if ( !m_animPlaying ) + { + m_controlFunc = NPC_CONTROL_MOVEMENT; + m_timerFunc = NPC_TIMER_ATTACK_DONE; + m_timerTimer = GameState::getOneSecondInFrames(); + m_sensorFunc = NPC_SENSOR_NONE; + } +} + +void CNpcIronDogfishEnemy::collidedWith(CThing *_thisThing) +{ + if ( m_isActive && !m_isCaught ) + { + switch(_thisThing->getThingType()) + { + case TYPE_PLAYER: + { + CPlayer *player = (CPlayer *) _thisThing; + + ATTACK_STATE playerState = player->getAttackState(); + + switch( playerState ) + { + case ATTACK_STATE__NONE: + { + if ( !player->isRecoveringFromHit() ) + { + switch( m_data[m_type].detectCollision ) + { + case DETECT_NO_COLLISION: + { + // ignore + + break; + } + + case DETECT_ALL_COLLISION: + { + m_oldControlFunc = m_controlFunc; + m_controlFunc = NPC_CONTROL_COLLISION; + + break; + } + + case DETECT_ATTACK_COLLISION_GENERIC: + { + switch( m_animNo ) + { + case ANIM_IRONDOGFISH_PUNCH: + case ANIM_IRONDOGFISH_TAILSMASH: + { + // only detect collision if in attack mode + + m_oldControlFunc = m_controlFunc; + m_controlFunc = NPC_CONTROL_COLLISION; + + break; + } + + default: + break; + } + } + } + } + + break; + } + + default: + { + // player is attacking, respond appropriately + + if ( m_controlFunc != NPC_CONTROL_SHOT ) + { + m_controlFunc = NPC_CONTROL_SHOT; + m_state = NPC_GENERIC_HIT_CHECK_HEALTH; + } + + break; + } + } + + break; + } + + case TYPE_ENEMY: + { + CNpcEnemy *enemy = (CNpcEnemy *) _thisThing; + + if ( enemy->canCollideWithEnemy() ) + { + processEnemyCollision( _thisThing ); + } + + break; + } + + default: + ASSERT(0); + break; + } + } +} diff --git a/source/enemy/ndogfish.h b/source/enemy/ndogfish.h index 3ce61a246..97be5dbbb 100644 --- a/source/enemy/ndogfish.h +++ b/source/enemy/ndogfish.h @@ -23,6 +23,8 @@ protected: virtual void processClose( int _frames ); virtual void processMovement( int _frames ); void processStandardIronDogfishAttack( int _frames ); + void processWalkToUser( int _frames, int speed ); + virtual void collidedWith(CThing *_thisThing); enum NPC_IRON_DOGFISH_STATE { diff --git a/source/enemy/npcdata.cpp b/source/enemy/npcdata.cpp index b004fe4b4..a356bb092 100644 --- a/source/enemy/npcdata.cpp +++ b/source/enemy/npcdata.cpp @@ -868,7 +868,7 @@ CNpcEnemy::NPC_DATA CNpcEnemy::m_data[NPC_UNIT_TYPE_MAX] = false, 3, 2048, - DETECT_NO_COLLISION, + DETECT_ATTACK_COLLISION_GENERIC, DAMAGE__HIT_ENEMY, 256, ANIM_IRONDOGFISH_WALK,