Skip to content

Commit

Permalink
[game] added car sounds for exit/entering and engine startup (disable…
Browse files Browse the repository at this point in the history
…d skyrim music)
  • Loading branch information
PanosK92 committed Dec 4, 2024
1 parent 894f4b6 commit 622c609
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 29 deletions.
4 changes: 2 additions & 2 deletions build_scripts/download_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import file_utilities

file_url = 'https://www.dropbox.com/scl/fi/xkc76vrsiwu4l2f67030e/assets.7z?rlkey=r3kym37skmay9e79slre6e60j&st=0jn5etfu&dl=1'
file_url = 'https://www.dropbox.com/scl/fi/xyvlqz1d83ppu25q2589u/assets.7z?rlkey=2q0ve3lqwq45cr8w6mdzcegzz&st=jq6lcr1h&dl=1'
file_destination = 'project/assets.7z'
file_expected_hash = 'e57b718a109a5fa94561d894cb67d33535754ad6926ab99f53ce457a751e90ac'
file_expected_hash = 'bebddf7a39e479e0ad9623a9251a465be9fb68a1a0a17ac2212f25de03255b21'

def main():
file_utilities.download_file(file_url, file_destination, file_expected_hash)
Expand Down
95 changes: 68 additions & 27 deletions runtime/Game/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ namespace Spartan
material->SetColor(Color::material_tire);
}
}

// add physics body
{
PhysicsBody* physics_body = m_default_car->AddComponent<PhysicsBody>().get();
Expand All @@ -252,49 +252,49 @@ namespace Spartan
{
physics_body->GetCar()->SetSteeringWheelTransform(entity_steering_wheel);
}

// load our own wheel
if (shared_ptr<Mesh> mesh = ResourceCache::Load<Mesh>("project\\models\\wheel\\model.blend"))
{
shared_ptr<Entity> entity_wheel_root = mesh->GetRootEntity().lock();
entity_wheel_root->SetScale(Vector3(wheel_scale));

if (Entity* entity_wheel = entity_wheel_root->GetDescendantByName("wheel Low"))
{
// create material
shared_ptr<Material> material = make_shared<Material>();
material->SetTexture(MaterialTextureType::Color, "project\\models\\wheel\\albedo.jpeg");
material->SetTexture(MaterialTextureType::Normal, "project\\models\\wheel\\normal.png");
material->SetTexture(MaterialTextureType::Color, "project\\models\\wheel\\albedo.jpeg");
material->SetTexture(MaterialTextureType::Normal, "project\\models\\wheel\\normal.png");
material->SetTexture(MaterialTextureType::Roughness, "project\\models\\wheel\\roughness.png");
material->SetTexture(MaterialTextureType::Metalness, "project\\models\\wheel\\metalness.png");

// create a file path for this material (required for the material to be able to be cached by the resource cache)
const string file_path = "project\\models\\wheel" + string(EXTENSION_MATERIAL);
material->SetResourceFilePath(file_path);

// set material
entity_wheel->GetComponent<Renderable>()->SetMaterial(material);
}

// add the wheels to the body
{
shared_ptr<Entity> wheel = entity_wheel_root;
wheel->SetObjectName("wheel_fl");
wheel->SetParent(m_default_car);
physics_body->GetCar()->SetWheelTransform(wheel.get(), 0);

wheel = entity_wheel_root->Clone();
wheel->SetObjectName("wheel_fr");
wheel->GetChildByIndex(0)->SetRotation(Quaternion::FromEulerAngles(0.0f, 0.0f, 180.0f));
wheel->GetChildByIndex(0)->SetPosition(Vector3(0.15f, 0.0f, 0.0f));
wheel->SetParent(m_default_car);
physics_body->GetCar()->SetWheelTransform(wheel.get(), 1);

wheel = entity_wheel_root->Clone();
wheel->SetObjectName("wheel_rl");
wheel->SetParent(m_default_car);
physics_body->GetCar()->SetWheelTransform(wheel.get(), 2);

wheel = entity_wheel_root->Clone();
wheel->SetObjectName("wheel_rr");
wheel->GetChildByIndex(0)->SetRotation(Quaternion::FromEulerAngles(0.0f, 0.0f, 180.0f));
Expand All @@ -304,30 +304,69 @@ namespace Spartan
}
}
}

