From 11bc3d34806c38625c8c954fc1d99bc728015831 Mon Sep 17 00:00:00 2001 From: Charles Date: Tue, 8 May 2001 18:57:00 +0000 Subject: [PATCH] --- source/enemy/ndustdev.cpp | 2 +- source/enemy/nhcrab.cpp | 2 +- source/enemy/npbug.cpp | 2 +- source/enemy/nscrab.cpp | 2 +- source/platform/pcart.cpp | 113 +++++++++++++++++++++++++++++++++++++- source/platform/pcart.h | 1 + 6 files changed, 117 insertions(+), 5 deletions(-) diff --git a/source/enemy/ndustdev.cpp b/source/enemy/ndustdev.cpp index a592915f6..cbf40c4d1 100644 --- a/source/enemy/ndustdev.cpp +++ b/source/enemy/ndustdev.cpp @@ -136,7 +136,7 @@ void CNpcDustDevilEnemy::processMovementModifier( int _frames, s32 distX, s32 di testPos2.vx += 10; testPos1.vy += m_layerCollision->getHeightFromGround( testPos1.vx, testPos1.vy, 16 ); - testPos2.vy += m_layerCollision->getHeightFromGround( testPos1.vx, testPos1.vy, 16 ); + testPos2.vy += m_layerCollision->getHeightFromGround( testPos2.vx, testPos2.vy, 16 ); s32 xDist = testPos2.vx - testPos1.vx; s32 yDist = testPos2.vy - testPos1.vy; diff --git a/source/enemy/nhcrab.cpp b/source/enemy/nhcrab.cpp index a5e4fe804..cc12260d5 100644 --- a/source/enemy/nhcrab.cpp +++ b/source/enemy/nhcrab.cpp @@ -220,7 +220,7 @@ void CNpcHermitCrabEnemy::processMovementModifier( int _frames, s32 distX, s32 d testPos2.vx += 10; testPos1.vy += m_layerCollision->getHeightFromGround( testPos1.vx, testPos1.vy, 16 ); - testPos2.vy += m_layerCollision->getHeightFromGround( testPos1.vx, testPos1.vy, 16 ); + testPos2.vy += m_layerCollision->getHeightFromGround( testPos2.vx, testPos2.vy, 16 ); s32 xDist = testPos2.vx - testPos1.vx; s32 yDist = testPos2.vy - testPos1.vy; diff --git a/source/enemy/npbug.cpp b/source/enemy/npbug.cpp index 3f47d6ea4..c684d533e 100644 --- a/source/enemy/npbug.cpp +++ b/source/enemy/npbug.cpp @@ -33,7 +33,7 @@ void CNpcPricklyBugEnemy::processMovementModifier( int _frames, s32 distX, s32 d testPos2.vx += 10; testPos1.vy += m_layerCollision->getHeightFromGround( testPos1.vx, testPos1.vy, 16 ); - testPos2.vy += m_layerCollision->getHeightFromGround( testPos1.vx, testPos1.vy, 16 ); + testPos2.vy += m_layerCollision->getHeightFromGround( testPos2.vx, testPos2.vy, 16 ); s32 xDist = testPos2.vx - testPos1.vx; s32 yDist = testPos2.vy - testPos1.vy; diff --git a/source/enemy/nscrab.cpp b/source/enemy/nscrab.cpp index e567dc28c..d5d569e92 100644 --- a/source/enemy/nscrab.cpp +++ b/source/enemy/nscrab.cpp @@ -315,7 +315,7 @@ void CNpcSpiderCrabEnemy::processMovementModifier( int _frames, s32 distX, s32 d testPos2.vx += 10; testPos1.vy += m_layerCollision->getHeightFromGround( testPos1.vx, testPos1.vy, 16 ); - testPos2.vy += m_layerCollision->getHeightFromGround( testPos1.vx, testPos1.vy, 16 ); + testPos2.vy += m_layerCollision->getHeightFromGround( testPos2.vx, testPos2.vy, 16 ); s32 xDist = testPos2.vx - testPos1.vx; s32 yDist = testPos2.vy - testPos1.vy; diff --git a/source/platform/pcart.cpp b/source/platform/pcart.cpp index c98ffdb5f..3c906df3f 100644 --- a/source/platform/pcart.cpp +++ b/source/platform/pcart.cpp @@ -19,6 +19,14 @@ #include "game\game.h" #endif +#ifndef __UTILS_HEADER__ +#include "utils\utils.h" +#endif + +#ifndef __VID_HEADER_ +#include "system\vid.h" +#endif + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// void CNpcCartPlatform::postInit() @@ -95,4 +103,107 @@ void CNpcCartPlatform::processMovement( int _frames ) Pos.vx += moveX; Pos.vy += moveY; -} \ No newline at end of file + + // sort out draw rotation + + DVECTOR testPos1, testPos2; + + testPos1 = testPos2 = Pos; + testPos1.vx -= 10; + testPos2.vx += 10; + + u8 sensorDist = 16; + + s32 yDiff; + + yDiff = m_layerCollision->getHeightFromGround( testPos1.vx, testPos1.vy, sensorDist + 1 ); + + if ( yDiff <= sensorDist ) + { + // only use if there is ground present + + testPos1.vy += yDiff; + } + + yDiff = m_layerCollision->getHeightFromGround( testPos2.vx, testPos2.vy, sensorDist + 1 ); + + if ( yDiff <= sensorDist ) + { + // only use if there is ground present + + testPos2.vy += yDiff; + } + + s32 xDist = testPos2.vx - testPos1.vx; + s32 yDist = testPos2.vy - testPos1.vy; + + heading = ratan2( yDist, xDist ); + + setCollisionAngle( heading ); +} + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void CNpcCartPlatform::render() +{ + if ( m_isActive ) + { + CPlatformThing::render(); + + // Render + DVECTOR renderPos; + DVECTOR offset = CLevel::getCameraPos(); + + renderPos.vx = Pos.vx - offset.vx ; + renderPos.vy = Pos.vy - offset.vy ; + + CRECT collisionRect = getCollisionArea(); + collisionRect.x1 -= Pos.vx; + collisionRect.x2 -= Pos.vx; + collisionRect.y1 -= Pos.vy; + collisionRect.y2 -= Pos.vy; + + if ( renderPos.vx + collisionRect.x2 >= 0 && renderPos.vx + collisionRect.x1 <= VidGetScrW() ) + { + if ( renderPos.vy + collisionRect.y2 >= 0 && renderPos.vy + collisionRect.y1 <= VidGetScrH() ) + { + SVECTOR rotation; + rotation.vx = 0; + rotation.vy = 0; + rotation.vz = getCollisionAngle(); + + VECTOR scale; + scale.vx = ONE; + scale.vy = ONE; + scale.vz = ONE; + + m_modelGfx->Render(renderPos,&rotation,&scale); + +#if defined (__USER_paul__) || defined (__USER_charles__) + DVECTOR size; + DVECTOR centre; + int halfLength; + int x1,y1,x2,y2; + + centre=getCollisionCentre(); + size=getCollisionSize(); + halfLength=size.vx>>1; + + x1=-halfLength*mcos(getCollisionAngle()&4095)>>12; + y1=-halfLength*msin(getCollisionAngle()&4095)>>12; + x2=+halfLength*mcos(getCollisionAngle()&4095)>>12; + y2=+halfLength*msin(getCollisionAngle()&4095)>>12; + + centre.vx-=offset.vx; + centre.vy-=offset.vy; + x1+=centre.vx; + y1+=centre.vy; + x2+=centre.vx; + y2+=centre.vy; + + DrawLine(x1,y1,x2,y2,0,255,0,0); +#endif + } + } + } +} diff --git a/source/platform/pcart.h b/source/platform/pcart.h index 0944ee30c..1fa453fb0 100644 --- a/source/platform/pcart.h +++ b/source/platform/pcart.h @@ -22,6 +22,7 @@ class CNpcCartPlatform : public CNpcPlatform { public: virtual void postInit(); + virtual void render(); protected: virtual void processMovement( int _frames );