From 7e318c0ab2fdf9844b6fb1b09dcd1ee531850d6a Mon Sep 17 00:00:00 2001 From: Charles Date: Fri, 27 Apr 2001 18:30:19 +0000 Subject: [PATCH] --- source/enemy/npc.cpp | 6 ++++-- source/enemy/nsdart.cpp | 21 ++++++++++++++++---- source/enemy/nsjfish.cpp | 42 ++++++++++++++++++++++++++++++++++++++-- source/friend/friend.cpp | 13 +++++++++++-- 4 files changed, 72 insertions(+), 10 deletions(-) diff --git a/source/enemy/npc.cpp b/source/enemy/npc.cpp index 8a47a2f3e..8506fb124 100644 --- a/source/enemy/npc.cpp +++ b/source/enemy/npc.cpp @@ -603,8 +603,6 @@ void CNpcEnemy::init() m_drawOffset.vx = 0; m_drawOffset.vy = -( ofs.vy >> 1 ); - setCollisionCentreOffset( 0, -( ofs.vy >> 1 ) ); - m_positionHistory = NULL; m_isShuttingDown = false; @@ -1276,6 +1274,10 @@ void CNpcEnemy::render() { SprFrame = m_actorGfx->Render(renderPos,m_animNo,( m_frame >> 8 ),m_reversed); m_actorGfx->RotateScale( SprFrame, renderPos, m_drawRotation, 4096, 4096 ); + + sBBox boundingBox = m_actorGfx->GetBBox(); + setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) ); + setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 ); } } } diff --git a/source/enemy/nsdart.cpp b/source/enemy/nsdart.cpp index 10017fa2b..fd40f9fdb 100644 --- a/source/enemy/nsdart.cpp +++ b/source/enemy/nsdart.cpp @@ -37,6 +37,7 @@ void CNpcSquidDartEnemy::render() // Render DVECTOR renderPos; + DVECTOR origRenderPos; DVECTOR offset = CLevel::getCameraPos(); int frame = 6 + ( m_frame >> 8 ); @@ -44,18 +45,21 @@ void CNpcSquidDartEnemy::render() int spriteWidth = m_spriteBank->getFrameWidth( frame ); int spriteHeight = m_spriteBank->getFrameHeight( frame ); - renderPos.vx = Pos.vx - offset.vx + m_drawOffset.vx; + renderPos.vx = Pos.vx - offset.vx; + origRenderPos.vx = renderPos.vx; if ( m_reversed ) { - renderPos.vx += spriteWidth >> 1; + renderPos.vx += ( spriteWidth >> 1 ) + m_drawOffset.vx; } else { - renderPos.vx -= spriteWidth >> 1; + renderPos.vx -= ( spriteWidth >> 1 ) + m_drawOffset.vx; } - renderPos.vy = Pos.vy - offset.vy - ( spriteHeight >> 1 ) + m_drawOffset.vy; + renderPos.vy = Pos.vy - offset.vy; + origRenderPos.vy = renderPos.vy; + renderPos.vy += m_drawOffset.vy - ( spriteHeight >> 1 ); if ( renderPos.vx >= 0 && renderPos.vx <= VidGetScrW() ) { @@ -63,6 +67,15 @@ void CNpcSquidDartEnemy::render() { SprFrame = m_spriteBank->printFT4(frame,renderPos.vx,renderPos.vy,m_reversed,0,10); setRGB0( SprFrame, 255, 128, 255 ); + + s32 XMax = SprFrame->x1 - origRenderPos.vx; + s32 XMin = SprFrame->x0 - origRenderPos.vx; + + s32 YMax = SprFrame->y2 - origRenderPos.vy; + s32 YMin = SprFrame->y0 - origRenderPos.vy; + + setCollisionSize( ( XMax - XMin ), ( YMax - YMin ) ); + setCollisionCentreOffset( ( XMax + XMin ) >> 1, ( YMax + YMin ) >> 1 ); } } } diff --git a/source/enemy/nsjfish.cpp b/source/enemy/nsjfish.cpp index 73448e717..3a683762c 100644 --- a/source/enemy/nsjfish.cpp +++ b/source/enemy/nsjfish.cpp @@ -45,13 +45,18 @@ void CNpcSmallJellyfishEnemy::render() // Render DVECTOR renderPos; + DVECTOR origRenderPos; DVECTOR offset = CLevel::getCameraPos(); int spriteWidth = m_spriteBank->getFrameWidth( m_frame >> 8 ); int spriteHeight = m_spriteBank->getFrameHeight( m_frame >> 8 ); - renderPos.vx = Pos.vx - offset.vx + m_drawOffset.vx; + renderPos.vx = Pos.vx - offset.vx; + origRenderPos.vx = renderPos.vx; + renderPos.vx += m_drawOffset.vx; - renderPos.vy = Pos.vy - offset.vy - ( spriteHeight >> 1 ) + m_drawOffset.vy; + renderPos.vy = Pos.vy - offset.vy; + origRenderPos.vy = renderPos.vy; + renderPos.vy += m_drawOffset.vy - ( spriteHeight >> 1 ); if ( renderPos.vx >= 0 && renderPos.vx <= VidGetScrW() ) { @@ -59,6 +64,39 @@ void CNpcSmallJellyfishEnemy::render() { SprFrame = m_spriteBank->printRotatedScaledSprite( m_frame>>8,renderPos.vx,renderPos.vy,4096,4096,m_drawRotation,10); setRGB0( SprFrame, 255, 128, 255 ); + + // get xmax, xmin, ymax, ymin + + s32 XMax; + s32 XMin; + + s32 YMax; + s32 YMin; + + XMin=SprFrame->x0; + if (XMin>SprFrame->x1) XMin=SprFrame->x1; + if (XMin>SprFrame->x2) XMin=SprFrame->x2; + if (XMin>SprFrame->x3) XMin=SprFrame->x3; + XMax=SprFrame->x0; + if (XMaxx1) XMax=SprFrame->x1; + if (XMaxx2) XMax=SprFrame->x2; + if (XMaxx3) XMax=SprFrame->x3; + YMin=SprFrame->y0; + if (YMin>SprFrame->y1) YMin=SprFrame->y1; + if (YMin>SprFrame->y2) YMin=SprFrame->y2; + if (YMin>SprFrame->y3) YMin=SprFrame->y3; + YMax=SprFrame->y0; + if (YMaxy1) YMax=SprFrame->y1; + if (YMaxy2) YMax=SprFrame->y2; + if (YMaxy3) YMax=SprFrame->y3; + + XMax -= origRenderPos.vx; + XMin -= origRenderPos.vx; + YMax -= origRenderPos.vy; + YMin -= origRenderPos.vy; + + setCollisionSize( ( XMax - XMin ), ( YMax - YMin ) ); + setCollisionCentreOffset( ( XMax + XMin ) >> 1, ( YMax + YMin ) >> 1 ); } } } diff --git a/source/friend/friend.cpp b/source/friend/friend.cpp index 7b8475938..d70846fc2 100644 --- a/source/friend/friend.cpp +++ b/source/friend/friend.cpp @@ -110,8 +110,6 @@ void CNpcFriend::init() m_drawOffset.vx = 0; m_drawOffset.vy = -( ofs.vy >> 1 ); - - setCollisionCentreOffset( 0, -( ofs.vy >> 1 ) ); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -136,6 +134,13 @@ void CNpcFriend::shutdown() void CNpcFriend::think(int _frames) { + if ( _frames > 2 ) + { + // make sure enemies don't go berserk if too many frames are dropped + + _frames = 2; + } + CNpcThing::think(_frames); if ( m_animPlaying ) @@ -206,6 +211,10 @@ void CNpcFriend::render() if ( renderPos.vy >= 0 && renderPos.vy <= VidGetScrH() ) { m_actorGfx->Render(renderPos,m_animNo,(m_frame>>8),m_reversed); + + sBBox boundingBox = m_actorGfx->GetBBox(); + setCollisionSize( ( boundingBox.XMax - boundingBox.XMin ), ( boundingBox.YMax - boundingBox.YMin ) ); + setCollisionCentreOffset( ( boundingBox.XMax + boundingBox.XMin ) >> 1, ( boundingBox.YMax + boundingBox.YMin ) >> 1 ); } } }