// disable all the wheels since they have weird rotations, we will add our own
{
entity_car->GetDescendantByName("FL_Wheel_RimMaterial_0")->SetActive(false);
entity_car->GetDescendantByName("FL_Wheel_Brake Disc_0")->SetActive(false);
entity_car->GetDescendantByName("FL_Wheel_TireMaterial_0")->SetActive(false);
entity_car->GetDescendantByName("FL_Caliper_BrakeCaliper_0")->SetActive(false);

entity_car->GetDescendantByName("FR_Wheel_RimMaterial_0")->SetActive(false);
entity_car->GetDescendantByName("FR_Wheel_Brake Disc_0")->SetActive(false);
entity_car->GetDescendantByName("FR_Wheel_TireMaterial_0")->SetActive(false);
entity_car->GetDescendantByName("FR_Caliper_BrakeCaliper_0")->SetActive(false);

entity_car->GetDescendantByName("RL_Wheel_RimMaterial_0")->SetActive(false);
entity_car->GetDescendantByName("RL_Wheel_Brake Disc_0")->SetActive(false);
entity_car->GetDescendantByName("RL_Wheel_TireMaterial_0")->SetActive(false);
entity_car->GetDescendantByName("RL_Caliper_BrakeCaliper_0")->SetActive(false);

entity_car->GetDescendantByName("RR_Wheel_RimMaterial_0")->SetActive(false);
entity_car->GetDescendantByName("RR_Wheel_Brake Disc_0")->SetActive(false);
entity_car->GetDescendantByName("RR_Wheel_TireMaterial_0")->SetActive(false);
entity_car->GetDescendantByName("RR_Caliper_BrakeCaliper_0")->SetActive(false);
}
}

// sounds
{
// start
{
shared_ptr<Entity> sound = World::CreateEntity();
sound->SetObjectName("sound_start");
sound->SetParent(m_default_car);

shared_ptr<AudioSource> audio_source = sound->AddComponent<AudioSource>();
audio_source->SetAudioClip("project\\music\\car_start.mp3");
audio_source->SetLoop(false);
audio_source->SetPlayOnStart(false);
}

// idle
{
shared_ptr<Entity> sound = World::CreateEntity();
sound->SetObjectName("sound_idle");
sound->SetParent(m_default_car);

shared_ptr<AudioSource> audio_source = sound->AddComponent<AudioSource>();
audio_source->SetAudioClip("project\\music\\car_idle.mp3");
audio_source->SetLoop(true);
audio_source->SetPlayOnStart(false);
}

// start
{
shared_ptr<Entity> sound = World::CreateEntity();
sound->SetObjectName("sound_door");
sound->SetParent(m_default_car);

shared_ptr<AudioSource> audio_source = sound->AddComponent<AudioSource>();
audio_source->SetAudioClip("project\\music\\car_door.wav");
audio_source->SetLoop(false);
audio_source->SetPlayOnStart(false);
}
}
}

void create_objects()
Expand Down Expand Up @@ -419,6 +458,7 @@ namespace Spartan

// mood adjustment
m_default_light_directional->GetComponent<Light>()->SetTemperature(2300.0f);
m_default_light_directional->GetComponent<Light>()->SetFlag(LightFlags::Volumetric, false);
Renderer::SetOption(Renderer_Option::Grid, 0.0f);

// create
Expand Down Expand Up @@ -474,17 +514,6 @@ namespace Spartan
audio_source->SetAudioClip("project\\music\\underwater.mp3");
audio_source->SetPlayOnStart(false);
}

// wind
{
shared_ptr<Entity> sound = World::CreateEntity();
sound->SetObjectName("skyrim");
sound->SetParent(entity);

shared_ptr<AudioSource> audio_source = sound->AddComponent<AudioSource>();
audio_source->SetAudioClip("project\\music\\skyrim.mp3");
audio_source->SetLoop(true);
}
}

// terrain
Expand Down Expand Up @@ -1109,6 +1138,11 @@ namespace Spartan
camera->SetPositionLocal(car_view_positions[static_cast<int>(current_view)]);
camera->SetRotationLocal(Quaternion::Identity);

if (AudioSource* audio_source = m_default_car->GetChildByName("sound_start")->GetComponent<AudioSource>().get())
{
audio_source->Play();
}

inside_the_car = true;
}
else
Expand All @@ -1123,9 +1157,16 @@ namespace Spartan

inside_the_car = false;
}


// enable/disabe car/camera control
camera->GetComponent<Camera>()->SetFlag(CameraFlags::CanBeControlled, !inside_the_car);
m_default_car->AddComponent<PhysicsBody>()->GetCar()->SetControlEnabled(inside_the_car);

// play exit/enter sound
if (AudioSource* audio_source = m_default_car->GetChildByName("sound_door")->GetComponent<AudioSource>().get())
{
audio_source->Play();
}
}

// change car view
Expand Down

0 comments on commit 622c609

Please sign in to comment.