| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- // ----------------------------------------------------------------
- // From Game Programming in C++ by Sanjay Madhav
- // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
- //
- // Released under the BSD License
- // See LICENSE in root directory for full details.
- // ----------------------------------------------------------------
- #include "BallActor.h"
- #include "Game.h"
- #include "Renderer.h"
- #include "MeshComponent.h"
- #include "Mesh.h"
- #include "BallMove.h"
- #include "AudioComponent.h"
- #include "LevelLoader.h"
- BallActor::BallActor(Game* game)
- :Actor(game)
- ,mLifeSpan(2.0f)
- {
- //SetScale(10.0f);
- MeshComponent* mc = new MeshComponent(this);
- Mesh* mesh = GetGame()->GetRenderer()->GetMesh("Assets/Sphere.gpmesh");
- mc->SetMesh(mesh);
- BallMove* move = new BallMove(this);
- move->SetForwardSpeed(1500.0f);
- mAudioComp = new AudioComponent(this);
- }
- void BallActor::UpdateActor(float deltaTime)
- {
- Actor::UpdateActor(deltaTime);
-
- mLifeSpan -= deltaTime;
- if (mLifeSpan < 0.0f)
- {
- SetState(EDead);
- }
- }
- void BallActor::HitTarget()
- {
- mAudioComp->PlayEvent("event:/Ding");
- }
- void BallActor::LoadProperties(const rapidjson::Value& inObj)
- {
- Actor::LoadProperties(inObj);
- JsonHelper::GetFloat(inObj, "lifespan", mLifeSpan);
- }
- void BallActor::SaveProperties(rapidjson::Document::AllocatorType& alloc, rapidjson::Value& inObj) const
- {
- Actor::SaveProperties(alloc, inObj);
- JsonHelper::AddFloat(alloc, inObj, "lifespan", mLifeSpan);
- }
|