Skip to content

Commit 1957eba

Browse files
committed
1 parent f490a11 commit 1957eba

10 files changed

Lines changed: 61 additions & 29 deletions

src/Convert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Convert
4040
{
4141
return {
4242
MetersToMapUnits(units.x),
43-
MetersToMapUnits(units.y),
43+
MetersToMapUnits(units.y + 0.5f), // extra offset for height to get things work
4444
MetersToMapUnits(units.z)
4545
};
4646
}

src/Decoration.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ void Decoration::UpdateFrame()
2020
float deltaTime = gTimeManager.mGameFrameDelta;
2121
if (mAnimationState.UpdateFrame(deltaTime))
2222
{
23-
gSpriteManager.GetSpriteTexture(mObjectID, mAnimationState.GetSpriteIndex(), 0, mDrawSprite);
24-
RefreshDrawSprite();
23+
SetupSpriteFrame();
2524
}
2625

2726
glm::vec3 newPosition = mTransform.mPosition + (mMoveVelocity * deltaTime);
@@ -44,8 +43,8 @@ void Decoration::HandleSpawn()
4443
{
4544
mAnimationState.ClearState();
4645
mAnimationState.PlayAnimation(eSpriteAnimLoop_FromStart);
47-
gSpriteManager.GetSpriteTexture(mObjectID, mAnimationState.GetSpriteIndex(), 0, mDrawSprite);
48-
RefreshDrawSprite();
46+
47+
SetupSpriteFrame();
4948
}
5049

5150
void Decoration::SetLifeDuration(int numCycles)
@@ -68,4 +67,10 @@ void Decoration::SetScale(float scale)
6867
void Decoration::SetMoveVelocity(const glm::vec3& moveVelocity)
6968
{
7069
mMoveVelocity = moveVelocity;
71-
}
70+
}
71+
72+
void Decoration::SetupSpriteFrame()
73+
{
74+
gSpriteManager.GetSpriteTexture(mObjectID, mAnimationState.GetSpriteIndex(), 0, mDrawSprite);
75+
RefreshDrawSprite();
76+
}

src/Decoration.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ class Decoration final: public GameObject
2525
// Change current draw order for decoration object
2626
void SetDrawOrder(eSpriteDrawOrder drawOrder);
2727

28+
private:
29+
void SetupSpriteFrame();
30+
2831
private:
2932
SpriteAnimation mAnimationState;
3033
glm::vec3 mMoveVelocity;

src/Explosion.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,7 @@ void Explosion::HandleSpawn()
7272
mAnimationState.PlayAnimation(eSpriteAnimLoop_FromStart);
7373
mAnimationState.SetMaxRepeatCycles(1);
7474

75-
if (!gSpriteManager.GetExplosionTexture(0, mDrawSprite))
76-
{
77-
debug_assert(false);
78-
}
75+
gSpriteManager.GetExplosionTexture(0, mDrawSprite);
7976
RefreshDrawSprite();
8077
// broadcast event
8178
glm::vec2 position2 (mTransform.mPosition.x, mTransform.mPosition.z);

src/GameMapManager.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,8 @@ const DistrictInfo* GameMapManager::GetDistrictByIndex(int districtIndex) const
304304
float GameMapManager::GetHeightAtPosition(const glm::vec3& position, bool excludeWater) const
305305
{
306306
// get map block position in which we are located
307-
glm::ivec3 mapBlock {
308-
Convert::MetersToMapUnits(position.x),
309-
Convert::MetersToMapUnits(position.y) + 0.5f,
310-
Convert::MetersToMapUnits(position.z)
311-
};
307+
glm::ivec3 mapBlock = Convert::MetersToMapUnits(position);
308+
312309
float currentHeight = (float) mapBlock.y; // set current height to ground, map units
313310
for (; currentHeight > 0.0f;)
314311
{

src/HUD.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -746,17 +746,20 @@ bool HUD::CheckCharacterObscure() const
746746
Pedestrian* pedestrian = mHumanPlayer->mCharacter;
747747
debug_assert(pedestrian);
748748

749-
const glm::vec3& worldPosition = pedestrian->mTransformSmooth.mPosition;
749+
const glm::vec3& worldPosition = pedestrian->mTransform.mPosition;
750750
// convert to map position
751751
glm::ivec3 mapPosition = Convert::MetersToMapUnits(worldPosition);
752-
for (int currentBlockLayer = mapPosition.y + 1; currentBlockLayer < MAP_LAYERS_COUNT; ++currentBlockLayer)
752+
for (int currentBlockLayer = mapPosition.y; currentBlockLayer < MAP_LAYERS_COUNT; ++currentBlockLayer)
753753
{
754754
const MapBlockInfo* currBlock = gGameMap.GetBlockInfo(mapPosition.x, mapPosition.z, currentBlockLayer);
755-
if (currBlock->mFaces[eBlockFace_Lid] > 0)
755+
if (currentBlockLayer == mapPosition.y)
756756
{
757-
int bp = 0;
758-
return true;
757+
if (currBlock->mSlopeType)
758+
continue;
759759
}
760+
761+
if (currBlock->mFaces[eBlockFace_Lid] && !currBlock->mIsFlat)
762+
return true;
760763
}
761764
return false;
762765
}

src/Obstacle.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ void Obstacle::UpdateFrame()
1919
float deltaTime = gTimeManager.mGameFrameDelta;
2020
if (mAnimationState.UpdateFrame(deltaTime))
2121
{
22-
gSpriteManager.GetSpriteTexture(mObjectID, mAnimationState.GetSpriteIndex(), 0, mDrawSprite);
23-
RefreshDrawSprite();
22+
SetupSpriteFrame();
2423
}
2524
}
2625

@@ -36,4 +35,12 @@ void Obstacle::HandleSpawn()
3635
mAnimationState.mAnimDesc = mGameObjectDesc->mAnimationData;
3736

3837
//mAnimationState.PlayAnimation(eSpriteAnimLoop_FromStart);
39-
}
38+
39+
SetupSpriteFrame();
40+
}
41+
42+
void Obstacle::SetupSpriteFrame()
43+
{
44+
gSpriteManager.GetSpriteTexture(mObjectID, mAnimationState.GetSpriteIndex(), 0, mDrawSprite);
45+
RefreshDrawSprite();
46+
}

src/Obstacle.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class Obstacle final: public GameObject
1414
void DebugDraw(DebugRenderer& debugRender) override;
1515
void HandleSpawn() override;
1616

17+
private:
18+
void SetupSpriteFrame();
19+
1720
private:
1821
SpriteAnimation mAnimationState;
1922
GameObjectInfo* mGameObjectDesc = nullptr;

src/PhysicsManager.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "PhysicsBody.h"
1313
#include "Collision.h"
1414
#include "GameObjectHelpers.h"
15+
#include "AudioManager.h"
1516

1617
//////////////////////////////////////////////////////////////////////////
1718

@@ -644,14 +645,15 @@ void PhysicsManager::HandleCollision_CarVsMap(Vehicle* car, b2Contact* contact,
644645
{
645646
debug_assert(car);
646647

648+
int pointCount = contact->GetManifold()->pointCount;
649+
float impact = 0.0f;
650+
for (int i = 0; i < pointCount; ++i)
651+
{
652+
impact = b2Max(impact, impulse->normalImpulses[i]);
653+
}
654+
647655
if (gParticleManager.IsCarSparksEffectEnabled())
648656
{
649-
int pointCount = contact->GetManifold()->pointCount;
650-
float impact = 0.0f;
651-
for (int i = 0; i < pointCount; ++i)
652-
{
653-
impact = b2Max(impact, impulse->normalImpulses[i]);
654-
}
655657
b2WorldManifold wmanifold;
656658
contact->GetWorldManifold(&wmanifold);
657659

@@ -663,6 +665,16 @@ void PhysicsManager::HandleCollision_CarVsMap(Vehicle* car, b2Contact* contact,
663665
gParticleManager.StartCarSparks(contactPoint, velocity, 3);
664666
}
665667
}
668+
669+
670+
// sound
671+
if (impact > 700.0f)
672+
{
673+
//gAudioManager.StartSound(eSfxSampleType_Level, SfxLevel_CarCrash4, SfxFlags_RandomPitch, car->mTransform.mPosition);
674+
}
675+
676+
// bounce
677+
666678
}
667679

668680
void PhysicsManager::ProcessInterpolation()

src/SpriteBatch.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ void SpriteBatch::Clear()
3030

3131
void SpriteBatch::DrawSprite(const Sprite2D& sourceSprite)
3232
{
33+
if (sourceSprite.mTexture == nullptr)
34+
{
35+
debug_assert(false);
36+
return;
37+
}
3338
mSpritesList.push_back(sourceSprite);
3439
}
3540

0 commit comments

Comments
 (0)